Skip to content

Commit

Permalink
chore(workflow): add update action
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschuerch committed May 2, 2024
1 parent 2dc5d07 commit 19f2f9c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .github/actions/deploy-to-netlify/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ inputs:
package_name:
description: The package that will be deployed
required: true
access-token:
description: The access token to use for commenting.
required: true

runs:
using: composite
Expand Down Expand Up @@ -117,3 +120,9 @@ runs:
edit-mode: append
body: ${{ steps.comment.outputs.message }}
reactions: rocket

- name: Update preview message
uses: ./.github/actions/preview/message/update
with:
access-token: ${{ inputs.access-token }}
preview-url: https://${{ steps.netlify_deploy.outputs.url_alias }}--${{ inputs.netlify_site_url }}
13 changes: 2 additions & 11 deletions .github/actions/preview/message/create/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ runs:
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)'
const credentials = {
repo: context.repo.repo,
Expand All @@ -27,16 +28,6 @@ runs:
if (!hasPreviewComment) {
github.rest.issues.createComment({
...credentials,
body: `${commentTitle}\nPreview URLs will be added here, once they are ready... ![loader](https://github.com/swisspost/design-system/assets/9716662/49a75898-7093-4ffb-9460-071ff194459d)`
body: `${commentTitle}\n${commentInitialBody}`
})
} else {
const previewComment = comments.find(c => c.user.login === 'swisspost-bot' && c.body.includes(commentTitle))
console.log(previewComment.body);
console.log('-------------');
const body = previewComment.body
.replace('Preview URLs will be added here, once they are ready... ![loader](https://github.com/swisspost/design-system/assets/9716662/49a75898-7093-4ffb-9460-071ff194459d)', '')
.concat('- previewurl\n')
console.log('-------------');
console.log(body);
}
44 changes: 44 additions & 0 deletions .github/actions/preview/message/update/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Preview message creation
description: Append a preview url message in the pr body, if not already present

inputs:
access-token:
description: The access token to use for commenting.
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:
PREVIEW_URL: ${{ inputs.preview-url }}
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)'
const credentials = {
repo: context.repo.repo,
owner: context.repo.owner,
issue_number: context.issue.number
}
const comments = (await github.rest.issues.listComments({ ...credentials })).data || []
const previewComment = comments.find(c => c.user.login === 'swisspost-bot' && c.body.includes(commentTitle))
if (previewComment) {
const body = previewComment.body
.replace(commentInitialBody, '')
.concat(`- ${PREVIEW_URL}`)
console.log(body)
github.rest.issues.updateComment({
...credentials,
body: body
})
}
1 change: 1 addition & 0 deletions .github/workflows/deploy-documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ jobs:
comment_token: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}
comment_author: swisspost-bot
package_name: '@swisspost/design-system-documentation'
access-token: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}

0 comments on commit 19f2f9c

Please sign in to comment.