Skip to content

ci: label pull requests from workflow_run instead of pull_request_target - #7482

Merged
andygrove merged 1 commit into
apache:mainfrom
andygrove:andygrove/7475-pr-labeler-workflow-run
Nov 7, 2026
Merged

andygrove merged 1 commit into
apache:mainfrom
andygrove:andygrove/7475-pr-labeler-workflow-run

Conversation

@andygrove

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #7475.

Rationale for this change

GitHub blocks the pull_request_target trigger by default on public repositories from December 2, 2026, with brownouts before then, and ASF infra is disabling it for ASF repositories. label_prs.yml runs on that trigger, so pull requests would stop getting their type and path labels. Upstream tracking issue: apache/datafusion#26406.

What changes are included in this PR?

The labeler is split into two workflows:

  • label_prs_trigger.yml (new) runs on pull_request for opened, synchronize and reopened, the same events as before. It has permissions: {} and does nothing. It exists only so its completion can start the labeler.
  • label_prs.yml now runs on workflow_run when the trigger workflow completes. workflow_run always runs the default branch's copy of the file with the repository token, so it can write labels on fork pull requests. It:
    • finds the open pull request whose head repository, branch and commit match the triggering run. Nothing produced by the PR's run is read, so there is no artifact to trust. If the head has moved on, the run for the newer push labels the PR instead.
    • applies the type label from the title with the existing dev/ci/pr-type-label.mjs, read from the default branch checkout. Dependabot PRs are still skipped.
    • applies the path labels with actions/labeler@v7, passing the PR through its pr-number input.
    • keeps the per-PR concurrency group with cancellation, now keyed on the head repository and branch because workflow_run doesn't carry the PR number. It also adds a repository guard so the workflow doesn't run in forks.

The standalone workflow table in .github/workflows/README.md is updated to match.

Behavior changes:

  • PRs targeting a release branch now get type and path rules from main instead of from their base branch.
  • Under pull_request, a first-time contributor's trigger run may wait for maintainer approval, depending on the repository's Actions settings. Their PR may not be labelled until a maintainer approves the run.

branch-1.2 still runs label_prs.yml on pull_request_target. After this merges, it needs a backport that adds label_prs_trigger.yml there and removes its label_prs.yml. A pull_request run uses the workflow files from the PR's base branch, but the labeler on main picks up the trigger run from any branch.

How are these changes tested?

  • python3 dev/ci/check-ci-config.py and actionlint pass on both workflows.
  • node --test dev/ci/pr-type-label.test.mjs still passes. The title logic is unchanged.
  • I checked the PR lookup with the same REST call on an open fork PR: GET /pulls?state=open&head=<owner>:<branch> returns docs: apply the style guide's "native" rules to timezones.md #7477 with the expected head SHA and repository.
  • workflow_run only fires from the default branch's copy of a workflow, so this can't be tested end to end until it merges. After merge, opening or pushing to any PR should start Label pull requests trigger and then Label pull requests, and the PR should get its labels.

GitHub blocks pull_request_target on public repositories from December 2,
2026, and ASF is disabling it. A no-op pull_request workflow now starts the
labeler, which runs on workflow_run from the default branch, finds the pull
request from the run's head repository, branch and commit, and applies the
type and path labels through the API.
@github-actions github-actions Bot added build Build environment enhancement New feature or request area:ci CI/CD, GitHub Actions, build tooling labels Nov 4, 2026

@manuzhang manuzhang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Do we need back-port to branch-1.1 as well?

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @andygrove. The privileged job reads nothing the PR's run produced, and only an API-derived PR number reaches with:, so the security model looks right to me. On @manuzhang's question: upstream/branch-1.1 also still has label_prs.yml on pull_request_target, so it needs the same backport as branch-1.2.

pull_request_target:
types: [opened, synchronize, reopened]
workflow_run:
workflows: [Label pull requests trigger]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing checks that this entry stays equal to the name: of label_prs_trigger.yml. If either is renamed, labeling stops without a failing check. dev/ci/check-ci-config.py already guards the same pairing for the fork bridge (BRIDGE_WORKFLOW against the name of ci.yml, plus the repository guard). Could it cover this pair too?

# when it completes, label_prs.yml runs from the default branch through workflow_run and writes
# the labels. Kept separate from Comet CI so labels arrive in seconds rather than after CI.
on:
pull_request:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The events reference says pull_request workflows do not run while the PR has a merge conflict, and pull_request_target ones do. A PR opened with a conflict now gets no labels until a push after the conflict is resolved. Could this go in the list of behavior changes, or be covered by a schedule sweep like the one in fork_ci_status.yml?

@andygrove
andygrove added this pull request to the merge queue Nov 7, 2026
Merged via the queue into apache:main with commit a872f69 Nov 7, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI/CD, GitHub Actions, build tooling build Build environment enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate workflows away from pull_request_target

3 participants