@mark1russell7/conventions 0.29.3 → 0.30.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 +1 -0
- package/build/cli.js +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -2
- package/build/{run-COJ2_vAb.js → run-5nn4yBKi.js} +721 -488
- package/build/run-5nn4yBKi.js.map +1 -0
- package/package.json +2 -2
- package/build/run-COJ2_vAb.js.map +0 -1
|
@@ -1015,6 +1015,31 @@ if (board) {
|
|
|
1015
1015
|
apply(false);
|
|
1016
1016
|
}
|
|
1017
1017
|
`;
|
|
1018
|
+
// ../site-pages/src/check/freshness.ts
|
|
1019
|
+
/**
|
|
1020
|
+
* This function gives each line `cron:` of a workflow. It is the one reader of these lines: the freshness gate and the rule `runner-budget` of conventions use it.
|
|
1021
|
+
* It skips a comment line. It reads a quoted key, a list item, a quoted value and a comment at the end of the line.
|
|
1022
|
+
*/
|
|
1023
|
+
function cronLines(workflow) {
|
|
1024
|
+
return workflow.split(/\r?\n/).flatMap((raw, index) => {
|
|
1025
|
+
const text = raw.trim().replace(/^- */, "");
|
|
1026
|
+
const key = [
|
|
1027
|
+
"cron:",
|
|
1028
|
+
"\"cron\":",
|
|
1029
|
+
"'cron':"
|
|
1030
|
+
].find((form) => text.startsWith(form));
|
|
1031
|
+
if (key === void 0) return [];
|
|
1032
|
+
const rest = text.slice(key.length);
|
|
1033
|
+
const comment = rest.search(/\s#/);
|
|
1034
|
+
const value = (comment >= 0 ? rest.slice(0, comment) : rest).trim();
|
|
1035
|
+
const quote = value.charAt(0);
|
|
1036
|
+
const quoted = value.length >= 2 && (quote === "\"" || quote === "'") && value.endsWith(quote);
|
|
1037
|
+
return [{
|
|
1038
|
+
line: index + 1,
|
|
1039
|
+
cron: quoted ? value.slice(1, -1).trim() : value
|
|
1040
|
+
}];
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1018
1043
|
// src/rules/changelog-version.ts
|
|
1019
1044
|
/**
|
|
1020
1045
|
* The rule `changelog-version`: the top release section of the changelog of a package is not above the version of
|
|
@@ -8903,118 +8928,6 @@ const pagesSite = {
|
|
|
8903
8928
|
}];
|
|
8904
8929
|
}
|
|
8905
8930
|
};
|
|
8906
|
-
// src/rules/pinned-git-deps.ts
|
|
8907
|
-
/**
|
|
8908
|
-
* The rule `pinned-git-deps`: a dependency from git names a full commit.
|
|
8909
|
-
*/
|
|
8910
|
-
/** The fields of the root `package.json` that replace the specifiers of dependencies. */
|
|
8911
|
-
const OVERRIDE_FIELDS = ["overrides", "resolutions"];
|
|
8912
|
-
/** This function tells if a specifier gets the package from git, not from a registry or the workspace. */
|
|
8913
|
-
function isGitSpecifier(spec) {
|
|
8914
|
-
const value = spec.trim();
|
|
8915
|
-
if (/^(github|gitlab|bitbucket|gist):/i.test(value)) return true;
|
|
8916
|
-
if (/^git(\+[a-z]+)?:/i.test(value) || /^git@/i.test(value)) return true;
|
|
8917
|
-
if (/^https?:\/\/(www\.)?(github\.com|gitlab\.com|bitbucket\.org|codeload\.github\.com)\//i.test(value)) return true;
|
|
8918
|
-
return /^[\w-][\w.-]*\/[\w.-]+(#.*)?$/.test(value) && !value.startsWith("@");
|
|
8919
|
-
}
|
|
8920
|
-
/**
|
|
8921
|
-
* This function tells if a git specifier names a commit. A specifier names a commit when its ref
|
|
8922
|
-
* (after `#`) is a commit SHA, or when a tarball URL has the SHA in its path.
|
|
8923
|
-
*/
|
|
8924
|
-
function isPinned(spec, fullSha) {
|
|
8925
|
-
const sha = fullSha ? /^[0-9a-f]{40}$/i : /^[0-9a-f]{7,40}$/i;
|
|
8926
|
-
const hash = spec.indexOf("#");
|
|
8927
|
-
if (hash >= 0) return spec.slice(hash + 1).split("&").some((part) => sha.test(part.replace(/^commit=/, "")));
|
|
8928
|
-
const path = /^https?:\/\/[^/]+\/(.*)$/i.exec(spec.trim())?.[1];
|
|
8929
|
-
return path !== void 0 && path.split(/[/.]/).some((part) => sha.test(part));
|
|
8930
|
-
}
|
|
8931
|
-
/** This function gives the specifiers of the fields of overrides, also the field `overrides` of `pnpm`. */
|
|
8932
|
-
function overridesOf(manifest) {
|
|
8933
|
-
const out = [];
|
|
8934
|
-
for (const field of OVERRIDE_FIELDS) for (const [name, spec] of specifiersOf(manifest, field)) out.push([
|
|
8935
|
-
field,
|
|
8936
|
-
name,
|
|
8937
|
-
spec
|
|
8938
|
-
]);
|
|
8939
|
-
const pnpm = manifest["pnpm"];
|
|
8940
|
-
if (typeof pnpm === "object" && pnpm !== null) for (const [name, spec] of specifiersOf(pnpm, "overrides")) out.push([
|
|
8941
|
-
"pnpm",
|
|
8942
|
-
name,
|
|
8943
|
-
spec
|
|
8944
|
-
]);
|
|
8945
|
-
return out;
|
|
8946
|
-
}
|
|
8947
|
-
const pinnedGitDeps = {
|
|
8948
|
-
id: "pinned-git-deps",
|
|
8949
|
-
title: "A dependency from git (github:, git+https: or owner/repo) names a full commit SHA.",
|
|
8950
|
-
reason: "A git ref without a commit moves with the branch. Then an install today and an install tomorrow get different code, and the lockfile hides the change.",
|
|
8951
|
-
fix: "Use the npm version, `workspace:*` for a package of this repository, or `github:owner/repo#<full commit SHA>`.",
|
|
8952
|
-
sources: [
|
|
8953
|
-
{
|
|
8954
|
-
repo: "coeval",
|
|
8955
|
-
rule: "pinned-deps",
|
|
8956
|
-
doc: "CLAUDE.md:41"
|
|
8957
|
-
},
|
|
8958
|
-
{
|
|
8959
|
-
repo: "coeval",
|
|
8960
|
-
rule: "unpublished-dep-pinned",
|
|
8961
|
-
doc: "CLAUDE.md:41"
|
|
8962
|
-
},
|
|
8963
|
-
{
|
|
8964
|
-
repo: "headroom",
|
|
8965
|
-
rule: "non-npm-deps-pinned",
|
|
8966
|
-
doc: "CLAUDE.md:38"
|
|
8967
|
-
},
|
|
8968
|
-
{
|
|
8969
|
-
repo: "headroom",
|
|
8970
|
-
rule: "pinned-github-specifier",
|
|
8971
|
-
doc: "CLAUDE.md:38"
|
|
8972
|
-
},
|
|
8973
|
-
{
|
|
8974
|
-
repo: "private",
|
|
8975
|
-
rule: "github-dep-full-sha",
|
|
8976
|
-
doc: "docs/decisions.md:1384"
|
|
8977
|
-
},
|
|
8978
|
-
{
|
|
8979
|
-
repo: "private",
|
|
8980
|
-
rule: "github-dep-pinned",
|
|
8981
|
-
doc: "docs/decisions.md:1384"
|
|
8982
|
-
},
|
|
8983
|
-
{
|
|
8984
|
-
repo: "client",
|
|
8985
|
-
rule: "general-npm-version",
|
|
8986
|
-
doc: "CLAUDE.md:54"
|
|
8987
|
-
}
|
|
8988
|
-
],
|
|
8989
|
-
options: { fullSha: {
|
|
8990
|
-
type: "boolean",
|
|
8991
|
-
default: true,
|
|
8992
|
-
description: "When false, a short SHA of 7 or more characters is also a commit."
|
|
8993
|
-
} },
|
|
8994
|
-
check(context, options) {
|
|
8995
|
-
const fullSha = options["fullSha"] !== false;
|
|
8996
|
-
const breaks = [];
|
|
8997
|
-
for (const info of [context.rootPackage, ...context.packages]) {
|
|
8998
|
-
const found = [];
|
|
8999
|
-
for (const field of DEPENDENCY_FIELDS) for (const [name, spec] of specifiersOf(info.manifest, field)) found.push([
|
|
9000
|
-
field,
|
|
9001
|
-
name,
|
|
9002
|
-
spec
|
|
9003
|
-
]);
|
|
9004
|
-
found.push(...overridesOf(info.manifest));
|
|
9005
|
-
for (const [field, name, spec] of found) {
|
|
9006
|
-
if (!isGitSpecifier(spec) || isPinned(spec, fullSha)) continue;
|
|
9007
|
-
const line = keyLine(info.text, field, name);
|
|
9008
|
-
breaks.push({
|
|
9009
|
-
file: info.file,
|
|
9010
|
-
...line === void 0 ? {} : { line },
|
|
9011
|
-
message: `${field} "${name}" is "${spec}": a git dependency without a ${fullSha ? "full " : ""}commit SHA.`
|
|
9012
|
-
});
|
|
9013
|
-
}
|
|
9014
|
-
}
|
|
9015
|
-
return breaks;
|
|
9016
|
-
}
|
|
9017
|
-
};
|
|
9018
8931
|
// src/rules/push-main-only.ts
|
|
9019
8932
|
/**
|
|
9020
8933
|
* The rule `push-main-only`: a workflow that starts on `push` and on `pull_request` limits `push` to the default branch.
|
|
@@ -9022,7 +8935,7 @@ const pinnedGitDeps = {
|
|
|
9022
8935
|
* can still start a run on a branch with no pull request.
|
|
9023
8936
|
*/
|
|
9024
8937
|
/** The file of the release flow. A person changes it, with the rule `release-files`, so the fix does not write it. */
|
|
9025
|
-
const RELEASE_FILE = "release.yml";
|
|
8938
|
+
const RELEASE_FILE$1 = "release.yml";
|
|
9026
8939
|
/** The patterns that match each branch. */
|
|
9027
8940
|
const EACH_BRANCH = /* @__PURE__ */ new Set(["*", "**"]);
|
|
9028
8941
|
/** A key of a block, in the quoted forms too. */
|
|
@@ -9246,7 +9159,7 @@ function findBreak(text, facts) {
|
|
|
9246
9159
|
}
|
|
9247
9160
|
/** This function gives the reason why a person must change the workflow, or undefined when the fix can write it. */
|
|
9248
9161
|
function refusal(file, text, finding, facts) {
|
|
9249
|
-
if (file.slice(file.lastIndexOf("/") + 1) === RELEASE_FILE) return `${RELEASE_FILE} belongs to the release flow`;
|
|
9162
|
+
if (file.slice(file.lastIndexOf("/") + 1) === RELEASE_FILE$1) return `${RELEASE_FILE$1} belongs to the release flow`;
|
|
9250
9163
|
const { triggers, filters, wide } = finding;
|
|
9251
9164
|
if (triggers.form === "map") return "on has the flow form of a map";
|
|
9252
9165
|
if (triggers.end > triggers.on + 1) return "on is a flow value of more than one line";
|
|
@@ -9413,121 +9326,704 @@ const pushMainOnly = {
|
|
|
9413
9326
|
return breaks;
|
|
9414
9327
|
}
|
|
9415
9328
|
};
|
|
9416
|
-
// src/rules/
|
|
9329
|
+
// src/rules/runner-budget.ts
|
|
9417
9330
|
/**
|
|
9418
|
-
* The rule `
|
|
9419
|
-
*
|
|
9331
|
+
* The rule `runner-budget`: the workflows share the runners of the account. Each matrix has a `max-parallel`, each
|
|
9332
|
+
* workflow has a concurrency group, and each schedule starts at the minute of its repository and file.
|
|
9420
9333
|
*/
|
|
9421
|
-
/** The registry of npm. */
|
|
9422
|
-
const NPM_REGISTRY = "https://registry.npmjs.org";
|
|
9423
|
-
/** The globs of the files of a package, relative to its folder, that do not ship: tests, fixtures, docs and configs. */
|
|
9424
|
-
const UNSHIPPED_FILES = [
|
|
9425
|
-
"**/*.md",
|
|
9426
|
-
"**/*.{test,spec}.*",
|
|
9427
|
-
"**/{test,tests,__tests__,fixtures,__fixtures__,__snapshots__,bench,benches,benchmarks,e2e}/**",
|
|
9428
|
-
"**/*.{bench,e2e}.*",
|
|
9429
|
-
"**/.*/**",
|
|
9430
|
-
"**/tsconfig*.json",
|
|
9431
|
-
"**/*.config.*",
|
|
9432
|
-
"docs/**",
|
|
9433
|
-
"examples/**",
|
|
9434
|
-
"scripts/**",
|
|
9435
|
-
"site/**",
|
|
9436
|
-
"LICENSE*",
|
|
9437
|
-
"pnpm-lock.yaml",
|
|
9438
|
-
"pnpm-workspace.yaml"
|
|
9439
|
-
];
|
|
9440
|
-
/** The fields of `package.json` that change what the package gives to a user. A change of the dependencies is not here. */
|
|
9441
|
-
const SHIPPED_FIELDS = [
|
|
9442
|
-
"main",
|
|
9443
|
-
"module",
|
|
9444
|
-
"types",
|
|
9445
|
-
"typings",
|
|
9446
|
-
"exports",
|
|
9447
|
-
"imports",
|
|
9448
|
-
"bin",
|
|
9449
|
-
"files",
|
|
9450
|
-
"type",
|
|
9451
|
-
"publishConfig",
|
|
9452
|
-
"sideEffects",
|
|
9453
|
-
"browser"
|
|
9454
|
-
];
|
|
9455
|
-
/** The script that `npmLookup` starts in a child process of Node, so that the rule stays synchronous. */
|
|
9456
|
-
const LOOKUP_SCRIPT = `
|
|
9457
|
-
const [registry, ...names] = process.argv.slice(1);
|
|
9458
|
-
let base = registry;
|
|
9459
|
-
while (base.endsWith("/")) base = base.slice(0, -1);
|
|
9460
|
-
Promise.all(names.map(async (name) => {
|
|
9461
|
-
try {
|
|
9462
|
-
const response = await fetch(base + "/" + name.replace("/", "%2f"), { headers: { accept: "application/json" }, signal: AbortSignal.timeout(20000) });
|
|
9463
|
-
if (response.status === 404) return [name, { versions: [] }];
|
|
9464
|
-
if (!response.ok) return [name, { error: "HTTP " + response.status }];
|
|
9465
|
-
const data = await response.json();
|
|
9466
|
-
const times = Object.fromEntries(Object.entries(data.time ?? {}).filter(([key]) => key !== "created" && key !== "modified"));
|
|
9467
|
-
return [name, { versions: [...new Set([...Object.keys(data.versions ?? {}), ...Object.keys(times)])], times, latest: data["dist-tags"]?.latest }];
|
|
9468
|
-
} catch (error) {
|
|
9469
|
-
return [name, { error: String(error && error.message ? error.message : error) }];
|
|
9470
|
-
}
|
|
9471
|
-
})).then((entries) => process.stdout.write(JSON.stringify(Object.fromEntries(entries))));
|
|
9472
|
-
`;
|
|
9473
9334
|
/**
|
|
9474
|
-
* This function
|
|
9475
|
-
*
|
|
9335
|
+
* This function gives the minute (1 to 59) of the schedules of a workflow: the FNV-1a hash of the repository and the
|
|
9336
|
+
* file. Two repositories with the same workflow thus start at different minutes, and no schedule starts at minute 0,
|
|
9337
|
+
* where GitHub has the most load.
|
|
9476
9338
|
*/
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
9482
|
-
LOOKUP_SCRIPT,
|
|
9483
|
-
registry,
|
|
9484
|
-
...names
|
|
9485
|
-
], {
|
|
9486
|
-
encoding: "utf8",
|
|
9487
|
-
timeout: 6e4,
|
|
9488
|
-
windowsHide: true
|
|
9489
|
-
});
|
|
9490
|
-
if (result.error !== void 0 || result.status !== 0) return fail(result.error?.message ?? `the lookup ended with exit code ${String(result.status)}`);
|
|
9491
|
-
try {
|
|
9492
|
-
const answers = JSON.parse(result.stdout);
|
|
9493
|
-
return new Map(names.map((name) => [name, answers[name] ?? { error: "no answer" }]));
|
|
9494
|
-
} catch {
|
|
9495
|
-
return fail("the lookup gave no JSON");
|
|
9496
|
-
}
|
|
9497
|
-
};
|
|
9498
|
-
/** This function gives the strings of a field of `package.json` that is a list of strings. */
|
|
9499
|
-
const stringsOf = (manifest, field) => {
|
|
9500
|
-
const value = manifest[field];
|
|
9501
|
-
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
9502
|
-
};
|
|
9503
|
-
/** This function tells if a path relative to the root is in the folder `folder`. The root is `""`. */
|
|
9504
|
-
const inside = (folder, path) => folder === "" || path.startsWith(`${folder}/`);
|
|
9505
|
-
/** This function gives the globs of an entry of the field `files`: the entry, and each path under it. */
|
|
9506
|
-
const entryGlobs = (entry) => {
|
|
9507
|
-
let glob = cleanPath(entry);
|
|
9508
|
-
while (glob.endsWith("/")) glob = glob.slice(0, -1);
|
|
9509
|
-
return [glob, `${glob}/**`];
|
|
9510
|
-
};
|
|
9511
|
-
/** This function reads the manifest of the text of a `package.json` file, or gives undefined. */
|
|
9512
|
-
function parseManifest(text) {
|
|
9513
|
-
if (text === void 0) return void 0;
|
|
9514
|
-
try {
|
|
9515
|
-
const parsed = JSON.parse(text);
|
|
9516
|
-
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
|
|
9517
|
-
} catch {
|
|
9518
|
-
return;
|
|
9339
|
+
function scheduleMinute(repository, file) {
|
|
9340
|
+
let hash = 2166136261;
|
|
9341
|
+
for (const char of `${repository.toLowerCase()}/${file}`) {
|
|
9342
|
+
hash ^= char.codePointAt(0) ?? 0;
|
|
9343
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
9519
9344
|
}
|
|
9345
|
+
return hash % 59 + 1;
|
|
9520
9346
|
}
|
|
9521
|
-
/** This function
|
|
9522
|
-
|
|
9523
|
-
|
|
9524
|
-
|
|
9525
|
-
|
|
9526
|
-
|
|
9347
|
+
/** This function gives `owner/name` from a git remote URL, or undefined for a URL that is not of GitHub. */
|
|
9348
|
+
function repositoryOfRemote(url) {
|
|
9349
|
+
const text = url.trim();
|
|
9350
|
+
for (const prefix of [
|
|
9351
|
+
"git@github.com:",
|
|
9352
|
+
"ssh://git@github.com/",
|
|
9353
|
+
"https://github.com/",
|
|
9354
|
+
"http://github.com/",
|
|
9355
|
+
"git+https://github.com/"
|
|
9356
|
+
]) {
|
|
9357
|
+
if (!text.startsWith(prefix)) continue;
|
|
9358
|
+
let rest = text.slice(prefix.length);
|
|
9359
|
+
if (rest.endsWith("/")) rest = rest.slice(0, -1);
|
|
9360
|
+
if (rest.endsWith(".git")) rest = rest.slice(0, -4);
|
|
9361
|
+
const parts = rest.split("/");
|
|
9362
|
+
return parts.length === 2 && parts.every((part) => part !== "") ? rest : void 0;
|
|
9363
|
+
}
|
|
9527
9364
|
}
|
|
9528
|
-
/** This function
|
|
9529
|
-
function
|
|
9530
|
-
|
|
9365
|
+
/** This function tells if a workflow is a shared workflow (`on: workflow_call`). Its caller gives the concurrency group. */
|
|
9366
|
+
function isShared(lines) {
|
|
9367
|
+
return lines.some((line) => {
|
|
9368
|
+
const text = line.trimStart();
|
|
9369
|
+
return text.startsWith("workflow_call:") || text === "workflow_call" || text === "- workflow_call" || text.startsWith("on:") && text.includes("workflow_call");
|
|
9370
|
+
});
|
|
9371
|
+
}
|
|
9372
|
+
/** This function gives the jobs of a workflow. */
|
|
9373
|
+
function jobsOf(lines) {
|
|
9374
|
+
const jobs = lines.findIndex((line) => indentOf$1(line) === 0 && line.startsWith("jobs:"));
|
|
9375
|
+
if (jobs < 0) return [];
|
|
9376
|
+
const jobIndent = childIndent(lines, jobs);
|
|
9377
|
+
const end = blockEnd(lines, jobs);
|
|
9378
|
+
const found = [];
|
|
9379
|
+
for (let i = jobs + 1; i < end; i++) {
|
|
9380
|
+
const line = lines[i] ?? "";
|
|
9381
|
+
if (line.trim() === "" || indentOf$1(line) !== jobIndent) continue;
|
|
9382
|
+
const keyIndent = childIndent(lines, i);
|
|
9383
|
+
const keys = lines.slice(i + 1, blockEnd(lines, i)).filter((text) => indentOf$1(text) === keyIndent);
|
|
9384
|
+
const uses = keys.map((text) => keyValue(text, "uses")).find((value) => value !== void 0);
|
|
9385
|
+
const at = uses === void 0 ? -1 : uses.indexOf(".github/workflows/");
|
|
9386
|
+
const calls = uses === void 0 || at < 0 ? void 0 : uses.slice(at + 18).split("@")[0] ?? "";
|
|
9387
|
+
found.push({
|
|
9388
|
+
name: line.trim().replace(/:$/, ""),
|
|
9389
|
+
line: i + 1,
|
|
9390
|
+
grouped: keys.some((text) => keyValue(text, "concurrency") !== void 0),
|
|
9391
|
+
...calls === void 0 ? {} : { calls }
|
|
9392
|
+
});
|
|
9393
|
+
}
|
|
9394
|
+
return found;
|
|
9395
|
+
}
|
|
9396
|
+
const hasTopGroup = (lines) => lines.some((line) => indentOf$1(line) === 0 && line.startsWith("concurrency:"));
|
|
9397
|
+
/**
|
|
9398
|
+
* This function gives the edit that adds a concurrency group at the top of a workflow, before `jobs:`. A new run of a pull
|
|
9399
|
+
* request stops the old run. A run of another event has the group of its commit, so that no release or scheduled run stops.
|
|
9400
|
+
*/
|
|
9401
|
+
function groupEdits(file, text, lines) {
|
|
9402
|
+
const jobs = lines.findIndex((line) => indentOf$1(line) === 0 && line.startsWith("jobs:"));
|
|
9403
|
+
if (jobs < 0) return [];
|
|
9404
|
+
const pad = " ".repeat(childIndent(lines, jobs) ?? 2);
|
|
9405
|
+
const original = text.split(/\r?\n/)[jobs] ?? "jobs:";
|
|
9406
|
+
const group = [
|
|
9407
|
+
"concurrency:",
|
|
9408
|
+
pad + "group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }}",
|
|
9409
|
+
pad + "cancel-in-progress: ${{ github.event_name == 'pull_request' }}",
|
|
9410
|
+
"",
|
|
9411
|
+
original
|
|
9412
|
+
];
|
|
9413
|
+
return [{
|
|
9414
|
+
file,
|
|
9415
|
+
before: text,
|
|
9416
|
+
after: replaceLine(text, jobs + 1, group)
|
|
9417
|
+
}];
|
|
9418
|
+
}
|
|
9419
|
+
/**
|
|
9420
|
+
* This function gives the breaks of the concurrency groups. A workflow with no group at the top needs one in each job.
|
|
9421
|
+
* A job that calls a shared workflow of `grouped` gets its group from the jobs of that workflow. A shared workflow gets
|
|
9422
|
+
* its group from its caller, but a shared workflow of `grouped` has a group in each job.
|
|
9423
|
+
*/
|
|
9424
|
+
function concurrencyBreaks(file, text, lines, grouped) {
|
|
9425
|
+
const name = file.slice(file.lastIndexOf("/") + 1);
|
|
9426
|
+
const jobs = jobsOf(lines);
|
|
9427
|
+
if (isShared(lines)) {
|
|
9428
|
+
if (!grouped.includes(name)) return [];
|
|
9429
|
+
return jobs.filter((job) => !job.grouped).map((job) => ({
|
|
9430
|
+
file,
|
|
9431
|
+
line: job.line,
|
|
9432
|
+
message: `${file}: the job ${job.name} has no concurrency group, and its callers rely on it (the option grouped).`
|
|
9433
|
+
}));
|
|
9434
|
+
}
|
|
9435
|
+
if (hasTopGroup(lines)) return [];
|
|
9436
|
+
const missing = jobs.filter((job) => !job.grouped && !(job.calls !== void 0 && grouped.includes(job.calls)));
|
|
9437
|
+
const edits = missing.length === 0 ? [] : groupEdits(file, text, lines);
|
|
9438
|
+
return missing.map((job) => ({
|
|
9439
|
+
file,
|
|
9440
|
+
line: job.line,
|
|
9441
|
+
message: `${file}: the job ${job.name} has no concurrency group, and the workflow has none.`,
|
|
9442
|
+
edits
|
|
9443
|
+
}));
|
|
9444
|
+
}
|
|
9445
|
+
/** This function gives the breaks of the matrices: each `strategy` with a `matrix` has a `max-parallel` of `limit` or less. */
|
|
9446
|
+
function matrixBreaks(file, text, lines, limit) {
|
|
9447
|
+
const breaks = [];
|
|
9448
|
+
const originals = text.split(/\r?\n/);
|
|
9449
|
+
lines.forEach((line, index) => {
|
|
9450
|
+
if (keyValue(line, "strategy") === void 0) return;
|
|
9451
|
+
const keyIndent = childIndent(lines, index);
|
|
9452
|
+
if (keyIndent === void 0) return;
|
|
9453
|
+
const keys = [];
|
|
9454
|
+
for (let i = index + 1; i < blockEnd(lines, index); i++) if ((lines[i] ?? "").trim() !== "" && indentOf$1(lines[i] ?? "") === keyIndent) keys.push(i);
|
|
9455
|
+
if (!keys.some((i) => keyValue(lines[i] ?? "", "matrix") !== void 0)) return;
|
|
9456
|
+
const at = keys.find((i) => keyValue(lines[i] ?? "", "max-parallel") !== void 0);
|
|
9457
|
+
const raw = at === void 0 ? void 0 : keyValue(lines[at] ?? "", "max-parallel");
|
|
9458
|
+
const value = raw === void 0 ? NaN : Number(raw);
|
|
9459
|
+
const wanted = `${" ".repeat(keyIndent)}max-parallel: ${String(limit)}`;
|
|
9460
|
+
if (at === void 0 || raw === void 0) {
|
|
9461
|
+
const after = replaceLine(text, index + 1, [originals[index] ?? line, wanted]);
|
|
9462
|
+
breaks.push({
|
|
9463
|
+
file,
|
|
9464
|
+
line: index + 1,
|
|
9465
|
+
message: `${file}: a matrix has no max-parallel.`,
|
|
9466
|
+
edits: [{
|
|
9467
|
+
file,
|
|
9468
|
+
before: text,
|
|
9469
|
+
after
|
|
9470
|
+
}]
|
|
9471
|
+
});
|
|
9472
|
+
} else if (!Number.isInteger(value) || value < 1 || value > limit) {
|
|
9473
|
+
const after = replaceLine(text, at + 1, [wanted]);
|
|
9474
|
+
breaks.push({
|
|
9475
|
+
file,
|
|
9476
|
+
line: index + 1,
|
|
9477
|
+
message: `${file}: a matrix has max-parallel ${raw}, and the most is ${String(limit)}.`,
|
|
9478
|
+
edits: [{
|
|
9479
|
+
file,
|
|
9480
|
+
before: text,
|
|
9481
|
+
after
|
|
9482
|
+
}]
|
|
9483
|
+
});
|
|
9484
|
+
}
|
|
9485
|
+
});
|
|
9486
|
+
return breaks;
|
|
9487
|
+
}
|
|
9488
|
+
/**
|
|
9489
|
+
* This function gives the minute field of a schedule that starts `perHour` times in each hour, at equal steps. One start is at
|
|
9490
|
+
* `minute`: `"18"` for 1, `"18,48"` for 2. The list is in the order of the numbers.
|
|
9491
|
+
*/
|
|
9492
|
+
function minuteField(minute, perHour) {
|
|
9493
|
+
const step = 60 / perHour;
|
|
9494
|
+
return Array.from({ length: perHour }, (_, k) => (minute + k * step) % 60).sort((a, b) => a - b).join(",");
|
|
9495
|
+
}
|
|
9496
|
+
/** This function gives the number of starts in each hour of a minute field (`"*\/30"` or `"5,35"` give 2), or 1 when it cannot tell. */
|
|
9497
|
+
function startsPerHour(field) {
|
|
9498
|
+
const step = /^\*\/(\d+)$/.exec(field);
|
|
9499
|
+
const count = step ? 60 / Number(step[1]) : field.split(",").length;
|
|
9500
|
+
return Number.isInteger(count) && count >= 1 && 60 % count === 0 ? count : 1;
|
|
9501
|
+
}
|
|
9502
|
+
/**
|
|
9503
|
+
* This function gives the breaks of the schedules: the minute of each `cron` is the minute of the repository and the file. A
|
|
9504
|
+
* schedule that starts more than once in each hour starts at equal steps from that minute (`18,48` for each 30 minutes).
|
|
9505
|
+
*/
|
|
9506
|
+
function cronBreaks(file, text, minute) {
|
|
9507
|
+
const breaks = [];
|
|
9508
|
+
const originals = text.split(/\r?\n/);
|
|
9509
|
+
for (const { line, cron: value } of cronLines(text)) {
|
|
9510
|
+
const fields = value.split(" ").filter((field) => field !== "");
|
|
9511
|
+
const wanted = minuteField(minute, startsPerHour(fields[0] ?? ""));
|
|
9512
|
+
if (fields[0] === wanted) continue;
|
|
9513
|
+
const expected = [wanted, ...fields.slice(1)].join(" ");
|
|
9514
|
+
const original = originals[line - 1] ?? "";
|
|
9515
|
+
const edits = original.includes(value) ? [{
|
|
9516
|
+
file,
|
|
9517
|
+
before: text,
|
|
9518
|
+
after: replaceLine(text, line, [original.replace(value, () => expected)])
|
|
9519
|
+
}] : [];
|
|
9520
|
+
breaks.push({
|
|
9521
|
+
file,
|
|
9522
|
+
line,
|
|
9523
|
+
message: `${file}: the schedule "${value}" starts at minute ${fields[0] ?? "?"}, and the minute of this repository and file is ${String(minute)}.`,
|
|
9524
|
+
fix: `cron: "${expected}"`,
|
|
9525
|
+
edits
|
|
9526
|
+
});
|
|
9527
|
+
}
|
|
9528
|
+
return breaks;
|
|
9529
|
+
}
|
|
9530
|
+
const runnerBudget = {
|
|
9531
|
+
id: "runner-budget",
|
|
9532
|
+
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.",
|
|
9533
|
+
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.",
|
|
9534
|
+
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.",
|
|
9535
|
+
sources: [{
|
|
9536
|
+
repo: "private",
|
|
9537
|
+
rule: "runner-slots",
|
|
9538
|
+
doc: "docs/STRATEGY.md (2026-10-30, the runner slots: a cap of 40, heavy work at most 28)"
|
|
9539
|
+
}],
|
|
9540
|
+
options: {
|
|
9541
|
+
maxParallel: {
|
|
9542
|
+
type: "number",
|
|
9543
|
+
default: 3,
|
|
9544
|
+
description: "The largest max-parallel of a matrix."
|
|
9545
|
+
},
|
|
9546
|
+
minute: {
|
|
9547
|
+
type: "boolean",
|
|
9548
|
+
default: true,
|
|
9549
|
+
description: "When false, the rule does not examine the minute of the schedules."
|
|
9550
|
+
},
|
|
9551
|
+
grouped: {
|
|
9552
|
+
type: "strings",
|
|
9553
|
+
default: ["reusable-ai-review.yml", "reusable-codex-review.yml"],
|
|
9554
|
+
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."
|
|
9555
|
+
}
|
|
9556
|
+
},
|
|
9557
|
+
check(context, options) {
|
|
9558
|
+
const files = context.gitFiles();
|
|
9559
|
+
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
9560
|
+
const workflows = files.filter((path) => WORKFLOW$1.test(path)).sort(byCode);
|
|
9561
|
+
if (workflows.length === 0) return { skipped: "the repository has no workflow" };
|
|
9562
|
+
const remote = context.git([
|
|
9563
|
+
"remote",
|
|
9564
|
+
"get-url",
|
|
9565
|
+
"origin"
|
|
9566
|
+
]);
|
|
9567
|
+
const repository = context.env["GITHUB_REPOSITORY"] ?? (remote === void 0 ? void 0 : repositoryOfRemote(remote));
|
|
9568
|
+
const limit = Number(options["maxParallel"]);
|
|
9569
|
+
const grouped = Array.isArray(options["grouped"]) ? options["grouped"] : [];
|
|
9570
|
+
const breaks = [];
|
|
9571
|
+
for (const file of workflows) {
|
|
9572
|
+
let text;
|
|
9573
|
+
try {
|
|
9574
|
+
text = readFileSync(join(context.root, file), "utf8");
|
|
9575
|
+
} catch {
|
|
9576
|
+
continue;
|
|
9577
|
+
}
|
|
9578
|
+
const lines = workflowLines(text);
|
|
9579
|
+
breaks.push(...matrixBreaks(file, text, lines, limit), ...concurrencyBreaks(file, text, lines, grouped));
|
|
9580
|
+
if (options["minute"] !== false) {
|
|
9581
|
+
if (cronLines(text).length > 0 && repository === void 0) breaks.push({
|
|
9582
|
+
file,
|
|
9583
|
+
message: `${file} has a schedule, and the rule cannot find the repository (GITHUB_REPOSITORY, or a GitHub URL of the remote origin).`
|
|
9584
|
+
});
|
|
9585
|
+
else if (repository !== void 0) breaks.push(...cronBreaks(file, text, scheduleMinute(repository, file)));
|
|
9586
|
+
}
|
|
9587
|
+
}
|
|
9588
|
+
return breaks;
|
|
9589
|
+
}
|
|
9590
|
+
};
|
|
9591
|
+
// src/rules/pages-after-release.ts
|
|
9592
|
+
/**
|
|
9593
|
+
* The rule `pages-after-release`: a repository that publishes a package and deploys a site starts its Pages workflow
|
|
9594
|
+
* after each release, and each day. Without this, the Releases page is behind npm until the next push.
|
|
9595
|
+
*/
|
|
9596
|
+
/** The file of the release flow. */
|
|
9597
|
+
const RELEASE_FILE = ".github/workflows/release.yml";
|
|
9598
|
+
/** The hour (UTC) of a daily build that the fix adds. */
|
|
9599
|
+
const DAILY_HOUR = 5;
|
|
9600
|
+
/** A job that deploys a site with its own steps, and not with the Pages workflow of the template. */
|
|
9601
|
+
const OWN_DEPLOY = /^\s*(?:-\s*)?uses:\s*["']?actions\/deploy-pages@/m;
|
|
9602
|
+
/** This function tells if a line is the key `on` at the top of a workflow. */
|
|
9603
|
+
const onKey = (line) => indentOf$1(line) === 0 && /^["']?on["']?\s*:/.test(line);
|
|
9604
|
+
/** This function gives the name of a workflow: its key `name` at the top of the file. */
|
|
9605
|
+
function workflowName(text) {
|
|
9606
|
+
for (const line of workflowLines(text)) {
|
|
9607
|
+
if (indentOf$1(line) !== 0) continue;
|
|
9608
|
+
const name = keyValue(line, "name");
|
|
9609
|
+
if (name !== void 0 && name !== "") return name;
|
|
9610
|
+
}
|
|
9611
|
+
}
|
|
9612
|
+
/** This function tells if a cron line starts on each day of each month. */
|
|
9613
|
+
function isDaily(cron) {
|
|
9614
|
+
const fields = cron.split(" ").filter((field) => field !== "");
|
|
9615
|
+
return fields.length === 5 && fields.slice(2).every((field) => field === "*");
|
|
9616
|
+
}
|
|
9617
|
+
/** This function gives the index of the key `name` under the key `on`, or undefined. */
|
|
9618
|
+
function triggerKey(lines, on, name) {
|
|
9619
|
+
return childKeys(lines, on).find((index) => keyValue(lines[index] ?? "", name) !== void 0);
|
|
9620
|
+
}
|
|
9621
|
+
/** This function gives the workflows that the trigger `workflow_run` names, or undefined when the rule cannot read them. */
|
|
9622
|
+
function runWorkflows(lines, on) {
|
|
9623
|
+
const run = triggerKey(lines, on, "workflow_run");
|
|
9624
|
+
if (run === void 0) return void 0;
|
|
9625
|
+
const at = childKeys(lines, run).find((index) => keyValue(lines[index] ?? "", "workflows") !== void 0);
|
|
9626
|
+
if (at === void 0) return void 0;
|
|
9627
|
+
const list = listItems(lines, at, keyValue(lines[at] ?? "", "workflows") ?? "");
|
|
9628
|
+
return list === void 0 ? void 0 : {
|
|
9629
|
+
at,
|
|
9630
|
+
items: list.items
|
|
9631
|
+
};
|
|
9632
|
+
}
|
|
9633
|
+
/** This function reads the two triggers of the text of a workflow. A form of `on` on one line has neither. */
|
|
9634
|
+
function pagesTriggers(text, release = "Release") {
|
|
9635
|
+
const lines = workflowLines(text);
|
|
9636
|
+
const on = lines.findIndex(onKey);
|
|
9637
|
+
const daily = cronLines(text).some(({ cron }) => isDaily(cron));
|
|
9638
|
+
if (on < 0) return {
|
|
9639
|
+
afterRelease: false,
|
|
9640
|
+
daily
|
|
9641
|
+
};
|
|
9642
|
+
return {
|
|
9643
|
+
afterRelease: runWorkflows(lines, on)?.items.includes(release) === true,
|
|
9644
|
+
daily
|
|
9645
|
+
};
|
|
9646
|
+
}
|
|
9647
|
+
/** This function gives the index after the last line with text of the block of the key at `index`. */
|
|
9648
|
+
function blockTextEnd(lines, index) {
|
|
9649
|
+
let end = blockEnd(lines, index);
|
|
9650
|
+
while (end > index + 1 && (lines[end - 1] ?? "").trim() === "") end -= 1;
|
|
9651
|
+
return end;
|
|
9652
|
+
}
|
|
9653
|
+
/** This function gives the text with the missing triggers, or undefined when the fix cannot write them. */
|
|
9654
|
+
function addPagesTriggers(text, facts) {
|
|
9655
|
+
const lines = workflowLines(text);
|
|
9656
|
+
const on = lines.findIndex(onKey);
|
|
9657
|
+
if (on < 0 || (keyValue(lines[on] ?? "", "on") ?? "") !== "") return void 0;
|
|
9658
|
+
const keys = childKeys(lines, on);
|
|
9659
|
+
const first = keys[0];
|
|
9660
|
+
if (first === void 0) return void 0;
|
|
9661
|
+
const pad = " ".repeat(indentOf$1(lines[first] ?? ""));
|
|
9662
|
+
const inner = `${pad} `;
|
|
9663
|
+
const splices = [];
|
|
9664
|
+
const found = pagesTriggers(text, facts.release);
|
|
9665
|
+
if (!found.afterRelease) {
|
|
9666
|
+
if (triggerKey(lines, on, "workflow_run") === void 0) {
|
|
9667
|
+
const after = triggerKey(lines, on, "push") ?? keys.at(-1) ?? first;
|
|
9668
|
+
splices.push({
|
|
9669
|
+
at: blockTextEnd(lines, after),
|
|
9670
|
+
remove: 0,
|
|
9671
|
+
insert: [
|
|
9672
|
+
`${pad}# After a release, so that the Releases page has the new version`,
|
|
9673
|
+
`${pad}workflow_run:`,
|
|
9674
|
+
`${inner}workflows: [${facts.release}]`,
|
|
9675
|
+
`${inner}types: [completed]`,
|
|
9676
|
+
`${inner}branches: [${facts.branch}]`
|
|
9677
|
+
]
|
|
9678
|
+
});
|
|
9679
|
+
} else {
|
|
9680
|
+
const named = runWorkflows(lines, on);
|
|
9681
|
+
if (named === void 0) return void 0;
|
|
9682
|
+
if ((keyValue(lines[named.at] ?? "", "workflows") ?? "") === "") {
|
|
9683
|
+
const end = blockTextEnd(lines, named.at);
|
|
9684
|
+
splices.push({
|
|
9685
|
+
at: end,
|
|
9686
|
+
remove: 0,
|
|
9687
|
+
insert: [`${" ".repeat(indentOf$1(lines[end - 1] ?? ""))}- ${facts.release}`]
|
|
9688
|
+
});
|
|
9689
|
+
} else {
|
|
9690
|
+
const original = text.split(/\r?\n/)[named.at] ?? "";
|
|
9691
|
+
const close = original.indexOf("]");
|
|
9692
|
+
if (close < 0) return void 0;
|
|
9693
|
+
splices.push({
|
|
9694
|
+
at: named.at,
|
|
9695
|
+
remove: 1,
|
|
9696
|
+
insert: [`${original.slice(0, close)}, ${facts.release}${original.slice(close)}`]
|
|
9697
|
+
});
|
|
9698
|
+
}
|
|
9699
|
+
}
|
|
9700
|
+
}
|
|
9701
|
+
if (!found.daily) {
|
|
9702
|
+
if (facts.minute === void 0) return void 0;
|
|
9703
|
+
const cron = `"${String(facts.minute)} ${String(DAILY_HOUR)} * * *"`;
|
|
9704
|
+
const schedule = triggerKey(lines, on, "schedule");
|
|
9705
|
+
if (schedule === void 0) {
|
|
9706
|
+
const at = blockTextEnd(lines, keys.at(-1) ?? first);
|
|
9707
|
+
splices.push({
|
|
9708
|
+
at,
|
|
9709
|
+
remove: 0,
|
|
9710
|
+
insert: [
|
|
9711
|
+
`${pad}# Each day, in case a release fails after it publishes`,
|
|
9712
|
+
`${pad}schedule:`,
|
|
9713
|
+
`${inner}- cron: ${cron}`
|
|
9714
|
+
]
|
|
9715
|
+
});
|
|
9716
|
+
} else {
|
|
9717
|
+
const end = blockTextEnd(lines, schedule);
|
|
9718
|
+
const indent = childIndent(lines, schedule) ?? indentOf$1(lines[schedule] ?? "") + 2;
|
|
9719
|
+
splices.push({
|
|
9720
|
+
at: end,
|
|
9721
|
+
remove: 0,
|
|
9722
|
+
insert: [`${" ".repeat(indent)}- cron: ${cron}`]
|
|
9723
|
+
});
|
|
9724
|
+
}
|
|
9725
|
+
}
|
|
9726
|
+
return applySplices(text, splices);
|
|
9727
|
+
}
|
|
9728
|
+
/** This function tells if the repository has a package that it publishes. */
|
|
9729
|
+
function publishes(context) {
|
|
9730
|
+
return [context.rootPackage, ...context.packages].some((info) => info.manifest["private"] !== true);
|
|
9731
|
+
}
|
|
9732
|
+
const pagesAfterRelease = {
|
|
9733
|
+
id: "pages-after-release",
|
|
9734
|
+
title: "A repository with a public package and a release workflow starts its Pages workflow after a release and on each day.",
|
|
9735
|
+
reason: "A release starts no Pages run, so a Releases page is behind npm until the next push. On 2026-11-04 four sites showed an older version than npm for this reason. A release can also fail after it publishes, and then only a daily build shows the version.",
|
|
9736
|
+
fix: "Add `workflow_run` with `workflows: [Release]`, `types: [completed]` and `branches: [<default branch>]` under `on`, and a daily `schedule` (CI.md, \"Pages\"). A workflow that deploys with its own steps also needs a condition that stops a run after a failed release.",
|
|
9737
|
+
sources: [
|
|
9738
|
+
{
|
|
9739
|
+
repo: "template",
|
|
9740
|
+
rule: "pages-after-release",
|
|
9741
|
+
doc: ".github/workflows/pages.yml (workflow_run of Release, and a schedule)"
|
|
9742
|
+
},
|
|
9743
|
+
{
|
|
9744
|
+
repo: "packing",
|
|
9745
|
+
rule: "pages-after-release",
|
|
9746
|
+
doc: ".github/workflows/pages.yml (workflow_run of Release, and a schedule)"
|
|
9747
|
+
},
|
|
9748
|
+
{
|
|
9749
|
+
repo: "ireko",
|
|
9750
|
+
rule: "pages-after-release",
|
|
9751
|
+
doc: ".github/workflows/pages.yml (workflow_run of CI and Release, and a schedule)"
|
|
9752
|
+
}
|
|
9753
|
+
],
|
|
9754
|
+
options: { workflows: {
|
|
9755
|
+
type: "strings",
|
|
9756
|
+
default: PAGES_WORKFLOWS,
|
|
9757
|
+
description: "The workflows that deploy a site, without the ref after `@`."
|
|
9758
|
+
} },
|
|
9759
|
+
check(context, options) {
|
|
9760
|
+
const files = context.gitFiles();
|
|
9761
|
+
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
9762
|
+
if (!files.includes(RELEASE_FILE) || !publishes(context)) return [];
|
|
9763
|
+
const read = (file) => readFileSync(join(context.root, file), "utf8");
|
|
9764
|
+
const release = workflowName(read(RELEASE_FILE)) ?? "Release";
|
|
9765
|
+
const remote = context.git([
|
|
9766
|
+
"remote",
|
|
9767
|
+
"get-url",
|
|
9768
|
+
"origin"
|
|
9769
|
+
]);
|
|
9770
|
+
const repository = context.env["GITHUB_REPOSITORY"] ?? (remote === void 0 ? void 0 : repositoryOfRemote(remote));
|
|
9771
|
+
const breaks = [];
|
|
9772
|
+
for (const file of files.filter((path) => WORKFLOW$1.test(path)).sort(byCode)) {
|
|
9773
|
+
const text = read(file);
|
|
9774
|
+
const calls = pagesCalls(text, options["workflows"]).filter((call) => call.deploys);
|
|
9775
|
+
const own = calls.length === 0 && OWN_DEPLOY.test(workflowLines(text).join("\n")) && !/^\s*workflow_call\s*:/m.test(workflowLines(text).join("\n"));
|
|
9776
|
+
if (calls.length === 0 && !own) continue;
|
|
9777
|
+
const found = pagesTriggers(text, release);
|
|
9778
|
+
if (found.afterRelease && found.daily) continue;
|
|
9779
|
+
const message = `${file} deploys a site, and ${[...found.afterRelease ? [] : [`it does not start after the workflow ${release}`], ...found.daily ? [] : ["it has no schedule with a start on each day"]].join(", and ")}.`;
|
|
9780
|
+
const after = own ? void 0 : addPagesTriggers(text, {
|
|
9781
|
+
release,
|
|
9782
|
+
branch: defaultBranch(context),
|
|
9783
|
+
minute: repository === void 0 ? void 0 : scheduleMinute(repository, file)
|
|
9784
|
+
});
|
|
9785
|
+
const ok = after !== void 0 && after !== text && pagesTriggers(after, release).afterRelease && pagesTriggers(after, release).daily;
|
|
9786
|
+
breaks.push({
|
|
9787
|
+
file,
|
|
9788
|
+
line: 1,
|
|
9789
|
+
message,
|
|
9790
|
+
...ok ? { edits: [{
|
|
9791
|
+
file,
|
|
9792
|
+
before: text,
|
|
9793
|
+
after
|
|
9794
|
+
}] } : own ? { fix: "A person must change it, because this workflow has its own steps. Add the triggers, and stop a run after a failed release with a condition on `github.event.workflow_run.conclusion`." } : {}
|
|
9795
|
+
});
|
|
9796
|
+
}
|
|
9797
|
+
return breaks;
|
|
9798
|
+
}
|
|
9799
|
+
};
|
|
9800
|
+
// src/rules/pinned-git-deps.ts
|
|
9801
|
+
/**
|
|
9802
|
+
* The rule `pinned-git-deps`: a dependency from git names a full commit.
|
|
9803
|
+
*/
|
|
9804
|
+
/** The fields of the root `package.json` that replace the specifiers of dependencies. */
|
|
9805
|
+
const OVERRIDE_FIELDS = ["overrides", "resolutions"];
|
|
9806
|
+
/** This function tells if a specifier gets the package from git, not from a registry or the workspace. */
|
|
9807
|
+
function isGitSpecifier(spec) {
|
|
9808
|
+
const value = spec.trim();
|
|
9809
|
+
if (/^(github|gitlab|bitbucket|gist):/i.test(value)) return true;
|
|
9810
|
+
if (/^git(\+[a-z]+)?:/i.test(value) || /^git@/i.test(value)) return true;
|
|
9811
|
+
if (/^https?:\/\/(www\.)?(github\.com|gitlab\.com|bitbucket\.org|codeload\.github\.com)\//i.test(value)) return true;
|
|
9812
|
+
return /^[\w-][\w.-]*\/[\w.-]+(#.*)?$/.test(value) && !value.startsWith("@");
|
|
9813
|
+
}
|
|
9814
|
+
/**
|
|
9815
|
+
* This function tells if a git specifier names a commit. A specifier names a commit when its ref
|
|
9816
|
+
* (after `#`) is a commit SHA, or when a tarball URL has the SHA in its path.
|
|
9817
|
+
*/
|
|
9818
|
+
function isPinned(spec, fullSha) {
|
|
9819
|
+
const sha = fullSha ? /^[0-9a-f]{40}$/i : /^[0-9a-f]{7,40}$/i;
|
|
9820
|
+
const hash = spec.indexOf("#");
|
|
9821
|
+
if (hash >= 0) return spec.slice(hash + 1).split("&").some((part) => sha.test(part.replace(/^commit=/, "")));
|
|
9822
|
+
const path = /^https?:\/\/[^/]+\/(.*)$/i.exec(spec.trim())?.[1];
|
|
9823
|
+
return path !== void 0 && path.split(/[/.]/).some((part) => sha.test(part));
|
|
9824
|
+
}
|
|
9825
|
+
/** This function gives the specifiers of the fields of overrides, also the field `overrides` of `pnpm`. */
|
|
9826
|
+
function overridesOf(manifest) {
|
|
9827
|
+
const out = [];
|
|
9828
|
+
for (const field of OVERRIDE_FIELDS) for (const [name, spec] of specifiersOf(manifest, field)) out.push([
|
|
9829
|
+
field,
|
|
9830
|
+
name,
|
|
9831
|
+
spec
|
|
9832
|
+
]);
|
|
9833
|
+
const pnpm = manifest["pnpm"];
|
|
9834
|
+
if (typeof pnpm === "object" && pnpm !== null) for (const [name, spec] of specifiersOf(pnpm, "overrides")) out.push([
|
|
9835
|
+
"pnpm",
|
|
9836
|
+
name,
|
|
9837
|
+
spec
|
|
9838
|
+
]);
|
|
9839
|
+
return out;
|
|
9840
|
+
}
|
|
9841
|
+
const pinnedGitDeps = {
|
|
9842
|
+
id: "pinned-git-deps",
|
|
9843
|
+
title: "A dependency from git (github:, git+https: or owner/repo) names a full commit SHA.",
|
|
9844
|
+
reason: "A git ref without a commit moves with the branch. Then an install today and an install tomorrow get different code, and the lockfile hides the change.",
|
|
9845
|
+
fix: "Use the npm version, `workspace:*` for a package of this repository, or `github:owner/repo#<full commit SHA>`.",
|
|
9846
|
+
sources: [
|
|
9847
|
+
{
|
|
9848
|
+
repo: "coeval",
|
|
9849
|
+
rule: "pinned-deps",
|
|
9850
|
+
doc: "CLAUDE.md:41"
|
|
9851
|
+
},
|
|
9852
|
+
{
|
|
9853
|
+
repo: "coeval",
|
|
9854
|
+
rule: "unpublished-dep-pinned",
|
|
9855
|
+
doc: "CLAUDE.md:41"
|
|
9856
|
+
},
|
|
9857
|
+
{
|
|
9858
|
+
repo: "headroom",
|
|
9859
|
+
rule: "non-npm-deps-pinned",
|
|
9860
|
+
doc: "CLAUDE.md:38"
|
|
9861
|
+
},
|
|
9862
|
+
{
|
|
9863
|
+
repo: "headroom",
|
|
9864
|
+
rule: "pinned-github-specifier",
|
|
9865
|
+
doc: "CLAUDE.md:38"
|
|
9866
|
+
},
|
|
9867
|
+
{
|
|
9868
|
+
repo: "private",
|
|
9869
|
+
rule: "github-dep-full-sha",
|
|
9870
|
+
doc: "docs/decisions.md:1384"
|
|
9871
|
+
},
|
|
9872
|
+
{
|
|
9873
|
+
repo: "private",
|
|
9874
|
+
rule: "github-dep-pinned",
|
|
9875
|
+
doc: "docs/decisions.md:1384"
|
|
9876
|
+
},
|
|
9877
|
+
{
|
|
9878
|
+
repo: "client",
|
|
9879
|
+
rule: "general-npm-version",
|
|
9880
|
+
doc: "CLAUDE.md:54"
|
|
9881
|
+
}
|
|
9882
|
+
],
|
|
9883
|
+
options: { fullSha: {
|
|
9884
|
+
type: "boolean",
|
|
9885
|
+
default: true,
|
|
9886
|
+
description: "When false, a short SHA of 7 or more characters is also a commit."
|
|
9887
|
+
} },
|
|
9888
|
+
check(context, options) {
|
|
9889
|
+
const fullSha = options["fullSha"] !== false;
|
|
9890
|
+
const breaks = [];
|
|
9891
|
+
for (const info of [context.rootPackage, ...context.packages]) {
|
|
9892
|
+
const found = [];
|
|
9893
|
+
for (const field of DEPENDENCY_FIELDS) for (const [name, spec] of specifiersOf(info.manifest, field)) found.push([
|
|
9894
|
+
field,
|
|
9895
|
+
name,
|
|
9896
|
+
spec
|
|
9897
|
+
]);
|
|
9898
|
+
found.push(...overridesOf(info.manifest));
|
|
9899
|
+
for (const [field, name, spec] of found) {
|
|
9900
|
+
if (!isGitSpecifier(spec) || isPinned(spec, fullSha)) continue;
|
|
9901
|
+
const line = keyLine(info.text, field, name);
|
|
9902
|
+
breaks.push({
|
|
9903
|
+
file: info.file,
|
|
9904
|
+
...line === void 0 ? {} : { line },
|
|
9905
|
+
message: `${field} "${name}" is "${spec}": a git dependency without a ${fullSha ? "full " : ""}commit SHA.`
|
|
9906
|
+
});
|
|
9907
|
+
}
|
|
9908
|
+
}
|
|
9909
|
+
return breaks;
|
|
9910
|
+
}
|
|
9911
|
+
};
|
|
9912
|
+
// src/rules/unreleased-change.ts
|
|
9913
|
+
/**
|
|
9914
|
+
* The rule `unreleased-change`: a change does not set a version that npm has. With the option `versionEachChange`, a
|
|
9915
|
+
* change of the files that a published package ships also raises its version. Else the release skips the change.
|
|
9916
|
+
*/
|
|
9917
|
+
/** The registry of npm. */
|
|
9918
|
+
const NPM_REGISTRY = "https://registry.npmjs.org";
|
|
9919
|
+
/** The globs of the files of a package, relative to its folder, that do not ship: tests, fixtures, docs and configs. */
|
|
9920
|
+
const UNSHIPPED_FILES = [
|
|
9921
|
+
"**/*.md",
|
|
9922
|
+
"**/*.{test,spec}.*",
|
|
9923
|
+
"**/{test,tests,__tests__,fixtures,__fixtures__,__snapshots__,bench,benches,benchmarks,e2e}/**",
|
|
9924
|
+
"**/*.{bench,e2e}.*",
|
|
9925
|
+
"**/.*/**",
|
|
9926
|
+
"**/tsconfig*.json",
|
|
9927
|
+
"**/*.config.*",
|
|
9928
|
+
"docs/**",
|
|
9929
|
+
"examples/**",
|
|
9930
|
+
"scripts/**",
|
|
9931
|
+
"site/**",
|
|
9932
|
+
"LICENSE*",
|
|
9933
|
+
"pnpm-lock.yaml",
|
|
9934
|
+
"pnpm-workspace.yaml"
|
|
9935
|
+
];
|
|
9936
|
+
/** The fields of `package.json` that change what the package gives to a user. A change of the dependencies is not here. */
|
|
9937
|
+
const SHIPPED_FIELDS = [
|
|
9938
|
+
"main",
|
|
9939
|
+
"module",
|
|
9940
|
+
"types",
|
|
9941
|
+
"typings",
|
|
9942
|
+
"exports",
|
|
9943
|
+
"imports",
|
|
9944
|
+
"bin",
|
|
9945
|
+
"files",
|
|
9946
|
+
"type",
|
|
9947
|
+
"publishConfig",
|
|
9948
|
+
"sideEffects",
|
|
9949
|
+
"browser"
|
|
9950
|
+
];
|
|
9951
|
+
/** The script that `npmLookup` starts in a child process of Node, so that the rule stays synchronous. */
|
|
9952
|
+
const LOOKUP_SCRIPT = `
|
|
9953
|
+
const [registry, ...names] = process.argv.slice(1);
|
|
9954
|
+
let base = registry;
|
|
9955
|
+
while (base.endsWith("/")) base = base.slice(0, -1);
|
|
9956
|
+
Promise.all(names.map(async (name) => {
|
|
9957
|
+
try {
|
|
9958
|
+
const response = await fetch(base + "/" + name.replace("/", "%2f"), { headers: { accept: "application/json" }, signal: AbortSignal.timeout(20000) });
|
|
9959
|
+
if (response.status === 404) return [name, { versions: [] }];
|
|
9960
|
+
if (!response.ok) return [name, { error: "HTTP " + response.status }];
|
|
9961
|
+
const data = await response.json();
|
|
9962
|
+
const times = Object.fromEntries(Object.entries(data.time ?? {}).filter(([key]) => key !== "created" && key !== "modified"));
|
|
9963
|
+
return [name, { versions: [...new Set([...Object.keys(data.versions ?? {}), ...Object.keys(times)])], times, latest: data["dist-tags"]?.latest }];
|
|
9964
|
+
} catch (error) {
|
|
9965
|
+
return [name, { error: String(error && error.message ? error.message : error) }];
|
|
9966
|
+
}
|
|
9967
|
+
})).then((entries) => process.stdout.write(JSON.stringify(Object.fromEntries(entries))));
|
|
9968
|
+
`;
|
|
9969
|
+
/**
|
|
9970
|
+
* This function asks the registry for the versions of each package, in one child process of Node. A version that npm
|
|
9971
|
+
* removed stays in the answer, because npm does not accept it again.
|
|
9972
|
+
*/
|
|
9973
|
+
const npmLookup = (names, registry) => {
|
|
9974
|
+
const fail = (error) => new Map(names.map((name) => [name, { error }]));
|
|
9975
|
+
if (names.length === 0) return /* @__PURE__ */ new Map();
|
|
9976
|
+
const result = spawnSync(process.execPath, [
|
|
9977
|
+
"-e",
|
|
9978
|
+
LOOKUP_SCRIPT,
|
|
9979
|
+
registry,
|
|
9980
|
+
...names
|
|
9981
|
+
], {
|
|
9982
|
+
encoding: "utf8",
|
|
9983
|
+
timeout: 6e4,
|
|
9984
|
+
windowsHide: true
|
|
9985
|
+
});
|
|
9986
|
+
if (result.error !== void 0 || result.status !== 0) return fail(result.error?.message ?? `the lookup ended with exit code ${String(result.status)}`);
|
|
9987
|
+
try {
|
|
9988
|
+
const answers = JSON.parse(result.stdout);
|
|
9989
|
+
return new Map(names.map((name) => [name, answers[name] ?? { error: "no answer" }]));
|
|
9990
|
+
} catch {
|
|
9991
|
+
return fail("the lookup gave no JSON");
|
|
9992
|
+
}
|
|
9993
|
+
};
|
|
9994
|
+
/** This function gives the strings of a field of `package.json` that is a list of strings. */
|
|
9995
|
+
const stringsOf = (manifest, field) => {
|
|
9996
|
+
const value = manifest[field];
|
|
9997
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
9998
|
+
};
|
|
9999
|
+
/** This function tells if a path relative to the root is in the folder `folder`. The root is `""`. */
|
|
10000
|
+
const inside = (folder, path) => folder === "" || path.startsWith(`${folder}/`);
|
|
10001
|
+
/** This function gives the globs of an entry of the field `files`: the entry, and each path under it. */
|
|
10002
|
+
const entryGlobs = (entry) => {
|
|
10003
|
+
let glob = cleanPath(entry);
|
|
10004
|
+
while (glob.endsWith("/")) glob = glob.slice(0, -1);
|
|
10005
|
+
return [glob, `${glob}/**`];
|
|
10006
|
+
};
|
|
10007
|
+
/** This function reads the manifest of the text of a `package.json` file, or gives undefined. */
|
|
10008
|
+
function parseManifest(text) {
|
|
10009
|
+
if (text === void 0) return void 0;
|
|
10010
|
+
try {
|
|
10011
|
+
const parsed = JSON.parse(text);
|
|
10012
|
+
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) ? parsed : void 0;
|
|
10013
|
+
} catch {
|
|
10014
|
+
return;
|
|
10015
|
+
}
|
|
10016
|
+
}
|
|
10017
|
+
/** This function tells if a version is a placeholder before the first release: `0.0.0` or `0.0.0-<stage>`. */
|
|
10018
|
+
const isPlaceholder = (version) => /^0\.0\.0(?:[-+].*)?$/.test(version);
|
|
10019
|
+
/** The published packages of the repository: the root package and the code packages that are not private and have a name and a version. */
|
|
10020
|
+
function publishedOf(context) {
|
|
10021
|
+
const all = [context.rootPackage, ...codePackages(context)];
|
|
10022
|
+
return all.filter((pkg, index) => all.findIndex((other) => other.file === pkg.file) === index).filter((pkg) => pkg.manifest["private"] !== true && typeof pkg.manifest["name"] === "string" && typeof pkg.manifest["version"] === "string");
|
|
10023
|
+
}
|
|
10024
|
+
/** This function gives the time of the push in milliseconds, from the field `repository.pushed_at` of the event file. */
|
|
10025
|
+
function pushedAt(context) {
|
|
10026
|
+
const file = context.env["GITHUB_EVENT_PATH"];
|
|
9531
10027
|
if (file === void 0 || file === "" || !existsSync(file)) return void 0;
|
|
9532
10028
|
try {
|
|
9533
10029
|
const value = JSON.parse(readFileSync(file, "utf8")).repository?.pushed_at;
|
|
@@ -10195,270 +10691,6 @@ const roadmapParses = {
|
|
|
10195
10691
|
return breaks;
|
|
10196
10692
|
}
|
|
10197
10693
|
};
|
|
10198
|
-
// src/rules/runner-budget.ts
|
|
10199
|
-
/**
|
|
10200
|
-
* The rule `runner-budget`: the workflows share the runners of the account. Each matrix has a `max-parallel`, each
|
|
10201
|
-
* workflow has a concurrency group, and each schedule starts at the minute of its repository and file.
|
|
10202
|
-
*/
|
|
10203
|
-
/**
|
|
10204
|
-
* This function gives the minute (1 to 59) of the schedules of a workflow: the FNV-1a hash of the repository and the
|
|
10205
|
-
* file. Two repositories with the same workflow thus start at different minutes, and no schedule starts at minute 0,
|
|
10206
|
-
* where GitHub has the most load.
|
|
10207
|
-
*/
|
|
10208
|
-
function scheduleMinute(repository, file) {
|
|
10209
|
-
let hash = 2166136261;
|
|
10210
|
-
for (const char of `${repository.toLowerCase()}/${file}`) {
|
|
10211
|
-
hash ^= char.codePointAt(0) ?? 0;
|
|
10212
|
-
hash = Math.imul(hash, 16777619) >>> 0;
|
|
10213
|
-
}
|
|
10214
|
-
return hash % 59 + 1;
|
|
10215
|
-
}
|
|
10216
|
-
/** This function gives `owner/name` from a git remote URL, or undefined for a URL that is not of GitHub. */
|
|
10217
|
-
function repositoryOfRemote(url) {
|
|
10218
|
-
const text = url.trim();
|
|
10219
|
-
for (const prefix of [
|
|
10220
|
-
"git@github.com:",
|
|
10221
|
-
"ssh://git@github.com/",
|
|
10222
|
-
"https://github.com/",
|
|
10223
|
-
"http://github.com/",
|
|
10224
|
-
"git+https://github.com/"
|
|
10225
|
-
]) {
|
|
10226
|
-
if (!text.startsWith(prefix)) continue;
|
|
10227
|
-
let rest = text.slice(prefix.length);
|
|
10228
|
-
if (rest.endsWith("/")) rest = rest.slice(0, -1);
|
|
10229
|
-
if (rest.endsWith(".git")) rest = rest.slice(0, -4);
|
|
10230
|
-
const parts = rest.split("/");
|
|
10231
|
-
return parts.length === 2 && parts.every((part) => part !== "") ? rest : void 0;
|
|
10232
|
-
}
|
|
10233
|
-
}
|
|
10234
|
-
/** This function tells if a workflow is a shared workflow (`on: workflow_call`). Its caller gives the concurrency group. */
|
|
10235
|
-
function isShared(lines) {
|
|
10236
|
-
return lines.some((line) => {
|
|
10237
|
-
const text = line.trimStart();
|
|
10238
|
-
return text.startsWith("workflow_call:") || text === "workflow_call" || text === "- workflow_call" || text.startsWith("on:") && text.includes("workflow_call");
|
|
10239
|
-
});
|
|
10240
|
-
}
|
|
10241
|
-
/** This function gives the jobs of a workflow. */
|
|
10242
|
-
function jobsOf(lines) {
|
|
10243
|
-
const jobs = lines.findIndex((line) => indentOf$1(line) === 0 && line.startsWith("jobs:"));
|
|
10244
|
-
if (jobs < 0) return [];
|
|
10245
|
-
const jobIndent = childIndent(lines, jobs);
|
|
10246
|
-
const end = blockEnd(lines, jobs);
|
|
10247
|
-
const found = [];
|
|
10248
|
-
for (let i = jobs + 1; i < end; i++) {
|
|
10249
|
-
const line = lines[i] ?? "";
|
|
10250
|
-
if (line.trim() === "" || indentOf$1(line) !== jobIndent) continue;
|
|
10251
|
-
const keyIndent = childIndent(lines, i);
|
|
10252
|
-
const keys = lines.slice(i + 1, blockEnd(lines, i)).filter((text) => indentOf$1(text) === keyIndent);
|
|
10253
|
-
const uses = keys.map((text) => keyValue(text, "uses")).find((value) => value !== void 0);
|
|
10254
|
-
const at = uses === void 0 ? -1 : uses.indexOf(".github/workflows/");
|
|
10255
|
-
const calls = uses === void 0 || at < 0 ? void 0 : uses.slice(at + 18).split("@")[0] ?? "";
|
|
10256
|
-
found.push({
|
|
10257
|
-
name: line.trim().replace(/:$/, ""),
|
|
10258
|
-
line: i + 1,
|
|
10259
|
-
grouped: keys.some((text) => keyValue(text, "concurrency") !== void 0),
|
|
10260
|
-
...calls === void 0 ? {} : { calls }
|
|
10261
|
-
});
|
|
10262
|
-
}
|
|
10263
|
-
return found;
|
|
10264
|
-
}
|
|
10265
|
-
const hasTopGroup = (lines) => lines.some((line) => indentOf$1(line) === 0 && line.startsWith("concurrency:"));
|
|
10266
|
-
/**
|
|
10267
|
-
* This function gives the edit that adds a concurrency group at the top of a workflow, before `jobs:`. A new run of a pull
|
|
10268
|
-
* request stops the old run. A run of another event has the group of its commit, so that no release or scheduled run stops.
|
|
10269
|
-
*/
|
|
10270
|
-
function groupEdits(file, text, lines) {
|
|
10271
|
-
const jobs = lines.findIndex((line) => indentOf$1(line) === 0 && line.startsWith("jobs:"));
|
|
10272
|
-
if (jobs < 0) return [];
|
|
10273
|
-
const pad = " ".repeat(childIndent(lines, jobs) ?? 2);
|
|
10274
|
-
const original = text.split(/\r?\n/)[jobs] ?? "jobs:";
|
|
10275
|
-
const group = [
|
|
10276
|
-
"concurrency:",
|
|
10277
|
-
pad + "group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }}",
|
|
10278
|
-
pad + "cancel-in-progress: ${{ github.event_name == 'pull_request' }}",
|
|
10279
|
-
"",
|
|
10280
|
-
original
|
|
10281
|
-
];
|
|
10282
|
-
return [{
|
|
10283
|
-
file,
|
|
10284
|
-
before: text,
|
|
10285
|
-
after: replaceLine(text, jobs + 1, group)
|
|
10286
|
-
}];
|
|
10287
|
-
}
|
|
10288
|
-
/**
|
|
10289
|
-
* This function gives the breaks of the concurrency groups. A workflow with no group at the top needs one in each job.
|
|
10290
|
-
* A job that calls a shared workflow of `grouped` gets its group from the jobs of that workflow. A shared workflow gets
|
|
10291
|
-
* its group from its caller, but a shared workflow of `grouped` has a group in each job.
|
|
10292
|
-
*/
|
|
10293
|
-
function concurrencyBreaks(file, text, lines, grouped) {
|
|
10294
|
-
const name = file.slice(file.lastIndexOf("/") + 1);
|
|
10295
|
-
const jobs = jobsOf(lines);
|
|
10296
|
-
if (isShared(lines)) {
|
|
10297
|
-
if (!grouped.includes(name)) return [];
|
|
10298
|
-
return jobs.filter((job) => !job.grouped).map((job) => ({
|
|
10299
|
-
file,
|
|
10300
|
-
line: job.line,
|
|
10301
|
-
message: `${file}: the job ${job.name} has no concurrency group, and its callers rely on it (the option grouped).`
|
|
10302
|
-
}));
|
|
10303
|
-
}
|
|
10304
|
-
if (hasTopGroup(lines)) return [];
|
|
10305
|
-
const missing = jobs.filter((job) => !job.grouped && !(job.calls !== void 0 && grouped.includes(job.calls)));
|
|
10306
|
-
const edits = missing.length === 0 ? [] : groupEdits(file, text, lines);
|
|
10307
|
-
return missing.map((job) => ({
|
|
10308
|
-
file,
|
|
10309
|
-
line: job.line,
|
|
10310
|
-
message: `${file}: the job ${job.name} has no concurrency group, and the workflow has none.`,
|
|
10311
|
-
edits
|
|
10312
|
-
}));
|
|
10313
|
-
}
|
|
10314
|
-
/** This function gives the breaks of the matrices: each `strategy` with a `matrix` has a `max-parallel` of `limit` or less. */
|
|
10315
|
-
function matrixBreaks(file, text, lines, limit) {
|
|
10316
|
-
const breaks = [];
|
|
10317
|
-
const originals = text.split(/\r?\n/);
|
|
10318
|
-
lines.forEach((line, index) => {
|
|
10319
|
-
if (keyValue(line, "strategy") === void 0) return;
|
|
10320
|
-
const keyIndent = childIndent(lines, index);
|
|
10321
|
-
if (keyIndent === void 0) return;
|
|
10322
|
-
const keys = [];
|
|
10323
|
-
for (let i = index + 1; i < blockEnd(lines, index); i++) if ((lines[i] ?? "").trim() !== "" && indentOf$1(lines[i] ?? "") === keyIndent) keys.push(i);
|
|
10324
|
-
if (!keys.some((i) => keyValue(lines[i] ?? "", "matrix") !== void 0)) return;
|
|
10325
|
-
const at = keys.find((i) => keyValue(lines[i] ?? "", "max-parallel") !== void 0);
|
|
10326
|
-
const raw = at === void 0 ? void 0 : keyValue(lines[at] ?? "", "max-parallel");
|
|
10327
|
-
const value = raw === void 0 ? NaN : Number(raw);
|
|
10328
|
-
const wanted = `${" ".repeat(keyIndent)}max-parallel: ${String(limit)}`;
|
|
10329
|
-
if (at === void 0 || raw === void 0) {
|
|
10330
|
-
const after = replaceLine(text, index + 1, [originals[index] ?? line, wanted]);
|
|
10331
|
-
breaks.push({
|
|
10332
|
-
file,
|
|
10333
|
-
line: index + 1,
|
|
10334
|
-
message: `${file}: a matrix has no max-parallel.`,
|
|
10335
|
-
edits: [{
|
|
10336
|
-
file,
|
|
10337
|
-
before: text,
|
|
10338
|
-
after
|
|
10339
|
-
}]
|
|
10340
|
-
});
|
|
10341
|
-
} else if (!Number.isInteger(value) || value < 1 || value > limit) {
|
|
10342
|
-
const after = replaceLine(text, at + 1, [wanted]);
|
|
10343
|
-
breaks.push({
|
|
10344
|
-
file,
|
|
10345
|
-
line: index + 1,
|
|
10346
|
-
message: `${file}: a matrix has max-parallel ${raw}, and the most is ${String(limit)}.`,
|
|
10347
|
-
edits: [{
|
|
10348
|
-
file,
|
|
10349
|
-
before: text,
|
|
10350
|
-
after
|
|
10351
|
-
}]
|
|
10352
|
-
});
|
|
10353
|
-
}
|
|
10354
|
-
});
|
|
10355
|
-
return breaks;
|
|
10356
|
-
}
|
|
10357
|
-
/**
|
|
10358
|
-
* This function gives the minute field of a schedule that starts `perHour` times in each hour, at equal steps. One start is at
|
|
10359
|
-
* `minute`: `"18"` for 1, `"18,48"` for 2. The list is in the order of the numbers.
|
|
10360
|
-
*/
|
|
10361
|
-
function minuteField(minute, perHour) {
|
|
10362
|
-
const step = 60 / perHour;
|
|
10363
|
-
return Array.from({ length: perHour }, (_, k) => (minute + k * step) % 60).sort((a, b) => a - b).join(",");
|
|
10364
|
-
}
|
|
10365
|
-
/** This function gives the number of starts in each hour of a minute field (`"*\/30"` or `"5,35"` give 2), or 1 when it cannot tell. */
|
|
10366
|
-
function startsPerHour(field) {
|
|
10367
|
-
const step = /^\*\/(\d+)$/.exec(field);
|
|
10368
|
-
const count = step ? 60 / Number(step[1]) : field.split(",").length;
|
|
10369
|
-
return Number.isInteger(count) && count >= 1 && 60 % count === 0 ? count : 1;
|
|
10370
|
-
}
|
|
10371
|
-
/**
|
|
10372
|
-
* This function gives the breaks of the schedules: the minute of each `cron` is the minute of the repository and the file. A
|
|
10373
|
-
* schedule that starts more than once in each hour starts at equal steps from that minute (`18,48` for each 30 minutes).
|
|
10374
|
-
*/
|
|
10375
|
-
function cronBreaks(file, text, lines, minute) {
|
|
10376
|
-
const breaks = [];
|
|
10377
|
-
const originals = text.split(/\r?\n/);
|
|
10378
|
-
lines.forEach((line, index) => {
|
|
10379
|
-
const value = keyValue(line, "cron");
|
|
10380
|
-
if (value === void 0) return;
|
|
10381
|
-
const fields = value.split(" ").filter((field) => field !== "");
|
|
10382
|
-
const wanted = minuteField(minute, startsPerHour(fields[0] ?? ""));
|
|
10383
|
-
if (fields[0] === wanted) return;
|
|
10384
|
-
const expected = [wanted, ...fields.slice(1)].join(" ");
|
|
10385
|
-
const original = originals[index] ?? line;
|
|
10386
|
-
const edits = original.includes(value) ? [{
|
|
10387
|
-
file,
|
|
10388
|
-
before: text,
|
|
10389
|
-
after: replaceLine(text, index + 1, [original.replace(value, () => expected)])
|
|
10390
|
-
}] : [];
|
|
10391
|
-
breaks.push({
|
|
10392
|
-
file,
|
|
10393
|
-
line: index + 1,
|
|
10394
|
-
message: `${file}: the schedule "${value}" starts at minute ${fields[0] ?? "?"}, and the minute of this repository and file is ${String(minute)}.`,
|
|
10395
|
-
fix: `cron: "${expected}"`,
|
|
10396
|
-
edits
|
|
10397
|
-
});
|
|
10398
|
-
});
|
|
10399
|
-
return breaks;
|
|
10400
|
-
}
|
|
10401
|
-
const runnerBudget = {
|
|
10402
|
-
id: "runner-budget",
|
|
10403
|
-
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.",
|
|
10404
|
-
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.",
|
|
10405
|
-
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.",
|
|
10406
|
-
sources: [{
|
|
10407
|
-
repo: "private",
|
|
10408
|
-
rule: "runner-slots",
|
|
10409
|
-
doc: "docs/STRATEGY.md (2026-10-30, the runner slots: a cap of 40, heavy work at most 28)"
|
|
10410
|
-
}],
|
|
10411
|
-
options: {
|
|
10412
|
-
maxParallel: {
|
|
10413
|
-
type: "number",
|
|
10414
|
-
default: 3,
|
|
10415
|
-
description: "The largest max-parallel of a matrix."
|
|
10416
|
-
},
|
|
10417
|
-
minute: {
|
|
10418
|
-
type: "boolean",
|
|
10419
|
-
default: true,
|
|
10420
|
-
description: "When false, the rule does not examine the minute of the schedules."
|
|
10421
|
-
},
|
|
10422
|
-
grouped: {
|
|
10423
|
-
type: "strings",
|
|
10424
|
-
default: ["reusable-ai-review.yml", "reusable-codex-review.yml"],
|
|
10425
|
-
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."
|
|
10426
|
-
}
|
|
10427
|
-
},
|
|
10428
|
-
check(context, options) {
|
|
10429
|
-
const files = context.gitFiles();
|
|
10430
|
-
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
10431
|
-
const workflows = files.filter((path) => WORKFLOW$1.test(path)).sort(byCode);
|
|
10432
|
-
if (workflows.length === 0) return { skipped: "the repository has no workflow" };
|
|
10433
|
-
const remote = context.git([
|
|
10434
|
-
"remote",
|
|
10435
|
-
"get-url",
|
|
10436
|
-
"origin"
|
|
10437
|
-
]);
|
|
10438
|
-
const repository = context.env["GITHUB_REPOSITORY"] ?? (remote === void 0 ? void 0 : repositoryOfRemote(remote));
|
|
10439
|
-
const limit = Number(options["maxParallel"]);
|
|
10440
|
-
const grouped = Array.isArray(options["grouped"]) ? options["grouped"] : [];
|
|
10441
|
-
const breaks = [];
|
|
10442
|
-
for (const file of workflows) {
|
|
10443
|
-
let text;
|
|
10444
|
-
try {
|
|
10445
|
-
text = readFileSync(join(context.root, file), "utf8");
|
|
10446
|
-
} catch {
|
|
10447
|
-
continue;
|
|
10448
|
-
}
|
|
10449
|
-
const lines = workflowLines(text);
|
|
10450
|
-
breaks.push(...matrixBreaks(file, text, lines, limit), ...concurrencyBreaks(file, text, lines, grouped));
|
|
10451
|
-
if (options["minute"] !== false) {
|
|
10452
|
-
if (lines.some((line) => keyValue(line, "cron") !== void 0) && repository === void 0) breaks.push({
|
|
10453
|
-
file,
|
|
10454
|
-
message: `${file} has a schedule, and the rule cannot find the repository (GITHUB_REPOSITORY, or a GitHub URL of the remote origin).`
|
|
10455
|
-
});
|
|
10456
|
-
else if (repository !== void 0) breaks.push(...cronBreaks(file, text, lines, scheduleMinute(repository, file)));
|
|
10457
|
-
}
|
|
10458
|
-
}
|
|
10459
|
-
return breaks;
|
|
10460
|
-
}
|
|
10461
|
-
};
|
|
10462
10694
|
// src/rules/shared-docs.ts
|
|
10463
10695
|
/**
|
|
10464
10696
|
* The rule `shared-docs`: each shared block of a document agrees with its lock, and each linked block points to its
|
|
@@ -11780,6 +12012,7 @@ const RULES = [
|
|
|
11780
12012
|
homePackage,
|
|
11781
12013
|
licenseFile,
|
|
11782
12014
|
pagesSite,
|
|
12015
|
+
pagesAfterRelease,
|
|
11783
12016
|
sharedDocs
|
|
11784
12017
|
];
|
|
11785
12018
|
// src/run.ts
|
|
@@ -12212,6 +12445,6 @@ function runMap(args, io) {
|
|
|
12212
12445
|
else io.stdout(mapText(found));
|
|
12213
12446
|
return 0;
|
|
12214
12447
|
}
|
|
12215
|
-
export {
|
|
12448
|
+
export { PAGES_WORKFLOWS as $, workspaceGlobs as $t, roadmapOfLine as A, convertGate as At, SHIPPED_FIELDS as B, hasFile as Bt, isSourcePath as C, findHomes as Ct, blockHash as D, readOverlay as Dt, HOME_TIMEOUT_MS as E, mergeHomes as Et, minorOf as F, STRICT_OPTIONS as Ft, isGitSpecifier as G, parseJsonc as Gt, npmLookup as H, keyLine as Ht, publishedMinor as I, cuePreset as It, pagesAfterRelease as J, runGit as Jt, isPinned as K, readJsonc as Kt, publishedMinorRule as L, DEPENDENCY_FIELDS as Lt, requiredScripts as M, prPathFilters as Mt, releaseFiles as N, summaryName as Nt, githubFetch as O, HOME_EXPORTS as Ot, lockedVersions as P, readWorkflow as Pt, pushMainOnly as Q, packageFolders as Qt, reachOf as R, cleanPath as Rt, tsconfigTest as S, MAP_RULE as St, sourceMain as T, mapText as Tt, unreleasedChange as U, lineOf as Ut, UNSHIPPED_FILES as V, inFolder as Vt, unreleasedChangeRule as W, matchesAny as Wt, runnerBudget as X, globFolders as Xt, repositoryOfRemote as Y, specifiersOf as Yt, scheduleMinute as Z, globToRegExp as Zt, configsOfScript as _, homePackage as _t, listRules as a, noLocalPaths as at, testsRequired as b, signaturesOf as bt, runCli as c, hasImportMetaMain as ct, RULES as d, authorOf as dt, defaultOptions as en, pagesCalls as et, workspaceProtocol as f, licenseFile as ft, typedScripts as g, declaredName as gt, trustPolicy as h, repositoryIsPublic as ht, formatResult as i, HOME_PATTERNS as it, roadmapParses as j, gateTrigger as jt, sharedDocsRule as k, ACTIONS_COMMIT as kt, runFix as l, mainCheck as lt, TRAIN_SCOPES as m, mitText as mt, annotations as n, apiReportScript as nt, readConfig as o, noBuildOutput as ot, IGNORE_AFTER as p, licenseFileOf as pt, pinnedGitDeps as q, replaceLine as qt, createContext as r, DEFAULT_ALLOWED as rt, runChecks as s, REAL_COMPARE as st, USAGE as t, parseConfig as tn, pagesSite as tt, summaryMarkdown as u, LICENSE_TEXTS as ut, scriptsOf as v, messageOf as vt, pathsOf as w, mapMarkdown as wt, hasTests as x, HOMES as xt, typedFiles as y, repoOf as yt, NPM_REGISTRY as z, codePackages as zt };
|
|
12216
12449
|
|
|
12217
|
-
//# sourceMappingURL=run-
|
|
12450
|
+
//# sourceMappingURL=run-5nn4yBKi.js.map
|