|
5 | 5 |
|
6 | 6 | permissions: |
7 | 7 | contents: read |
| 8 | + issues: write |
| 9 | + pull-requests: write |
8 | 10 |
|
9 | 11 | jobs: |
10 | 12 | governance: |
|
24 | 26 | - name: Run BEAR governance (observe) |
25 | 27 | run: ./.bear/ci/bear-gates.sh --mode observe |
26 | 28 |
|
| 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 | +
|
27 | 87 | - name: Upload BEAR CI artifacts |
28 | 88 | if: always() |
29 | 89 | uses: actions/upload-artifact@v4 |
|
0 commit comments