diff --git a/.github/validate-pr/index.js b/.github/validate-pr/index.js index 475fd5c87a..2987254b8a 100644 --- a/.github/validate-pr/index.js +++ b/.github/validate-pr/index.js @@ -141,12 +141,10 @@ async function run() { } comment += `\nYou can validate ${table.length === 1 ? 'this' : 'these'} API${table.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 d0b7e9951b..76715e2823 100644 --- a/.github/workflows/validate-pr.yml +++ b/.github/workflows/validate-pr.yml @@ -63,15 +63,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