forked from Homebrew/homebrew-core
-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (94 loc) · 3.7 KB
/
triage-ci.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Triage CI failure
on:
workflow_run:
workflows:
- CI
types:
- completed
concurrency:
group: triage-ci-${{ github.event.workflow_run.event }}-${{ github.event.workflow_run.id }}
cancel-in-progress: true
env:
HOMEBREW_DEVELOPER: 1
HOMEBREW_NO_AUTO_UPDATE: 1
GH_REPO: ${{ github.repository }}
GH_NO_UPDATE_NOTIFIER: 1
GH_PROMPT_DISABLED: 1
jobs:
comment:
runs-on: ubuntu-latest
if: >
github.repository_owner == 'Homebrew' &&
github.event.workflow_run.conclusion == 'failure' &&
github.event.workflow_run.event == 'pull_request'
permissions:
contents: read
pull-requests: write
env:
COMMENT_BODY_FILE: comment.txt
steps:
- uses: Homebrew/actions/find-related-workflow-run-id@master
with:
run-id: ${{ github.event.workflow_run.id }}
workflow-name: Triage tasks
- name: Download `event_payload` artifact
uses: Homebrew/actions/gh-try-download@master
with:
artifact-name: event_payload
workflow-id: ${{ env.workflow_run_id }}
- run: echo "number=$(jq --raw-output .number event.json)" >> "$GITHUB_OUTPUT"
id: pr
- name: Check PR
id: check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR: ${{ steps.pr.outputs.number }}
NEW_CONTRIBUTOR_MESSAGE: >
Thanks for contributing to Homebrew! :tada: It looks like you're having trouble
with a CI failure. See our [contribution guide](${{ github.event.repository.html_url }}/blob/HEAD/CONTRIBUTING.md)
for help. You may be most interested in the section on
[dealing with CI failures](${{ github.event.repository.html_url }}/blob/HEAD/CONTRIBUTING.md#dealing-with-ci-failures).
You can find the CI logs in the
[Checks tab](${{ github.event.repository.html_url }}/pull/${{ steps.pr.outputs.number }}/checks)
of your pull request.
run: |
rm -f "$COMMENT_BODY_FILE"
comment=false
response="$(
gh api \
--header 'Accept: application/vnd.github+json' \
--header 'X-GitHub-Api-Version: 2022-11-28' \
"repos/{owner}/{repo}/pulls/$PR"
)"
pip_audit_filter='.body | contains("brew-pip-audit")'
new_contributor_filter='.author_association == "FIRST_TIME_CONTRIBUTOR" or .author_association == "NONE"'
new_contributor_comment_posted_filter='any(.[].body; contains("'"$NEW_CONTRIBUTOR_MESSAGE"'"))'
comments_api_url="$(jq --raw-output '.comments_url' <<< "$response")"
if jq --exit-status "$pip_audit_filter"
then
echo 'Ping @woodruffw @alex' >> "$COMMENT_BODY_FILE"
fi <<< "$response"
if jq --exit-status "$new_contributor_filter"
then
# Check that we haven't posted the new contributor message yet.
if jq --exit-status "$new_contributor_comment_posted_filter | not"
then
echo "$NEW_CONTRIBUTOR_MESSAGE" >> "$COMMENT_BODY_FILE"
fi < <(
gh api \
--header 'Accept: application/vnd.github+json' \
--header 'X-GitHub-Api-Version: 2022-11-28' \
"$comments_api_url"
)
fi <<< "$response"
if [[ -s "$COMMENT_BODY_FILE" ]]
then
comment=true
fi
echo "comment=$comment" >> "$GITHUB_OUTPUT"
- name: Post comment
if: fromJson(steps.check.outputs.comment)
run: gh pr comment "$PR" --body-file "$COMMENT_BODY_FILE"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR: ${{ steps.pr.outputs.number }}