test(flow): comments on failed #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!' | ||
}) |