From 4cd014384fc7835d871963fe955eaf72f606519d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Sun, 9 Mar 2025 21:26:19 +0100 Subject: [PATCH] action shouldn't comment on a pr if last comment is from action (#18196) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective - While a PR is in work, if several commits fail and trigger a comment from the action, this can create a lot of comments from actions with low value - Noticed on https://github.com/bevyengine/bevy/pull/18139 ## Solution - If last comment on a PR is from an action, don't add a new comment --------- Co-authored-by: Martín Maita <47983254+mnmaita@users.noreply.github.com> --- .github/workflows/ci-comment-failures.yml | 45 +++++++++++++++++++++-- .github/workflows/example-run-report.yml | 14 ++++++- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-comment-failures.yml b/.github/workflows/ci-comment-failures.yml index 68372d5fac..c39ad70a88 100644 --- a/.github/workflows/ci-comment-failures.yml +++ b/.github/workflows/ci-comment-failures.yml @@ -48,8 +48,21 @@ jobs: return "true" - run: unzip missing-examples.zip if: ${{ steps.find-artifact.outputs.result == 'true' }} - - name: 'Comment on PR' + - name: "Check if last comment is already from actions" if: ${{ steps.find-artifact.outputs.result == 'true' }} + id: check-last-comment + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + PR=`cat ./NR` + if [[ `gh api --jq '.[-1].user.login' /repos/bevyengine/bevy/issues/$PR/comments` == 'github-actions[bot]' ]] + then + echo "result=true" >> $GITHUB_OUTPUT + else + echo "result=false" >> $GITHUB_OUTPUT + fi + - name: "Comment on PR" + if: ${{ steps.find-artifact.outputs.result == 'true' && check-last-comment.outputs.result == 'false' }} uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -106,8 +119,21 @@ jobs: return "true" - run: unzip missing-features.zip if: ${{ steps.find-artifact.outputs.result == 'true' }} - - name: 'Comment on PR' + - name: "Check if last comment is already from actions" if: ${{ steps.find-artifact.outputs.result == 'true' }} + id: check-last-comment + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + PR=`cat ./NR` + if [[ `gh api --jq '.[-1].user.login' /repos/bevyengine/bevy/issues/$PR/comments` == 'github-actions[bot]' ]] + then + echo "result=true" >> $GITHUB_OUTPUT + else + echo "result=false" >> $GITHUB_OUTPUT + fi + - name: "Comment on PR" + if: ${{ steps.find-artifact.outputs.result == 'true' && steps.check-last-comment.outputs.result == 'false' }} uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -164,8 +190,21 @@ jobs: return "true" - run: unzip msrv.zip if: ${{ steps.find-artifact.outputs.result == 'true' }} - - name: 'Comment on PR' + - name: "Check if last comment is already from actions" if: ${{ steps.find-artifact.outputs.result == 'true' }} + id: check-last-comment + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + PR=`cat ./NR` + if [[ `gh api --jq '.[-1].user.login' /repos/bevyengine/bevy/issues/$PR/comments` == 'github-actions[bot]' ]] + then + echo "result=true" >> $GITHUB_OUTPUT + else + echo "result=false" >> $GITHUB_OUTPUT + fi + - name: "Comment on PR" + if: ${{ steps.find-artifact.outputs.result == 'true' && steps.check-last-comment.outputs.result == 'false' }} uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/example-run-report.yml b/.github/workflows/example-run-report.yml index c2b1e93b02..198dee72e4 100644 --- a/.github/workflows/example-run-report.yml +++ b/.github/workflows/example-run-report.yml @@ -96,8 +96,20 @@ jobs: else echo "result=false" >> $GITHUB_OUTPUT fi + - name: "Check if last comment is already from actions" + id: check-last-comment + env: + PR: ${{ needs.make-macos-screenshots-available.outputs.pr-number }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + if [[ `gh api --jq '.[-1].user.login' /repos/bevyengine/bevy/issues/$PR/comments` == 'github-actions[bot' ]] + then + echo "result=true" >> $GITHUB_OUTPUT + else + echo "result=false" >> $GITHUB_OUTPUT + fi - name: "Comment on PR" - if: ${{ steps.check-label.outputs.result == 'false' }} + if: ${{ steps.check-label.outputs.result == 'false' && steps.check-last-comment.outputs.result == 'false' }} env: PROJECT: B04F67C0-C054-4A6F-92EC-F599FEC2FD1D PR: ${{ needs.make-macos-screenshots-available.outputs.pr-number }}