-
Notifications
You must be signed in to change notification settings - Fork 332
48 lines (46 loc) · 1.68 KB
/
comment-on-failed.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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!'
})