Unverified 提交 41a46a9b authored 作者: Will Chen's avatar Will Chen 提交者: GitHub

Fix playwright comment workflow (#2041)

<!-- CURSOR_SUMMARY --> > [!NOTE] > Improves reliability of the Playwright comment workflow by deriving the PR from the `workflow_run` commit and gating execution accordingly. > > - Add `actions/github-script` step to look up PR via `listPullRequestsAssociatedWithCommit` and expose `steps.pr.outputs.number` > - Conditionally skip all subsequent steps when no PR is found; remove job-level `if` > - Checkout base branch using `workflow_run.base_ref`; update `PR_NUMBER` to use the step output > - Use `types: [completed]` for `workflow_run` and remove `if-no-artifact-found` options on artifact downloads > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 581369150b84ba4bc6a680f309f78afd399d93ca. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Fixes the Playwright report comment workflow so it reliably posts to the correct PR, including from forks. Skips cleanly when the CI run isn’t tied to a PR. - **Bug Fixes** - Resolve PR by commit SHA via listPullRequestsAssociatedWithCommit; works when workflow_run.pull_requests is empty (e.g., forks). - Add early exit and guard all steps behind a PR check to avoid running on push/scheduled builds. - Checkout base_ref and pass the resolved PR number to the summary comment step. <sup>Written for commit 581369150b84ba4bc6a680f309f78afd399d93ca. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. -->
上级 1b2a2746
...@@ -3,8 +3,7 @@ name: Playwright Report Comment ...@@ -3,8 +3,7 @@ name: Playwright Report Comment
on: on:
workflow_run: workflow_run:
workflows: ["CI"] workflows: ["CI"]
types: types: [completed]
- completed
permissions: permissions:
contents: read contents: read
...@@ -14,20 +13,54 @@ permissions: ...@@ -14,20 +13,54 @@ permissions:
jobs: jobs:
comment: comment:
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.pull_requests[0].number }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repository - name: Find PR number for this CI run (works for forks)
id: pr
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const sha = context.payload.workflow_run.head_sha;
core.info(`Looking up PR for sha=${sha}`);
// Lists PRs associated with this commit (reliable when workflow_run.pull_requests is empty)
const res = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner,
repo,
commit_sha: sha,
});
const pr = res.data?.[0];
if (!pr) {
core.info("No PR associated with this workflow_run. Likely a push/schedule run.");
core.setOutput("number", "");
return;
}
core.info(`Found PR #${pr.number}`);
core.setOutput("number", String(pr.number));
- name: Stop if no PR found
if: ${{ steps.pr.outputs.number == '' }}
run: echo "No PR found for this CI run; skipping."
- name: Checkout repository (base branch)
if: ${{ steps.pr.outputs.number != '' }}
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
# base_ref is typically the target branch (e.g., main) and is safe to fetch
ref: ${{ github.event.workflow_run.base_ref }} ref: ${{ github.event.workflow_run.base_ref }}
- name: Setup Node.js - name: Setup Node.js
if: ${{ steps.pr.outputs.number != '' }}
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
node-version: lts/* node-version: lts/*
- name: Download Playwright HTML report - name: Download Playwright HTML report
if: ${{ steps.pr.outputs.number != '' }}
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
name: html-report--attempt-${{ github.event.workflow_run.run_attempt }} name: html-report--attempt-${{ github.event.workflow_run.run_attempt }}
...@@ -35,9 +68,9 @@ jobs: ...@@ -35,9 +68,9 @@ jobs:
github-token: ${{ github.token }} github-token: ${{ github.token }}
repository: ${{ github.event.workflow_run.repository.full_name }} repository: ${{ github.event.workflow_run.repository.full_name }}
run-id: ${{ github.event.workflow_run.id }} run-id: ${{ github.event.workflow_run.id }}
if-no-artifact-found: warn
- name: Download blob reports - name: Download blob reports
if: ${{ steps.pr.outputs.number != '' }}
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
path: all-blob-reports path: all-blob-reports
...@@ -46,12 +79,12 @@ jobs: ...@@ -46,12 +79,12 @@ jobs:
github-token: ${{ github.token }} github-token: ${{ github.token }}
repository: ${{ github.event.workflow_run.repository.full_name }} repository: ${{ github.event.workflow_run.repository.full_name }}
run-id: ${{ github.event.workflow_run.id }} run-id: ${{ github.event.workflow_run.id }}
if-no-artifact-found: warn
- name: Generate Playwright summary comment - name: Generate Playwright summary comment
if: ${{ steps.pr.outputs.number != '' }}
uses: actions/github-script@v7 uses: actions/github-script@v7
env: env:
PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }} PR_NUMBER: ${{ steps.pr.outputs.number }}
PLAYWRIGHT_RUN_ID: ${{ github.event.workflow_run.id }} PLAYWRIGHT_RUN_ID: ${{ github.event.workflow_run.id }}
with: with:
script: | script: |
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论