diff --git a/.github/workflows/create-comment-perf.yml b/.github/workflows/create-comment-perf.yml index 3f3dfe902c..03dd021e14 100644 --- a/.github/workflows/create-comment-perf.yml +++ b/.github/workflows/create-comment-perf.yml @@ -42,13 +42,34 @@ jobs: uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 with: github-token: ${{ secrets.GITHUB_TOKEN }} + # Taken from https://github.com/actions/github-script/blob/main/.github/workflows/pull-request-test.yml script: | var fs = require('fs'); var issue_number = Number(fs.readFileSync('./NR')); var comment_body = fs.readFileSync('./COMMENT'); - await github.rest.issues.createComment({ + + // Get the existing comments. + const {data: comments} = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: issue_number, - body: comment_body.toString('utf8') }); + + // Find any comment already made by the bot. + const botComment = comments.find(comment => comment.user.id === 41898282 && comment.body.includes('# Perf diff from master')); + + if (botComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: comment_body.toString('utf8') + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue_number, + body: comment_body.toString('utf8') + }); + }