Repository navigation
ci: key workflow concurrency groups on pull request number - #7829
adityavaish wants to merge 4 commits into
Conversation
Switch concurrency.group in codeql.yml, miri.yml, and pr_title_check.yml from github.head_ref to github.event.pull_request.number (preserving the github.sha fallback for non-PR events), matching ci.yml so pull requests from different forks sharing a branch name cannot cancel each other's runs. Add check_concurrency_groups() to dev/ci/check-ci-config.py to pin this invariant across all workflows, including same-branch cross-fork PRs, case-only branch variants, same-PR superseding, ci_label.yml -> ci.yml label runs, workflow_run fork isolation, and non-PR commit fallbacks. Resolves apache#7315 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
comphead
left a comment
There was a problem hiding this comment.
The three workflow edits are correct. For codeql.yml's push and schedule and for pr_title_check.yml's pull_request events the fallback to github.sha behaves as before, because github.head_ref is also empty on push and schedule. The 330 line checker is far larger than the bug needs, and it carries drive-by refactors of shared helpers. A grep-level rule would guard the same regression.
|
|
||
| concurrency: | ||
| group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }} | ||
| group: ${{ github.repository }}-${{ github.event.pull_request.number || github.sha }}-${{ github.workflow }} |
There was a problem hiding this comment.
miri.yml triggers only on schedule and workflow_dispatch (see its on: block), and nothing calls it through workflow_call. github.event.pull_request.number is never set there, and github.head_ref was already empty, so this edit changes no group at runtime. Keeping it for consistency is fine, but the PR description and the issue should not count it as a fix.
There was a problem hiding this comment.
Good catch—kept the miri.yml change for consistency and updated the PR description to note that miri.yml only triggers on schedule/workflow_dispatch and is a consistency edit rather than a runtime fix.
Auto-replied by the GitHub Copilot app
| } | ||
|
|
||
|
|
||
| def check_concurrency_groups(): |
There was a problem hiding this comment.
The bug is that a concurrency group names github.head_ref. A check that scans .github/workflows/*.y*ml for a group: line containing github.head_ref is about 15 lines and fails on exactly the three files this PR fixes. check_concurrency_groups instead adds a hand-rolled YAML block parser (concurrency_blocks, about 60 lines), simulates pull request, workflow_run, push, merge_group, schedule and workflow_dispatch contexts, and re-derives the case-only and cross-fork properties by evaluating expressions. The script already holds a concurrency: regex check in check_fork_runs (line 1767) that could host the simple rule. I would replace the new function with the short scan and drop the helpers it needs.
There was a problem hiding this comment.
Simplified in 5c7929e3a—replaced the parser and context simulation with a concise check_concurrency_groups() scan (~35 lines) that flags any workflow- or job-level concurrency: block referencing github.head_ref (handling inline scalar/flow and multiline group: values while ignoring comments). Confirmed it catches the three pre-fix files and passes on the updated workflows.
Auto-replied by the GitHub Copilot app
| # ci_label.yml calls ci.yml on `labeled`; ci.yml owns the concurrency group | ||
| # and shares the caller's pull_request context. | ||
| if LABEL_WORKFLOW.exists(): |
There was a problem hiding this comment.
This block re-tests ci.yml's group against ci_label.yml runs and asserts that ci_label.yml has no concurrency. ci.yml is not touched by this PR (its group was fixed in #7311), so this is new coverage for a different property and belongs in its own change if it is wanted.
There was a problem hiding this comment.
Removed in 5c7929e3a so this PR stays focused strictly on preventing github.head_ref in concurrency groups.
Auto-replied by the GitHub Copilot app
| """Return {event: its `types:` list, or None} from ci.yml's top-level `on:`.""" | ||
| lines = (WORKFLOWS / "ci.yml").read_text(encoding="utf-8").splitlines() | ||
| event_key = re.compile(r"^ ([a-z_]+):\s*$") | ||
| def workflow_triggers(path): |
There was a problem hiding this comment.
workflow_triggers (generalizing ci_triggers), the _unquote_yaml_scalar change to workflow_name, and the evaluate_condition to evaluate_expression split exist only to serve the new checker. If the checker shrinks to the short scan from my other comment, these edits to shared helpers are not needed, and the PR then does what its title says with no change to existing checks.
There was a problem hiding this comment.
Reverted all shared-helper edits in 5c7929e3a (ci_triggers, workflow_name, and evaluate_condition are now unchanged from main).
Auto-replied by the GitHub Copilot app
comphead
left a comment
There was a problem hiding this comment.
thanks @adityavaish, the PR goes into right direction, please check some nits!
sunchao
left a comment
There was a problem hiding this comment.
The new keys separate same-named branches across forks and keep successive runs on one PR together. The CI configuration checks passed locally. I found one case the new regression check misses.
Automated review by Codex.
| "github.head_ref": head_ref, | ||
| "github.ref": f"refs/pull/{number}/merge", | ||
| "github.ref_name": f"{number}/merge", | ||
| "github.sha": sha, |
There was a problem hiding this comment.
I appended -${{ github.event.pull_request.head.sha }} to the CodeQL group and python3 dev/ci/check-ci-config.py still passed. pr_context varies github.sha but leaves the PR head SHA unset, so the evaluator substitutes an empty string on both pushes. In Actions the suffix changes and the previous run keeps running. If we keep this simulation, can we give successive pushes distinct head SHAs and check that this mutation fails?
There was a problem hiding this comment.
Thanks for catching that—per @comphead's feedback, 5c7929e3a replaced the context simulation with a direct github.head_ref concurrency-group scan, so pr_context has been removed.
Auto-replied by the GitHub Copilot app
Replace the expression-evaluating concurrency checker and shared-helper refactors in dev/ci/check-ci-config.py with a concise scan that rejects github.head_ref in any workflow concurrency group. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Thanks @comphead and @sunchao for the review! Addressed all comments in 5c7929e (simplified \check_concurrency_groups()\ to a concise \github.head_ref\ scan, reverted unrelated helper edits, removed the \ci_label.yml\ check, and clarified \miri.yml\ in the PR description). @comphead could you please approve the workflow runs on this updated commit (and queue for merge once CI is green)? |
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
5c7929e3a447b9db68d3866bf96c4e89cf32a94ccodeql.yml,pr_title_check.yml, and (for consistency)miri.yml, simplifiescheck_concurrency_groups()to a focusedgithub.head_refscan with zero edits to shared helpers, and passes all 19check-ci-config.pychecks,test-docs-permissions.py, andactionlint --shellcheck=off.↓ Live GitHub Actions runs on Linux and
check_local_ci_config()under native Linux bash are pending CI approval.codeql.ymlandpr_title_check.ymlstill keyed PRconcurrency.groupongithub.head_ref(andmiri.ymlcarried the same template on non-PR triggers), whileci.ymlwas already updated in #7311.github.head_refindev/ci/check-ci-config.py.Which issue does this PR close?
Closes #7315.
Rationale for this change
codeql.ymlandpr_title_check.ymlstill keyedconcurrency.groupongithub.head_ref || github.sha. Becausegithub.head_refis only the branch name without the fork repository or PR number, two open pull requests from different forks sharing a branch name (such asmainorpatch-1) collide in the same concurrency group and cancel each other's runs. (ci.ymlwas already switched togithub.event.pull_request.numberin #7311;miri.ymlonly triggers onschedule/workflow_dispatchso its matching edit is for consistency rather than a runtime fix.)What changes are included in this PR?
concurrency.groupin.github/workflows/codeql.ymland.github/workflows/pr_title_check.ymlfromgithub.head_ref || github.shatogithub.event.pull_request.number || github.sha(and updated.github/workflows/miri.ymlto match for consistency).check_concurrency_groups()scan indev/ci/check-ci-config.pythat checks.github/workflows/*.y*mland fails if any workflow- or job-levelconcurrency:block referencesgithub.head_ref.How are these changes tested?
check_concurrency_groups()fails on the pre-fixcodeql.yml,miri.yml, andpr_title_check.ymlfrommain(3 failures) and passes on the updated files.check_concurrency_groups()(inline scalar/flowconcurrency:, multilinegroup: >-, job-levelconcurrency:, ignoring comments andrun:blocks).dev/ci/check-ci-config.pypass (bash -n dev/local-ci.shpassed separately;check_local_ci_config()has a pre-existing Windows backslash quirk).python dev/ci/test-docs-permissions.py— passed.actionlint --shellcheck=off(v1.7.12) across all workflows — passed (exit code 0).