@mark1russell7/conventions 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1351,6 +1351,20 @@ function childKeys(lines, index) {
1351
1351
  for (let i = index + 1; i < blockEnd(lines, index); i++) if ((lines[i] ?? "").trim() !== "" && indentOf$1(lines[i] ?? "") === indent) keys.push(i);
1352
1352
  return keys;
1353
1353
  }
1354
+ /**
1355
+ * This function applies changes to the lines of `text`, and keeps its line ends. The changes go from the end to the
1356
+ * start, so each index stays correct. At one index, a splice that removes lines goes first, so it removes only the old
1357
+ * lines. Then the inserts go in, the later one first, so they keep their order.
1358
+ */
1359
+ function applySplices(text, splices) {
1360
+ const eol = text.includes("\r\n") ? "\r\n" : "\n";
1361
+ const out = text.split(/\r?\n/);
1362
+ for (const item of splices.map((value, order) => ({
1363
+ ...value,
1364
+ order
1365
+ })).sort((a, b) => b.at - a.at || b.remove - a.remove || b.order - a.order)) out.splice(item.at, item.remove, ...item.insert);
1366
+ return out.join(eol);
1367
+ }
1354
1368
  /** This function gives the text of a block scalar (`|`, `|-`, `>`, `>-`) under the line `index`. */
