diff --git a/.github/actions/preview/message/create/action.yaml b/.github/actions/preview/message/create/action.yaml new file mode 100644 index 0000000000..4c1d344530 --- /dev/null +++ b/.github/actions/preview/message/create/action.yaml @@ -0,0 +1,42 @@ +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 + +runs: + using: composite + steps: + - uses: actions/github-script@v7 + with: + github-token: ${{ inputs.access-token }} + script: | + const commentTitle = '**Related Previews**' + + 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 hasPreviewComment = comments.some(c => c.user.login === 'swisspost-bot' && c.body.includes(commentTitle)) + + 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)` + }) + } else { + const previewComment = comments.find(c => c.user.login === 'swisspost-bot' && c.body.includes(commentTitle)) + console.log(body); + console.log('-------------'); + const body = previewComment.body + .replace('\nPreview 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') + + console.log('-------------'); + console.log(body); + } diff --git a/.github/actions/preview/message/creation/action.yaml b/.github/actions/preview/message/creation/action.yaml deleted file mode 100644 index e3b8f0b2b6..0000000000 --- a/.github/actions/preview/message/creation/action.yaml +++ /dev/null @@ -1,30 +0,0 @@ -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 - -runs: - using: composite - steps: - - uses: actions/github-script@v7 - with: - github-token: ${{ inputs.access-token }} - script: | - 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 hasPreviewComment = comments.some(c => c.user.login === 'swisspost-bot' && c.body.includes('**Related Previews**\n')) - - if (!hasPreviewComment) { - github.rest.issues.createComment({ - ...credentials, - body: '**Related Previews**\n Preview URLs will be added here, once they are ready... ![loader](https://github.com/swisspost/design-system/assets/9716662/49a75898-7093-4ffb-9460-071ff194459d)' - }) - } diff --git a/.github/workflows/build-documentation.yaml b/.github/workflows/build-documentation.yaml index 7187d99e1c..290172590c 100644 --- a/.github/workflows/build-documentation.yaml +++ b/.github/workflows/build-documentation.yaml @@ -25,8 +25,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Provide preview message - uses: ./.github/actions/preview/message/creation + - name: Create preview message + uses: ./.github/actions/preview/message/create with: access-token: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}