From fb8a32ab914019a4ef4584b53a9d82955e3b8e53 Mon Sep 17 00:00:00 2001 From: Lucas Werey Date: Fri, 9 Aug 2024 11:23:50 +0200 Subject: [PATCH] test(flow): comments on failed --- .github/workflows/comment-on-failed.yml | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/comment-on-failed.yml diff --git a/.github/workflows/comment-on-failed.yml b/.github/workflows/comment-on-failed.yml new file mode 100644 index 000000000000..49dded0e3d62 --- /dev/null +++ b/.github/workflows/comment-on-failed.yml @@ -0,0 +1,48 @@ +name: Comment on PR when a check fails or succeeds + +on: + check_suite: + types: [completed] + workflow_dispatch: + +jobs: + check-workflows: + if: github.event.check_suite.pull_requests != '' + runs-on: ubuntu-latest + steps: + - name: Check if any check run failed + id: check + run: | + failed=false + check_suite_id=${{ github.event.check_suite.id }} + for check_run in $(gh api repos/${{ github.repository }}/check-suites/$check_suite_id/check-runs --jq '.check_runs[].conclusion'); do + if [ "$check_run" == "failure" ]; then + failed=true + break + fi + done + echo "::set-output name=failed::$failed" + - name: Comment on PR if failed + if: steps.check.outputs.failed == 'true' + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.issues.createComment({ + issue_number: context.payload.check_suite.pull_requests[0].number, + owner: context.repo.owner, + repo: context.repo.repo, + body: 'One or more check runs failed. Please check the logs.' + }) + - name: Comment on PR if succeeded + if: steps.check.outputs.failed == 'false' + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.issues.createComment({ + issue_number: context.payload.check_suite.pull_requests[0].number, + owner: context.repo.owner, + repo: context.repo.repo, + body: 'All check runs succeeded. Great job!' + })