From 19f2f9cd3b21afc8982a350dd743db1b2fbbd184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Sch=C3=BCrch?= Date: Thu, 2 May 2024 17:05:34 +0200 Subject: [PATCH] chore(workflow): add update action --- .github/actions/deploy-to-netlify/action.yaml | 9 ++++ .../preview/message/create/action.yaml | 13 +----- .../preview/message/update/action.yaml | 44 +++++++++++++++++++ .github/workflows/deploy-documentation.yaml | 1 + 4 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 .github/actions/preview/message/update/action.yaml diff --git a/.github/actions/deploy-to-netlify/action.yaml b/.github/actions/deploy-to-netlify/action.yaml index 665ebb2226..4d25cd788a 100644 --- a/.github/actions/deploy-to-netlify/action.yaml +++ b/.github/actions/deploy-to-netlify/action.yaml @@ -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 @@ -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 }} diff --git a/.github/actions/preview/message/create/action.yaml b/.github/actions/preview/message/create/action.yaml index 20a60ab226..f41cb4056f 100644 --- a/.github/actions/preview/message/create/action.yaml +++ b/.github/actions/preview/message/create/action.yaml @@ -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, @@ -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); } diff --git a/.github/actions/preview/message/update/action.yaml b/.github/actions/preview/message/update/action.yaml new file mode 100644 index 0000000000..957f56b081 --- /dev/null +++ b/.github/actions/preview/message/update/action.yaml @@ -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 + }) + } diff --git a/.github/workflows/deploy-documentation.yaml b/.github/workflows/deploy-documentation.yaml index 1b6b060f8a..050d7bc4f9 100644 --- a/.github/workflows/deploy-documentation.yaml +++ b/.github/workflows/deploy-documentation.yaml @@ -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 }}