1355
1369
  function scalar(lines, index, style) {
1356
1370
  const body = lines.slice(index + 1, blockEnd(lines, index));
@@ -1492,10 +1506,15 @@ function readWorkflow(file, text) {
1492
1506
  // src/rules/main-runs-finish.ts
1493
1507
  /**
1494
1508
  * The rule `main-runs-finish`: a workflow that starts on `push` or on `workflow_call` does not cancel a run in progress.
1495
- * Only the run of a pull request is cancelled by a newer push.
1509
+ * Only the run of a pull request is cancelled by a newer push. Each commit of main has its own concurrency group, because
1510
+ * GitHub keeps only the newest run that waits in a group.
1496
1511
  */
1497
1512
  /** The value of `cancel-in-progress` that cancels only the run of a pull request. */
1498
1513
  const PULL_REQUEST_ONLY = "${{ github.event_name == 'pull_request' }}";
1514
+ /** The end of a concurrency group: a pull request has one group, and each other run has the group of its commit. */
1515
+ const OWN_GROUP = "${{ github.event_name == 'pull_request' && github.ref || github.sha }}";
1516
+ /** The end of a concurrency group that one run of main can share with the next run. */
1517
+ const SHARED_GROUP = "${{ github.ref }}";
1499
1518
  /** This function tells if the workflow starts on the event: `on: <event>`, `on: [<event>, ...]` or a key `<event>` under `on`. */
1500
1519
  function startsOn(lines, event) {
1501
1520
  const on = lines.findIndex((line) => indentOf$1(line) === 0 && keyValue(line, "on") !== void 0);
@@ -1520,18 +1539,26 @@ function runsOnMain(lines) {
1520
1539
  }
1521
1540
  const mainRunsFinish = {
1522
1541
  id: "main-runs-finish",
1523
- title: "A workflow that starts on push or on workflow_call does not cancel a run in progress. A newer push cancels only the run of a pull request.",
1542
+ title: "A workflow that starts on push or on workflow_call does not cancel a run in progress, and each commit of main has its own concurrency group. A newer push cancels only the run of a pull request.",
1524
1543
  reason: "On 2026-11-03 the next merge cancelled the CI run of a commit on main, so the main check of that commit had no result. A shared concurrency group also cancelled a bench run on main, and its claim had no measurement. The CI workflow of the template had `cancel-in-progress: true`, and each repository copied it. A called workflow gets the event of its caller, so a `true` in a workflow that starts on `workflow_call` cancels the run of main too (packing, time-gate.yml, 2026-11-03).",
1525
- fix: `Set \`cancel-in-progress: ${PULL_REQUEST_ONLY}\`. A newer run of main then waits for the older run, and GitHub keeps only the newest run that waits.`,
1526
- sources: [{
1527
- repo: "fleet",
1528
- rule: "main-runs-finish",
1529
- doc: "docs/STRATEGY.md (2026-11-03, a run of main ends)"
1530
- }, {
1531
- repo: "algebra",
1532
- rule: "main-check",
1533
- doc: "the A2 and A5 results (2026-11-03): a cancelled main run, and a cancelled bench run"
1534
- }],
1544
+ fix: `Set \`cancel-in-progress: ${PULL_REQUEST_ONLY}\`, and end the concurrency group with \`${OWN_GROUP}\`. In one group, GitHub cancels a run that waits when a newer run comes, whatever \`cancel-in-progress\` says.`,
1545
+ sources: [
1546
+ {
1547
+ repo: "fleet",
1548
+ rule: "main-runs-finish",
1549
+ doc: "docs/STRATEGY.md (2026-11-03, a run of main ends)"
1550
+ },
1551
+ {
1552
+ repo: "client",
1553
+ rule: "release",
1554
+ doc: "the release of 0.47.0 (2026-11-03): four waiting CI runs of main were cancelled, so the version commit had no result"
1555
+ },
1556
+ {
1557
+ repo: "algebra",
1558
+ rule: "main-check",
1559
+ doc: "the A2 and A5 results (2026-11-03): a cancelled main run, and a cancelled bench run"
1560
+ }
1561
+ ],
1535
1562
  options: {},
1536
1563
  check(context) {
1537
1564
  const files = context.gitFiles();
@@ -1550,6 +1577,20 @@ const mainRunsFinish = {
1550
1577
  if (!runsOnMain(lines)) continue;
1551
1578
  pushed += 1;
1552
1579
  lines.forEach((line, index) => {
1580
+ if (keyValue(line, "group")?.includes(SHARED_GROUP) === true) {
1581
+ const original = text.split(/\r?\n/)[index] ?? line;
1582
+ breaks.push({
1583
+ file,
1584
+ line: index + 1,
1585
+ message: `${file} starts on push or on workflow_call, and its concurrency group ends with the ref. Runs of main share the group, so a newer push cancels a run that waits, and that commit gets no result.`,
1586
+ edits: [{
1587
+ file,
1588
+ before: text,
1589
+ after: replaceLine(text, index + 1, [original.replace(SHARED_GROUP, () => OWN_GROUP)])
1590
+ }]
1591
+ });
1592
+ return;
1593
+ }
1553
1594
  if (keyValue(line, "cancel-in-progress") !== "true") return;
1554
1595
  const original = text.split(/\r?\n/)[index] ?? line;
1555
1596
  const after = replaceLine(text, index + 1, [original.replace(/cancel-in-progress:\s*["']?true["']?/, () => `cancel-in-progress: ${PULL_REQUEST_ONLY}`)]);
@@ -1642,8 +1683,6 @@ const ifValue = (expression) => {
1642
1683
  * person must convert the workflow.
1643
1684
  */
1644
1685
  function convertGate(text, file, commit = ACTIONS_COMMIT) {
1645
- const eol = text.includes("\r\n") ? "\r\n" : "\n";
1646
- const original = text.split(/\r?\n/);
1647
1686
  const lines = workflowLines(text);
1648
1687
  const top = (key) => lines.findIndex((line) => indentOf$1(line) === 0 && keyValue(line, key) !== void 0);
1649
1688
  const on = top("on");
@@ -1762,7 +1801,7 @@ function convertGate(text, file, commit = ACTIONS_COMMIT) {
1762
1801
  const grouped = top("concurrency") >= 0;
1763
1802
  const group = (id) => grouped ? [] : [
1764
1803
  `${job}concurrency:`,
1765
- `${job}${unit}group: \${{ github.workflow }}-${id}-\${{ github.ref }}`,
1804
+ `${job}${unit}group: \${{ github.workflow }}-${id}-${OWN_GROUP}`,
1766
1805
  `${job}${unit}cancel-in-progress: ${PULL_REQUEST_ONLY}`
1767
1806
  ];
1768
1807
  const changes = [
@@ -1811,12 +1850,7 @@ function convertGate(text, file, commit = ACTIONS_COMMIT) {
1811
1850
  remove: 0,
1812
1851
  insert: summary
1813
1852
  });
1814
- const out = [...original];
1815
- for (const item of splices.map((value, order) => ({
1816
- ...value,
1817
- order
1818
- })).sort((a, b) => b.at - a.at || b.remove - a.remove || b.order - a.order)) out.splice(item.at, item.remove, ...item.insert);
1819
- return { text: out.join(eol) };
1853
+ return { text: applySplices(text, splices) };
1820
1854
  }
1821
1855
  const gateTrigger = {
1822
1856
  id: "gate-trigger",
@@ -8265,6 +8299,404 @@ const pinnedGitDeps = {
8265
8299
  return breaks;
8266
8300
  }
8267
8301
  };
8302
+ // src/rules/push-main-only.ts
8303
+ /**
8304
+ * The rule `push-main-only`: a workflow that starts on `push` and on `pull_request` limits `push` to the default branch.
8305
+ * It also has `workflow_dispatch`. Then a commit of a branch with an open pull request starts one run, not two. A person
8306
+ * can still start a run on a branch with no pull request.
8307
+ */
8308
+ /** The file of the release flow. A person changes it, with the rule `release-files`, so the fix does not write it. */
8309
+ const RELEASE_FILE = "release.yml";
8310
+ /** The patterns that match each branch. */
8311
+ const EACH_BRANCH = /* @__PURE__ */ new Set(["*", "**"]);
8312
+ /** A key of a block, in the quoted forms too. */
8313
+ const KEY = /^\s*(?:"([^"]*)"|'([^']*)'|([^\s:]+))\s*:(\s.*)?$/;
8314
+ /** A value with no filters: `{}`, `~` or `null`. */
8315
+ const NO_FILTERS = /^(\{\s*\}|~|null)$/;
8316
+ /** A text that shows that a workflow reads the tag of a run. */
8317
+ const READS_TAGS = /refs\/tags|ref_type/i;
8318
+ /** A workflow of the repository that a job calls. */
8319
+ const LOCAL_CALL = /uses:\s*["']?\.\/(\.github\/workflows\/[^\s"'@]+)/g;
8320
+ /** A text that names a branch: `refs/heads/<branch>`, or `ref_name == '<branch>'`. */
8321
+ const NAMED_BRANCH = /refs\/heads\/([\w./-]+)|ref_name\s*[!=]=\s*["']([^"']+)["']/gi;
8322
+ /** This function tells if the brackets of a flow value are closed. */
8323
+ function closed(text) {
8324
+ let depth = 0;
8325
+ let quote = "";
8326
+ for (const char of text) if (quote !== "") {
8327
+ if (char === quote) quote = "";
8328
+ } else if (char === "\"" || char === "'") quote = char;
8329
+ else if (char === "[" || char === "{") depth += 1;
8330
+ else if (char === "]" || char === "}") depth -= 1;
8331
+ return depth <= 0;
8332
+ }
8333
+ /** This function gives the whole text of a flow value that starts on the line `index`, and the index after its last line. */
8334
+ function flowValue(lines, index, value) {
8335
+ let text = value;
8336
+ let end = index + 1;
8337
+ while (!closed(text) && end < lines.length) {
8338
+ text += ` ${valueOf$1(lines[end] ?? "")}`;
8339
+ end += 1;
8340
+ }
8341
+ return {
8342
+ text,
8343
+ end
8344
+ };
8345
+ }
8346
+ /** This function splits the text in the outer brackets of a flow value, at each comma of the first level. */
8347
+ function flowParts(text) {
8348
+ const parts = [];
8349
+ let depth = 0;
8350
+ let quote = "";
8351
+ let part = "";
8352
+ for (const char of text.slice(1, -1)) {
8353
+ if (quote !== "") {
8354
+ if (char === quote) quote = "";
8355
+ } else if (char === "\"" || char === "'") quote = char;
8356
+ else if (char === "[" || char === "{") depth += 1;
8357
+ else if (char === "]" || char === "}") depth -= 1;
8358
+ else if (char === "," && depth === 0) {
8359
+ parts.push(part);
8360
+ part = "";
8361
+ continue;
8362
+ }
8363
+ part += char;
8364
+ }
8365
+ parts.push(part);
8366
+ return parts.map((item) => item.trim()).filter((item) => item !== "");
8367
+ }
8368
+ /** This function gives the key and the value of an entry of a flow map. */
8369
+ function flowEntry(part) {
8370
+ const colon = part.search(/:(\s|$)/);
8371
+ return colon < 0 ? {
8372
+ key: valueOf$1(part),
8373
+ value: ""
8374
+ } : {
8375
+ key: valueOf$1(part.slice(0, colon)),
8376
+ value: valueOf$1(part.slice(colon + 1))
8377
+ };
8378
+ }
8379
+ /** This function gives the key and the value of a line of a block. */
8380
+ function keyOf(line) {
8381
+ const found = KEY.exec(line);
8382
+ if (found === null) return void 0;
8383
+ return {
8384
+ key: found[1] ?? found[2] ?? found[3] ?? "",
8385
+ value: valueOf$1(found[4] ?? "")
8386
+ };
8387
+ }
8388
+ const isItem = (line) => line.trimStart().startsWith("- ");
8389
+ /** This function reads the triggers of a workflow, in each form of `on`. */
8390
+ function readTriggers(lines) {
8391
+ const on = lines.findIndex((line) => indentOf$1(line) === 0 && keyValue(line, "on") !== void 0);
8392
+ if (on < 0) return void 0;
8393
+ const value = keyValue(lines[on] ?? "", "on") ?? "";
8394
+ if (value === "") {
8395
+ const next = lines.findIndex((line, index) => index > on && line.trim() !== "");
8396
+ const first = lines[next] ?? "";
8397
+ if (next >= 0 && isItem(first)) {
8398
+ const list = [];
8399
+ for (let index = next; index < lines.length; index++) {
8400
+ const line = lines[index] ?? "";
8401
+ if (line.trim() === "") continue;
8402
+ if (!isItem(line) || indentOf$1(line) !== indentOf$1(first)) break;
8403
+ list.push({
8404
+ name: valueOf$1(line.trimStart().slice(2)),
8405
+ at: index,
8406
+ value: ""
8407
+ });
8408
+ }
8409
+ return {
8410
+ form: "items",
8411
+ on,
8412
+ end: on + 1,
8413
+ list
8414
+ };
8415
+ }
8416
+ const list = childKeys(lines, on).flatMap((at) => {
8417
+ const entry = keyOf(lines[at] ?? "");
8418
+ return entry === void 0 ? [] : [{
8419
+ name: entry.key,
8420
+ at,
8421
+ value: entry.value
8422
+ }];
8423
+ });
8424
+ return {
8425
+ form: "keys",
8426
+ on,
8427
+ end: on + 1,
8428
+ list
8429
+ };
8430
+ }
8431
+ const flow = flowValue(lines, on, value);
8432
+ if (value.startsWith("[")) return {
8433
+ form: "flow",
8434
+ on,
8435
+ end: flow.end,
8436
+ list: flowParts(flow.text).map((part) => ({
8437
+ name: valueOf$1(part),
8438
+ at: on,
8439
+ value: ""
8440
+ }))
8441
+ };
8442
+ if (value.startsWith("{")) {
8443
+ const list = flowParts(flow.text).map((part) => {
8444
+ const entry = flowEntry(part);
8445
+ return {
8446
+ name: entry.key,
8447
+ at: on,
8448
+ value: entry.value
8449
+ };
8450
+ });
8451
+ return {
8452
+ form: "map",
8453
+ on,
8454
+ end: flow.end,
8455
+ list
8456
+ };
8457
+ }
8458
+ return {
8459
+ form: "flow",
8460
+ on,
8461
+ end: on + 1,
8462
+ list: [{
8463
+ name: value,
8464
+ at: on,
8465
+ value: ""
8466
+ }]
8467
+ };
8468
+ }
8469
+ /** This function gives the filters of a trigger, in the block form and in the flow form. */
8470
+ function filtersOf(lines, trigger) {
8471
+ if (trigger.value.startsWith("{")) {
8472
+ const flow = flowValue(lines, trigger.at, trigger.value);
8473
+ return flowParts(flow.text).map((part) => {
8474
+ const entry = flowEntry(part);
8475
+ const items = entry.value.startsWith("[") ? flowParts(entry.value).map(valueOf$1) : [entry.value];
8476
+ return {
8477
+ key: entry.key,
8478
+ at: trigger.at,
8479
+ end: flow.end,
8480
+ items
8481
+ };
8482
+ });
8483
+ }
8484
+ if (trigger.value !== "") return [];
8485
+ return childKeys(lines, trigger.at).flatMap((at) => {
8486
+ const entry = keyOf(lines[at] ?? "");
8487
+ if (entry === void 0) return [];
8488
+ const list = listItems(lines, at, entry.value);
8489
+ if (list !== void 0) return [{
8490
+ key: entry.key,
8491
+ at,
8492
+ end: list.end,
8493
+ items: list.items
8494
+ }];
8495
+ return [{
8496
+ key: entry.key,
8497
+ at,
8498
+ end: at + 1,
8499
+ items: /^[[{]/.test(entry.value) ? void 0 : [entry.value]
8500
+ }];
8501
+ });
8502
+ }
8503
+ /** This function gives the break of a workflow, or undefined when the rule leaves the workflow alone. */
8504
+ function findBreak(text, facts) {
8505
+ const lines = workflowLines(text);
8506
+ const triggers = readTriggers(lines);
8507
+ if (triggers === void 0) return void 0;
8508
+ const push = triggers.list.find((trigger) => trigger.name === "push");
8509
+ const pull = triggers.list.find((trigger) => trigger.name === "pull_request");
8510
+ if (push === void 0 || pull === void 0) return void 0;
8511
+ const types = filtersOf(lines, pull).find((filter) => filter.key === "types");
8512
+ if (types?.items !== void 0 && !types.items.includes("synchronize")) return void 0;
8513
+ const filters = filtersOf(lines, push);
8514
+ const has = (key) => filters.find((filter) => filter.key === key);
8515
+ const branches = has("branches");
8516
+ if (branches === void 0 && has("branches-ignore") === void 0 && (has("tags") ?? has("tags-ignore")) !== void 0) return void 0;
8517
+ const allowed = [facts.branch, ...facts.more];
8518
+ const items = branches?.items;
8519
+ const wide = items === void 0 || items.length === 0 || !items.every((item) => allowed.includes(item));
8520
+ const noDispatch = !triggers.list.some((trigger) => trigger.name === "workflow_dispatch");
8521
+ if (!wide && !noDispatch) return void 0;
8522
+ return {
8523
+ lines,
8524
+ triggers,
8525
+ push,
8526
+ filters,
8527
+ wide,
8528
+ noDispatch
8529
+ };
8530
+ }
8531
+ /** This function gives the reason why a person must change the workflow, or undefined when the fix can write it. */
8532
+ function refusal(file, text, finding, facts) {
8533
+ if (file.slice(file.lastIndexOf("/") + 1) === RELEASE_FILE) return `${RELEASE_FILE} belongs to the release flow`;
8534
+ const { triggers, filters, wide } = finding;
8535
+ if (triggers.form === "map") return "on has the flow form of a map";
8536
+ if (triggers.end > triggers.on + 1) return "on is a flow value of more than one line";
8537
+ if (!wide) return void 0;
8538
+ if (filters.some((filter) => filter.key === "branches-ignore")) return "on.push has branches-ignore, and only a person can tell which ignored branches stay";
8539
+ const allowed = [facts.branch, ...facts.more];
8540
+ const branches = filters.find((filter) => filter.key === "branches");
8541
+ if (branches !== void 0) {
8542
+ if (branches.items === void 0) return "the rule cannot read on.push.branches";
8543
+ if (branches.at === finding.push.at) return "on.push.branches is in the flow form of a map";
8544
+ const named = branches.items.filter((item) => !EACH_BRANCH.has(item) && !allowed.includes(item));
8545
+ if (named.length > 0 || branches.items.length === 0) return `on.push.branches names ${named.join(", ") || "no branch"}. Remove them, or add them to the option branches of the rule`;
8546
+ }
8547
+ const others = [...`${workflowLines(text).join("\n")}\n${facts.called(text)}`.matchAll(NAMED_BRANCH)].map((match) => match[1] ?? match[2] ?? "").filter((name) => !allowed.includes(name));
8548
+ if (others.length > 0) return `the workflow reads the branch ${[...new Set(others)].join(", ")}, so a limit on push can stop a job`;
8549
+ }
8550
+ /** This function gives a comment at the end of a line, with its space, or an empty text. */
8551
+ const commentOf = (line) => /\s+#.*$/.exec(line)?.[0] ?? "";
8552
+ /** This function writes the fix of a break: the new filter of `push`, and `workflow_dispatch`. Each other line stays. */
8553
+ function convert(text, file, finding, facts) {
8554
+ const { lines, triggers, push, filters, wide, noDispatch } = finding;
8555
+ const original = text.split(/\r?\n/);
8556
+ const branches = filters.find((filter) => filter.key === "branches");
8557
+ const tags = wide && branches === void 0 && READS_TAGS.test(`${workflowLines(text).join("\n")}\n${facts.called(text)}`);
8558
+ const limit = `branches: [${facts.branch}]`;
8559
+ const limits = (pad) => wide ? [`${pad}${limit}`, ...tags ? [`${pad}tags: ["**"]`] : []] : [];
8560
+ const name = file.slice(file.lastIndexOf("/") + 1);
8561
+ const dispatch = (pad) => noDispatch ? [`${pad}# A person starts a run on a branch with no pull request: gh workflow run ${name} --ref <branch>`, `${pad}workflow_dispatch:`] : [];
8562
+ const splices = [];
8563
+ if (triggers.form === "flow") {
8564
+ const line = original[triggers.on] ?? "";
8565
+ const body = triggers.list.flatMap((trigger) => [` ${trigger.name}:`, ...trigger === push ? limits(" ") : []]);
8566
+ splices.push({
8567
+ at: triggers.on,
8568
+ remove: 1,
8569
+ insert: [
8570
+ `${line.slice(0, line.indexOf(":") + 1)}${commentOf(line)}`,
8571
+ ...body,
8572
+ ...dispatch(" ")
8573
+ ]
8574
+ });
8575
+ } else if (triggers.form === "items") {
8576
+ const pad = " ".repeat(Math.max(indentOf$1(lines[triggers.list[0]?.at ?? 0] ?? ""), 2));
8577
+ for (const trigger of triggers.list) splices.push({
8578
+ at: trigger.at,
8579
+ remove: 1,
8580
+ insert: [`${pad}${trigger.name}:${commentOf(original[trigger.at] ?? "")}`, ...trigger === push ? limits(`${pad} `) : []]
8581
+ });
8582
+ splices.push({
8583
+ at: (triggers.list.at(-1)?.at ?? triggers.on) + 1,
8584
+ remove: 0,
8585
+ insert: dispatch(pad)
8586
+ });
8587
+ } else {
8588
+ const line = original[push.at] ?? "";
8589
+ const pad = indentOf$1(lines[push.at] ?? "");
8590
+ const inner = " ".repeat(childIndent(lines, push.at) ?? pad + Math.max(pad - indentOf$1(lines[triggers.on] ?? ""), 2));
8591
+ if (wide && branches !== void 0) splices.push({
8592
+ at: branches.at,
8593
+ remove: branches.end - branches.at,
8594
+ insert: [`${" ".repeat(indentOf$1(lines[branches.at] ?? ""))}${limit}${commentOf(original[branches.at] ?? "")}`]
8595
+ });
8596
+ else if (wide && push.value !== "" && !NO_FILTERS.test(push.value)) {
8597
+ const added = [limit, ...tags ? ["tags: [\"**\"]"] : []].join(", ");
8598
+ splices.push({
8599
+ at: push.at,
8600
+ remove: 1,
8601
+ insert: [line.replace(/\{\s*/, () => `{ ${added}, `)]
8602
+ });
8603
+ } else if (wide) splices.push({
8604
+ at: push.at,
8605
+ remove: 1,
8606
+ insert: [line.replace(/:\s+(\{\s*\}|~|null)/, ":"), ...limits(inner)]
8607
+ });
8608
+ const last = triggers.list.at(-1)?.at ?? triggers.on;
8609
+ let end = blockEnd(lines, last);
8610
+ while (end > last + 1 && (lines[end - 1] ?? "").trim() === "") end -= 1;
8611
+ splices.push({
8612
+ at: end,
8613
+ remove: 0,
8614
+ insert: dispatch(" ".repeat(pad))
8615
+ });
8616
+ }
8617
+ return applySplices(text, splices);
8618
+ }
8619
+ /** This function gives the default branch: the event file of GitHub Actions, the `HEAD` of the remote, or else `main`. */
8620
+ function defaultBranch(context) {
8621
+ const file = context.env["GITHUB_EVENT_PATH"];
8622
+ if (file !== void 0 && file !== "") try {
8623
+ const branch = JSON.parse(readFileSync(file, "utf8")).repository?.default_branch;
8624
+ if (typeof branch === "string" && branch !== "") return branch;
8625
+ } catch {}
8626
+ const head = context.git([
8627
+ "symbolic-ref",
8628
+ "--quiet",
8629
+ "--short",
8630
+ "refs/remotes/origin/HEAD"
8631
+ ])?.trim();
8632
+ return head === void 0 || head === "" ? "main" : head.replace(/^origin\//, "");
8633
+ }
8634
+ const pushMainOnly = {
8635
+ id: "push-main-only",
8636
+ title: "A workflow that starts on push and on pull_request limits push to the default branch with branches, and has workflow_dispatch.",
8637
+ reason: "A commit on a branch with an open pull request starts such a workflow two times: one run for push and one run for pull_request. On 2026-11-04 the CI queue held about 263 jobs, and a rough estimate puts about 65 of them in such second runs. The run for pull_request gives the required checks, so the run for push adds nothing. With workflow_dispatch, a person can still start a run on a branch with no pull request.",
8638
+ fix: "Add `branches: [<default branch>]` under `on.push`, and add `workflow_dispatch:` under `on` (CI.md, \"One run for each commit\"). A push with only a tag filter, or a pull request trigger with no `synchronize`, is not a break. For a long-lived branch, add the branch to the option branches.",
8639
+ sources: [
8640
+ {
8641
+ repo: "template",
8642
+ rule: "push-main-only",
8643
+ doc: ".github/workflows/security.yml (push has branches: [main], and the file has workflow_dispatch)"
8644
+ },
8645
+ {
8646
+ repo: "crawler",
8647
+ rule: "push-main-only",
8648
+ doc: ".github/workflows/ci.yml (push has branches: [main], and the file has workflow_dispatch)"
8649
+ },
8650
+ {
8651
+ repo: "systems",
8652
+ rule: "push-main-only",
8653
+ doc: ".github/workflows/process.yml (push has branches: [main], and the file has workflow_dispatch)"
8654
+ }
8655
+ ],
8656
+ options: { branches: {
8657
+ type: "strings",
8658
+ default: [],
8659
+ description: "More branches that `on.push.branches` can name, for example a long-lived release branch."
8660
+ } },
8661
+ check(context, options) {
8662
+ const files = context.gitFiles();
8663
+ if (files === void 0) return { skipped: "the root is not in a git repository" };
8664
+ const workflows = files.filter((path) => WORKFLOW$1.test(path)).sort(byCode);
8665
+ if (workflows.length === 0) return { skipped: "the repository has no workflow" };
8666
+ const read = (file) => {
8667
+ try {
8668
+ return readFileSync(join(context.root, file), "utf8");
8669
+ } catch {
8670
+ return "";
8671
+ }
8672
+ };
8673
+ const facts = {
8674
+ branch: defaultBranch(context),
8675
+ more: Array.isArray(options["branches"]) ? options["branches"] : [],
8676
+ called: (text) => [...text.matchAll(LOCAL_CALL)].map((match) => workflowLines(read(match[1] ?? "")).join("\n")).join("\n")
8677
+ };
8678
+ const breaks = [];
8679
+ for (const file of workflows) {
8680
+ const text = read(file);
8681
+ const finding = findBreak(text, facts);
8682
+ if (finding === void 0) continue;
8683
+ const parts = [...finding.wide ? [`push starts on more branches than ${[facts.branch, ...facts.more].join(", ")}, so a commit of a pull request starts it two times`] : [], ...finding.noDispatch ? ["it has no workflow_dispatch, so a person cannot start a run on a branch"] : []];
8684
+ const reason = refusal(file, text, finding, facts);
8685
+ const after = reason === void 0 ? convert(text, file, finding, facts) : void 0;
8686
+ breaks.push({
8687
+ file,
8688
+ line: finding.push.at + 1,
8689
+ message: `${file} starts on push and on pull_request: ${parts.join(", and ")}.`,
8690
+ ...after !== void 0 && findBreak(after, facts) === void 0 ? { edits: [{
8691
+ file,
8692
+ before: text,
8693
+ after
8694
+ }] } : { fix: `A person must change it, because ${reason ?? "the fix does not end the break"}. ${pushMainOnly.fix}` }
8695
+ });
8696
+ }
8697
+ return breaks;
8698
+ }
8699
+ };
8268
8700
  // src/rules/release-files.ts
8269
8701
  /**
8270
8702
  * The rule `release-files`: a pull request changes a file of the release flow only with a reason
@@ -8699,7 +9131,7 @@ function jobsOf(lines) {
8699
9131
  const hasTopGroup = (lines) => lines.some((line) => indentOf$1(line) === 0 && line.startsWith("concurrency:"));
8700
9132
  /**
8701
9133
  * This function gives the edit that adds a concurrency group at the top of a workflow, before `jobs:`. A new run of a pull
8702
- * request stops the old run. A run of another event waits for the old run, so that no release or scheduled run stops.
9134
+ * request stops the old run. A run of another event has the group of its commit, so that no release or scheduled run stops.
8703
9135
  */
8704
9136
  function groupEdits(file, text, lines) {
8705
9137
  const jobs = lines.findIndex((line) => indentOf$1(line) === 0 && line.startsWith("jobs:"));
@@ -8708,7 +9140,7 @@ function groupEdits(file, text, lines) {
8708
9140
  const original = text.split(/\r?\n/)[jobs] ?? "jobs:";
8709
9141
  const group = [
8710
9142
  "concurrency:",
8711
- pad + "group: ${{ github.workflow }}-${{ github.ref }}",
9143
+ pad + "group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }}",
8712
9144
  pad + "cancel-in-progress: ${{ github.event_name == 'pull_request' }}",
8713
9145
  "",
8714
9146
  original
@@ -8836,7 +9268,7 @@ const runnerBudget = {
8836
9268
  id: "runner-budget",
8837
9269
  title: "Each matrix has a max-parallel of 3 or less, each workflow has a concurrency group, and each schedule starts at the minute that the repository and the file give.",
8838
9270
  reason: "All repositories of the account share 40 runners, and heavy work keeps at most 28 of them. On 2026-10-30, a matrix with no max-parallel and the sync pull requests of about 20 repositories filled 39 of the 40 runners, with 88 jobs in the queue. Each repository copied the weekly scan at `23 5 * * 1`, so all scans started at the same minute. A workflow with no concurrency group starts a new run on each push, and the old runs keep their runners.",
8839
- fix: "Add `max-parallel: 3` (or less) under `strategy`. Add a concurrency group at the top of the workflow (`concurrency: { group: <name>-${{ github.ref }}, cancel-in-progress: ${{ github.event_name == 'pull_request' }} }`), or in each job. Change the minute of each `cron` to the minute that the message gives; the hour and the days stay.",
9271
+ fix: "Add `max-parallel: 3` (or less) under `strategy`. Add a concurrency group at the top of the workflow (`concurrency: { group: <name>-${{ github.event_name == 'pull_request' && github.ref || github.sha }}, cancel-in-progress: ${{ github.event_name == 'pull_request' }} }`), or in each job. Change the minute of each `cron` to the minute that the message gives; the hour and the days stay.",
8840
9272
  sources: [{
8841
9273
  repo: "fleet",
8842
9274
  rule: "runner-slots",
@@ -10475,6 +10907,7 @@ const RULES = [
10475
10907
  roadmapParses,
10476
10908
  runnerBudget,
10477
10909
  mainRunsFinish,
10910
+ pushMainOnly,
10478
10911
  gateTrigger,
10479
10912
  homePackage,
10480
10913
  licenseFile,
@@ -10882,6 +11315,6 @@ function runMap(args, io) {
10882
11315
  else io.stdout(mapText(found));
10883
11316
  return 0;
10884
11317
  }
10885
- export { REAL_COMPARE as $, pathsOf as A, cleanPath as At, roadmapParses as B, runGit as Bt, configsOfScript as C, gateTrigger as Ct, hasTests as D, STRICT_OPTIONS as Dt, testsRequired as E, readWorkflow as Et, sharedDocsRule as F, lineOf as Ft, pinnedGitDeps as G, workspaceGlobs as Gt, releaseFiles as H, globFolders as Ht, repositoryOfRemote as I, matchesAny as It, pagesSite as J, PAGES_WORKFLOWS as K, defaultOptions as Kt, runnerBudget as L, parseJsonc as Lt, HOME_TIMEOUT_MS as M, hasFile as Mt, blockHash as N, inFolder as Nt, tsconfigTest as O, cuePreset as Ot, githubFetch as P, keyLine as Pt, noBuildOutput as Q, scheduleMinute as R, readJsonc as Rt, typedScripts as S, convertGate as St, typedFiles as T, summaryName as Tt, isGitSpecifier as U, globToRegExp as Ut, requiredScripts as V, specifiersOf as Vt, isPinned as W, packageFolders as Wt, HOME_PATTERNS as X, DEFAULT_ALLOWED as Y, noLocalPaths as Z, unreleasedChange as _, mapText as _t, listRules as a, licenseFileOf as at, TRAIN_SCOPES as b, HOME_EXPORTS as bt, runCli as c, declaredName as ct, RULES as d, repoOf as dt, hasImportMetaMain as et, workspaceProtocol as f, signaturesOf as ft, npmLookup as g, mapMarkdown as gt, UNSHIPPED_FILES as h, findHomes as ht, formatResult as i, licenseFile as it, sourceMain as j, codePackages as jt, isSourcePath as k, DEPENDENCY_FIELDS as kt, runFix as l, homePackage as lt, SHIPPED_FIELDS as m, MAP_RULE as mt, annotations as n, LICENSE_TEXTS as nt, readConfig as o, mitText as ot, NPM_REGISTRY as p, HOMES as pt, pagesCalls as q, parseConfig as qt, createContext as r, authorOf as rt, runChecks as s, repositoryIsPublic as st, USAGE as t, mainCheck as tt, summaryMarkdown as u, messageOf as ut, unreleasedChangeRule as v, mergeHomes as vt, scriptsOf as w, prPathFilters as wt, trustPolicy as x, ACTIONS_COMMIT as xt, IGNORE_AFTER as y, readOverlay as yt, roadmapOfLine as z, replaceLine as zt };
11318
+ export { noBuildOutput as $, pathsOf as A, DEPENDENCY_FIELDS as At, roadmapParses as B, replaceLine as Bt, configsOfScript as C, convertGate as Ct, hasTests as D, readWorkflow as Dt, testsRequired as E, summaryName as Et, sharedDocsRule as F, keyLine as Ft, isPinned as G, packageFolders as Gt, releaseFiles as H, specifiersOf as Ht, repositoryOfRemote as I, lineOf as It, pagesCalls as J, parseConfig as Jt, pinnedGitDeps as K, workspaceGlobs as Kt, runnerBudget as L, matchesAny as Lt, HOME_TIMEOUT_MS as M, codePackages as Mt, blockHash as N, hasFile as Nt, tsconfigTest as O, STRICT_OPTIONS as Ot, githubFetch as P, inFolder as Pt, noLocalPaths as Q, scheduleMinute as R, parseJsonc as Rt, typedScripts as S, ACTIONS_COMMIT as St, typedFiles as T, prPathFilters as Tt, pushMainOnly as U, globFolders as Ut, requiredScripts as V, runGit as Vt, isGitSpecifier as W, globToRegExp as Wt, DEFAULT_ALLOWED as X, pagesSite as Y, HOME_PATTERNS as Z, unreleasedChange as _, mapMarkdown as _t, listRules as a, licenseFile as at, TRAIN_SCOPES as b, readOverlay as bt, runCli as c, repositoryIsPublic as ct, RULES as d, messageOf as dt, REAL_COMPARE as et, workspaceProtocol as f, repoOf as ft, npmLookup as g, findHomes as gt, UNSHIPPED_FILES as h, MAP_RULE as ht, formatResult as i, authorOf as it, sourceMain as j, cleanPath as jt, isSourcePath as k, cuePreset as kt, runFix as l, declaredName as lt, SHIPPED_FIELDS as m, HOMES as mt, annotations as n, mainCheck as nt, readConfig as o, licenseFileOf as ot, NPM_REGISTRY as p, signaturesOf as pt, PAGES_WORKFLOWS as q, defaultOptions as qt, createContext as r, LICENSE_TEXTS as rt, runChecks as s, mitText as st, USAGE as t, hasImportMetaMain as tt, summaryMarkdown as u, homePackage as ut, unreleasedChangeRule as v, mapText as vt, scriptsOf as w, gateTrigger as wt, trustPolicy as x, HOME_EXPORTS as xt, IGNORE_AFTER as y, mergeHomes as yt, roadmapOfLine as z, readJsonc as zt };
10886
11319
 
10887
- //# sourceMappingURL=run-DrDMwxGF.js.map
11320
+ //# sourceMappingURL=run-DRAlJPKd.js.map