Skip to content

Commit

Permalink
test(flow): comments on failed
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasWerey committed Aug 9, 2024
1 parent 1fb2b90 commit fb8a32a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/comment-on-failed.yml
Original file line number Diff line number Diff line change
@@ -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!'
})

0 comments on commit fb8a32a

Please sign in to comment.