Skip to content

Commit 521ddce

Browse files
committed
package_core: write PR comment with status
1 parent 60ca76a commit 521ddce

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
name: Leave PR comment
4+
5+
on:
6+
workflow_run:
7+
workflows: ["Package, test and upload core"]
8+
types:
9+
- completed
10+
11+
permissions:
12+
contents: read
13+
pull-requests: write
14+
15+
jobs:
16+
comment-on-pr:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Download artifact
20+
uses: dawidd6/action-download-artifact@ac66b43f0e6a346234dd65d4d0c8fbb31cb316e5 # v11
21+
with:
22+
workflow: package-core.yml
23+
run_id: ${{ github.event.workflow_run.id }}
24+
name: comment-request
25+
if_no_artifact_found: ignore
26+
27+
- name: Load PR number
28+
run: |
29+
echo "PR_NUM=$(cat pr_number || true)" >> $GITHUB_ENV
30+
31+
- name: Check PR number
32+
id: check-pr
33+
uses: carpentries/actions/check-valid-pr@2e20fd5ee53b691e27455ce7ca3b16ea885140e8 # v0.15.0
34+
with:
35+
pr: ${{ env.PR_NUM }}
36+
sha: ${{ github.event.workflow_run.head_sha }}
37+
38+
- name: Validate PR number
39+
if: ${{ steps.check-pr.outputs.VALID != 'true' }}
40+
run: |
41+
echo "ABORT: PR number validation failed!"
42+
exit 1
43+
44+
- name: Update PR comment
45+
if: ${{ steps.check-pr.outputs.VALID == 'true' }}
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
GH_REPO: ${{ github.repository }}
49+
run: |
50+
BODY="$(cat comment_body || echo '# :fire: CI failure processing logs!')"
51+
52+
# delete existing comment, if present, then add a new one
53+
gh pr comment ${PR_NUM} --delete-last --yes || true
54+
gh pr comment ${PR_NUM} --body "${BODY}"
55+
56+
- name: Clean up intermediate artifacts
57+
if: ${{ steps.check-pr.outputs.VALID == 'true' }}
58+
uses: geekyeggo/delete-artifact@v5.1.0
59+
with:
60+
name: comment-request

.github/workflows/package_core.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,21 @@ jobs:
320320
cat full_log >> $GITHUB_STEP_SUMMARY
321321
echo "CI_RESULT=$(cat result)" > $GITHUB_OUTPUT
322322
323+
if [ "${{ github.event_name }}" == "pull_request" ]; then
324+
mkdir -p comment-request
325+
echo "${{ github.event.pull_request.number }}" > comment-request/pr_number
326+
echo -e "## Built \`$(extra/get_core_version.sh)\`\n" > comment-request/comment_body
327+
echo >> comment-request/comment_body
328+
cat summary | sed -e 's!\${\\color{\S*}\(.*\)}\$!\1!g' -e 's!\\%!%!g' >> comment-request/comment_body
329+
fi
330+
331+
- name: Archive comment information
332+
uses: actions/upload-artifact@v4
333+
if: ${{ github.event_name == 'pull_request' }}
334+
with:
335+
name: comment-request
336+
path: comment-request/
337+
323338
- name: Clean up intermediate artifacts
324339
uses: geekyeggo/delete-artifact@v5.1.0
325340
with:

0 commit comments

Comments
 (0)