Skip to content

Commit cfedc06

Browse files
authored
Merge pull request #793 from HaoboGu/feat/ci
Fix ci comment permission issue
2 parents eba96a1 + a053b75 commit cfedc06

2 files changed

Lines changed: 66 additions & 35 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Bloat Comment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
types: [completed]
7+
8+
jobs:
9+
comment:
10+
if: github.event.workflow_run.event == 'pull_request'
11+
runs-on: ubuntu-latest
12+
permissions:
13+
pull-requests: write
14+
steps:
15+
- name: Download comment data
16+
uses: actions/download-artifact@v7
17+
with:
18+
name: bloat-comment
19+
run-id: ${{ github.event.workflow_run.id }}
20+
github-token: ${{ secrets.GITHUB_TOKEN }}
21+
22+
- name: Post PR comment
23+
uses: actions/github-script@v7
24+
with:
25+
script: |
26+
const fs = require('fs');
27+
28+
const prNumber = parseInt(fs.readFileSync('pr-number.txt', 'utf8').trim());
29+
const body = fs.readFileSync('report.md', 'utf8').trim();
30+
31+
if (!body) {
32+
console.log('Empty report, skipping comment.');
33+
return;
34+
}
35+
36+
const marker = '## Size Report';
37+
const { data: comments } = await github.rest.issues.listComments({
38+
issue_number: prNumber,
39+
owner: context.repo.owner,
40+
repo: context.repo.repo,
41+
});
42+
const existing = comments.find(c => c.body.includes(marker));
43+
if (existing) {
44+
await github.rest.issues.updateComment({
45+
comment_id: existing.id,
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
body,
49+
});
50+
} else {
51+
await github.rest.issues.createComment({
52+
issue_number: prNumber,
53+
owner: context.repo.owner,
54+
repo: context.repo.repo,
55+
body,
56+
});
57+
}

.github/workflows/ci.yml

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,11 @@ jobs:
178178
path: bloat-data/
179179
retention-days: 1
180180

181-
# Assemble bloat report from matrix artifacts and post as PR comment
181+
# Assemble bloat report from matrix artifacts and save for the comment workflow
182182
bloat-report:
183183
if: github.event_name == 'pull_request'
184184
needs: build
185185
runs-on: ubuntu-latest
186-
permissions:
187-
pull-requests: write
188186
steps:
189187
- uses: actions/checkout@v6
190188
- uses: actions/download-artifact@v7
@@ -193,41 +191,17 @@ jobs:
193191
pattern: bloat-*
194192
merge-multiple: true
195193
- name: Generate report
196-
id: report
197194
run: |
198195
report=$(.github/ci/bloat-report.sh bloat-artifacts)
199-
# Save for the comment step (handle multi-line)
200-
echo "REPORT<<EOF" >> "$GITHUB_ENV"
201-
echo "$report" >> "$GITHUB_ENV"
202-
echo "EOF" >> "$GITHUB_ENV"
203-
- name: Post PR comment
204-
uses: actions/github-script@v7
196+
mkdir -p bloat-comment
197+
echo "${{ github.event.pull_request.number }}" > bloat-comment/pr-number.txt
198+
echo "$report" > bloat-comment/report.md
199+
- name: Upload comment data
200+
uses: actions/upload-artifact@v7
205201
with:
206-
github-token: ${{ secrets.GITHUB_TOKEN }}
207-
script: |
208-
const marker = '## Size Report';
209-
const body = process.env.REPORT;
210-
const { data: comments } = await github.rest.issues.listComments({
211-
issue_number: context.issue.number,
212-
owner: context.repo.owner,
213-
repo: context.repo.repo,
214-
});
215-
const existing = comments.find(c => c.body.includes(marker));
216-
if (existing) {
217-
await github.rest.issues.updateComment({
218-
comment_id: existing.id,
219-
owner: context.repo.owner,
220-
repo: context.repo.repo,
221-
body,
222-
});
223-
} else {
224-
await github.rest.issues.createComment({
225-
issue_number: context.issue.number,
226-
owner: context.repo.owner,
227-
repo: context.repo.repo,
228-
body,
229-
});
230-
}
202+
name: bloat-comment
203+
path: bloat-comment/
204+
retention-days: 1
231205

232206
# Build ESP/xtensa examples (separate toolchain)
233207
build-esp:

0 commit comments

Comments
 (0)