@mark1russell7/conventions 0.50.2 → 0.50.3

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.
@@ -2321,6 +2321,398 @@ const gateTrigger = {
2321
2321
  return breaks;
2322
2322
  }
2323
2323
  };
2324
+ // src/rules/license-file.ts
2325
+ /**
2326
+ * The rule `license-file`. Each public package has a license field and, in its own folder, a license file with the
2327
+ * same license. A repository with a public package has a license file at its root.
2328
+ */
2329
+ /** The names of a license file, without case. */
2330
+ const LICENSE_NAME = /^licen[cs]e(?:\.(?:md|txt))?$/i;
2331
+ /** For each license that the rule knows, a pattern of its text. The text of another license is not checked. */
2332
+ const LICENSE_TEXTS = {
2333
+ MIT: /\bMIT License\b|Permission is hereby granted, free of charge/,
2334
+ ISC: /\bISC License\b|Permission to use, copy, modify, and\/or distribute/,
2335
+ "Apache-2.0": /Apache License,?\s+Version 2\.0/,
2336
+ "BSD-3-Clause": /Redistribution and use in source and binary forms[\s\S]*Neither the name/
2337
+ };
2338
+ /** This function gives the name of the license file in a folder, or undefined. */
2339
+ function licenseFileOf(dir) {
2340
+ if (!existsSync(dir)) return void 0;
2341
+ return readdirSync(dir, { withFileTypes: true }).find((entry) => entry.isFile() && LICENSE_NAME.test(entry.name))?.name;
2342
+ }
2343
+ /** This function gives the name of the author of a manifest: the string before `<` or `(`, or the field `name`. */
2344
+ function authorOf(author) {
2345
+ const before = (text) => {
2346
+ const at = text.search(/[<(]/);
2347
+ return at === -1 ? text : text.slice(0, at);
2348
+ };
2349
+ const name = typeof author === "string" ? before(author) : typeof author === "object" && author !== null && typeof author.name === "string" ? author.name : void 0;
2350
+ return name === void 0 || name.trim() === "" ? void 0 : name.trim();
2351
+ }
2352
+ /** This function gives the text of the MIT license. */
2353
+ function mitText(year, holder) {
2354
+ return `MIT License
2355
+
2356
+ Copyright (c) ${year} ${holder}
2357
+
2358
+ Permission is hereby granted, free of charge, to any person obtaining a copy
2359
+ of this software and associated documentation files (the "Software"), to deal
2360
+ in the Software without restriction, including without limitation the rights
2361
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2362
+ copies of the Software, and to permit persons to whom the Software is
2363
+ furnished to do so, subject to the following conditions:
2364
+
2365
+ The above copyright notice and this permission notice shall be included in all
2366
+ copies or substantial portions of the Software.
2367
+
2368
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2369
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2370
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2371
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2372
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2373
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2374
+ SOFTWARE.
2375
+ `;
2376
+ }
2377
+ const isPublic = (pkg) => pkg.manifest["private"] !== true;
2378
+ /**
2379
+ * This function tells if the repository is public, from the event file of a GitHub Actions run. Outside a run, or with no
2380
+ * field `repository.private` in the event, it gives undefined.
2381
+ */
2382
+ function repositoryIsPublic(context) {
2383
+ const file = context.env["GITHUB_EVENT_PATH"];
2384
+ if (file === void 0 || file === "" || !existsSync(file)) return void 0;
2385
+ try {
2386
+ const event = JSON.parse(readFileSync(file, "utf8"));
2387
+ return typeof event.repository?.private === "boolean" ? !event.repository.private : void 0;
2388
+ } catch {
2389
+ return;
2390
+ }
2391
+ }
2392
+ const licenseFile = {
2393
+ id: "license-file",
2394
+ title: "Each public package has a license field and, in its own folder, a license file with the same license. A public repository, or a repository with a public package, has a license file at its root.",
2395
+ reason: "npm packs the license file of the folder of the package only, and GitHub reads the license file of the root only. On 2026-11-02 five public repositories (packing, rigor, layout-contract, typeset, template) had no license file at the root, so GitHub showed them as without a license while their packages on npm said MIT.",
2396
+ fix: "Add a license field to package.json (the option `license`, MIT by default, is the license of the root of a public repository with no public package). `conventions fix` writes each missing license file: a copy of a license file of the repository with the same license, or else the MIT text with the author of the manifest. Correct a license file whose text is not the license of the field.",
2397
+ sources: [
2398
+ "vex",
2399
+ "coeval",
2400
+ "client",
2401
+ "highways"
2402
+ ].map((repo) => ({
2403
+ repo,
2404
+ rule: "license-file",
2405
+ doc: "LICENSE (MIT, at the root, with license MIT in each package.json)"
2406
+ })),
2407
+ options: { license: {
2408
+ type: "string",
2409
+ default: "MIT",
2410
+ description: "The license of the root of a public repository with no public package."
2411
+ } },
2412
+ check(context, options) {
2413
+ const unique = rootAndCodePackages(context);
2414
+ const published = unique.filter(isPublic);
2415
+ const publicRepo = repositoryIsPublic(context) === true;
2416
+ if (published.length === 0 && !publicRepo) return [];
2417
+ const breaks = [];
2418
+ const texts = /* @__PURE__ */ new Map();
2419
+ const licenseOf = (pkg) => typeof pkg.manifest["license"] === "string" ? pkg.manifest["license"] : void 0;
2420
+ for (const pkg of unique) {
2421
+ const name = licenseFileOf(pkg.dir);
2422
+ if (name === void 0) continue;
2423
+ const text = readFileSync(join(pkg.dir, name), "utf8");
2424
+ const license = Object.keys(LICENSE_TEXTS).find((id) => LICENSE_TEXTS[id]?.test(text) === true) ?? licenseOf(pkg);
2425
+ if (license !== void 0 && !texts.has(license)) texts.set(license, text);
2426
+ }
2427
+ const missing = (folder, license, author, why) => {
2428
+ const file = inFolder(folder, "LICENSE");
2429
+ const holder = authorOf(author) ?? authorOf(context.rootPackage.manifest["author"]);
2430
+ const text = texts.get(license) ?? (license === "MIT" && holder !== void 0 ? mitText((/* @__PURE__ */ new Date()).getFullYear(), holder) : void 0);
2431
+ breaks.push({
2432
+ file,
2433
+ message: `${folder === "" ? "The root" : folder} has no license file: ${why}`,
2434
+ ...text === void 0 ? {} : { edits: [{
2435
+ file,
2436
+ before: "",
2437
+ after: text
2438
+ }] }
2439
+ });
2440
+ };
2441
+ for (const pkg of published) {
2442
+ const license = licenseOf(pkg);
2443
+ const name = String(pkg.manifest["name"] ?? pkg.folder);
2444
+ if (license === void 0) {
2445
+ breaks.push({
2446
+ file: pkg.file,
2447
+ message: `The public package ${name} has no license field.`
2448
+ });
2449
+ continue;
2450
+ }
2451
+ const found = licenseFileOf(pkg.dir);
2452
+ if (found === void 0) {
2453
+ missing(pkg.folder, license, pkg.manifest["author"], `npm packs only the license file of the folder of ${name} (${license}).`);
2454
+ continue;
2455
+ }
2456
+ const text = readFileSync(join(pkg.dir, found), "utf8");
2457
+ if (LICENSE_TEXTS[license]?.test(text) === false) {
2458
+ const line = lineOf(pkg.text, "\"license\"");
2459
+ breaks.push({
2460
+ file: inFolder(pkg.folder, found),
2461
+ message: `${inFolder(pkg.folder, found)} is not the text of ${license}, the license field of ${name}${line === void 0 ? "" : ` (${pkg.file}:${line})`}.`
2462
+ });
2463
+ }
2464
+ }
2465
+ if (!published.includes(context.rootPackage) && licenseFileOf(context.root) === void 0) {
2466
+ const license = published.map(licenseOf).find((item) => item !== void 0) ?? (publicRepo ? String(options["license"]) : void 0);
2467
+ if (license !== void 0) missing("", license, published[0]?.manifest["author"], "GitHub reads only the license file of the root.");
2468
+ }
2469
+ return breaks;
2470
+ }
2471
+ };
2472
+ // src/rules/runner-budget.ts
2473
+ /**
2474
+ * The rule `runner-budget`: the workflows share the runners of the account. Each matrix has a `max-parallel`, each
2475
+ * workflow has a concurrency group, and each schedule starts at the minute of its repository and file.
2476
+ */
2477
+ /**
2478
+ * This function gives the minute (1 to 59) of the schedules of a workflow: the FNV-1a hash of the repository and the
2479
+ * file. Two repositories with the same workflow thus start at different minutes, and no schedule starts at minute 0,
2480
+ * where GitHub has the most load.
2481
+ */
2482
+ function scheduleMinute(repository, file) {
2483
+ let hash = 2166136261;
2484
+ for (const char of `${repository.toLowerCase()}/${file}`) {
2485
+ hash ^= char.codePointAt(0) ?? 0;
2486
+ hash = Math.imul(hash, 16777619) >>> 0;
2487
+ }
2488
+ return hash % 59 + 1;
2489
+ }
2490
+ /** This function tells if a workflow is a shared workflow (`on: workflow_call`). Its caller gives the concurrency group. */
2491
+ function isShared(lines) {
2492
+ return lines.some((line) => {
2493
+ const text = line.trimStart();
2494
+ return text.startsWith("workflow_call:") || text === "workflow_call" || text === "- workflow_call" || text.startsWith("on:") && text.includes("workflow_call");
2495
+ });
2496
+ }
2497
+ /** This function gives the jobs of a workflow. */
2498
+ function jobsOf(lines) {
2499
+ const jobs = lines.findIndex((line) => indentOf$1(line) === 0 && line.startsWith("jobs:"));
2500
+ if (jobs < 0) return [];
2501
+ const jobIndent = childIndent(lines, jobs);
2502
+ const end = blockEnd(lines, jobs);
2503
+ const found = [];
2504
+ for (let i = jobs + 1; i < end; i++) {
2505
+ const line = lines[i] ?? "";
2506
+ if (line.trim() === "" || indentOf$1(line) !== jobIndent) continue;
2507
+ const keyIndent = childIndent(lines, i);
2508
+ const keys = lines.slice(i + 1, blockEnd(lines, i)).filter((text) => indentOf$1(text) === keyIndent);
2509
+ const uses = keys.map((text) => keyValue(text, "uses")).find((value) => value !== void 0);
2510
+ const at = uses === void 0 ? -1 : uses.indexOf(".github/workflows/");
2511
+ const calls = uses === void 0 || at < 0 ? void 0 : uses.slice(at + 18).split("@")[0] ?? "";
2512
+ found.push({
2513
+ name: line.trim().replace(/:$/, ""),
2514
+ line: i + 1,
2515
+ grouped: keys.some((text) => keyValue(text, "concurrency") !== void 0),
2516
+ ...calls === void 0 ? {} : { calls }
2517
+ });
2518
+ }
2519
+ return found;
2520
+ }
2521
+ const hasTopGroup = (lines) => lines.some((line) => indentOf$1(line) === 0 && line.startsWith("concurrency:"));
2522
+ /**
2523
+ * This function gives the edit that adds a concurrency group at the top of a workflow, before `jobs:`. A new run of a pull
2524
+ * request stops the old run. A run of another event has the group of its commit, so that no release or scheduled run stops.
2525
+ */
2526
+ function groupEdits(file, text, lines) {
2527
+ const jobs = lines.findIndex((line) => indentOf$1(line) === 0 && line.startsWith("jobs:"));
2528
+ if (jobs < 0) return [];
2529
+ const pad = " ".repeat(childIndent(lines, jobs) ?? 2);
2530
+ const original = text.split(/\r?\n/)[jobs] ?? "jobs:";
2531
+ const group = [
2532
+ "concurrency:",
2533
+ pad + "group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }}",
2534
+ pad + "cancel-in-progress: ${{ github.event_name == 'pull_request' }}",
2535
+ "",
2536
+ original
2537
+ ];
2538
+ return [{
2539
+ file,
2540
+ before: text,
2541
+ after: replaceLine(text, jobs + 1, group)
2542
+ }];
2543
+ }
2544
+ /**
2545
+ * This function gives the breaks of the concurrency groups. A workflow with no group at the top needs one in each job.
2546
+ * A job that calls a shared workflow of `grouped` gets its group from the jobs of that workflow. A shared workflow gets
2547
+ * its group from its caller, but a shared workflow of `grouped` has a group in each job.
2548
+ */
2549
+ function concurrencyBreaks(file, text, lines, grouped) {
2550
+ const name = file.slice(file.lastIndexOf("/") + 1);
2551
+ const jobs = jobsOf(lines);
2552
+ if (isShared(lines)) {
2553
+ if (!grouped.includes(name)) return [];
2554
+ return jobs.filter((job) => !job.grouped).map((job) => ({
2555
+ file,
2556
+ line: job.line,
2557
+ message: `${file}: the job ${job.name} has no concurrency group, and its callers rely on it (the option grouped).`
2558
+ }));
2559
+ }
2560
+ if (hasTopGroup(lines)) return [];
2561
+ const missing = jobs.filter((job) => !job.grouped && !(job.calls !== void 0 && grouped.includes(job.calls)));
2562
+ const edits = missing.length === 0 ? [] : groupEdits(file, text, lines);
2563
+ return missing.map((job) => ({
2564
+ file,
2565
+ line: job.line,
2566
+ message: `${file}: the job ${job.name} has no concurrency group, and the workflow has none.`,
2567
+ edits
2568
+ }));
2569
+ }
2570
+ /** This function gives the breaks of the matrices: each `strategy` with a `matrix` has a `max-parallel` of `limit` or less. */
2571
+ function matrixBreaks(file, text, lines, limit) {
2572
+ const breaks = [];
2573
+ const originals = text.split(/\r?\n/);
2574
+ lines.forEach((line, index) => {
2575
+ if (keyValue(line, "strategy") === void 0) return;
2576
+ const keyIndent = childIndent(lines, index);
2577
+ if (keyIndent === void 0) return;
2578
+ const keys = [];
2579
+ for (let i = index + 1; i < blockEnd(lines, index); i++) if ((lines[i] ?? "").trim() !== "" && indentOf$1(lines[i] ?? "") === keyIndent) keys.push(i);
2580
+ if (!keys.some((i) => keyValue(lines[i] ?? "", "matrix") !== void 0)) return;
2581
+ const at = keys.find((i) => keyValue(lines[i] ?? "", "max-parallel") !== void 0);
2582
+ const raw = at === void 0 ? void 0 : keyValue(lines[at] ?? "", "max-parallel");
2583
+ const value = raw === void 0 ? NaN : Number(raw);
2584
+ const wanted = `${" ".repeat(keyIndent)}max-parallel: ${String(limit)}`;
2585
+ if (at === void 0 || raw === void 0) {
2586
+ const after = replaceLine(text, index + 1, [originals[index] ?? line, wanted]);
2587
+ breaks.push({
2588
+ file,
2589
+ line: index + 1,
2590
+ message: `${file}: a matrix has no max-parallel.`,
2591
+ edits: [{
2592
+ file,
2593
+ before: text,
2594
+ after
2595
+ }]
2596
+ });
2597
+ } else if (!Number.isInteger(value) || value < 1 || value > limit) {
2598
+ const after = replaceLine(text, at + 1, [wanted]);
2599
+ breaks.push({
2600
+ file,
2601
+ line: index + 1,
2602
+ message: `${file}: a matrix has max-parallel ${raw}, and the most is ${String(limit)}.`,
2603
+ edits: [{
2604
+ file,
2605
+ before: text,
2606
+ after
2607
+ }]
2608
+ });
2609
+ }
2610
+ });
2611
+ return breaks;
2612
+ }
2613
+ /**
2614
+ * This function gives the minute field of a schedule that starts `perHour` times in each hour, at equal steps. One start is at
2615
+ * `minute`: `"18"` for 1, `"18,48"` for 2. The list is in the order of the numbers.
2616
+ */
2617
+ function minuteField(minute, perHour) {
2618
+ const step = 60 / perHour;
2619
+ return Array.from({ length: perHour }, (_, k) => (minute + k * step) % 60).sort((a, b) => a - b).join(",");
2620
+ }
2621
+ /** 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. */
2622
+ function startsPerHour(field) {
2623
+ const step = /^\*\/(\d+)$/.exec(field);
2624
+ const count = step ? 60 / Number(step[1]) : field.split(",").length;
2625
+ return Number.isInteger(count) && count >= 1 && 60 % count === 0 ? count : 1;
2626
+ }
2627
+ /**
2628
+ * This function gives the breaks of the schedules: the minute of each `cron` is the minute of the repository and the file. A
2629
+ * schedule that starts more than once in each hour starts at equal steps from that minute (`18,48` for each 30 minutes).
2630
+ */
2631
+ function cronBreaks(file, text, minute) {
2632
+ const breaks = [];
2633
+ const originals = text.split(/\r?\n/);
2634
+ for (const { line, cron: value } of cronLines(text)) {
2635
+ const fields = value.split(" ").filter((field) => field !== "");
2636
+ const wanted = minuteField(minute, startsPerHour(fields[0] ?? ""));
2637
+ if (fields[0] === wanted) continue;
2638
+ const expected = [wanted, ...fields.slice(1)].join(" ");
2639
+ const original = originals[line - 1] ?? "";
2640
+ const edits = original.includes(value) ? [{
2641
+ file,
2642
+ before: text,
2643
+ after: replaceLine(text, line, [original.replace(value, () => expected)])
2644
+ }] : [];
2645
+ breaks.push({
2646
+ file,
2647
+ line,
2648
+ message: `${file}: the schedule "${value}" starts at minute ${fields[0] ?? "?"}, and the minute of this repository and file is ${String(minute)}.`,
2649
+ fix: `cron: "${expected}"`,
2650
+ edits
2651
+ });
2652
+ }
2653
+ return breaks;
2654
+ }
2655
+ const runnerBudget = {
2656
+ id: "runner-budget",
2657
+ 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.",
2658
+ 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.",
2659
+ 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.",
2660
+ sources: [{
2661
+ repo: "private",
2662
+ rule: "runner-slots",
2663
+ doc: "a decision of 2026-10-30: the runner slots: a cap of 40, heavy work at most 28"
2664
+ }],
2665
+ options: {
2666
+ maxParallel: {
2667
+ type: "number",
2668
+ default: 3,
2669
+ description: "The largest max-parallel of a matrix."
2670
+ },
2671
+ minute: {
2672
+ type: "boolean",
2673
+ default: true,
2674
+ description: "When false, the rule does not examine the minute of the schedules."
2675
+ },
2676
+ grouped: {
2677
+ type: "strings",
2678
+ default: ["reusable-ai-review.yml", "reusable-codex-review.yml"],
2679
+ 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."
2680
+ }
2681
+ },
2682
+ check(context, options) {
2683
+ const files = context.gitFiles();
2684
+ if (files === void 0) return { skipped: "the root is not in a git repository" };
2685
+ const workflows = files.filter((path) => WORKFLOW$1.test(path)).sort(byCode);
2686
+ if (workflows.length === 0) return { skipped: "the repository has no workflow" };
2687
+ const remote = context.git([
2688
+ "remote",
2689
+ "get-url",
2690
+ "origin"
2691
+ ]);
2692
+ const repository = context.env["GITHUB_REPOSITORY"] ?? (remote === void 0 ? void 0 : repositoryOfRemote(remote));
2693
+ const limit = Number(options["maxParallel"]);
2694
+ const grouped = Array.isArray(options["grouped"]) ? options["grouped"] : [];
2695
+ const breaks = [];
2696
+ for (const file of workflows) {
2697
+ let text;
2698
+ try {
2699
+ text = readFileSync(join(context.root, file), "utf8");
2700
+ } catch {
2701
+ continue;
2702
+ }
2703
+ const lines = workflowLines(text);
2704
+ breaks.push(...matrixBreaks(file, text, lines, limit), ...concurrencyBreaks(file, text, lines, grouped));
2705
+ if (options["minute"] !== false) {
2706
+ if (cronLines(text).length > 0 && repository === void 0) breaks.push({
2707
+ file,
2708
+ message: `${file} has a schedule, and the rule cannot find the repository (GITHUB_REPOSITORY, or a GitHub URL of the remote origin).`
2709
+ });
2710
+ else if (repository !== void 0) breaks.push(...cronBreaks(file, text, scheduleMinute(repository, file)));
2711
+ }
2712
+ }
2713
+ return breaks;
2714
+ }
2715
+ };
2324
2716
  // src/rules/security-one-job.ts
2325
2717
  /**
2326
2718
  * The rule `security-one-job`: the security scans of a repository run in one job, with the action `security-scan` of the
@@ -2529,7 +2921,7 @@ const securityOneJob = {
2529
2921
  /** The gate workflows of the template: each one gives one summary check that the ruleset names. */
2530
2922
  const SUMMARY_GATES = ["ci.yml", "security.yml"];
2531
2923
  /** The deprecated shared workflow of the scans. The rule `security-one-job` replaces its caller and the summary job with one job. */
2532
- const REUSABLE_SECURITY = /(^|\/)\.github\/workflows\/reusable-security\.ya?ml(@|$)/;
2924
+ const REUSABLE_SECURITY$1 = /(^|\/)\.github\/workflows\/reusable-security\.ya?ml(@|$)/;
2533
2925
  const PULL_REQUEST$1 = /^(pull_request|pull_request_target)$/;
2534
2926
  /** This function tells if a workflow starts on a pull request: `on: pull_request`, the flow form, or a key of the block. */
2535
2927
  function startsOnPullRequest(text) {
@@ -2633,7 +3025,7 @@ const summaryJobRule = {
2633
3025
  } catch {
2634
3026
  continue;
2635
3027
  }
2636
- if (!startsOnPullRequest(text) || hasSummaryJob(text) || REUSABLE_SECURITY.test(text)) continue;
3028
+ if (!startsOnPullRequest(text) || hasSummaryJob(text) || REUSABLE_SECURITY$1.test(text)) continue;
2637
3029
  const added = addSummaryJob(text, file);
2638
3030
  breaks.push({
2639
3031
  file,
@@ -2648,6 +3040,149 @@ const summaryJobRule = {
2648
3040
  return breaks;
2649
3041
  }
2650
3042
  };
3043
+ // src/rules/security-gate.ts
3044
+ /**
3045
+ * The rule `security-gate`: a repository with the gate `ci.yml` also has the gate `security.yml`, with its one job
3046
+ * `Security OK` (CI.md, "The check of the ruleset"). The stamp gives the file to each new repository. This rule finds an
3047
+ * older repository with no security gate, and its fix writes the file of the template.
3048
+ */
3049
+ /** The path of the security gate in a repository. */
3050
+ const SECURITY_FILE = ".github/workflows/security.yml";
3051
+ /** The action security-scan of the template, in the template (`./`) and pinned in another repository. */
3052
+ const SCAN_ACTIONS = ["./.github/actions/security-scan", "mark1russell7/template/.github/actions/security-scan"];
3053
+ /** The deprecated shared workflow of the scans. The rule `security-one-job` changes its caller to one job. */
3054
+ const REUSABLE_SECURITY = [".github/workflows/reusable-security.yml", ".github/workflows/reusable-security.yaml"];
3055
+ /**
3056
+ * This function tells if a workflow is a security gate. A security gate has a job `Security OK`, a step with the action
3057
+ * security-scan, or a job that uses the shared workflow of the scans. It reads each line with the reader of the workflows.
3058
+ */
3059
+ function isSecurityGate(text) {
3060
+ return text.split("\n").some((line) => {
3061
+ if (keyValue(line, "name") === "Security OK") return true;
3062
+ const target = (keyValue(line, "uses") ?? "").split("@")[0] ?? "";
3063
+ return SCAN_ACTIONS.includes(target) || REUSABLE_SECURITY.some((file) => target === `./${file}` || target.endsWith(`/${file}`));
3064
+ });
3065
+ }
3066
+ /**
3067
+ * The lines of `.github/workflows/security.yml` of the template, as the stamp writes them into a new repository: the
3068
+ * action is pinned to a commit. A test of the template holds them equal to its file. `@COMMIT` is the pin of the
3069
+ * action, and `MINUTE` is the minute of the schedule.
3070
+ */
3071
+ const STANDARD = [
3072
+ "# The security scans of this repository (the action security-scan, CI.md): dependency review, osv-scanner and",
3073
+ "# CodeQL, in one job. A pull request fails only for a new finding at or above high.",
3074
+ "# Other repositories use mark1russell7/template/.github/actions/security-scan@<commit> # main",
3075
+ "name: Security",
3076
+ "",
3077
+ "on:",
3078
+ " pull_request:",
3079
+ " push:",
3080
+ " branches: [main]",
3081
+ " # A weekly scan finds the new advisories for the dependencies that do not change. The minute comes from the",
3082
+ " # repository and the file (the rule runner-budget), so the scans of the repositories do not start together.",
3083
+ " schedule:",
3084
+ " - cron: \"MINUTE 5 * * 1\"",
3085
+ " workflow_dispatch:",
3086
+ "",
3087
+ "permissions: {}",
3088
+ "",
3089
+ "concurrency:",
3090
+ " group: security-${{ github.event_name == 'pull_request' && github.ref || github.sha }}",
3091
+ " cancel-in-progress: ${{ github.event_name == 'pull_request' }}",
3092
+ "",
3093
+ "defaults:",
3094
+ " run:",
3095
+ " shell: bash",
3096
+ "",
3097
+ "jobs:",
3098
+ " # The one check of this file that the ruleset of main names, next to CI OK (CI.md, \"The check of the",
3099
+ " # ruleset\"). The scans run in this job, so a run asks for one runner. The last step of the action fails when",
3100
+ " # a scan fails, and names that scan. The scans stay out of ci.yml, because release.yml calls ci.yml with",
3101
+ " # contents: read only.",
3102
+ " security-ok:",
3103
+ " name: Security OK",
3104
+ " runs-on: ubuntu-latest",
3105
+ " # The time limit of the three scans together",
3106
+ " timeout-minutes: 30",
3107
+ " # security-events: write uploads the results (not on a pull request). actions: read lets CodeQL and the",
3108
+ " # upload read the run in a private repository.",
3109
+ " permissions:",
3110
+ " contents: read",
3111
+ " security-events: write",
3112
+ " actions: read",
3113
+ " steps:",
3114
+ " # The template runs the action of this commit, so it checks out the folder of the actions first. A",
3115
+ " # repository that pins the action to a commit needs no such step: the action checks out the repository.",
3116
+ " # The stamp copies this file, so the step runs only in the template. In a private repository, its partial",
3117
+ " # clone makes the later checkout of the base fail: the fetch from the promisor remote has no credentials.",
3118
+ " - if: github.repository == 'mark1russell7/template'",
3119
+ " uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1",
3120
+ " with:",
3121
+ " sparse-checkout: .github/actions",
3122
+ " persist-credentials: false",
3123
+ " - uses: mark1russell7/template/.github/actions/security-scan@COMMIT # main"
3124
+ ];
3125
+ /** This function gives the security gate of a repository. It is the file of the template, with the pin of the action and the minute of the repository. */
3126
+ function securityWorkflow(repository, commit = SECURITY_SCAN_COMMIT) {
3127
+ const minute = String(scheduleMinute(repository, SECURITY_FILE));
3128
+ return `${STANDARD.join("\n").replace("@COMMIT", `@${commit}`).replace("\"MINUTE ", `"${minute} `)}\n`;
3129
+ }
3130
+ const securityGate = {
3131
+ id: "security-gate",
3132
+ failsFrom: "2026-12-07",
3133
+ title: "A repository with the gate ci.yml has the gate security.yml: the scans of the action security-scan in one job Security OK.",
3134
+ reason: "The ruleset of main names the summary checks \"CI OK\" and \"Security OK\" (CI.md, \"The check of the ruleset\"). With no security gate, a pull request can add a dependency with a known advisory, and no scan reads the code. On 2026-11-22, 16 of 61 public repositories of the account had \"CI OK\" and no \"Security OK\".",
3135
+ fix: "Add .github/workflows/security.yml of the template: the fix writes it, with the action security-scan pinned and the minute of the repository. In a repository that uses the default setup of code scanning, give the input codeql: \"false\", because the two conflict. Then add \"Security OK\" to the ruleset of main (ruleset-ci-ok.ts --only-summary in the template).",
3136
+ sources: [{
3137
+ repo: "private",
3138
+ rule: "security-gate",
3139
+ doc: "a decision of 2026-11-22 (the daily check of the rulesets of 61 public repositories)"
3140
+ }],
3141
+ options: {},
3142
+ check(context) {
3143
+ const files = context.gitFiles();
3144
+ if (files === void 0) return { skipped: "the root is not in a git repository" };
3145
+ const workflows = files.filter((path) => WORKFLOW$1.test(path)).sort(byCode);
3146
+ const read = (file) => {
3147
+ try {
3148
+ return readFileSync(join(context.root, file), "utf8");
3149
+ } catch {
3150
+ return;
3151
+ }
3152
+ };
3153
+ const ci = workflows.find((path) => path.slice(path.lastIndexOf("/") + 1) === "ci.yml");
3154
+ const ciText = ci === void 0 ? void 0 : read(ci);
3155
+ if (ciText === void 0 || !startsOnPullRequest(ciText)) return { skipped: "the repository has no gate ci.yml that starts on a pull request" };
3156
+ const onDisk = existsSync(join(context.root, SECURITY_FILE));
3157
+ if ((onDisk && !workflows.includes(".github/workflows/security.yml") ? [...workflows, ".github/workflows/security.yml"] : workflows).some((file) => isSecurityGate(read(file) ?? ""))) return [];
3158
+ if (repositoryIsPublic(context) === false) return { skipped: "the repository is private" };
3159
+ const message = "The repository has the gate ci.yml and no security gate (a job \"Security OK\" with the action security-scan).";
3160
+ if (onDisk) return [{
3161
+ file: SECURITY_FILE,
3162
+ message,
3163
+ fix: `A person must change it, because ${SECURITY_FILE} is there and is not a security gate. ${securityGate.fix}`
3164
+ }];
3165
+ const remote = context.git([
3166
+ "remote",
3167
+ "get-url",
3168
+ "origin"
3169
+ ]);
3170
+ const repository = context.env["GITHUB_REPOSITORY"] ?? (remote === void 0 ? void 0 : repositoryOfRemote(remote));
3171
+ return [repository === void 0 ? {
3172
+ file: SECURITY_FILE,
3173
+ message,
3174
+ fix: `A person must add it, because the repository has no remote origin to give the minute of its schedule. ${securityGate.fix}`
3175
+ } : {
3176
+ file: SECURITY_FILE,
3177
+ message,
3178
+ edits: [{
3179
+ file: SECURITY_FILE,
3180
+ before: "",
3181
+ after: securityWorkflow(repository)
3182
+ }]
3183
+ }];
3184
+ }
3185
+ };
2651
3186
  // src/rules/setup-cue.ts
2652
3187
  /**
2653
3188
  * The rule `setup-cue`: no workflow or action downloads the cue CLI with its own command. The shared action `setup-cue`
@@ -14819,165 +15354,17 @@ const homeModule = {
14819
15354
  } catch {
14820
15355
  continue;
14821
15356
  }
14822
- const lines = added?.get(file);
14823
- for (const use of moduleUses(text)) {
14824
- if (lines !== void 0 && !lines.has(use.line)) continue;
14825
- const found = modules.find((item) => item.specifier === use.specifier);
14826
- if (found !== void 0) breaks.push({
14827
- file,
14828
- line: use.line,
14829
- message: moduleMessage(file, use.specifier, found.home)
14830
- });
14831
- }
14832
- }
14833
- return breaks;
14834
- }
14835
- };
14836
- // src/rules/license-file.ts
14837
- /**
14838
- * The rule `license-file`. Each public package has a license field and, in its own folder, a license file with the
14839
- * same license. A repository with a public package has a license file at its root.
14840
- */
14841
- /** The names of a license file, without case. */
14842
- const LICENSE_NAME = /^licen[cs]e(?:\.(?:md|txt))?$/i;
14843
- /** For each license that the rule knows, a pattern of its text. The text of another license is not checked. */
14844
- const LICENSE_TEXTS = {
14845
- MIT: /\bMIT License\b|Permission is hereby granted, free of charge/,
14846
- ISC: /\bISC License\b|Permission to use, copy, modify, and\/or distribute/,
14847
- "Apache-2.0": /Apache License,?\s+Version 2\.0/,
14848
- "BSD-3-Clause": /Redistribution and use in source and binary forms[\s\S]*Neither the name/
14849
- };
14850
- /** This function gives the name of the license file in a folder, or undefined. */
14851
- function licenseFileOf(dir) {
14852
- if (!existsSync(dir)) return void 0;
14853
- return readdirSync(dir, { withFileTypes: true }).find((entry) => entry.isFile() && LICENSE_NAME.test(entry.name))?.name;
14854
- }
14855
- /** This function gives the name of the author of a manifest: the string before `<` or `(`, or the field `name`. */
14856
- function authorOf(author) {
14857
- const before = (text) => {
14858
- const at = text.search(/[<(]/);
14859
- return at === -1 ? text : text.slice(0, at);
14860
- };
14861
- const name = typeof author === "string" ? before(author) : typeof author === "object" && author !== null && typeof author.name === "string" ? author.name : void 0;
14862
- return name === void 0 || name.trim() === "" ? void 0 : name.trim();
14863
- }
14864
- /** This function gives the text of the MIT license. */
14865
- function mitText(year, holder) {
14866
- return `MIT License
14867
-
14868
- Copyright (c) ${year} ${holder}
14869
-
14870
- Permission is hereby granted, free of charge, to any person obtaining a copy
14871
- of this software and associated documentation files (the "Software"), to deal
14872
- in the Software without restriction, including without limitation the rights
14873
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14874
- copies of the Software, and to permit persons to whom the Software is
14875
- furnished to do so, subject to the following conditions:
14876
-
14877
- The above copyright notice and this permission notice shall be included in all
14878
- copies or substantial portions of the Software.
14879
-
14880
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14881
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14882
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14883
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14884
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14885
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
14886
- SOFTWARE.
14887
- `;
14888
- }
14889
- const isPublic = (pkg) => pkg.manifest["private"] !== true;
14890
- /**
14891
- * This function tells if the repository is public, from the event file of a GitHub Actions run. Outside a run, or with no
14892
- * field `repository.private` in the event, it gives undefined.
14893
- */
14894
- function repositoryIsPublic(context) {
14895
- const file = context.env["GITHUB_EVENT_PATH"];
14896
- if (file === void 0 || file === "" || !existsSync(file)) return void 0;
14897
- try {
14898
- const event = JSON.parse(readFileSync(file, "utf8"));
14899
- return typeof event.repository?.private === "boolean" ? !event.repository.private : void 0;
14900
- } catch {
14901
- return;
14902
- }
14903
- }
14904
- const licenseFile = {
14905
- id: "license-file",
14906
- title: "Each public package has a license field and, in its own folder, a license file with the same license. A public repository, or a repository with a public package, has a license file at its root.",
14907
- reason: "npm packs the license file of the folder of the package only, and GitHub reads the license file of the root only. On 2026-11-02 five public repositories (packing, rigor, layout-contract, typeset, template) had no license file at the root, so GitHub showed them as without a license while their packages on npm said MIT.",
14908
- fix: "Add a license field to package.json (the option `license`, MIT by default, is the license of the root of a public repository with no public package). `conventions fix` writes each missing license file: a copy of a license file of the repository with the same license, or else the MIT text with the author of the manifest. Correct a license file whose text is not the license of the field.",
14909
- sources: [
14910
- "vex",
14911
- "coeval",
14912
- "client",
14913
- "highways"
14914
- ].map((repo) => ({
14915
- repo,
14916
- rule: "license-file",
14917
- doc: "LICENSE (MIT, at the root, with license MIT in each package.json)"
14918
- })),
14919
- options: { license: {
14920
- type: "string",
14921
- default: "MIT",
14922
- description: "The license of the root of a public repository with no public package."
14923
- } },
14924
- check(context, options) {
14925
- const unique = rootAndCodePackages(context);
14926
- const published = unique.filter(isPublic);
14927
- const publicRepo = repositoryIsPublic(context) === true;
14928
- if (published.length === 0 && !publicRepo) return [];
14929
- const breaks = [];
14930
- const texts = /* @__PURE__ */ new Map();
14931
- const licenseOf = (pkg) => typeof pkg.manifest["license"] === "string" ? pkg.manifest["license"] : void 0;
14932
- for (const pkg of unique) {
14933
- const name = licenseFileOf(pkg.dir);
14934
- if (name === void 0) continue;
14935
- const text = readFileSync(join(pkg.dir, name), "utf8");
14936
- const license = Object.keys(LICENSE_TEXTS).find((id) => LICENSE_TEXTS[id]?.test(text) === true) ?? licenseOf(pkg);
14937
- if (license !== void 0 && !texts.has(license)) texts.set(license, text);
14938
- }
14939
- const missing = (folder, license, author, why) => {
14940
- const file = inFolder(folder, "LICENSE");
14941
- const holder = authorOf(author) ?? authorOf(context.rootPackage.manifest["author"]);
14942
- const text = texts.get(license) ?? (license === "MIT" && holder !== void 0 ? mitText((/* @__PURE__ */ new Date()).getFullYear(), holder) : void 0);
14943
- breaks.push({
14944
- file,
14945
- message: `${folder === "" ? "The root" : folder} has no license file: ${why}`,
14946
- ...text === void 0 ? {} : { edits: [{
14947
- file,
14948
- before: "",
14949
- after: text
14950
- }] }
14951
- });
14952
- };
14953
- for (const pkg of published) {
14954
- const license = licenseOf(pkg);
14955
- const name = String(pkg.manifest["name"] ?? pkg.folder);
14956
- if (license === void 0) {
14957
- breaks.push({
14958
- file: pkg.file,
14959
- message: `The public package ${name} has no license field.`
14960
- });
14961
- continue;
14962
- }
14963
- const found = licenseFileOf(pkg.dir);
14964
- if (found === void 0) {
14965
- missing(pkg.folder, license, pkg.manifest["author"], `npm packs only the license file of the folder of ${name} (${license}).`);
14966
- continue;
14967
- }
14968
- const text = readFileSync(join(pkg.dir, found), "utf8");
14969
- if (LICENSE_TEXTS[license]?.test(text) === false) {
14970
- const line = lineOf(pkg.text, "\"license\"");
14971
- breaks.push({
14972
- file: inFolder(pkg.folder, found),
14973
- message: `${inFolder(pkg.folder, found)} is not the text of ${license}, the license field of ${name}${line === void 0 ? "" : ` (${pkg.file}:${line})`}.`
15357
+ const lines = added?.get(file);
15358
+ for (const use of moduleUses(text)) {
15359
+ if (lines !== void 0 && !lines.has(use.line)) continue;
15360
+ const found = modules.find((item) => item.specifier === use.specifier);
15361
+ if (found !== void 0) breaks.push({
15362
+ file,
15363
+ line: use.line,
15364
+ message: moduleMessage(file, use.specifier, found.home)
14974
15365
  });
14975
15366
  }
14976
15367
  }
14977
- if (!published.includes(context.rootPackage) && licenseFileOf(context.root) === void 0) {
14978
- const license = published.map(licenseOf).find((item) => item !== void 0) ?? (publicRepo ? String(options["license"]) : void 0);
14979
- if (license !== void 0) missing("", license, published[0]?.manifest["author"], "GitHub reads only the license file of the root.");
14980
- }
14981
15368
  return breaks;
14982
15369
  }
14983
15370
  };
@@ -17301,250 +17688,6 @@ const pushMainOnly = {
17301
17688
  return breaks;
17302
17689
  }
17303
17690
  };
17304
- // src/rules/runner-budget.ts
17305
- /**
17306
- * The rule `runner-budget`: the workflows share the runners of the account. Each matrix has a `max-parallel`, each
17307
- * workflow has a concurrency group, and each schedule starts at the minute of its repository and file.
17308
- */
17309
- /**
17310
- * This function gives the minute (1 to 59) of the schedules of a workflow: the FNV-1a hash of the repository and the
17311
- * file. Two repositories with the same workflow thus start at different minutes, and no schedule starts at minute 0,
17312
- * where GitHub has the most load.
17313
- */
17314
- function scheduleMinute(repository, file) {
17315
- let hash = 2166136261;
17316
- for (const char of `${repository.toLowerCase()}/${file}`) {
17317
- hash ^= char.codePointAt(0) ?? 0;
17318
- hash = Math.imul(hash, 16777619) >>> 0;
17319
- }
17320
- return hash % 59 + 1;
17321
- }
17322
- /** This function tells if a workflow is a shared workflow (`on: workflow_call`). Its caller gives the concurrency group. */
17323
- function isShared(lines) {
17324
- return lines.some((line) => {
17325
- const text = line.trimStart();
17326
- return text.startsWith("workflow_call:") || text === "workflow_call" || text === "- workflow_call" || text.startsWith("on:") && text.includes("workflow_call");
17327
- });
17328
- }
17329
- /** This function gives the jobs of a workflow. */
17330
- function jobsOf(lines) {
17331
- const jobs = lines.findIndex((line) => indentOf$1(line) === 0 && line.startsWith("jobs:"));
17332
- if (jobs < 0) return [];
17333
- const jobIndent = childIndent(lines, jobs);
17334
- const end = blockEnd(lines, jobs);
17335
- const found = [];
17336
- for (let i = jobs + 1; i < end; i++) {
17337
- const line = lines[i] ?? "";
17338
- if (line.trim() === "" || indentOf$1(line) !== jobIndent) continue;
17339
- const keyIndent = childIndent(lines, i);
17340
- const keys = lines.slice(i + 1, blockEnd(lines, i)).filter((text) => indentOf$1(text) === keyIndent);
17341
- const uses = keys.map((text) => keyValue(text, "uses")).find((value) => value !== void 0);
17342
- const at = uses === void 0 ? -1 : uses.indexOf(".github/workflows/");
17343
- const calls = uses === void 0 || at < 0 ? void 0 : uses.slice(at + 18).split("@")[0] ?? "";
17344
- found.push({
17345
- name: line.trim().replace(/:$/, ""),
17346
- line: i + 1,
17347
- grouped: keys.some((text) => keyValue(text, "concurrency") !== void 0),
17348
- ...calls === void 0 ? {} : { calls }
17349
- });
17350
- }
17351
- return found;
17352
- }
17353
- const hasTopGroup = (lines) => lines.some((line) => indentOf$1(line) === 0 && line.startsWith("concurrency:"));
17354
- /**
17355
- * This function gives the edit that adds a concurrency group at the top of a workflow, before `jobs:`. A new run of a pull
17356
- * request stops the old run. A run of another event has the group of its commit, so that no release or scheduled run stops.
17357
- */
17358
- function groupEdits(file, text, lines) {
17359
- const jobs = lines.findIndex((line) => indentOf$1(line) === 0 && line.startsWith("jobs:"));
17360
- if (jobs < 0) return [];
17361
- const pad = " ".repeat(childIndent(lines, jobs) ?? 2);
17362
- const original = text.split(/\r?\n/)[jobs] ?? "jobs:";
17363
- const group = [
17364
- "concurrency:",
17365
- pad + "group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.sha }}",
17366
- pad + "cancel-in-progress: ${{ github.event_name == 'pull_request' }}",
17367
- "",
17368
- original
17369
- ];
17370
- return [{
17371
- file,
17372
- before: text,
17373
- after: replaceLine(text, jobs + 1, group)
17374
- }];
17375
- }
17376
- /**
17377
- * This function gives the breaks of the concurrency groups. A workflow with no group at the top needs one in each job.
17378
- * A job that calls a shared workflow of `grouped` gets its group from the jobs of that workflow. A shared workflow gets
17379
- * its group from its caller, but a shared workflow of `grouped` has a group in each job.
17380
- */
17381
- function concurrencyBreaks(file, text, lines, grouped) {
17382
- const name = file.slice(file.lastIndexOf("/") + 1);
17383
- const jobs = jobsOf(lines);
17384
- if (isShared(lines)) {
17385
- if (!grouped.includes(name)) return [];
17386
- return jobs.filter((job) => !job.grouped).map((job) => ({
17387
- file,
17388
- line: job.line,
17389
- message: `${file}: the job ${job.name} has no concurrency group, and its callers rely on it (the option grouped).`
17390
- }));
17391
- }
17392
- if (hasTopGroup(lines)) return [];
17393
- const missing = jobs.filter((job) => !job.grouped && !(job.calls !== void 0 && grouped.includes(job.calls)));
17394
- const edits = missing.length === 0 ? [] : groupEdits(file, text, lines);
17395
- return missing.map((job) => ({
17396
- file,
17397
- line: job.line,
17398
- message: `${file}: the job ${job.name} has no concurrency group, and the workflow has none.`,
17399
- edits
17400
- }));
17401
- }
17402
- /** This function gives the breaks of the matrices: each `strategy` with a `matrix` has a `max-parallel` of `limit` or less. */
17403
- function matrixBreaks(file, text, lines, limit) {
17404
- const breaks = [];
17405
- const originals = text.split(/\r?\n/);
17406
- lines.forEach((line, index) => {
17407
- if (keyValue(line, "strategy") === void 0) return;
17408
- const keyIndent = childIndent(lines, index);
17409
- if (keyIndent === void 0) return;
17410
- const keys = [];
17411
- for (let i = index + 1; i < blockEnd(lines, index); i++) if ((lines[i] ?? "").trim() !== "" && indentOf$1(lines[i] ?? "") === keyIndent) keys.push(i);
17412
- if (!keys.some((i) => keyValue(lines[i] ?? "", "matrix") !== void 0)) return;
17413
- const at = keys.find((i) => keyValue(lines[i] ?? "", "max-parallel") !== void 0);
17414
- const raw = at === void 0 ? void 0 : keyValue(lines[at] ?? "", "max-parallel");
17415
- const value = raw === void 0 ? NaN : Number(raw);
17416
- const wanted = `${" ".repeat(keyIndent)}max-parallel: ${String(limit)}`;
17417
- if (at === void 0 || raw === void 0) {
17418
- const after = replaceLine(text, index + 1, [originals[index] ?? line, wanted]);
17419
- breaks.push({
17420
- file,
17421
- line: index + 1,
17422
- message: `${file}: a matrix has no max-parallel.`,
17423
- edits: [{
17424
- file,
17425
- before: text,
17426
- after
17427
- }]
17428
- });
17429
- } else if (!Number.isInteger(value) || value < 1 || value > limit) {
17430
- const after = replaceLine(text, at + 1, [wanted]);
17431
- breaks.push({
17432
- file,
17433
- line: index + 1,
17434
- message: `${file}: a matrix has max-parallel ${raw}, and the most is ${String(limit)}.`,
17435
- edits: [{
17436
- file,
17437
- before: text,
17438
- after
17439
- }]
17440
- });
17441
- }
17442
- });
17443
- return breaks;
17444
- }
17445
- /**
17446
- * This function gives the minute field of a schedule that starts `perHour` times in each hour, at equal steps. One start is at
17447
- * `minute`: `"18"` for 1, `"18,48"` for 2. The list is in the order of the numbers.
17448
- */
17449
- function minuteField(minute, perHour) {
17450
- const step = 60 / perHour;
17451
- return Array.from({ length: perHour }, (_, k) => (minute + k * step) % 60).sort((a, b) => a - b).join(",");
17452
- }
17453
- /** 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. */
17454
- function startsPerHour(field) {
17455
- const step = /^\*\/(\d+)$/.exec(field);
17456
- const count = step ? 60 / Number(step[1]) : field.split(",").length;
17457
- return Number.isInteger(count) && count >= 1 && 60 % count === 0 ? count : 1;
17458
- }
17459
- /**
17460
- * This function gives the breaks of the schedules: the minute of each `cron` is the minute of the repository and the file. A
17461
- * schedule that starts more than once in each hour starts at equal steps from that minute (`18,48` for each 30 minutes).
17462
- */
17463
- function cronBreaks(file, text, minute) {
17464
- const breaks = [];
17465
- const originals = text.split(/\r?\n/);
17466
- for (const { line, cron: value } of cronLines(text)) {
17467
- const fields = value.split(" ").filter((field) => field !== "");
17468
- const wanted = minuteField(minute, startsPerHour(fields[0] ?? ""));
17469
- if (fields[0] === wanted) continue;
17470
- const expected = [wanted, ...fields.slice(1)].join(" ");
17471
- const original = originals[line - 1] ?? "";
17472
- const edits = original.includes(value) ? [{
17473
- file,
17474
- before: text,
17475
- after: replaceLine(text, line, [original.replace(value, () => expected)])
17476
- }] : [];
17477
- breaks.push({
17478
- file,
17479
- line,
17480
- message: `${file}: the schedule "${value}" starts at minute ${fields[0] ?? "?"}, and the minute of this repository and file is ${String(minute)}.`,
17481
- fix: `cron: "${expected}"`,
17482
- edits
17483
- });
17484
- }
17485
- return breaks;
17486
- }
17487
- const runnerBudget = {
17488
- id: "runner-budget",
17489
- 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.",
17490
- 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.",
17491
- 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.",
17492
- sources: [{
17493
- repo: "private",
17494
- rule: "runner-slots",
17495
- doc: "a decision of 2026-10-30: the runner slots: a cap of 40, heavy work at most 28"
17496
- }],
17497
- options: {
17498
- maxParallel: {
17499
- type: "number",
17500
- default: 3,
17501
- description: "The largest max-parallel of a matrix."
17502
- },
17503
- minute: {
17504
- type: "boolean",
17505
- default: true,
17506
- description: "When false, the rule does not examine the minute of the schedules."
17507
- },
17508
- grouped: {
17509
- type: "strings",
17510
- default: ["reusable-ai-review.yml", "reusable-codex-review.yml"],
17511
- 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."
17512
- }
17513
- },
17514
- check(context, options) {
17515
- const files = context.gitFiles();
17516
- if (files === void 0) return { skipped: "the root is not in a git repository" };
17517
- const workflows = files.filter((path) => WORKFLOW$1.test(path)).sort(byCode);
17518
- if (workflows.length === 0) return { skipped: "the repository has no workflow" };
17519
- const remote = context.git([
17520
- "remote",
17521
- "get-url",
17522
- "origin"
17523
- ]);
17524
- const repository = context.env["GITHUB_REPOSITORY"] ?? (remote === void 0 ? void 0 : repositoryOfRemote(remote));
17525
- const limit = Number(options["maxParallel"]);
17526
- const grouped = Array.isArray(options["grouped"]) ? options["grouped"] : [];
17527
- const breaks = [];
17528
- for (const file of workflows) {
17529
- let text;
17530
- try {
17531
- text = readFileSync(join(context.root, file), "utf8");
17532
- } catch {
17533
- continue;
17534
- }
17535
- const lines = workflowLines(text);
17536
- breaks.push(...matrixBreaks(file, text, lines, limit), ...concurrencyBreaks(file, text, lines, grouped));
17537
- if (options["minute"] !== false) {
17538
- if (cronLines(text).length > 0 && repository === void 0) breaks.push({
17539
- file,
17540
- message: `${file} has a schedule, and the rule cannot find the repository (GITHUB_REPOSITORY, or a GitHub URL of the remote origin).`
17541
- });
17542
- else if (repository !== void 0) breaks.push(...cronBreaks(file, text, scheduleMinute(repository, file)));
17543
- }
17544
- }
17545
- return breaks;
17546
- }
17547
- };
17548
17691
  // src/rules/pages-after-release.ts
17549
17692
  /**
17550
17693
  * The rule `pages-after-release`: a repository that publishes a package and deploys a site starts its Pages workflow
@@ -21157,6 +21300,7 @@ const RULES = [
21157
21300
  gateAfterCancel,
21158
21301
  gateTrigger,
21159
21302
  securityOneJob,
21303
+ securityGate,
21160
21304
  summaryJobRule,
21161
21305
  sharedCi,
21162
21306
  setupCue,
@@ -22180,6 +22324,6 @@ function runHook(args, io) {
22180
22324
  git: (gitArgs) => runGit(io.cwd, gitArgs)
22181
22325
  }, io);
22182
22326
  }
22183
- export { unreleasedChange as $, readAction as $n, licenseFileOf as $t, scriptsOf as A, callsSharedCi as An, privateNamesFiles as At, roadmapOfLine as B, SECURITY_TIMEOUT_MINUTES as Bn, mergePrivateNames as Bt, setVersions as C, runCalls as Cn, parseConfig as Cr, HOME_PATTERNS as Ct, trustPolicy as D, SHARED_ACTIONS as Dn, invalidPatternBreaks as Dt, TRAIN_SCOPES as E, tsconfigTest as En, PRIVATE_PATTERNS_VARIABLE as Et, sourceMain as F, hasSummaryJob as Fn, firstNameMatch as Ft, minorOf as G, convertGate as Gn, REAL_COMPARE as Gt, requiredScripts as H, securityOneJob as Hn, parsePrivateNames as Ht, HOME_TIMEOUT_MS as I, startsOnPullRequest as In, isAllowedHit as It, reachOf as J, skippableJobs as Jn, coverageProvider as Jt, publishedMinor as K, gateTrigger as Kn, hasImportMetaMain as Kt, blockHash as L, summaryJobRule as Ln, isCommonUse as Lt, testsRequired as M, setupCue as Mn, privateTextBreaks as Mt, isSourcePath as N, SUMMARY_GATES as Nn, PRIVATE_NAME_LIST as Nt, typedScripts as O, SHARED_CI as On, noLocalPaths as Ot, pathsOf as P, addSummaryJob as Pn, PrivateNameListError as Pt, npmLookup as Q, parseWorkflow as Qn, licenseFile as Qt, githubFetch as R, SECURITY_SCAN_COMMIT as Rn, lineNameHit as Rt, namedVersions as S, SERVICE_PACKAGE as Sn, defaultOptions as Sr, DEFAULT_ALLOWED as St, IGNORE_AFTER as T, hasTests as Tn, PRIVATE_NAMES_FILE_VARIABLE as Tt, releaseFiles as U, withOneJob as Un, pathNameHit as Ut, roadmapParses as V, securityCallers as Vn, nameMatches as Vt, lockedVersions as W, ACTIONS_COMMIT as Wn, noBuildOutput as Wt, SHIPPED_FIELDS as X, summaryName as Xn, LICENSE_TEXTS as Xt, NPM_REGISTRY as Y, summaryJob as Yn, apiReportScript as Yt, UNSHIPPED_FILES as Z, gateAfterCancel as Zn, authorOf as Zt, runPrePushArgs as _, mapText as _n, repositoryOfRemote as _r, pagesCalls as _t, listRules as a, modulesOf as an, RULE_WARN_DAYS as ar, startsTests as at, GITHUB_YAML as b, npmNames as bn, showFiles as br, publishTextSafe as bt, runCli as c, messageOf as cn, hasFile as cr, isGitSpecifier as ct, HOOK_MARKER as d, signaturesOf as dn, lineOf as dr, siteCheckInCi as dt, mitText as en, readWorkflow as er, unreleasedChangeRule as et, NO_READ_LINE as f, HOME_EXPORTS as fn, matchesAny as fr, pagesAfterRelease as ft, prePush as g, mapMarkdown as gn, replaceLine as gr, PAGES_WORKFLOWS as gt, parsePrePushArgs as h, findHomes as hn, readJsonc as hr, pushMainOnly as ht, formatResult as i, moduleUses as in, DEPENDENCY_FIELDS as ir, parseAdvisory as it, typedFiles as j, sharedCi as jn, privatePatterns as jt, configsOfScript as k, SHARED_WORKFLOWS as kn, privateNamesFile as kt, runFix as l, repoOf as ln, inFolder as lr, isPinned as lt, installHook as m, MAP_RULE as mn, parseJsonc as mr, scheduleMinute as mt, annotations as n, homeModule as nn, STRICT_OPTIONS as nr, hiddenFailures as nt, readConfig as o, declaredName as on, cleanPath as or, swallowsTests as ot, PRE_PUSH_HOOK as p, HOMES as pn, parseCatFileBatch as pr, runnerBudget as pt, publishedMinorRule as q, prPathFilters as qn, mainCheck as qt, createContext as r, moduleMessage as rn, cuePreset as rr, jobFails as rt, runChecks as s, homePackage as sn, codePackages as sr, pipeFails as st, USAGE as t, repositoryIsPublic as tn, yamlFaults as tr, playwrightInstall as tt, summaryMarkdown as u, reposOf as un, keyLine as ur, pinnedGitDeps as ut, RULES as v, mergeHomes as vn, runGit as vr, pagesSite as vt, versionTitle as w, serviceRunMain as wn, parseRuleConfig as wr, PRIVATE_NAMES_FILE_CONFIG as wt, workflowParses as x, readOverlay as xn, specifiersOf as xr, packNoBuildinfo as xt, workspaceProtocol as y, npmDrift as yn, runGitShow as yr, exportsRequire as yt, sharedDocsRule as z, SECURITY_SCAN_INPUTS as zn, lineNameHits as zt };
22327
+ export { unreleasedChange as $, summaryJob as $n, homePackage as $t, scriptsOf as A, addSummaryJob as An, privateTextBreaks as At, roadmapOfLine as B, runnerBudget as Bn, parsePrivateNames as Bt, setVersions as C, sharedCi as Cn, runGitShow as Cr, PRIVATE_NAMES_FILE_VARIABLE as Ct, trustPolicy as D, securityGate as Dn, parseConfig as Dr, privateNamesFile as Dt, TRAIN_SCOPES as E, isSecurityGate as En, defaultOptions as Er, noLocalPaths as Et, sourceMain as F, SECURITY_SCAN_INPUTS as Fn, isCommonUse as Ft, minorOf as G, licenseFileOf as Gn, mainCheck as Gt, requiredScripts as H, LICENSE_TEXTS as Hn, noBuildOutput as Ht, HOME_TIMEOUT_MS as I, SECURITY_TIMEOUT_MINUTES as In, lineNameHit as It, reachOf as J, ACTIONS_COMMIT as Jn, homeModule as Jt, publishedMinor as K, mitText as Kn, coverageProvider as Kt, blockHash as L, securityCallers as Ln, lineNameHits as Lt, testsRequired as M, startsOnPullRequest as Mn, PrivateNameListError as Mt, isSourcePath as N, summaryJobRule as Nn, firstNameMatch as Nt, typedScripts as O, securityWorkflow as On, parseRuleConfig as Or, privateNamesFiles as Ot, pathsOf as P, SECURITY_SCAN_COMMIT as Pn, isAllowedHit as Pt, npmLookup as Q, skippableJobs as Qn, declaredName as Qt, githubFetch as R, securityOneJob as Rn, mergePrivateNames as Rt, namedVersions as S, callsSharedCi as Sn, runGit as Sr, PRIVATE_NAMES_FILE_CONFIG as St, IGNORE_AFTER as T, SECURITY_FILE as Tn, specifiersOf as Tr, invalidPatternBreaks as Tt, releaseFiles as U, authorOf as Un, REAL_COMPARE as Ut, roadmapParses as V, scheduleMinute as Vn, pathNameHit as Vt, lockedVersions as W, licenseFile as Wn, hasImportMetaMain as Wt, SHIPPED_FIELDS as X, gateTrigger as Xn, moduleUses as Xt, NPM_REGISTRY as Y, convertGate as Yn, moduleMessage as Yt, UNSHIPPED_FILES as Z, prPathFilters as Zn, modulesOf as Zt, runPrePushArgs as _, hasTests as _n, parseCatFileBatch as _r, exportsRequire as _t, listRules as a, HOMES as an, yamlFaults as ar, startsTests as at, GITHUB_YAML as b, SHARED_CI as bn, replaceLine as br, DEFAULT_ALLOWED as bt, runCli as c, mapMarkdown as cn, DEPENDENCY_FIELDS as cr, isGitSpecifier as ct, HOOK_MARKER as d, npmDrift as dn, codePackages as dr, siteCheckInCi as dt, messageOf as en, summaryName as er, unreleasedChangeRule as et, NO_READ_LINE as f, npmNames as fn, hasFile as fr, pagesAfterRelease as ft, prePush as g, serviceRunMain as gn, matchesAny as gr, pagesSite as gt, parsePrePushArgs as h, runCalls as hn, lineOf as hr, pagesCalls as ht, formatResult as i, HOME_EXPORTS as in, readWorkflow as ir, parseAdvisory as it, typedFiles as j, hasSummaryJob as jn, PRIVATE_NAME_LIST as jt, configsOfScript as k, SUMMARY_GATES as kn, privatePatterns as kt, runFix as l, mapText as ln, RULE_WARN_DAYS as lr, isPinned as lt, installHook as m, SERVICE_PACKAGE as mn, keyLine as mr, PAGES_WORKFLOWS as mt, annotations as n, reposOf as nn, parseWorkflow as nr, hiddenFailures as nt, readConfig as o, MAP_RULE as on, STRICT_OPTIONS as or, swallowsTests as ot, PRE_PUSH_HOOK as p, readOverlay as pn, inFolder as pr, pushMainOnly as pt, publishedMinorRule as q, repositoryIsPublic as qn, apiReportScript as qt, createContext as r, signaturesOf as rn, readAction as rr, jobFails as rt, runChecks as s, findHomes as sn, cuePreset as sr, pipeFails as st, USAGE as t, repoOf as tn, gateAfterCancel as tr, playwrightInstall as tt, summaryMarkdown as u, mergeHomes as un, cleanPath as ur, pinnedGitDeps as ut, RULES as v, tsconfigTest as vn, parseJsonc as vr, publishTextSafe as vt, versionTitle as w, setupCue as wn, showFiles as wr, PRIVATE_PATTERNS_VARIABLE as wt, workflowParses as x, SHARED_WORKFLOWS as xn, repositoryOfRemote as xr, HOME_PATTERNS as xt, workspaceProtocol as y, SHARED_ACTIONS as yn, readJsonc as yr, packNoBuildinfo as yt, sharedDocsRule as z, withOneJob as zn, nameMatches as zt };
22184
22328
 
22185
- //# sourceMappingURL=run-DNe9I3-M.js.map
22329
+ //# sourceMappingURL=run-DRCOlvNx.js.map