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 1e25ba5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 11 deletions.
8 changes: 8 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,14 @@ inputs:
package_name:
description: The package that will be deployed
required: true
access-token:
description: The access token to use for commenting.
required: true

outputs:
preview-url:
description: The deployed preview url.
value: https://${{ steps.netlify_deploy.outputs.url_alias }}--${{ inputs.netlify_site_url }}

runs:
using: composite
Expand Down
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);
}
52 changes: 52 additions & 0 deletions .github/actions/preview/message/update/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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))
console.log('---------------')
console.log(previewComment?.body || 'previewComment not found')
if (previewComment) {
console.log('---------------')
console.log(previewComment.body)
const containsPreviewUrl = body.includes(PREVIEW_URL)
if (!containsPreviewUrl) {
const body = previewComment.body
.replace(commentInitialBody, '')
.concat(`- ${PREVIEW_URL}\n`)
console.log(body)
github.rest.issues.updateComment({
...credentials,
body: body
})
}
}
6 changes: 6 additions & 0 deletions .github/workflows/deploy-documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ jobs:
comment_token: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}
comment_author: swisspost-bot
package_name: '@swisspost/design-system-documentation'

- name: Update preview message
uses: ./.github/actions/preview/message/update
with:
access-token: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}
preview-url: https://${{ steps.deploy.outputs.preview-url }}

0 comments on commit 1e25ba5

Please sign in to comment.