Skip to content

Commit d93e949

Browse files
authored
ci: fix PR comment for fork PRs (#102)
* ci: fix PR comment for fork PRs using pull_request_target GITHUB_TOKEN for pull_request events from forks only gets read permissions, so the rootfs profile comment fails. Move the comment posting to a separate workflow using pull_request_target (which runs in the base repo context with write permissions), matching openpilot's pattern. * ci: rename pr-comment.yml to profile.yml
1 parent 99bfd2c commit d93e949

File tree

2 files changed

+84
-42
lines changed

2 files changed

+84
-42
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -64,48 +64,6 @@ jobs:
6464
build/rootfs-profile.md
6565
if-no-files-found: error
6666

67-
- name: download master baseline
68-
if: github.event_name == 'pull_request'
69-
env:
70-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71-
run: |
72-
mkdir -p baseline
73-
RUN_ID=$(gh run list --workflow=build.yml --branch=master \
74-
--status=success --limit=1 --json databaseId --jq '.[0].databaseId')
75-
if [ -n "$RUN_ID" ]; then
76-
gh run download "$RUN_ID" --name rootfs-profile --dir baseline/ || true
77-
fi
78-
79-
- name: post PR comment
80-
if: github.event_name == 'pull_request'
81-
env:
82-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83-
run: |
84-
# Generate diff (gracefully handles missing baseline)
85-
DIFF_MD=$(./vamos profile diff baseline/rootfs-profile.json build/rootfs-profile.json 2>/dev/null || echo "No baseline available")
86-
PROFILE_MD=$(cat build/rootfs-profile.md)
87-
88-
# Assemble comment with hidden marker for find-and-update
89-
printf -v COMMENT_BODY '%s\n%s\n\n%s\n%s\n\n---\n\n%s' \
90-
'<!-- rootfs-profile-bot -->' \
91-
'## vamOS System Profile' \
92-
'### Changes vs master' \
93-
"$DIFF_MD" \
94-
"$PROFILE_MD"
95-
96-
# Find existing comment by marker
97-
COMMENT_ID=$(gh api \
98-
"repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
99-
--jq '.[] | select(.body | contains("<!-- rootfs-profile-bot -->")) | .id' \
100-
| head -1)
101-
102-
if [ -n "$COMMENT_ID" ]; then
103-
gh api "repos/${{ github.repository }}/issues/comments/$COMMENT_ID" \
104-
-X PATCH -f body="$COMMENT_BODY"
105-
else
106-
gh pr comment "${{ github.event.pull_request.number }}" --body "$COMMENT_BODY"
107-
fi
108-
10967
release:
11068
if: github.event_name == 'push'
11169
needs: [build-kernel, build-system]

.github/workflows/profile.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: profile
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, synchronize, reopened]
6+
7+
env:
8+
SHA: ${{ github.event.pull_request.head.sha }}
9+
10+
jobs:
11+
pr-comment:
12+
if: github.repository == 'commaai/vamOS'
13+
runs-on: ubuntu-24.04
14+
timeout-minutes: 30
15+
permissions:
16+
contents: read
17+
pull-requests: write
18+
actions: read
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: wait for build
23+
uses: lewagon/wait-on-check-action@v1.3.4
24+
with:
25+
ref: ${{ env.SHA }}
26+
check-name: build-system
27+
repo-token: ${{ secrets.GITHUB_TOKEN }}
28+
allowed-conclusions: success
29+
wait-interval: 20
30+
31+
- name: get build run ID
32+
id: get_run_id
33+
env:
34+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
run: |
36+
RUN_ID=$(gh api "repos/${{ github.repository }}/commits/${{ env.SHA }}/check-runs" \
37+
--jq '.check_runs[] | select(.name == "build-system") | .html_url | capture("(?<n>[0-9]+)") | .n' \
38+
| head -1)
39+
echo "run_id=$RUN_ID" >> "$GITHUB_OUTPUT"
40+
41+
- name: download rootfs profile
42+
uses: dawidd6/action-download-artifact@v6
43+
with:
44+
github_token: ${{ secrets.GITHUB_TOKEN }}
45+
run_id: ${{ steps.get_run_id.outputs.run_id }}
46+
name: rootfs-profile
47+
path: build/
48+
49+
- name: download master baseline
50+
env:
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
run: |
53+
mkdir -p baseline
54+
RUN_ID=$(gh run list --workflow=build.yml --branch=master \
55+
--status=success --limit=1 --json databaseId --jq '.[0].databaseId')
56+
if [ -n "$RUN_ID" ]; then
57+
gh run download "$RUN_ID" --name rootfs-profile --dir baseline/ || true
58+
fi
59+
60+
- name: post PR comment
61+
env:
62+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
run: |
64+
DIFF_MD=$(./vamos profile diff baseline/rootfs-profile.json build/rootfs-profile.json 2>/dev/null || echo "No baseline available")
65+
PROFILE_MD=$(cat build/rootfs-profile.md)
66+
67+
printf -v COMMENT_BODY '%s\n%s\n\n%s\n%s\n\n---\n\n%s' \
68+
'<!-- rootfs-profile-bot -->' \
69+
'## vamOS System Profile' \
70+
'### Changes vs master' \
71+
"$DIFF_MD" \
72+
"$PROFILE_MD"
73+
74+
COMMENT_ID=$(gh api \
75+
"repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
76+
--jq '.[] | select(.body | contains("<!-- rootfs-profile-bot -->")) | .id' \
77+
| head -1)
78+
79+
if [ -n "$COMMENT_ID" ]; then
80+
gh api "repos/${{ github.repository }}/issues/comments/$COMMENT_ID" \
81+
-X PATCH -f body="$COMMENT_BODY"
82+
else
83+
gh pr comment "${{ github.event.pull_request.number }}" --body "$COMMENT_BODY"
84+
fi

0 commit comments

Comments
 (0)