12 types: [opened, reopened, synchronize]
19 check-changed-ebuilds:
20 name: check changed ebuilds
21 runs-on: ubuntu-latest
26 image: ghcr.io/liangyongxiang/gentoo-testing:master
29 - name: Sync main tree
30 run: emerge --sync gentoo
31 - name: Checkout the head ref of the pull request
32 uses: actions/checkout@v4
35 repository: ${{ github.event.pull_request.head.repo.full_name }}
36 ref: ${{ github.event.pull_request.head.sha }}
38 - name: Get the base commit
42 COMMITS_URL: ${{ github.event.pull_request.commits_url }}
43 COMMITS_JSON: /tmp/commits.json
46 curl -H "Accept: application/vnd.github.v3+json" \
47 -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
48 -o ${COMMITS_JSON} ${COMMITS_URL}
49 [[ $(file --mime-type ${COMMITS_JSON}) =~ application/json$ ]]
50 <${COMMITS_JSON} jq '.message' && false || true
51 commits=( $(<${COMMITS_JSON} jq '.[].sha' | cut -d'"' -f2) )
52 pcommits=( $(<${COMMITS_JSON} jq '.[].parents[].sha' | cut -d'"' -f2) )
54 for pcommit in ${pcommits[@]}; do
56 for commit in ${commits[@]}; do
57 if [[ ${pcommit} == ${commit} ]]; then
61 if [[ ${pcommit_not_matched} == 0 ]]; then
66 echo "sha=$sha" >> $GITHUB_OUTPUT
71 THEBASEREF: ${{ steps.basecommit.outputs.sha }}
74 mv ${GITHUB_WORKSPACE}/gentoo-zh /var/db/repos/
75 mkdir -p /etc/portage/repos.conf
77 location = /var/db/repos/gentoo
78 " >/etc/portage/repos.conf/gentoo.conf
80 location = /var/db/repos/gentoo-zh
81 " >/etc/portage/repos.conf/gentoo-zh.conf
82 cd /var/db/repos/gentoo-zh
83 echo "git diff --raw ${THEBASEREF}"
84 git diff --raw ${THEBASEREF}
85 diff_files=$(git diff --raw --name-only ${THEBASEREF})
86 cates=$(cat /var/db/repos/gentoo{,-zh}/profiles/categories | sort -du)
88 for file in ${diff_files}; do
90 for cate in ${cates}; do
91 if [[ ${c} == ${cate} ]]; then
94 check_pkgs+=( ${c}/${n} )
98 check_pkgs=( $(echo "${check_pkgs[@]}" | tr ' ' '\n' | sort -du | tr '\n' ' ') )
100 echo "pkgs: ${check_pkgs[@]}"
101 set -- pkgcheck scan --exit error "${check_pkgs[@]}"
103 "${@}" >/var/tmp/report.txt || ret=$?
104 cat /var/tmp/report.txt || true
106 echo "ret=$ret" >> $GITHUB_OUTPUT
108 - name: Format report
113 ret: ${{ steps.check.outputs.ret }}
117 v_pkgcheck=$(pkgcheck --version) || true
118 commit_gentoo=$(cd /var/db/repos/gentoo && git rev-list -n1 HEAD) || true
120 r_len=$(wc -c /var/tmp/report.txt | awk -F'[[:space:]]' '{printf $1}')
121 r_header='`pkgcheck` checks'
122 if [[ ${r_len} == 0 ]]; then
123 r_title=":heavy_check_mark: ${r_header} passed"
125 r_explain="[:mag: QA Keywords Explanation](https://pkgcore.github.io/pkgcheck/man/pkgcheck.html#keywords)"
126 if [[ ${ret} == 0 ]]; then
127 r_title=":white_circle: ${r_header} passed but with something can be improved!"
129 r_title=":x: ${r_header} failed"
133 cat <<EOF >/var/tmp/report.md
137 * the corresponding _**::gentoo**_ commit: https://github.com/gentoo-mirror/gentoo/commit/${commit_gentoo}
141 if [[ -n ${r_explain} ]]; then
142 echo "<details open><summary><b>QA Results:</b></summary>
143 " >>/var/tmp/report.md
144 if [[ ${r_len} -le 65000 ]]; then
145 echo '```' >>/var/tmp/report.md
146 cat /var/tmp/report.txt >>/var/tmp/report.md
147 echo '```' >>/var/tmp/report.md
149 cd /var/db/repos/gentoo-zh || true
150 commit_id=$(git rev-list -n1 HEAD | cut -b1-7)
151 cat <<EOF >>/var/tmp/report.md
152 * _the report is too long, can be downloaded from **Artifacts** list of the current run:
153 https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}
154 filename: **pkgcheck-report-${commit_id}**_
156 echo "commit=$commit_id" >> $GITHUB_OUTPUT
158 cat <<EOF >>/var/tmp/report.md
164 echo "has=true" >> $GITHUB_OUTPUT
165 - name: Hide previous results
169 COMMENTS_URL: ${{ github.event.pull_request.comments_url }}
170 COMMENTS_JSON: /tmp/comments.json
172 curl -H "Accept: application/vnd.github.v3+json" \
173 -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
174 -o ${COMMENTS_JSON} ${COMMENTS_URL}
175 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) )
176 echo "${node_ids[@]}"
177 json="{ \"query\": \"mutation {
178 minimizeComment(input: {
179 subjectId: \\\"NODEID\\\",
191 json=$(tr -d '\n' <<<${json})
192 for node_id in ${node_ids[@]}; do
194 -H "Content-Type: application/json" \
195 -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
196 -d "${json/NODEID/${node_id}}" \
197 https://api.github.com/graphql
200 if: ${{ always() && steps.report.outputs.has }}
201 uses: actions/github-script@v7
204 const fs = require("fs").promises;
205 var cbody = await fs.readFile("/var/tmp/report.md", "utf8");
206 github.rest.issues.createComment({
207 issue_number: context.issue.number,
208 owner: context.repo.owner,
209 repo: context.repo.repo,
212 - name: Upload big result
213 if: ${{ always() && steps.report.outputs.commit }}
214 uses: actions/upload-artifact@v4
216 name: pkgcheck-report-${{ steps.report.outputs.commit }}
217 path: /var/tmp/report.txt