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