Skip to content

CI: use pull_request_target so review-checklist runs on fork PRs#6435

Open
brtnfld wants to merge 15 commits into
HDFGroup:developfrom
brtnfld:fix/review-checklist-fork-prs
Open

CI: use pull_request_target so review-checklist runs on fork PRs#6435
brtnfld wants to merge 15 commits into
HDFGroup:developfrom
brtnfld:fix/review-checklist-fork-prs

Conversation

@brtnfld

@brtnfld brtnfld commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Switches the review-checklist workflow trigger from pull_request to pull_request_target so it runs on PRs that originate from forks (e.g. contributor forks targeting HDFGroup/hdf5:develop)
  • Removes the now-redundant cross-repo guard (head.repo.full_name == github.repository) — pull_request_target only fires for PRs targeting this repo's branches
  • Updates the job comment to explain the security posture: GitHub always executes the workflow from the base repo with a full write token; the fork's code is never checked out or executed

Why

pull_request events from forks receive a read-only GITHUB_TOKEN. The job condition evaluated to false for all fork PRs, so no checklist comment was posted and no reviewers were assigned. Reported against #6434.

pull_request events from forks receive a read-only GITHUB_TOKEN and
are skipped by the job condition, so no checklist comment is posted
and no reviewers are assigned.  Switching to pull_request_target fixes
this: GitHub always executes the workflow from the base repo
(HDFGroup/hdf5) with a full write token, regardless of whether the PR
comes from a fork.  The fork's code is never checked out or executed.

The cross-repo guard (head.repo.full_name == github.repository) is
removed since it is no longer needed — pull_request_target only fires
for PRs targeting this repo's branches.
brtnfld added 4 commits June 8, 2026 11:19
…rk PRs

pull_request_target carries a GitHub security warning because it grants
write access to the privileged workflow at trigger time, which is risky
if the checkout is ever changed to use the fork's head ref.

Replace it with the recommended two-workflow pattern:
- review-checklist-gather.yml fires on pull_request (read-only, safe
  for forks) and uploads the PR number as a short-lived artifact.
- review-checklist.yml fires on workflow_run when the gather job
  completes, downloads the artifact for the PR number, then posts the
  checklist comment and assigns reviewers with a full write token.
  It never executes any code from the fork.

The script gains a prNumber parameter so the main workflow can supply
the PR number it read from the artifact; falls back to the event
payload for pull_request_review triggers.
…un context

In the workflow_run path context.payload.pull_request is undefined, so
reading .user.login from it throws a TypeError. Use prData.user.login
instead — prData is already fetched from the API at step 5.

Also remove the stale comment saying fork PRs require pull_request_target;
they are now handled via the two-workflow pattern.
The workflow_run approach adds a second hop before the checklist posts
and introduced a context.payload.pull_request crash in the gather path.
pull_request_target is simpler and equally safe here: GitHub always
executes the workflow from HDFGroup/hdf5:develop with a full write
token — the fork's code is never checked out or executed.
zizmor is a static analyser that catches security issues specific to
GitHub Actions: pull_request_target misuse, expression injection,
unpinned action SHAs, and overly broad permissions.

Runs on push to develop and on PRs that touch .github/, uploads SARIF
to the Security tab (free for public repos via Advanced Security), and
annotates PR diffs inline with any findings.
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

Comment thread .github/workflows/zizmor.yml Fixed
Replace zizmorcore/zizmor-action (third-party) with a direct pip install
of zizmor==1.25.2. SARIF output is still uploaded to the Security tab via
github/codeql-action/upload-sarif (first-party). The only actions used
are from actions/ and github/, both trusted.
Comment thread .github/workflows/zizmor.yml Fixed
@brtnfld brtnfld requested a review from jhendersonHDF June 8, 2026 21:40
jhendersonHDF
jhendersonHDF previously approved these changes Jun 8, 2026
brtnfld added 4 commits June 8, 2026 17:03
…t finding

- zizmor.yml: pin zizmor wheel to its SHA256 hash via --require-hashes so
  the install is fully reproducible and passes zizmor's unpinned-tools audit
- review-checklist.yml: add zizmor: ignore[pull-request-target] comment so
  zizmor does not flag its own host workflow; document why the usage is safe
- actions/checkout:          v4.2.2 → v5.0.1  (node20 → node24)
- actions/github-script:     v7.0.1 → v8.0.0  (node20 → node24)
- github/codeql-action:      v3.36.2 → v4.36.2 (node20 → node24; v3 deprecated Dec 2026)
jhendersonHDF
jhendersonHDF previously approved these changes Jun 8, 2026
GitHub only grants a read-only GITHUB_TOKEN for pull_request_review events
when the PR originates from a fork, so the comment post fails with 403.
Restrict the review trigger to same-repo PRs; pull_request_target already
handles fork PRs for the open/sync/reopen case with a full write token.
pull_request_review grants only a read-only token for fork PRs, causing
a 403 when posting the checklist comment. Fix with a two-path design:

- pull_request_target handles open/sync/reopen for all PRs (full token,
  immediate)
- A new gather workflow (review-checklist-gather.yml) fires on
  pull_request_review, saves the PR number as an artifact, and exits.
  The main workflow then fires via workflow_run with a full write token.

The script gains prNumber and isReview parameters. isReview suppresses
reviewer assignment (which only applies on open/sync/reopen). prAuthor
is sourced from prData.user.login since context.payload.pull_request is
not populated in the workflow_run context.
Comment thread .github/workflows/review-checklist-gather.yml Fixed
…orkflow

pull_request_review triggers a fork workflow approval gate for first-time
contributors, which blocks every PR. There is no pull_request_review_target
equivalent in GitHub Actions.

Instead, rely on pull_request_target (opened/synchronize/reopened) only.
Approval boxes are still evaluated correctly: computeApprovals() re-reads
all existing reviews on every push, so boxes auto-check the next time the
author pushes after a reviewer approves.

Also restores the simpler script signature (no prNumber/isReview params)
and sources prAuthor from prData.user.login which works in all contexts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To be triaged

Development

Successfully merging this pull request may close these issues.

3 participants