From 962064413f9d6f112561aaad752b6b5dde9f8158 Mon Sep 17 00:00:00 2001 From: Guillaume Charest <1690085+gcharest@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:09:34 +0000 Subject: [PATCH] fix: update the last comment --- .github/workflows/ci_code.yml | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/.github/workflows/ci_code.yml b/.github/workflows/ci_code.yml index 1923a123..16cfb5bd 100644 --- a/.github/workflows/ci_code.yml +++ b/.github/workflows/ci_code.yml @@ -57,3 +57,42 @@ jobs: NOTIFY_OPS_CHANNEL_ID: ${{ secrets.NOTIFY_OPS_CHANNEL_ID }} SRE_BOT_EMAIL: ${{ secrets.SRE_BOT_EMAIL }} AWS_ORG_ACCOUNT_ROLE_ARN: ${{ secrets.AWS_ORG_ACCOUNT_ROLE_ARN }} + + - name: Find previous comment + id: find-comment + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + script: | + const { data: comments } = await github.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + comments.sort((a, b) => new Date(b.created_at) - new Date(a.created_at)); + + const comment = comments.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes('Lint, format and test code results')); + return comment ? comment.id : null; + + - name: Update comment + if: steps.find-comment.outputs.result != 'null' + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + script: | + await github.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: steps.find-comment.outputs.result, + body: 'Lint, format and test code results: ...', + }); + + - name: Create comment + if: steps.find-comment.outputs.result == 'null' + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + script: | + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: 'Lint, format and test code results: ...', + }); \ No newline at end of file