Skip to content

Commit abfcbae

Browse files
authored
fix(ci): 修复 PR 性能报告评论权限 (#1147)
* fix(ci): 修复性能报告评论权限 * fix(ci): 放宽自动创建 release pr 的证书门禁
1 parent fd90a46 commit abfcbae

4 files changed

Lines changed: 32 additions & 6 deletions

File tree

.github/workflows/benchmark-pr-report.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ concurrency:
1212
permissions:
1313
actions: read
1414
contents: read
15-
issues: write
16-
pull-requests: read
15+
pull-requests: write
1716

1817
jobs:
1918
publish:

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ jobs:
8080
pnpm exec playwright install chromium chromium-headless-shell
8181
8282
- name: Download same-commit coverage certificate
83+
if: inputs.mode == 'publish' || inputs.mode == 'publish-unpublished'
8384
env:
8485
GH_TOKEN: ${{ github.token }}
8586
RELEASE_CERTIFICATE_RUN_ID: ${{ vars.RELEASE_CERTIFICATE_RUN_ID }}
@@ -112,6 +113,7 @@ jobs:
112113
gh run download "$run_id" --name "$certificate_name" --dir e2e/.artifacts/release-certificate
113114
114115
- name: Validate release certificate
116+
if: inputs.mode == 'publish' || inputs.mode == 'publish-unpublished'
115117
shell: bash
116118
run: |
117119
report="$(find e2e/.artifacts/release-certificate -type f \( -name 'nightly-report.json' -o -name 'pr-report.json' -o -name 'coverage-report.json' \) -print -quit)"

e2e/RELEASE-CERTIFICATION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ pnpm e2e:local:full-report --profile full
2323

2424
## Release gate
2525

26-
release workflow 只下载与 `$GITHUB_SHA` 相同的 `coverage-certificate-$GITHUB_SHA` artifact,然后执行:
26+
只有显式执行 `publish``publish-unpublished` 时,release workflow 才下载与 `$GITHUB_SHA` 相同的 `coverage-certificate-$GITHUB_SHA` artifact,然后执行:
2727

2828
```bash
2929
pnpm e2e:coverage:release-gate --report <coverage-report.json>
3030
```
3131

32-
validator 会重新计算 summary,检查 registry/catalog/toolchain identity、required layer、artifact checksum 和 cosign 签名元数据。没有同 SHA 的认证 artifact、没有 local-required 证据或签名校验失败时,`repo release ci` 不会执行。
32+
validator 会重新计算 summary,检查 registry/catalog/toolchain identity、required layer、artifact checksum 和 cosign 签名元数据。显式发布模式没有同 SHA 的认证 artifact、没有 local-required 证据或签名校验失败时,`repo release ci` 不会执行。默认 `auto``prepare` 模式跳过该门禁,可正常创建 release PR
3333

3434
认证 artifact 必须来自仓库变量 `RELEASE_CERTIFICATE_RUN_ID` 指定的已完成成功 workflow run。Release 不会自动选择 nightly run:hosted nightly 当前只上传诊断 artifact,且在发布启动时可能仍处于运行状态,自动选择会造成竞态并可能把诊断报告误当认证证书。生成本地/自托管认证报告后,应将上传该 artifact 的 workflow run ID 写入 `RELEASE_CERTIFICATE_RUN_ID`,并确保其 head SHA 等于发布 commit。
3535

packages/weapp-tailwindcss/test/ci/workflows.test.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,14 @@ describe('ci workflows', () => {
594594
expect(source).not.toContain('NODE_AUTH_TOKEN:')
595595
})
596596

597-
it('requires an explicit same-commit release certificate run', () => {
598-
const { source } = readWorkflow('release.yml')
597+
it('requires a certificate only for explicit release publishing', () => {
598+
const { source, workflow } = readWorkflow('release.yml')
599+
const releaseSteps: Array<Record<string, any>> = workflow.jobs.release.steps
600+
const downloadStep = releaseSteps.find(step => step.name === 'Download same-commit coverage certificate')
601+
const validateStep = releaseSteps.find(step => step.name === 'Validate release certificate')
599602

603+
expect(downloadStep.if).toBe("inputs.mode == 'publish' || inputs.mode == 'publish-unpublished'")
604+
expect(validateStep.if).toBe("inputs.mode == 'publish' || inputs.mode == 'publish-unpublished'")
600605
expect(source).toContain('RELEASE_CERTIFICATE_RUN_ID: ${{ vars.RELEASE_CERTIFICATE_RUN_ID }}')
601606
expect(source).toContain('Release certificate is not configured')
602607
expect(source).toContain('gh run view "$run_id" --json headSha,status,conclusion')
@@ -653,6 +658,26 @@ describe('ci workflows', () => {
653658
})).toBe(true)
654659
})
655660

661+
it('grants the PR benchmark reporter permission to publish pull request comments', () => {
662+
const { source, workflow } = readWorkflow('benchmark-pr-report.yml')
663+
const commentStep = workflow.jobs.publish.steps.find((step: Record<string, unknown>) => {
664+
return step.name === 'Update PR comment'
665+
})
666+
667+
expect(workflow.permissions).toMatchObject({
668+
actions: 'read',
669+
contents: 'read',
670+
'pull-requests': 'write',
671+
})
672+
expect(workflow.permissions.issues).toBeUndefined()
673+
expect(commentStep).toMatchObject({
674+
uses: 'actions/github-script@v7',
675+
})
676+
expect(String(commentStep.if)).toContain("steps.report.outcome == 'success'")
677+
expect(commentStep['continue-on-error']).not.toBe(true)
678+
expect(source).toContain('github.rest.issues.createComment')
679+
})
680+
656681
it('delegates the complete package lifecycle to repoctl', () => {
657682
const { source, workflow } = readWorkflow('release.yml')
658683
const { workflow: releaseGateWorkflow } = readWorkflow('release-gate.yml')

0 commit comments

Comments
 (0)