From 22cec9fa3c2e80db0c25337e4b17bbbef1c8a917 Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Thu, 19 Jun 2025 18:11:04 +0400 Subject: [PATCH] Update PR comments in place (#4620) * Update PR comments in place Currently, we post a new comment for each change, which is just spam for PRs with many iterations. * Pin actions by hash (cherry picked from commit 914b5d82aed66edbb9d2adf0671fd3f233836957) --- .github/validate-pr/index.js | 10 ++++------ .github/workflows/validate-pr.yml | 28 +++++++++++++++++++--------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.github/validate-pr/index.js b/.github/validate-pr/index.js index 2ec385b2c1..a9095fcf5d 100644 --- a/.github/validate-pr/index.js +++ b/.github/validate-pr/index.js @@ -147,12 +147,10 @@ async function run() { } comment += `\nYou can validate ${changedApis.length === 1 ? 'this' : 'these'} API${changedApis.length === 1 ? '' : 's'} yourself by using the ${tick}make validate${tick} target.\n` - await octokit.rest.issues.createComment({ - owner: 'elastic', - repo: 'elasticsearch-specification', - issue_number: context.payload.pull_request.number, - body: comment - }) + core.setOutput('has_results', 'true') + core.setOutput('comment_body', comment) + } else { + core.setOutput('has_results', 'false') } core.info('Done!') diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml index 5c92f6aa94..43f8208c91 100644 --- a/.github/workflows/validate-pr.yml +++ b/.github/workflows/validate-pr.yml @@ -64,15 +64,25 @@ jobs: env: GCS_CREDENTIALS: ${{ secrets.GCS_CREDENTIALS }} - - name: Remove previous comment - uses: maheshrayas/action-pr-comment-delete@v1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - org: elastic - repo: elasticsearch-specification - user: github-actions[bot] - issue: ${{ github.event.number }} - - name: Run validation + id: validation working-directory: ./elasticsearch-specification run: node .github/validate-pr --token ${{ secrets.GITHUB_TOKEN }} + + - name: Find existing comment + uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0 + id: find-comment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: 'Following you can find the validation results' + + - name: Create or update comment + if: steps.validation.outputs.has_results == 'true' + uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + comment-id: ${{ steps.find-comment.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: ${{ steps.validation.outputs.comment_body }} + edit-mode: replace