Skip to content

Commit 5af19ab

Browse files
authored
fix(ci): Use workflow_run for perf PR comments to support fork PRs (#15758)
1 parent 2a27703 commit 5af19ab

2 files changed

Lines changed: 94 additions & 9 deletions

File tree

.github/workflows/perf-comment.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Post Perf Results to PR
2+
3+
# Runs after the Perf Tests workflow completes. Uses workflow_run so
4+
# the GITHUB_TOKEN is scoped to the base repo and can write PR comments
5+
# even when the PR comes from a fork.
6+
on:
7+
workflow_run:
8+
workflows: ['Perf Tests']
9+
types: [completed]
10+
11+
jobs:
12+
comment:
13+
name: Post PR Comment
14+
runs-on: ubuntu-latest
15+
if: >
16+
github.event.workflow_run.event == 'pull_request' &&
17+
github.event.workflow_run.conclusion != 'cancelled'
18+
19+
permissions:
20+
pull-requests: write
21+
actions: read
22+
23+
steps:
24+
- name: Download perf results artifact
25+
uses: actions/download-artifact@v4
26+
with:
27+
name: perf-results
28+
path: perf-results
29+
run-id: ${{ github.event.workflow_run.id }}
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Read PR number
33+
id: pr
34+
run: |
35+
if [ ! -f perf-results/pr-number.txt ]; then
36+
echo "No PR number file found — skipping."
37+
echo "skip=true" >> "$GITHUB_OUTPUT"
38+
exit 0
39+
fi
40+
PR_NUMBER=$(cat perf-results/pr-number.txt | tr -d '[:space:]')
41+
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
42+
echo "skip=false" >> "$GITHUB_OUTPUT"
43+
44+
- name: Read markdown report
45+
if: steps.pr.outputs.skip != 'true'
46+
id: report
47+
run: |
48+
if [ ! -f perf-results/report.md ]; then
49+
echo "No report.md found — skipping."
50+
echo "skip=true" >> "$GITHUB_OUTPUT"
51+
exit 0
52+
fi
53+
echo "skip=false" >> "$GITHUB_OUTPUT"
54+
55+
- name: Post or update PR comment
56+
if: steps.pr.outputs.skip != 'true' && steps.report.outputs.skip != 'true'
57+
uses: actions/github-script@v7
58+
with:
59+
script: |
60+
const fs = require('fs');
61+
const marker = '<!-- rnw-perf-results -->';
62+
const reportPath = 'perf-results/report.md';
63+
const prNumber = parseInt('${{ steps.pr.outputs.number }}', 10);
64+
65+
const markdown = fs.readFileSync(reportPath, 'utf-8');
66+
const body = `${marker}\n${markdown}`;
67+
68+
// Find existing comment
69+
const { data: comments } = await github.rest.issues.listComments({
70+
owner: context.repo.owner,
71+
repo: context.repo.repo,
72+
issue_number: prNumber,
73+
per_page: 100,
74+
});
75+
76+
const existing = comments.find(c => c.body && c.body.includes(marker));
77+
78+
if (existing) {
79+
await github.rest.issues.updateComment({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
comment_id: existing.id,
83+
body,
84+
});
85+
core.info(`Updated existing comment (id: ${existing.id})`);
86+
} else {
87+
await github.rest.issues.createComment({
88+
owner: context.repo.owner,
89+
repo: context.repo.repo,
90+
issue_number: prNumber,
91+
body,
92+
});
93+
core.info('Created new comment');
94+
}

.github/workflows/perf-tests.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
permissions:
3333
contents: read
3434
actions: read
35-
pull-requests: write
3635

3736
steps:
3837
# ── Setup ──────────────────────────────────────────────
@@ -84,14 +83,6 @@ jobs:
8483
packages/e2e-test-app-fabric/test/__perf__/**/__perf_snapshots__/
8584
retention-days: 30
8685

87-
# ── PR Comment ────────────────────────────────────────
88-
- name: Post perf results to PR
89-
if: github.event_name == 'pull_request' && always()
90-
working-directory: packages/e2e-test-app-fabric
91-
env:
92-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93-
run: yarn perf:ci:report
94-
9586
# ── Status Gate ────────────────────────────────────────
9687
- name: Check for regressions
9788
if: steps.compare.outcome == 'failure'

0 commit comments

Comments
 (0)