Skip to content

test(flow): comments on failed #1

test(flow): comments on failed

test(flow): comments on failed #1

name: Comment on PR when a check fails or succeeds
on:
check_suite:

Check failure on line 4 in .github/workflows/comment-on-failed.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/comment-on-failed.yml

Invalid workflow file

You have an error in your yaml syntax on line 4
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!'
})