Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

ci: a re-run never cancels the run for a pull request's current head (#10445)

Cindy Zhang56a9df762533
diff --git a/.github/scripts/pr-concurrency.test.mjs b/.github/scripts/pr-concurrency.test.mjs
index 1a16be7309..c45281f43b 100644
--- a/.github/scripts/pr-concurrency.test.mjs
+++ b/.github/scripts/pr-concurrency.test.mjs
@@ -81,3 +81,39 @@ describe('pull-request workflow concurrency', () => {
},
);
});
+
+describe('ci.yml re-runs', () => {
+ const ci = workflows.find(({name}) => name === 'ci.yml').value;
+ const format = (text, ...args) =>
+ text.replace(/\{(\d+)\}/g, (_, i) => String(args[i]));
+ // The group GitHub computes for a run.
+ const groupFor = github => {
+ const [, expression] = /^ci-\$\{\{\s*(.*?)\s*\}\}$/.exec(
+ ci.concurrency.group,
+ );
+ return `ci-${Function('github', 'format', `return (${expression});`)(github, format)}`;
+ };
+ // GitHub reads a missing property as null; the stubs carry both objects.
+ const pull = attempt => ({
+ event_name: 'pull_request',
+ event: {pull_request: {number: 7}, merge_group: {}},
+ run_attempt: attempt,
+ run_id: 99,
+ });
+
+ it("gives a re-run a group of its own, so it never cancels the run for the pull request's current head", () => {
+ // A push's run shares the pull request's group, so a newer push cancels it.
+ expect(groupFor(pull('1'))).toBe('ci-7');
+ // Any attempt after the first runs apart from it.
+ expect(groupFor(pull('2'))).toBe('ci-7-rerun-99');
+ expect(groupFor(pull('3'))).toBe('ci-7-rerun-99');
+ expect(
+ groupFor({
+ event_name: 'merge_group',
+ event: {pull_request: {}, merge_group: {head_sha: 'abc'}},
+ run_attempt: '1',
+ run_id: 5,
+ }),
+ ).toBe('ci-abc');
+ });
+});
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 051ce168ff..a161db9ee0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -88,8 +88,11 @@ permissions: {}
# A release-check runs its browser owners in wide shards that all start at
# once, so a full check takes minutes; pull requests keep their narrower legs
# (spec:AST-030 FR23, DEC-17).
+# A pull request's newer push cancels its older run. A re-run takes a group of
+# its own, so re-running an older head never cancels the run for the pull
+# request's current head.
concurrency:
- group: "ci-${{ github.event.pull_request.number || github.event.merge_group.head_sha || (github.event_name == 'workflow_dispatch' && github.triggering_actor == 'github-actions[bot]' && 'main-heavy-lanes') || github.run_id }}"
+ group: "ci-${{ github.event.pull_request.number && (github.run_attempt == '1' && github.event.pull_request.number || format('{0}-rerun-{1}', github.event.pull_request.number, github.run_id)) || github.event.merge_group.head_sha || (github.event_name == 'workflow_dispatch' && github.triggering_actor == 'github-actions[bot]' && 'main-heavy-lanes') || github.run_id }}"
cancel-in-progress: ${{ github.event_name != 'workflow_dispatch' || (inputs.recheck && github.triggering_actor == 'github-actions[bot]') }}
jobs: