Repository navigation
ci: migrate pull_request_target workflows to workflow_run #26683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
comphead
wants to merge
1
commit into
apache:main
Choose a base branch
from
comphead:ci-pr-target-workflow-run
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+140
−32
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| # Signal for the workflows that need a write token on a pull request. | ||
| # | ||
| # ASF infra policy disables `pull_request_target` | ||
| # (https://infra.apache.org/github-actions-policy.html), and GitHub is adding a | ||
| # default policy that blocks it. The `workflow_run` workflows below run from the | ||
| # default branch with a write token and never check out or run pull request | ||
| # code. They trigger on the `requested` event of this workflow, which GitHub | ||
| # sends at once for every run, even for a first-time contributor whose run waits | ||
| # for approval: | ||
| # - labeler.yml | ||
| # - fork_ci_status.yml | ||
| name: Pull request signal | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, synchronize] | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| signal: | ||
| name: Signal pull request update | ||
| runs-on: ubuntu-slim | ||
| steps: | ||
| - run: echo "This run triggers the workflow_run workflows that handle the pull request." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A head branch and SHA do not uniquely identify a PR: the same branch can target main and a release branch. pulls.list defaults to newest first, so find() selects the newer PR for every signal and the older PR never receives labels.
The equivalent lookup in fork_ci_status.yml should filter to main before selecting, otherwise it can select the release PR and skip the main notification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, confirmed. A fork can have open PRs to
mainand to a release branch from the same branch, and both matchhead+head_sha.pulls.listreturns newest first, sofind()always picks the newer PR.There is one more piece: both PRs share the new concurrency group (head repo + branch) with
cancel-in-progress: true, so the two signal runs from one push cancel each other. Fixingfind()alone is not enough. The run that survives has to handle every matching PR.Suggested changes:
labeler.yml: label every matching PR.actions/labelerv7 accepts several numbers inpr-number, one per line:fork_ci_status.yml: only PRs tomainget the mirrored check, so filter on the base in the lookup:const { data } = await github.rest.pulls.list({ ...upstream, state: 'open', head: `${run.head_repository.owner.login}:${run.head_branch}`, + base: 'main', });With that, whichever signal run survives the cancellation finds the
mainPR.test_fork_ci_status.cjs: add a case with two open PRs from the same head branch, one tomainand one to a release branch, where the release PR is newer. TheRust (fork)check should still be created for themainPR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to draft PR to your PR if you prefer.