forked from microcai/gentoo-zh
-
Notifications
You must be signed in to change notification settings - Fork 0
252 lines (246 loc) · 9.13 KB
/
repoman-check-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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
name: repoman
on:
pull_request_target:
branches:
- master
paths-ignore:
- '.github/**'
- 'metadata/**'
types: [opened, reopened, synchronize]
jobs:
check-changed-ebuilds:
name: check changed ebuilds
runs-on: ubuntu-20.04
permissions:
contents: read
pull-requests: write
steps:
- name: Setup python3.9
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Prepare environment
shell: bash
run: |
set -xe
python -V
python -VV
sudo mkdir -m 777 -p /etc/portage
sudo mkdir -m 777 -p /var/db/repos/gentoo{,-zh}
sudo mkdir -m 777 -p /var/tmp/portage
- name: Install dependencies
run: sudo apt-get install -y --no-install-recommends libxslt-dev libxml2-dev libxml2-utils zstd python3-lxml jq
- name: Fetch portage
uses: actions/checkout@v2
with:
repository: gentoo/portage
- name: Install portage
shell: bash
run: |
set -xe
printf "[build_ext]\nportage-ext-modules=true" >>setup.cfg
sudo ./setup.py install
sudo useradd portage -d /var/tmp/portage -s /bin/false
sudo ln -s /var/db/repos/gentoo/profiles/default/linux/amd64/17.1 /etc/portage/make.profile
sudo printf "[gentoo-zh]\nlocation = /var/db/repos/gentoo-zh" >>/etc/portage/repos.conf
- name: Install repoman
shell: bash
run: |
set -xe
cd repoman
sudo ./setup.py install
sudo mv /usr/local/share/repoman /usr/share/ || true
- name: Checkout the head ref of the pull request
uses: actions/checkout@v2
with:
fetch-depth: 0
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.sha }}
path: gentoo-zh
- name: Fetch ::gentoo repo
uses: actions/checkout@v2
with:
repository: gentoo-mirror/gentoo
path: gentoo
- 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 "::set-output name=sha::${sha}"
- name: Check
id: check
shell: bash
env:
THEBASEREF: ${{ steps.basecommit.outputs.sha }}
run: |
set -e
sudo mv ${{ github.workspace }}/gentoo{,-zh} /var/db/repos/
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' ' ') )
echo -n >/var/tmp/report.txt
ret=0
echo "pkgs: ${check_pkgs[@]}"
sum=${#check_pkgs[@]}
declare -i i=0
for pkg in ${check_pkgs[@]}; do
i+=1
echo
echo "======================================"
echo ">>> [${i}/${sum}] Checking ${pkg} ..."
echo "======================================"
if [[ ! -d ${pkg} ]]; then
echo "not exists, skip it"
continue
fi
pushd ${pkg}
[[ ${i} == 1 ]] || echo >>/var/tmp/report.txt
echo "=== Package: ${pkg} ===" >>/var/tmp/report.txt
repoman full -q > >(tee -ai /var/tmp/report.txt) || ret=1
popd
done
echo "::set-output name=ret::${ret}"
[[ ${ret} == 0 ]]
- name: Format report
id: report
if: ${{ always() }}
shell: bash
env:
ret: ${{ steps.check.outputs.ret }}
run: |
set -e
if grep '=' /var/tmp/report.txt &>/dev/null; then
cd /var/db/repos/gentoo || true
v_repoman=$(repoman --version) || true
commit_gentoo=$(git rev-list -n1 HEAD) || true
r_restat="open"
r_explain="[:mag: QA Keywords Explanation](https://dev.gentoo.org/~zmedico/portage/doc/man/repoman.1.html#lbAG)"
if [[ ${ret} == 0 ]]; then
if ! egrep -v 'No QA issues found|^=== Package:.*|^[[:space:]]*$' /var/tmp/report.txt &>/dev/null; then
r_title=":heavy_check_mark: repoman checks passed"
r_restat=""
r_explain=""
else
r_title=":white_circle: repoman checks passed with non-fatal QA errors"
fi
else
r_title=":x: repoman checks failed"
fi
cat <<EOF >/var/tmp/report.md
## ${r_title}
${v_repoman}
_::gentoo_ repo latest commit: https://github.com/gentoo-mirror/gentoo/commit/${commit_gentoo}
<details ${r_restat}>
<summary>QA Result:</summary>
EOF
if [[ $(wc -c /var/tmp/report.txt | awk -F'[[:space:]]' '{printf $1}') -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: **repoman-report-${commit_id}**_
EOF
echo "::set-output name=commit::${commit_id}"
fi
cat <<EOF >>/var/tmp/report.md
</details>
${r_explain}
EOF
echo "::set-output name=has::true"
fi
- 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*repoman\\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@v4
with:
script: |
const fs = require("fs").promises;
var cbody = await fs.readFile("/var/tmp/report.md", "utf8");
github.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@v2
with:
name: repoman-report-${{ steps.report.outputs.commit }}
path: /var/tmp/report.txt