-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(workflows): update deploy-to-netlify workflows
- Loading branch information
1 parent
bf9dab8
commit e389808
Showing
5 changed files
with
205 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Create preview message | ||
description: Add a preview comment to the pr, if not already present | ||
|
||
inputs: | ||
access-token: | ||
description: The access token to use for commenting. | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ inputs.access-token }} | ||
script: | | ||
const commentTitle = '**Related Previews**' | ||
const commentInitialBody = 'Preview URLs will be added here, once they are ready... ![loader](https://github.com/swisspost/design-system/assets/9716662/49a75898-7093-4ffb-9460-071ff194459d)' | ||
let comments | ||
let previewComment | ||
await getPreviewComment() | ||
if (!previewComment) { | ||
await github.rest.issues.createComment({ | ||
repo: context.repo.repo, | ||
owner: context.repo.owner, | ||
issue_number: context.issue.number, | ||
body: `${commentTitle}\n${commentInitialBody}` | ||
}) | ||
await getPreviewComment() | ||
github.rest.reactions.createForIssueComment({ | ||
repo: context.repo.repo, | ||
owner: context.repo.owner, | ||
comment_id: previewComment.id, | ||
content: 'eyes' | ||
}) | ||
} else { | ||
console.info('Skipped action, because preview comment already existed.') | ||
} | ||
async function getPreviewComment () { | ||
comments = (await github.rest.issues.listComments({ | ||
repo: context.repo.repo, | ||
owner: context.repo.owner, | ||
issue_number: context.issue.number | ||
})).data || [] | ||
previewComment = comments.find(c => c.user.login === 'swisspost-bot' && c.body.includes(commentTitle)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Update preview message | ||
description: Add a preview url to the existing preview comment, if not already present | ||
|
||
inputs: | ||
access-token: | ||
description: The access token to use for commenting. | ||
required: true | ||
issue-number: | ||
description: The issue number from the caller workflow. | ||
required: true | ||
preview-url: | ||
description: The preview url to add in the comment. | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: actions/github-script@v7 | ||
env: | ||
ISSUE_NUMBER: ${{ inputs.issue-number }} | ||
PREVIEW_URL: ${{ inputs.preview-url }} | ||
with: | ||
github-token: ${{ inputs.access-token }} | ||
script: | | ||
const { ISSUE_NUMBER, PREVIEW_URL } = process.env | ||
const commentTitle = '**Related Previews**' | ||
const commentInitialBody = 'Preview URLs will be added here, once they are ready... ![loader](https://github.com/swisspost/design-system/assets/9716662/49a75898-7093-4ffb-9460-071ff194459d)' | ||
const comments = (await github.rest.issues.listComments({ | ||
repo: context.repo.repo, | ||
owner: context.repo.owner, | ||
issue_number: Number(ISSUE_NUMBER) | ||
})).data || [] | ||
const previewComment = comments.find(c => c.user.login === 'swisspost-bot' && c.body.includes(commentTitle)) | ||
if (previewComment && !previewComment.body.includes(PREVIEW_URL)) { | ||
github.rest.issues.updateComment({ | ||
repo: context.repo.repo, | ||
owner: context.repo.owner, | ||
comment_id: previewComment.id, | ||
body: previewComment.body | ||
.replace(commentInitialBody, '') | ||
.concat(`- ${PREVIEW_URL}\n`) | ||
}) | ||
const reactions = (await github.rest.reactions.listForIssueComment({ | ||
repo: context.repo.repo, | ||
owner: context.repo.owner, | ||
comment_id: previewComment.id, | ||
})).data || [] | ||
const createReaction = reactions.find(r => r.user.login === 'swisspost-bot' && r.content === 'eyes') | ||
const updateReaction = reactions.find(r => r.user.login === 'swisspost-bot' && r.content === 'rocket') | ||
if (createReaction) { | ||
github.rest.reactions.deleteForIssueComment({ | ||
repo: context.repo.repo, | ||
owner: context.repo.owner, | ||
comment_id: previewComment.id, | ||
reaction_id: createReaction.id | ||
}) | ||
} | ||
if (!updateReaction) { | ||
github.rest.reactions.createForIssueComment({ | ||
repo: context.repo.repo, | ||
owner: context.repo.owner, | ||
comment_id: previewComment.id, | ||
content: 'rocket' | ||
}) | ||
} | ||
} else { | ||
console.warn('Skipped action, because preview comment could not be found!') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters