-
Notifications
You must be signed in to change notification settings - Fork 189
217 lines (207 loc) · 7.61 KB
/
pkgcheck-checks-on-pr.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: pkgcheck
on:
workflow_dispatch:
pull_request_target:
branches:
- master
paths-ignore:
- '.github/**'
- 'metadata/**'
- 'README.md'
- '.gitignore'
types: [opened, reopened, synchronize]
permissions:
contents: read
pull-requests: write
jobs:
check-changed-ebuilds:
name: check changed ebuilds
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
container:
image: ghcr.io/liangyongxiang/gentoo-testing:master
steps:
- name: Sync main tree
run: emerge --sync gentoo
- name: Checkout the head ref of the pull request
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
path: gentoo-zh
- name: Get the base commit
id: basecommit
shell: bash
env:
COMMITS_URL: ${{ github.event.pull_request.commits_url }}
COMMITS_JSON: /tmp/commits.json
run: |
set -xe
curl -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-o ${COMMITS_JSON} ${COMMITS_URL}
[[ $(file --mime-type ${COMMITS_JSON}) =~ application/json$ ]]
<${COMMITS_JSON} jq '.message' && false || true
commits=( $(<${COMMITS_JSON} jq '.[].sha' | cut -d'"' -f2) )
pcommits=( $(<${COMMITS_JSON} jq '.[].parents[].sha' | cut -d'"' -f2) )
sha=${pcommits[0]}
for pcommit in ${pcommits[@]}; do
pcommit_not_matched=0
for commit in ${commits[@]}; do
if [[ ${pcommit} == ${commit} ]]; then
pcommit_not_matched=1
fi
done
if [[ ${pcommit_not_matched} == 0 ]]; then
sha=${pcommit}
break
fi
done
echo "sha=$sha" >> $GITHUB_OUTPUT
- name: Check
id: check
shell: bash
env:
THEBASEREF: ${{ steps.basecommit.outputs.sha }}
run: |
set -e
mv ${GITHUB_WORKSPACE}/gentoo-zh /var/db/repos/
mkdir -p /etc/portage/repos.conf
echo "[gentoo]
location = /var/db/repos/gentoo
" >/etc/portage/repos.conf/gentoo.conf
echo "[gentoo-zh]
location = /var/db/repos/gentoo-zh
" >/etc/portage/repos.conf/gentoo-zh.conf
cd /var/db/repos/gentoo-zh
echo "git diff --raw ${THEBASEREF}"
git diff --raw ${THEBASEREF}
diff_files=$(git diff --raw --name-only ${THEBASEREF})
cates=$(cat /var/db/repos/gentoo{,-zh}/profiles/categories | sort -du)
declare -a check_pkgs
for file in ${diff_files}; do
c=${file%%/*}
for cate in ${cates}; do
if [[ ${c} == ${cate} ]]; then
n=${file#*/}
n=${n%%/*}
check_pkgs+=( ${c}/${n} )
fi
done
done
check_pkgs=( $(echo "${check_pkgs[@]}" | tr ' ' '\n' | sort -du | tr '\n' ' ') )
ret=0
echo "pkgs: ${check_pkgs[@]}"
set -- pkgcheck scan --exit error "${check_pkgs[@]}"
echo ">>> " "${@}"
"${@}" >/var/tmp/report.txt || ret=$?
cat /var/tmp/report.txt || true
set --
echo "ret=$ret" >> $GITHUB_OUTPUT
[[ ${ret} == 0 ]]
- name: Format report
if: ${{ always() }}
id: report
shell: bash
env:
ret: ${{ steps.check.outputs.ret }}
run: |
set -e
v_pkgcheck=$(pkgcheck --version) || true
commit_gentoo=$(cd /var/db/repos/gentoo && git rev-list -n1 HEAD) || true
r_len=$(wc -c /var/tmp/report.txt | awk -F'[[:space:]]' '{printf $1}')
r_header='`pkgcheck` checks'
if [[ ${r_len} == 0 ]]; then
r_title=":heavy_check_mark: ${r_header} passed"
else
r_explain="[:mag: QA Keywords Explanation](https://pkgcore.github.io/pkgcheck/man/pkgcheck.html#keywords)"
if [[ ${ret} == 0 ]]; then
r_title=":white_circle: ${r_header} passed but with something can be improved!"
else
r_title=":x: ${r_header} failed"
fi
fi
cat <<EOF >/var/tmp/report.md
## ${r_title}
* ${v_pkgcheck}
* the corresponding _**::gentoo**_ commit: https://github.com/gentoo-mirror/gentoo/commit/${commit_gentoo}
EOF
if [[ -n ${r_explain} ]]; then
echo "<details open><summary><b>QA Results:</b></summary>
" >>/var/tmp/report.md
if [[ ${r_len} -le 65000 ]]; then
echo '```' >>/var/tmp/report.md
cat /var/tmp/report.txt >>/var/tmp/report.md
echo '```' >>/var/tmp/report.md
else
cd /var/db/repos/gentoo-zh || true
commit_id=$(git rev-list -n1 HEAD | cut -b1-7)
cat <<EOF >>/var/tmp/report.md
* _the report is too long, can be downloaded from **Artifacts** list of the current run:
https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
filename: **pkgcheck-report-${commit_id}**_
EOF
echo "commit=$commit_id" >> $GITHUB_OUTPUT
fi
cat <<EOF >>/var/tmp/report.md
</details>
${r_explain}
EOF
fi
echo "has=true" >> $GITHUB_OUTPUT
- name: Hide previous results
if: ${{ always() }}
shell: bash
env:
COMMENTS_URL: ${{ github.event.pull_request.comments_url }}
COMMENTS_JSON: /tmp/comments.json
run: |
curl -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-o ${COMMENTS_JSON} ${COMMENTS_URL}
node_ids=( $(<${COMMENTS_JSON} jq '.[] | select(.body|test("^##\\s*[a-zA-Z_:]+\\s*`pkgcheck`\\s*checks")) | select(.user.id == 41898282) | .node_id' | cut -d'"' -f2) )
echo "${node_ids[@]}"
json="{ \"query\": \"mutation {
minimizeComment(input: {
subjectId: \\\"NODEID\\\",
classifier: OUTDATED
}) {
clientMutationId,
minimizedComment {
isMinimized,
minimizedReason,
viewerCanMinimize
}
}
}\"
}"
json=$(tr -d '\n' <<<${json})
for node_id in ${node_ids[@]}; do
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d "${json/NODEID/${node_id}}" \
https://api.github.com/graphql
done
- name: Post result
if: ${{ always() && steps.report.outputs.has }}
uses: actions/github-script@v7
with:
script: |
const fs = require("fs").promises;
var cbody = await fs.readFile("/var/tmp/report.md", "utf8");
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: cbody
})
- name: Upload big result
if: ${{ always() && steps.report.outputs.commit }}
uses: actions/upload-artifact@v4
with:
name: pkgcheck-report-${{ steps.report.outputs.commit }}
path: /var/tmp/report.txt