@mark1russell7/conventions 0.6.0 → 0.8.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.
- package/README.md +5 -1
- package/build/cli.js +1 -1
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/{run-BYTCunT5.js → run-d-5ceKnT.js} +291 -15
- package/build/run-d-5ceKnT.js.map +1 -0
- package/package.json +1 -1
- package/build/run-BYTCunT5.js.map +0 -1
package/README.md
CHANGED
|
@@ -37,7 +37,8 @@ The rules come from the invariants audit of 2026-10-26 (strategy item s38). The
|
|
|
37
37
|
| `typed-scripts` | Git keeps no JavaScript source (`.js`, `.mjs`, `.cjs`, `.jsx`, or a file with a `#!` line of `node`) and no shell script (`.sh`, `.bash`, `.zsh`, `.ps1`, or a `#!` line of a shell) of more than one line of code. Each script is TypeScript, which Node 22.18 and later starts directly. A file that must stay (generated output, vendored code, a configuration that a tool reads only as JavaScript) goes in `ignore` with its reason, so the list of exceptions can only get shorter. | fleet `typed-everything` (STRATEGY.md, direction 15). |
|
|
38
38
|
| `typed-files` | Each TypeScript file that git keeps (`.ts`, `.tsx`, `.mts`, `.cts`, not `.d.ts`) is in the program of a tsconfig that a `typecheck` script names: the tests, the e2e specs, the scripts, the benches and the configs too. The rule reads the configs of each `tsc`, `tsgo` or `vue-tsc` (`-p`, `--project`, `-b`, or `tsconfig.json`) and of `svelte-check --tsconfig`, follows their `references`, and lists the files with `tsc --listFilesOnly`. A file that a covered file imports is covered. A config that does not exist, and a repository where no typecheck names a config, are a break. | fleet `fail-closed` (STRATEGY.md, 2026-10-30). |
|
|
39
39
|
| `tests-required` | No test runner passes when it finds no test: no `passWithNoTests: true` in a config of vitest, vite, jest or Playwright, and no `--passWithNoTests` in `package.json`. With the option, a broken include pattern turns the test gate green with no test run. | fleet `fail-closed` (STRATEGY.md, 2026-10-30). |
|
|
40
|
-
| `roadmap-parses` | Each roadmap that a workflow gives to the Status page (a `roadmap:` key) parses as `@mark1russell7/site-pages` reads it. The rule uses the parser of site-pages. Thus a pull request finds a bad row, and the Pages job on `main` does not stop on it. | fleet `fail-closed` (STRATEGY.md, 2026-10-30). |
|
|
40
|
+
| `roadmap-parses` | Each call of the Pages workflow of the template (`reusable-pages.yml`) gives a `roadmap`, or `site-pages: false`. Without it, the Status page shows no item of the plan. Each roadmap that a workflow gives to the Status page (a `roadmap:` key) parses as `@mark1russell7/site-pages` reads it. The rule uses the parser of site-pages. Thus a pull request finds a bad row, and the Pages job on `main` does not stop on it. | fleet `fail-closed` (STRATEGY.md, 2026-10-30). |
|
|
41
|
+
| `runner-budget` | All repositories of the account share 40 runners. Each `strategy` with a `matrix` has a `max-parallel` of 3 or less. Each workflow has a concurrency group at the top or in each job. A job that calls a shared workflow of the option `grouped` gets its group from that workflow, and each job of that workflow has a group. The minute of each `cron` comes from a hash of the repository and the file (1 to 59), so the schedules of the repositories do not start together. The repository comes from `GITHUB_REPOSITORY` or from the remote `origin`. | fleet `runner-slots` (STRATEGY.md, 2026-10-30). |
|
|
41
42
|
|
|
42
43
|
The rule `release-files` needs the base of the change. On a pull request, the checkout is a merge commit, and the rule reads its two parents (`fetch-depth` 2 or more). In other runs, give `--base <ref>`. Without a base, the rule shows `skip`.
|
|
43
44
|
|
|
@@ -88,6 +89,9 @@ An unknown rule, an unknown option, or an exception or a changed option without
|
|
|
88
89
|
| `typed-scripts.shellLines` | `1` | The most lines of code of a shell script (a launcher). Empty lines and comments do not count. |
|
|
89
90
|
| `typed-files.configs` | `[]` | More tsconfig files, relative to the root, that CI examines with another command (for example a script that the typecheck starts). |
|
|
90
91
|
| `roadmap-parses.roadmaps` | `[]` | More roadmap files, relative to the root, for a roadmap that no workflow names. |
|
|
92
|
+
| `runner-budget.maxParallel` | `3` | The largest `max-parallel` of a matrix. |
|
|
93
|
+
| `runner-budget.minute` | `true` | When `false`, the rule does not examine the minute of the schedules. |
|
|
94
|
+
| `runner-budget.grouped` | `["reusable-ai-review.yml", "reusable-codex-review.yml"]` | The shared workflows that give a concurrency group in each of their jobs. |
|
|
91
95
|
|
|
92
96
|
## Commands
|
|
93
97
|
|
package/build/cli.js
CHANGED
package/build/index.d.ts
CHANGED
|
@@ -155,6 +155,15 @@ export declare const requiredScripts: Rule;
|
|
|
155
155
|
/** This function gives the value of a `roadmap: <file>` line, or undefined for another line, an empty value or an expression. */
|
|
156
156
|
export declare function roadmapOfLine(line: string): string | undefined;
|
|
157
157
|
export declare const roadmapParses: Rule;
|
|
158
|
+
/**
|
|
159
|
+
* This function gives the minute (1 to 59) of the schedules of a workflow: the FNV-1a hash of the repository and the
|
|
160
|
+
* file. Two repositories with the same workflow thus start at different minutes, and no schedule starts at minute 0,
|
|
161
|
+
* where GitHub has the most load.
|
|
162
|
+
*/
|
|
163
|
+
export declare function scheduleMinute(repository: string, file: string): number;
|
|
164
|
+
/** This function gives `owner/name` from a git remote URL, or undefined for a URL that is not of GitHub. */
|
|
165
|
+
export declare function repositoryOfRemote(url: string): string | undefined;
|
|
166
|
+
export declare const runnerBudget: Rule;
|
|
158
167
|
/** This function gives each path in the value of an entry field (a string, or the strings in an object). */
|
|
159
168
|
export declare function pathsOf(value: unknown): string[];
|
|
160
169
|
/** This function tells if a path is a source file: a file in `src/`, or a TypeScript file that is not a declaration file. */
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/rule.ts","../src/config.ts","../src/rules/cue-preset.ts","../src/rules/no-build-output.ts","../src/rules/no-local-paths.ts","../src/rules/pinned-git-deps.ts","../src/rules/release-files.ts","../src/rules/required-scripts.ts","../src/rules/roadmap-parses.ts","../src/rules/source-main.ts","../src/rules/tests-required.ts","../src/rules/tsconfig-test.ts","../src/rules/typed-files.ts","../src/rules/typed-scripts.ts","../src/rules/workspace-protocol.ts","../src/rules/index.ts","../src/run.ts","../src/workspace.ts"],"mappings":";UASiB;WACN;WACA;WACA;;;UAIM;;WAEN;;WAEA;WACA;;WAEA;;;KAIC;;KAGA,UAAU,SAAS,eAAe;;UAG7B;WACN;WACA,SAAS;WACT;;;KAIC,WAAW,SAAS;;UAGf;;WAEN;;WAEA;;WAEA;;WAEA;WACA,UAAU;;;UAIJ;;WAEN;;WAEA,aAAa;;WAEb,mBAAmB;;WAEnB,KAAK,SAAS;;WAEd;;EAET;;EAEA,IAAI;;;KAIM,uBAAuB;WAAqB;;;UAGvC;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,kBAAkB;;WAElB,SAAS,SAAS,eAAe;EAC1C,MAAM,SAAS,aAAa,SAAS,UAAU;;;qBAIpC;;wBAGG,aAAa,UAAU,UAAU;;wBAOjC,OAAO,cAAc,gBAAgB;;wBAOrC,QAAQ,cAAc,eAAe;;qBAMxC,WAAY,gBAAgB;;qBAG5B,YAAa;;wBAGV,WAAW,cAAc;;;;;;wBASzB,WAAW;;wBA2BX,UAAU;;wBAUV,OAAO,cAAc;;qBAOxB,UAAW,aAAa;;;;;wBAMrB,aAAa,SAAS,KAAK,oDAAoD;;UC9K9E;;WAEN;;WAEA;;WAEA;;WAEA,SAAS;;;UAIH;;WAEN;;WAEA,OAAO,SAAS,eAAe;;;wBAW1B,eAAe,MAAM,OAAO;;;;;;;wBAU5B,YAAY,gBAAgB,gBAAgB,SAAS;;qBCnCxD;qBA2FA,WAAW;qBC/FX,eAAe;;qBCYf;;qBAGA,wBAAwB;qBAOxB,cAAc;;wBCnBX,eAAe;;;;;wBAaf,SAAS,cAAc;qBAqB1B,eAAe;qBCEf,cAAc;qBCrBd,iBAAiB;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/rule.ts","../src/config.ts","../src/rules/cue-preset.ts","../src/rules/no-build-output.ts","../src/rules/no-local-paths.ts","../src/rules/pinned-git-deps.ts","../src/rules/release-files.ts","../src/rules/required-scripts.ts","../src/rules/roadmap-parses.ts","../src/rules/runner-budget.ts","../src/rules/source-main.ts","../src/rules/tests-required.ts","../src/rules/tsconfig-test.ts","../src/rules/typed-files.ts","../src/rules/typed-scripts.ts","../src/rules/workspace-protocol.ts","../src/rules/index.ts","../src/run.ts","../src/workspace.ts"],"mappings":";UASiB;WACN;WACA;WACA;;;UAIM;;WAEN;;WAEA;WACA;;WAEA;;;KAIC;;KAGA,UAAU,SAAS,eAAe;;UAG7B;WACN;WACA,SAAS;WACT;;;KAIC,WAAW,SAAS;;UAGf;;WAEN;;WAEA;;WAEA;;WAEA;WACA,UAAU;;;UAIJ;;WAEN;;WAEA,aAAa;;WAEb,mBAAmB;;WAEnB,KAAK,SAAS;;WAEd;;EAET;;EAEA,IAAI;;;KAIM,uBAAuB;WAAqB;;;UAGvC;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,kBAAkB;;WAElB,SAAS,SAAS,eAAe;EAC1C,MAAM,SAAS,aAAa,SAAS,UAAU;;;qBAIpC;;wBAGG,aAAa,UAAU,UAAU;;wBAOjC,OAAO,cAAc,gBAAgB;;wBAOrC,QAAQ,cAAc,eAAe;;qBAMxC,WAAY,gBAAgB;;qBAG5B,YAAa;;wBAGV,WAAW,cAAc;;;;;;wBASzB,WAAW;;wBA2BX,UAAU;;wBAUV,OAAO,cAAc;;qBAOxB,UAAW,aAAa;;;;;wBAMrB,aAAa,SAAS,KAAK,oDAAoD;;UC9K9E;;WAEN;;WAEA;;WAEA;;WAEA,SAAS;;;UAIH;;WAEN;;WAEA,OAAO,SAAS,eAAe;;;wBAW1B,eAAe,MAAM,OAAO;;;;;;;wBAU5B,YAAY,gBAAgB,gBAAgB,SAAS;;qBCnCxD;qBA2FA,WAAW;qBC/FX,eAAe;;qBCYf;;qBAGA,wBAAwB;qBAOxB,cAAc;;wBCnBX,eAAe;;;;;wBAaf,SAAS,cAAc;qBAqB1B,eAAe;qBCEf,cAAc;qBCrBd,iBAAiB;;wBCqCd,cAAc;qBAajB,eAAe;;;;;;wBCnBZ,eAAe,oBAAoB;;wBAUnC,mBAAmB;qBAqGtB,cAAc;;wBC5JX,QAAQ;;wBAQR,aAAa;qBAKhB,YAAY;qBCVZ,eAAe;;wBCHZ,SAAS,0BAA0B;qBAKtC,cAAc;;wBC4CX,gBAAgB;;;;;wBA4BhB,UAAU,SAAS,SAAS,0BAA0B,cAAc,OAAM;qBA+C7E,YAAY;qBChGZ,cAAc;qBC9Bd,mBAAmB;;qBCYnB,gBAAgB;;UCRZ;WACN;WACA;WACA;;WAEA;WACA,iBAAiB;;WAEjB;;WAEA;;;UAIM;WACN,gBAAgB;;WAEhB;;;UAIM;;WAEN;;WAEA;;WAEA;WACA,MAAM,SAAS;;WAEf,iBAAiB;;;wBAaZ,WAAW,cAAc,iBAAgB,SAAiB;;wBAO1D,cAAc,cAAc,QAAQ,mBAAmB,UAAS,KAAK,gCAAqC;;wBAwB1G,UAAU,SAAS,eAAe;;wBA0ClC,aAAa,QAAQ;;wBA0BrB,gBAAgB,QAAQ;;wBAsBxB,YAAY,QAAQ;;wBAYpB,UAAU,QAAQ,+BAA+B,iBAAgB;;UAkBhE;WACN;WACA,KAAK,SAAS;WACd,SAAS;WACT,SAAS;;;qBAIP;;wBAwBG,OAAO,yBAAyB,IAAI;;;;;;wBCxNpC,aAAa,eAAe;;;;;wBA+C5B,YAAY,cAAc;;;;;;wBA8B1B,eAAe;;;;;;;wBAwCf,eAAe,cAAc"}
|
package/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { M as DEFAULT_ALLOWED, R as DEPENDENCY_FIELDS, N as HOME_PATTERNS, u as RULES, I as STRICT_OPTIONS, t as USAGE, n as annotations, z as cleanPath, B as codePackages, p as configsOfScript, r as createContext, L as cuePreset, et as defaultOptions, i as formatResult, X as globFolders, Z as globToRegExp, V as hasFile, g as hasTests, H as inFolder, k as isGitSpecifier, A as isPinned, y as isSourcePath, U as keyLine, W as lineOf, a as listRules, G as matchesAny, F as noBuildOutput, P as noLocalPaths, Q as packageFolders, tt as parseConfig, K as parseJsonc, b as pathsOf, j as pinnedGitDeps, o as readConfig, q as readJsonc, O as releaseFiles, S as repositoryOfRemote, D as requiredScripts, T as roadmapOfLine, E as roadmapParses, s as runChecks, c as runCli, J as runGit, C as runnerBudget, w as scheduleMinute, m as scriptsOf, x as sourceMain, Y as specifiersOf, l as summaryMarkdown, v as testsRequired, _ as tsconfigTest, h as typedFiles, f as typedScripts, $ as workspaceGlobs, d as workspaceProtocol } from "./run-d-5ceKnT.js";
|
|
@@ -1611,7 +1611,47 @@ if (board) {
|
|
|
1611
1611
|
* The rule `roadmap-parses`: each roadmap that a workflow gives to the Status page parses, on the pull request.
|
|
1612
1612
|
*/
|
|
1613
1613
|
/** A workflow file. */
|
|
1614
|
-
const WORKFLOW = /^\.github\/workflows\/[^/]+\.ya?ml$/;
|
|
1614
|
+
const WORKFLOW$1 = /^\.github\/workflows\/[^/]+\.ya?ml$/;
|
|
1615
|
+
/** This function tells if a line calls the Pages workflow of the template (`uses: ...reusable-pages.yml`). */
|
|
1616
|
+
function callsPages(line) {
|
|
1617
|
+
let text = line.trimStart();
|
|
1618
|
+
if (text.startsWith("- ")) text = text.slice(2).trimStart();
|
|
1619
|
+
if (!text.startsWith("uses:")) return false;
|
|
1620
|
+
const value = text.slice(5).trim();
|
|
1621
|
+
return /(?:^|\/)reusable-pages\.ya?ml(?:@|$|\s)/.test(value);
|
|
1622
|
+
}
|
|
1623
|
+
const indentOf$1 = (line) => line.length - line.trimStart().length;
|
|
1624
|
+
/** This function tells if a line is `site-pages: false`: the site has no Status page. */
|
|
1625
|
+
function noStatusPage(line) {
|
|
1626
|
+
const text = line.trimStart();
|
|
1627
|
+
if (!text.startsWith("site-pages:")) return false;
|
|
1628
|
+
let value = text.slice(11);
|
|
1629
|
+
const comment = value.indexOf(" #");
|
|
1630
|
+
if (comment >= 0) value = value.slice(0, comment);
|
|
1631
|
+
return [
|
|
1632
|
+
"false",
|
|
1633
|
+
"\"false\"",
|
|
1634
|
+
"'false'"
|
|
1635
|
+
].includes(value.trim());
|
|
1636
|
+
}
|
|
1637
|
+
/**
|
|
1638
|
+
* This function gives the line numbers of each call of the Pages workflow that gives no `roadmap` key. The key is in the
|
|
1639
|
+
* job of the call: the lines around it with the same indent or more. A job with `site-pages: false` has no Status page.
|
|
1640
|
+
*/
|
|
1641
|
+
function callsWithoutRoadmap(lines) {
|
|
1642
|
+
const found = [];
|
|
1643
|
+
lines.forEach((line, index) => {
|
|
1644
|
+
if (!callsPages(line)) return;
|
|
1645
|
+
const indent = indentOf$1(line);
|
|
1646
|
+
const inJob = (text) => text.trim() === "" || indentOf$1(text) >= indent;
|
|
1647
|
+
let first = index;
|
|
1648
|
+
while (first > 0 && inJob(lines[first - 1] ?? "")) first -= 1;
|
|
1649
|
+
let last = index;
|
|
1650
|
+
while (last < lines.length - 1 && inJob(lines[last + 1] ?? "")) last += 1;
|
|
1651
|
+
if (!lines.slice(first, last + 1).some((text) => text.trimStart().startsWith("roadmap:") || noStatusPage(text))) found.push(index + 1);
|
|
1652
|
+
});
|
|
1653
|
+
return found;
|
|
1654
|
+
}
|
|
1615
1655
|
/** This function gives the value of a `roadmap: <file>` line, or undefined for another line, an empty value or an expression. */
|
|
1616
1656
|
function roadmapOfLine(line) {
|
|
1617
1657
|
const text = line.trimStart();
|
|
@@ -1627,9 +1667,9 @@ function roadmapOfLine(line) {
|
|
|
1627
1667
|
}
|
|
1628
1668
|
const roadmapParses = {
|
|
1629
1669
|
id: "roadmap-parses",
|
|
1630
|
-
title: "Each roadmap that a workflow gives to the Status page (the input `roadmap`) parses as site-pages reads it.",
|
|
1631
|
-
reason: "Only the Pages job on main reads the roadmap. A pull request with a bad table row passes each check, and then the build of the site stops and the site stays stale. On 2026-10-30, one repository had 3 red Pages runs in a row because of one row with 2 cells under a header with 4.",
|
|
1632
|
-
fix: "Correct the row or the heading that the message names. Each table row has one cell for each column of its header, and the file has a table with an ID column and a Status column, or a heading \"### `id`: Title\".",
|
|
1670
|
+
title: "Each call of the Pages workflow gives a roadmap, and each roadmap that a workflow gives to the Status page (the input `roadmap`) parses as site-pages reads it.",
|
|
1671
|
+
reason: "Only the Pages job on main reads the roadmap. A pull request with a bad table row passes each check, and then the build of the site stops and the site stays stale. On 2026-10-30, one repository had 3 red Pages runs in a row because of one row with 2 cells under a header with 4. A site with no roadmap is the same fault with no error: its Status page shows no item of the plan, and each check is green. On 2026-10-30, 2 repositories had a site with no roadmap.",
|
|
1672
|
+
fix: "Give the roadmap file to the Pages workflow (`roadmap: docs/ROADMAP.md`). Correct the row or the heading that the message names. Each table row has one cell for each column of its header, and the file has a table with an ID column and a Status column, or a heading \"### `id`: Title\".",
|
|
1633
1673
|
sources: [{
|
|
1634
1674
|
repo: "fleet",
|
|
1635
1675
|
rule: "fail-closed",
|
|
@@ -1644,21 +1684,29 @@ const roadmapParses = {
|
|
|
1644
1684
|
const files = context.gitFiles();
|
|
1645
1685
|
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
1646
1686
|
const named = [];
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1687
|
+
const breaks = [];
|
|
1688
|
+
for (const file of files.filter((path) => WORKFLOW$1.test(path)).sort(byCode)) {
|
|
1689
|
+
const lines = readFileSync(join(context.root, file), "utf8").split(/\r?\n/);
|
|
1690
|
+
lines.forEach((line, index) => {
|
|
1691
|
+
const roadmap = roadmapOfLine(line);
|
|
1692
|
+
if (roadmap !== void 0) named.push({
|
|
1693
|
+
roadmap,
|
|
1694
|
+
file,
|
|
1695
|
+
line: index + 1
|
|
1696
|
+
});
|
|
1697
|
+
});
|
|
1698
|
+
for (const line of callsWithoutRoadmap(lines)) breaks.push({
|
|
1651
1699
|
file,
|
|
1652
|
-
line
|
|
1700
|
+
line,
|
|
1701
|
+
message: `${file} builds the site with the Pages workflow and gives no roadmap, so the Status page shows no roadmap item.`
|
|
1653
1702
|
});
|
|
1654
|
-
}
|
|
1703
|
+
}
|
|
1655
1704
|
for (const roadmap of options["roadmaps"]) named.push({
|
|
1656
1705
|
roadmap: cleanPath(roadmap),
|
|
1657
1706
|
file: "the option roadmaps",
|
|
1658
1707
|
line: 0
|
|
1659
1708
|
});
|
|
1660
|
-
if (named.length === 0) return { skipped: "no workflow
|
|
1661
|
-
const breaks = [];
|
|
1709
|
+
if (named.length === 0 && breaks.length === 0) return { skipped: "no workflow builds a site with the Pages workflow, and no workflow names a roadmap" };
|
|
1662
1710
|
const seen = /* @__PURE__ */ new Set();
|
|
1663
1711
|
for (const { roadmap, file, line } of named) {
|
|
1664
1712
|
if (seen.has(roadmap)) continue;
|
|
@@ -1687,6 +1735,233 @@ const roadmapParses = {
|
|
|
1687
1735
|
return breaks;
|
|
1688
1736
|
}
|
|
1689
1737
|
};
|
|
1738
|
+
// src/rules/runner-budget.ts
|
|
1739
|
+
/**
|
|
1740
|
+
* The rule `runner-budget`: the workflows share the runners of the account. Each matrix has a `max-parallel`, each
|
|
1741
|
+
* workflow has a concurrency group, and each schedule starts at the minute of its repository and file.
|
|
1742
|
+
*/
|
|
1743
|
+
/** A workflow file. */
|
|
1744
|
+
const WORKFLOW = /^\.github\/workflows\/[^/]+\.ya?ml$/;
|
|
1745
|
+
const indentOf = (line) => line.length - line.trimStart().length;
|
|
1746
|
+
/** This function removes a comment at the end of a value, and the quotes around it. */
|
|
1747
|
+
function valueOf(raw) {
|
|
1748
|
+
const comment = raw.indexOf(" #");
|
|
1749
|
+
let value = (comment >= 0 ? raw.slice(0, comment) : raw).trim();
|
|
1750
|
+
const quote = value.charAt(0);
|
|
1751
|
+
if (value.length >= 2 && (quote === "\"" || quote === "'") && value.endsWith(quote)) value = value.slice(1, -1).trim();
|
|
1752
|
+
return value;
|
|
1753
|
+
}
|
|
1754
|
+
/** This function gives the value of the key `key` on a line, or undefined when the line has another key. */
|
|
1755
|
+
function keyValue(line, key) {
|
|
1756
|
+
let text = line.trimStart();
|
|
1757
|
+
if (text.startsWith("- ")) text = text.slice(2).trimStart();
|
|
1758
|
+
if (!text.startsWith(`${key}:`)) return void 0;
|
|
1759
|
+
return valueOf(text.slice(key.length + 1));
|
|
1760
|
+
}
|
|
1761
|
+
/** This function gives the lines of the block under the line `index`: the next lines with a larger indent. */
|
|
1762
|
+
function blockEnd(lines, index) {
|
|
1763
|
+
const indent = indentOf(lines[index] ?? "");
|
|
1764
|
+
let end = index + 1;
|
|
1765
|
+
while (end < lines.length) {
|
|
1766
|
+
const line = lines[end] ?? "";
|
|
1767
|
+
if (line.trim() !== "" && indentOf(line) <= indent) break;
|
|
1768
|
+
end += 1;
|
|
1769
|
+
}
|
|
1770
|
+
return end;
|
|
1771
|
+
}
|
|
1772
|
+
/** This function gives the indent of the first key of the block under the line `index`, or undefined for an empty block. */
|
|
1773
|
+
function childIndent(lines, index) {
|
|
1774
|
+
const end = blockEnd(lines, index);
|
|
1775
|
+
for (let i = index + 1; i < end; i++) if ((lines[i] ?? "").trim() !== "") return indentOf(lines[i] ?? "");
|
|
1776
|
+
}
|
|
1777
|
+
/**
|
|
1778
|
+
* This function gives the minute (1 to 59) of the schedules of a workflow: the FNV-1a hash of the repository and the
|
|
1779
|
+
* file. Two repositories with the same workflow thus start at different minutes, and no schedule starts at minute 0,
|
|
1780
|
+
* where GitHub has the most load.
|
|
1781
|
+
*/
|
|
1782
|
+
function scheduleMinute(repository, file) {
|
|
1783
|
+
let hash = 2166136261;
|
|
1784
|
+
for (const char of `${repository.toLowerCase()}/${file}`) {
|
|
1785
|
+
hash ^= char.codePointAt(0) ?? 0;
|
|
1786
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
1787
|
+
}
|
|
1788
|
+
return hash % 59 + 1;
|
|
1789
|
+
}
|
|
1790
|
+
/** This function gives `owner/name` from a git remote URL, or undefined for a URL that is not of GitHub. */
|
|
1791
|
+
function repositoryOfRemote(url) {
|
|
1792
|
+
const text = url.trim();
|
|
1793
|
+
for (const prefix of [
|
|
1794
|
+
"git@github.com:",
|
|
1795
|
+
"ssh://git@github.com/",
|
|
1796
|
+
"https://github.com/",
|
|
1797
|
+
"http://github.com/",
|
|
1798
|
+
"git+https://github.com/"
|
|
1799
|
+
]) {
|
|
1800
|
+
if (!text.startsWith(prefix)) continue;
|
|
1801
|
+
let rest = text.slice(prefix.length);
|
|
1802
|
+
if (rest.endsWith("/")) rest = rest.slice(0, -1);
|
|
1803
|
+
if (rest.endsWith(".git")) rest = rest.slice(0, -4);
|
|
1804
|
+
const parts = rest.split("/");
|
|
1805
|
+
return parts.length === 2 && parts.every((part) => part !== "") ? rest : void 0;
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
/** This function tells if a workflow is a shared workflow (`on: workflow_call`). Its caller gives the concurrency group. */
|
|
1809
|
+
function isShared(lines) {
|
|
1810
|
+
return lines.some((line) => {
|
|
1811
|
+
const text = line.trimStart();
|
|
1812
|
+
return text.startsWith("workflow_call:") || text === "workflow_call" || text === "- workflow_call" || text.startsWith("on:") && text.includes("workflow_call");
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
/** This function gives the jobs of a workflow. */
|
|
1816
|
+
function jobsOf(lines) {
|
|
1817
|
+
const jobs = lines.findIndex((line) => indentOf(line) === 0 && line.startsWith("jobs:"));
|
|
1818
|
+
if (jobs < 0) return [];
|
|
1819
|
+
const jobIndent = childIndent(lines, jobs);
|
|
1820
|
+
const end = blockEnd(lines, jobs);
|
|
1821
|
+
const found = [];
|
|
1822
|
+
for (let i = jobs + 1; i < end; i++) {
|
|
1823
|
+
const line = lines[i] ?? "";
|
|
1824
|
+
if (line.trim() === "" || indentOf(line) !== jobIndent) continue;
|
|
1825
|
+
const keyIndent = childIndent(lines, i);
|
|
1826
|
+
const keys = lines.slice(i + 1, blockEnd(lines, i)).filter((text) => indentOf(text) === keyIndent);
|
|
1827
|
+
const uses = keys.map((text) => keyValue(text, "uses")).find((value) => value !== void 0);
|
|
1828
|
+
const at = uses === void 0 ? -1 : uses.indexOf(".github/workflows/");
|
|
1829
|
+
const calls = uses === void 0 || at < 0 ? void 0 : uses.slice(at + 18).split("@")[0] ?? "";
|
|
1830
|
+
found.push({
|
|
1831
|
+
name: line.trim().replace(/:$/, ""),
|
|
1832
|
+
line: i + 1,
|
|
1833
|
+
grouped: keys.some((text) => keyValue(text, "concurrency") !== void 0),
|
|
1834
|
+
...calls === void 0 ? {} : { calls }
|
|
1835
|
+
});
|
|
1836
|
+
}
|
|
1837
|
+
return found;
|
|
1838
|
+
}
|
|
1839
|
+
const hasTopGroup = (lines) => lines.some((line) => indentOf(line) === 0 && line.startsWith("concurrency:"));
|
|
1840
|
+
/**
|
|
1841
|
+
* This function gives the breaks of the concurrency groups. A workflow with no group at the top needs one in each job.
|
|
1842
|
+
* A job that calls a shared workflow of `grouped` gets its group from the jobs of that workflow. A shared workflow gets
|
|
1843
|
+
* its group from its caller, but a shared workflow of `grouped` has a group in each job.
|
|
1844
|
+
*/
|
|
1845
|
+
function concurrencyBreaks(file, lines, grouped) {
|
|
1846
|
+
const name = file.slice(file.lastIndexOf("/") + 1);
|
|
1847
|
+
const jobs = jobsOf(lines);
|
|
1848
|
+
if (isShared(lines)) {
|
|
1849
|
+
if (!grouped.includes(name)) return [];
|
|
1850
|
+
return jobs.filter((job) => !job.grouped).map((job) => ({
|
|
1851
|
+
file,
|
|
1852
|
+
line: job.line,
|
|
1853
|
+
message: `${file}: the job ${job.name} has no concurrency group, and its callers rely on it (the option grouped).`
|
|
1854
|
+
}));
|
|
1855
|
+
}
|
|
1856
|
+
if (hasTopGroup(lines)) return [];
|
|
1857
|
+
return jobs.filter((job) => !job.grouped && !(job.calls !== void 0 && grouped.includes(job.calls))).map((job) => ({
|
|
1858
|
+
file,
|
|
1859
|
+
line: job.line,
|
|
1860
|
+
message: `${file}: the job ${job.name} has no concurrency group, and the workflow has none.`
|
|
1861
|
+
}));
|
|
1862
|
+
}
|
|
1863
|
+
/** This function gives the breaks of the matrices: each `strategy` with a `matrix` has a `max-parallel` of `limit` or less. */
|
|
1864
|
+
function matrixBreaks(file, lines, limit) {
|
|
1865
|
+
const breaks = [];
|
|
1866
|
+
lines.forEach((line, index) => {
|
|
1867
|
+
if (keyValue(line, "strategy") === void 0) return;
|
|
1868
|
+
const keyIndent = childIndent(lines, index);
|
|
1869
|
+
const keys = lines.slice(index + 1, blockEnd(lines, index)).filter((text) => indentOf(text) === keyIndent);
|
|
1870
|
+
if (!keys.some((text) => keyValue(text, "matrix") !== void 0)) return;
|
|
1871
|
+
const raw = keys.map((text) => keyValue(text, "max-parallel")).find((value) => value !== void 0);
|
|
1872
|
+
const value = raw === void 0 ? NaN : Number(raw);
|
|
1873
|
+
if (raw === void 0) breaks.push({
|
|
1874
|
+
file,
|
|
1875
|
+
line: index + 1,
|
|
1876
|
+
message: `${file}: a matrix has no max-parallel.`
|
|
1877
|
+
});
|
|
1878
|
+
else if (!Number.isInteger(value) || value < 1 || value > limit) breaks.push({
|
|
1879
|
+
file,
|
|
1880
|
+
line: index + 1,
|
|
1881
|
+
message: `${file}: a matrix has max-parallel ${raw}, and the most is ${String(limit)}.`
|
|
1882
|
+
});
|
|
1883
|
+
});
|
|
1884
|
+
return breaks;
|
|
1885
|
+
}
|
|
1886
|
+
/** This function gives the breaks of the schedules: the minute of each `cron` is the minute of the repository and the file. */
|
|
1887
|
+
function cronBreaks(file, lines, minute) {
|
|
1888
|
+
const breaks = [];
|
|
1889
|
+
lines.forEach((line, index) => {
|
|
1890
|
+
const value = keyValue(line, "cron");
|
|
1891
|
+
if (value === void 0) return;
|
|
1892
|
+
const fields = value.split(" ").filter((field) => field !== "");
|
|
1893
|
+
if (fields[0] === String(minute)) return;
|
|
1894
|
+
const expected = [String(minute), ...fields.slice(1)].join(" ");
|
|
1895
|
+
breaks.push({
|
|
1896
|
+
file,
|
|
1897
|
+
line: index + 1,
|
|
1898
|
+
message: `${file}: the schedule "${value}" starts at minute ${fields[0] ?? "?"}, and the minute of this repository and file is ${String(minute)}.`,
|
|
1899
|
+
fix: `cron: "${expected}"`
|
|
1900
|
+
});
|
|
1901
|
+
});
|
|
1902
|
+
return breaks;
|
|
1903
|
+
}
|
|
1904
|
+
const runnerBudget = {
|
|
1905
|
+
id: "runner-budget",
|
|
1906
|
+
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.",
|
|
1907
|
+
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.",
|
|
1908
|
+
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: true }`), or in each job. Change the minute of each `cron` to the minute that the message gives; the hour and the days stay.",
|
|
1909
|
+
sources: [{
|
|
1910
|
+
repo: "fleet",
|
|
1911
|
+
rule: "runner-slots",
|
|
1912
|
+
doc: "docs/STRATEGY.md (2026-10-30, the runner slots: a cap of 40, heavy work at most 28)"
|
|
1913
|
+
}],
|
|
1914
|
+
options: {
|
|
1915
|
+
maxParallel: {
|
|
1916
|
+
type: "number",
|
|
1917
|
+
default: 3,
|
|
1918
|
+
description: "The largest max-parallel of a matrix."
|
|
1919
|
+
},
|
|
1920
|
+
minute: {
|
|
1921
|
+
type: "boolean",
|
|
1922
|
+
default: true,
|
|
1923
|
+
description: "When false, the rule does not examine the minute of the schedules."
|
|
1924
|
+
},
|
|
1925
|
+
grouped: {
|
|
1926
|
+
type: "strings",
|
|
1927
|
+
default: ["reusable-ai-review.yml", "reusable-codex-review.yml"],
|
|
1928
|
+
description: "The shared workflows that give a concurrency group in each of their jobs. A job that calls one needs no group of its own."
|
|
1929
|
+
}
|
|
1930
|
+
},
|
|
1931
|
+
check(context, options) {
|
|
1932
|
+
const files = context.gitFiles();
|
|
1933
|
+
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
1934
|
+
const workflows = files.filter((path) => WORKFLOW.test(path)).sort(byCode);
|
|
1935
|
+
if (workflows.length === 0) return { skipped: "the repository has no workflow" };
|
|
1936
|
+
const remote = context.git([
|
|
1937
|
+
"remote",
|
|
1938
|
+
"get-url",
|
|
1939
|
+
"origin"
|
|
1940
|
+
]);
|
|
1941
|
+
const repository = context.env["GITHUB_REPOSITORY"] ?? (remote === void 0 ? void 0 : repositoryOfRemote(remote));
|
|
1942
|
+
const limit = Number(options["maxParallel"]);
|
|
1943
|
+
const grouped = Array.isArray(options["grouped"]) ? options["grouped"] : [];
|
|
1944
|
+
const breaks = [];
|
|
1945
|
+
for (const file of workflows) {
|
|
1946
|
+
let text;
|
|
1947
|
+
try {
|
|
1948
|
+
text = readFileSync(join(context.root, file), "utf8");
|
|
1949
|
+
} catch {
|
|
1950
|
+
continue;
|
|
1951
|
+
}
|
|
1952
|
+
const lines = text.split(/\r?\n/).map((line) => line.trimStart().startsWith("#") ? "" : line);
|
|
1953
|
+
breaks.push(...matrixBreaks(file, lines, limit), ...concurrencyBreaks(file, lines, grouped));
|
|
1954
|
+
if (options["minute"] !== false) {
|
|
1955
|
+
if (lines.some((line) => keyValue(line, "cron") !== void 0) && repository === void 0) breaks.push({
|
|
1956
|
+
file,
|
|
1957
|
+
message: `${file} has a schedule, and the rule cannot find the repository (GITHUB_REPOSITORY, or a GitHub URL of the remote origin).`
|
|
1958
|
+
});
|
|
1959
|
+
else if (repository !== void 0) breaks.push(...cronBreaks(file, lines, scheduleMinute(repository, file)));
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
return breaks;
|
|
1963
|
+
}
|
|
1964
|
+
};
|
|
1690
1965
|
// src/rules/source-main.ts
|
|
1691
1966
|
/**
|
|
1692
1967
|
* The rule `source-main`: a workspace package is a source package, and a public package moves its
|
|
@@ -2349,7 +2624,8 @@ const RULES = [
|
|
|
2349
2624
|
typedScripts,
|
|
2350
2625
|
typedFiles,
|
|
2351
2626
|
testsRequired,
|
|
2352
|
-
roadmapParses
|
|
2627
|
+
roadmapParses,
|
|
2628
|
+
runnerBudget
|
|
2353
2629
|
];
|
|
2354
2630
|
// src/run.ts
|
|
2355
2631
|
/**
|
|
@@ -2639,6 +2915,6 @@ function runCli(args, io) {
|
|
|
2639
2915
|
if (summary) appendFileSync(summary, summaryMarkdown(result));
|
|
2640
2916
|
return result.failed ? 1 : 0;
|
|
2641
2917
|
}
|
|
2642
|
-
export {
|
|
2918
|
+
export { workspaceGlobs as $, isPinned as A, codePackages as B, runnerBudget as C, requiredScripts as D, roadmapParses as E, noBuildOutput as F, matchesAny as G, inFolder as H, STRICT_OPTIONS as I, runGit as J, parseJsonc as K, cuePreset as L, DEFAULT_ALLOWED as M, HOME_PATTERNS as N, releaseFiles as O, noLocalPaths as P, packageFolders as Q, DEPENDENCY_FIELDS as R, repositoryOfRemote as S, roadmapOfLine as T, keyLine as U, hasFile as V, lineOf as W, globFolders as X, specifiersOf as Y, globToRegExp as Z, tsconfigTest as _, listRules as a, pathsOf as b, runCli as c, workspaceProtocol as d, defaultOptions as et, typedScripts as f, hasTests as g, typedFiles as h, formatResult as i, pinnedGitDeps as j, isGitSpecifier as k, summaryMarkdown as l, scriptsOf as m, annotations as n, readConfig as o, configsOfScript as p, readJsonc as q, createContext as r, runChecks as s, USAGE as t, parseConfig as tt, RULES as u, testsRequired as v, scheduleMinute as w, sourceMain as x, isSourcePath as y, cleanPath as z };
|
|
2643
2919
|
|
|
2644
|
-
//# sourceMappingURL=run-
|
|
2920
|
+
//# sourceMappingURL=run-d-5ceKnT.js.map
|