Skip to content

Commit c65be36

Browse files
committed
Add BEAR PR summary comment
1 parent 84b8baf commit c65be36

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

.github/workflows/pr-gate.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55

66
permissions:
77
contents: read
8+
issues: write
9+
pull-requests: write
810

911
jobs:
1012
governance:
@@ -24,6 +26,64 @@ jobs:
2426
- name: Run BEAR governance (observe)
2527
run: ./.bear/ci/bear-gates.sh --mode observe
2628

29+
- name: Publish BEAR PR summary
30+
if: always()
31+
uses: actions/github-script@v7
32+
with:
33+
script: |
34+
const fs = require('fs');
35+
const marker = '<!-- bear-ci-governance -->';
36+
const reportPath = 'build/bear/ci/bear-ci-report.json';
37+
const summaryPath = 'build/bear/ci/bear-ci-summary.md';
38+
39+
let body = `${marker}\n## BEAR CI\n\nBEAR did not produce its expected CI report. Check the workflow logs.`;
40+
if (fs.existsSync(reportPath) && fs.existsSync(summaryPath)) {
41+
const report = JSON.parse(fs.readFileSync(reportPath, 'utf8'));
42+
const summary = fs.readFileSync(summaryPath, 'utf8').trim();
43+
const decision = String(report.decision || 'unknown').toUpperCase().replace(/-/g, ' ');
44+
const mode = report.mode || 'unknown';
45+
const baseSha = report.resolvedBaseSha || 'unknown';
46+
body = [
47+
marker,
48+
'## BEAR CI',
49+
'',
50+
`- Decision: \`${decision}\``,
51+
`- Mode: \`${mode}\``,
52+
`- Base SHA: \`${baseSha}\``,
53+
'',
54+
'<details><summary>BEAR summary</summary>',
55+
'',
56+
summary,
57+
'',
58+
'</details>'
59+
].join('\n');
60+
}
61+
62+
const pr = context.payload.pull_request;
63+
const { data: comments } = await github.rest.issues.listComments({
64+
owner: context.repo.owner,
65+
repo: context.repo.repo,
66+
issue_number: pr.number,
67+
per_page: 100
68+
});
69+
70+
const existing = comments.find((comment) => comment.user?.type === 'Bot' && comment.body?.includes(marker));
71+
if (existing) {
72+
await github.rest.issues.updateComment({
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
comment_id: existing.id,
76+
body
77+
});
78+
} else {
79+
await github.rest.issues.createComment({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
issue_number: pr.number,
83+
body
84+
});
85+
}
86+
2787
- name: Upload BEAR CI artifacts
2888
if: always()
2989
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)