Skip to content

Commit c44bb37

Browse files
sbryngelsonmre
authored andcommitted
Add pr-comment workflow to post check results on fork PRs
1 parent 5362f90 commit c44bb37

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

.github/workflows/pr-comment.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: PR Check Comment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["PR Check"]
6+
types: [completed]
7+
8+
jobs:
9+
comment:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
pull-requests: write
13+
steps:
14+
- name: Download check results
15+
uses: actions/download-artifact@v4
16+
with:
17+
name: pr-check-output
18+
github-token: ${{ secrets.GITHUB_TOKEN }}
19+
run-id: ${{ github.event.workflow_run.id }}
20+
continue-on-error: true
21+
22+
- name: Post or update PR comment
23+
if: hashFiles('pr_number.txt') != '' && hashFiles('comment.md') != ''
24+
env:
25+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
GH_REPO: ${{ github.repository }}
27+
run: |
28+
PR_NUMBER=$(cat pr_number.txt)
29+
COMMENT_BODY=$(cat comment.md)
30+
31+
EXISTING_ID=$(gh api "repos/$GH_REPO/issues/$PR_NUMBER/comments" \
32+
--jq '[.[] | select(.body | contains("<!-- pr-check-bot -->"))] | first | .id // empty')
33+
34+
if [ -n "$EXISTING_ID" ]; then
35+
gh api --method PATCH "repos/$GH_REPO/issues/comments/$EXISTING_ID" \
36+
--field body="$COMMENT_BODY"
37+
else
38+
gh api --method POST "repos/$GH_REPO/issues/$PR_NUMBER/comments" \
39+
--field body="$COMMENT_BODY"
40+
fi

0 commit comments

Comments
 (0)