@mark1russell7/conventions 0.10.1 → 0.12.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 +4 -1
- package/build/cli.js +1 -1
- package/build/index.d.ts +25 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/{run-c3bySjnK.js → run-Dgb6gjZJ.js} +390 -58
- package/build/run-Dgb6gjZJ.js.map +1 -0
- package/package.json +1 -1
- package/build/run-c3bySjnK.js.map +0 -1
|
@@ -503,6 +503,356 @@ const cuePreset = {
|
|
|
503
503
|
return breaks;
|
|
504
504
|
}
|
|
505
505
|
};
|
|
506
|
+
// src/workflow.ts
|
|
507
|
+
/**
|
|
508
|
+
* A small reader of GitHub workflow files, by the indent of the lines. The rules that read workflows share it. It
|
|
509
|
+
* knows the block form and the inline values of keys, which is what the workflows of the template use.
|
|
510
|
+
*/
|
|
511
|
+
/** A workflow file. */
|
|
512
|
+
const WORKFLOW$1 = /^\.github\/workflows\/[^/]+\.ya?ml$/;
|
|
513
|
+
const indentOf$1 = (line) => line.length - line.trimStart().length;
|
|
514
|
+
/** This function gives the lines of a workflow, with each line of a comment made empty. */
|
|
515
|
+
const workflowLines = (text) => text.split(/\r?\n/).map((line) => line.trimStart().startsWith("#") ? "" : line);
|
|
516
|
+
/** This function removes a comment at the end of a value, and the quotes around it. */
|
|
517
|
+
function valueOf$1(raw) {
|
|
518
|
+
const comment = raw.indexOf(" #");
|
|
519
|
+
let value = (comment >= 0 ? raw.slice(0, comment) : raw).trim();
|
|
520
|
+
const quote = value.charAt(0);
|
|
521
|
+
if (value.length >= 2 && (quote === "\"" || quote === "'") && value.endsWith(quote)) value = value.slice(1, -1).trim();
|
|
522
|
+
return value;
|
|
523
|
+
}
|
|
524
|
+
/** This function gives the value of the key `key` on a line, or undefined when the line has another key. A quoted key ("on") counts too. */
|
|
525
|
+
function keyValue(line, key) {
|
|
526
|
+
let text = line.trimStart();
|
|
527
|
+
if (text.startsWith("- ")) text = text.slice(2).trimStart();
|
|
528
|
+
for (const form of [
|
|
529
|
+
key,
|
|
530
|
+
`"${key}"`,
|
|
531
|
+
`'${key}'`
|
|
532
|
+
]) if (text.startsWith(`${form}:`)) return valueOf$1(text.slice(form.length + 1));
|
|
533
|
+
}
|
|
534
|
+
/** This function gives the end of the block under the line `index`. The end is the next line with the same indent or a smaller one. */
|
|
535
|
+
function blockEnd(lines, index) {
|
|
536
|
+
const indent = indentOf$1(lines[index] ?? "");
|
|
537
|
+
let end = index + 1;
|
|
538
|
+
while (end < lines.length) {
|
|
539
|
+
const line = lines[end] ?? "";
|
|
540
|
+
if (line.trim() !== "" && indentOf$1(line) <= indent) break;
|
|
541
|
+
end += 1;
|
|
542
|
+
}
|
|
543
|
+
return end;
|
|
544
|
+
}
|
|
545
|
+
/** This function gives the indent of the first key of the block under the line `index`, or undefined for an empty block. */
|
|
546
|
+
function childIndent(lines, index) {
|
|
547
|
+
const end = blockEnd(lines, index);
|
|
548
|
+
for (let i = index + 1; i < end; i++) if ((lines[i] ?? "").trim() !== "") return indentOf$1(lines[i] ?? "");
|
|
549
|
+
}
|
|
550
|
+
/** This function gives the indexes of the keys of the block under the line `index`: the lines at the indent of its first key. */
|
|
551
|
+
function childKeys(lines, index) {
|
|
552
|
+
const indent = childIndent(lines, index);
|
|
553
|
+
if (indent === void 0) return [];
|
|
554
|
+
const keys = [];
|
|
555
|
+
for (let i = index + 1; i < blockEnd(lines, index); i++) if ((lines[i] ?? "").trim() !== "" && indentOf$1(lines[i] ?? "") === indent) keys.push(i);
|
|
556
|
+
return keys;
|
|
557
|
+
}
|
|
558
|
+
// src/rules/gate-trigger.ts
|
|
559
|
+
/**
|
|
560
|
+
* The rule `gate-trigger`: a workflow that runs on pull requests starts on each pull request, with no path filter. The
|
|
561
|
+
* ruleset needs the summary check "<Name> OK" of each gate. A workflow with `on.pull_request.paths` does not start
|
|
562
|
+
* on each pull request, so its check is not always there, and the ruleset cannot ask for it.
|
|
563
|
+
*/
|
|
564
|
+
const TRIGGERS = ["pull_request", "pull_request_target"];
|
|
565
|
+
const FILTERS = ["paths", "paths-ignore"];
|
|
566
|
+
/** This function gives the path filters of the pull request triggers of a workflow. */
|
|
567
|
+
function prPathFilters(text) {
|
|
568
|
+
const lines = workflowLines(text);
|
|
569
|
+
const on = lines.findIndex((line) => indentOf$1(line) === 0 && keyValue(line, "on") !== void 0);
|
|
570
|
+
if (on < 0) return [];
|
|
571
|
+
if ((keyValue(lines[on] ?? "", "on") ?? "") !== "") return [];
|
|
572
|
+
const found = [];
|
|
573
|
+
for (const at of childKeys(lines, on)) for (const trigger of TRIGGERS) {
|
|
574
|
+
const value = keyValue(lines[at] ?? "", trigger);
|
|
575
|
+
if (value === void 0) continue;
|
|
576
|
+
for (const key of FILTERS) if (new RegExp(`(^|[{,\\s])${key}\\s*:`).test(value)) found.push({
|
|
577
|
+
line: at + 1,
|
|
578
|
+
trigger,
|
|
579
|
+
key
|
|
580
|
+
});
|
|
581
|
+
for (const child of childKeys(lines, at)) for (const key of FILTERS) if (keyValue(lines[child] ?? "", key) !== void 0) found.push({
|
|
582
|
+
line: child + 1,
|
|
583
|
+
trigger,
|
|
584
|
+
key
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
return found;
|
|
588
|
+
}
|
|
589
|
+
/** The commit of the template with the actions `changes` and `gate-summary`. Renovate updates the pins after the fix. */
|
|
590
|
+
const ACTIONS_COMMIT = "f05c6eeb35e33a040bdfdcd7d07a1d2c00640f8d";
|
|
591
|
+
/** This function gives the items of a list value: the flow form `[a, "b"]`, or the block form under the line `index`. */
|
|
592
|
+
function listItems(lines, index, value) {
|
|
593
|
+
if (value.startsWith("[") && value.endsWith("]")) return {
|
|
594
|
+
items: value.slice(1, -1).split(",").map((item) => valueOf$1(item)).filter((item) => item !== ""),
|
|
595
|
+
end: index + 1
|
|
596
|
+
};
|
|
597
|
+
if (value !== "") return void 0;
|
|
598
|
+
const indent = indentOf$1(lines[index] ?? "");
|
|
599
|
+
const items = [];
|
|
600
|
+
let end = index + 1;
|
|
601
|
+
for (let i = index + 1; i < lines.length; i++) {
|
|
602
|
+
const line = lines[i] ?? "";
|
|
603
|
+
if (line.trim() === "") continue;
|
|
604
|
+
if (!(indentOf$1(line) > indent || indentOf$1(line) === indent && line.trimStart().startsWith("- "))) break;
|
|
605
|
+
if (!line.trimStart().startsWith("- ")) return void 0;
|
|
606
|
+
items.push(valueOf$1(line.trimStart().slice(2)));
|
|
607
|
+
end = i + 1;
|
|
608
|
+
}
|
|
609
|
+
return {
|
|
610
|
+
items,
|
|
611
|
+
end
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
/** This function gives the name of the summary check of a workflow: its name with "OK", in the form that ruleset-ci-ok.ts reads. */
|
|
615
|
+
function summaryName(workflowName) {
|
|
616
|
+
const words = workflowName.replace(/[^A-Za-z0-9]+/g, " ").trim();
|
|
617
|
+
return `${words === "" ? "Gate" : words.charAt(0).toUpperCase() + words.slice(1)} OK`;
|
|
618
|
+
}
|
|
619
|
+
/** This function puts an expression into the value of an `if`, as YAML that keeps it. */
|
|
620
|
+
const ifValue = (expression) => {
|
|
621
|
+
const value = `\${{ ${expression} }}`;
|
|
622
|
+
return value.includes(": ") || value.includes(" #") ? `"${value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}"` : value;
|
|
623
|
+
};
|
|
624
|
+
/**
|
|
625
|
+
* This function converts a gate workflow with a path filter on its pull request trigger. The trigger loses the filter,
|
|
626
|
+
* and a job `changes` gets the same patterns. Each other job needs it and runs only on a match. A summary job
|
|
627
|
+
* `<Name> OK` with the action gate-summary needs each job. The function gives the new text, or the reason why a
|
|
628
|
+
* person must convert the workflow.
|
|
629
|
+
*/
|
|
630
|
+
function convertGate(text, file, commit = ACTIONS_COMMIT) {
|
|
631
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
632
|
+
const original = text.split(/\r?\n/);
|
|
633
|
+
const lines = workflowLines(text);
|
|
634
|
+
const top = (key) => lines.findIndex((line) => indentOf$1(line) === 0 && keyValue(line, key) !== void 0);
|
|
635
|
+
const on = top("on");
|
|
636
|
+
const jobsAt = top("jobs");
|
|
637
|
+
if (on < 0 || jobsAt < 0) return { reason: "the workflow has no on block or no jobs block" };
|
|
638
|
+
const splices = [];
|
|
639
|
+
const filters = {};
|
|
640
|
+
for (const at of childKeys(lines, on)) {
|
|
641
|
+
const trigger = TRIGGERS.find((name) => keyValue(lines[at] ?? "", name) !== void 0);
|
|
642
|
+
if (trigger === void 0) continue;
|
|
643
|
+
if ((keyValue(lines[at] ?? "", trigger) ?? "") !== "") return { reason: `on.${trigger} has the flow form` };
|
|
644
|
+
let filtered = false;
|
|
645
|
+
for (const child of childKeys(lines, at)) {
|
|
646
|
+
const key = FILTERS.find((name) => keyValue(lines[child] ?? "", name) !== void 0);
|
|
647
|
+
if (key === void 0) continue;
|
|
648
|
+
const list = listItems(lines, child, keyValue(lines[child] ?? "", key) ?? "");
|
|
649
|
+
if (list === void 0) return { reason: `on.${trigger}.${key} is not a list` };
|
|
650
|
+
const before = filters[key];
|
|
651
|
+
if (before !== void 0 && before.join("\n") !== list.items.join("\n")) return { reason: `the triggers have different ${key}` };
|
|
652
|
+
filters[key] = list.items;
|
|
653
|
+
splices.push({
|
|
654
|
+
at: child,
|
|
655
|
+
remove: list.end - child,
|
|
656
|
+
insert: []
|
|
657
|
+
});
|
|
658
|
+
filtered = true;
|
|
659
|
+
}
|
|
660
|
+
if (filtered) {
|
|
661
|
+
const pad = " ".repeat(indentOf$1(lines[at] ?? ""));
|
|
662
|
+
splices.push({
|
|
663
|
+
at,
|
|
664
|
+
remove: 0,
|
|
665
|
+
insert: [`${pad}# Each pull request starts this workflow, so its summary check is always there. The job changes skips the`, `${pad}# work when the pull request changes no file of the gate (CI.md of the template, "A gate with paths").`]
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
if (Object.keys(filters).length === 0) return { reason: "the workflow has no path filter on a pull request trigger" };
|
|
670
|
+
const jobs = childKeys(lines, jobsAt);
|
|
671
|
+
const first = jobs[0];
|
|
672
|
+
if (first === void 0) return { reason: "the workflow has no job" };
|
|
673
|
+
const ids = jobs.map((at) => (lines[at] ?? "").trim().replace(/:$/, ""));
|
|
674
|
+
const jobIndent = " ".repeat(indentOf$1(lines[first] ?? ""));
|
|
675
|
+
const unit = " ".repeat((childIndent(lines, first) ?? indentOf$1(lines[first] ?? "") + 2) - jobIndent.length);
|
|
676
|
+
const nameAt = top("name");
|
|
677
|
+
const name = summaryName(nameAt >= 0 ? keyValue(lines[nameAt] ?? "", "name") ?? "" : (file.split("/").pop() ?? "").replace(/\.ya?ml$/, ""));
|
|
678
|
+
const summaryId = name.toLowerCase().replaceAll(" ", "-");
|
|
679
|
+
for (const id of ["changes", summaryId]) if (ids.includes(id)) return { reason: `the workflow already has a job ${id}` };
|
|
680
|
+
const needsOf = /* @__PURE__ */ new Map();
|
|
681
|
+
const own = /* @__PURE__ */ new Set();
|
|
682
|
+
for (const [index, at] of jobs.entries()) {
|
|
683
|
+
const id = ids[index] ?? "";
|
|
684
|
+
const keys = childKeys(lines, at);
|
|
685
|
+
const pad = " ".repeat(childIndent(lines, at) ?? indentOf$1(lines[at] ?? "") + unit.length);
|
|
686
|
+
const needsAt = keys.find((key) => keyValue(lines[key] ?? "", "needs") !== void 0);
|
|
687
|
+
const ifAt = keys.find((key) => keyValue(lines[key] ?? "", "if") !== void 0);
|
|
688
|
+
if (needsAt === void 0) {
|
|
689
|
+
needsOf.set(id, []);
|
|
690
|
+
splices.push({
|
|
691
|
+
at: at + 1,
|
|
692
|
+
remove: 0,
|
|
693
|
+
insert: [`${pad}needs: changes`]
|
|
694
|
+
});
|
|
695
|
+
} else {
|
|
696
|
+
const value = keyValue(lines[needsAt] ?? "", "needs") ?? "";
|
|
697
|
+
const list = value === "" || value.startsWith("[") ? listItems(lines, needsAt, value) : {
|
|
698
|
+
items: [value],
|
|
699
|
+
end: needsAt + 1
|
|
700
|
+
};
|
|
701
|
+
if (list === void 0) return { reason: `the needs of the job ${id} is not a list` };
|
|
702
|
+
needsOf.set(id, list.items);
|
|
703
|
+
if (value === "") {
|
|
704
|
+
const item = lines.findIndex((line, i) => i > needsAt && line.trim() !== "");
|
|
705
|
+
splices.push({
|
|
706
|
+
at: item,
|
|
707
|
+
remove: 0,
|
|
708
|
+
insert: [`${" ".repeat(indentOf$1(lines[item] ?? ""))}- changes`]
|
|
709
|
+
});
|
|
710
|
+
} else splices.push({
|
|
711
|
+
at: needsAt,
|
|
712
|
+
remove: 1,
|
|
713
|
+
insert: [`${pad}needs: [${["changes", ...list.items].join(", ")}]`]
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
if (ifAt === void 0) splices.push({
|
|
717
|
+
at: at + 1,
|
|
718
|
+
remove: 0,
|
|
719
|
+
insert: [`${pad}if: needs.changes.outputs.match == 'true'`]
|
|
720
|
+
});
|
|
721
|
+
else {
|
|
722
|
+
let old = keyValue(lines[ifAt] ?? "", "if") ?? "";
|
|
723
|
+
if (/^[>|]/.test(old)) return { reason: `the if of the job ${id} has more than one line` };
|
|
724
|
+
const whole = /^\$\{\{(.*)\}\}$/.exec(old);
|
|
725
|
+
if (whole !== null) old = (whole[1] ?? "").trim();
|
|
726
|
+
if (old.includes("${{")) return { reason: `the if of the job ${id} has a part in \${{ }}` };
|
|
727
|
+
own.add(id);
|
|
728
|
+
splices.push({
|
|
729
|
+
at: ifAt,
|
|
730
|
+
remove: 1,
|
|
731
|
+
insert: [`${pad}if: ${ifValue(`needs.changes.outputs.match == 'true' && (${old})`)}`]
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
const skippable = new Set(own);
|
|
736
|
+
for (let grew = true; grew;) {
|
|
737
|
+
grew = false;
|
|
738
|
+
for (const [id, needs] of needsOf) {
|
|
739
|
+
if (skippable.has(id) || !needs.some((need) => skippable.has(need))) continue;
|
|
740
|
+
skippable.add(id);
|
|
741
|
+
grew = true;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
const action = (step) => `mark1russell7/template/.github/actions/${step}@${commit} # main`;
|
|
745
|
+
const block = (indent, key, items) => [`${indent}${key}: |`, ...items.map((item) => `${indent}${unit}${item}`)];
|
|
746
|
+
const job = jobIndent + unit;
|
|
747
|
+
const step = job + unit;
|
|
748
|
+
const grouped = top("concurrency") >= 0;
|
|
749
|
+
const group = (id) => grouped ? [] : [
|
|
750
|
+
`${job}concurrency:`,
|
|
751
|
+
`${job}${unit}group: \${{ github.workflow }}-${id}-\${{ github.ref }}`,
|
|
752
|
+
`${job}${unit}cancel-in-progress: true`
|
|
753
|
+
];
|
|
754
|
+
const changes = [
|
|
755
|
+
`${jobIndent}changes:`,
|
|
756
|
+
`${job}runs-on: ubuntu-latest`,
|
|
757
|
+
`${job}timeout-minutes: 5`,
|
|
758
|
+
...group("changes"),
|
|
759
|
+
`${job}permissions:`,
|
|
760
|
+
`${job}${unit}contents: read`,
|
|
761
|
+
`${job}${unit}pull-requests: read`,
|
|
762
|
+
`${job}outputs:`,
|
|
763
|
+
`${job}${unit}match: \${{ steps.changes.outputs.match }}`,
|
|
764
|
+
`${job}steps:`,
|
|
765
|
+
`${step}- id: changes`,
|
|
766
|
+
`${step} uses: ${action("changes")}`,
|
|
767
|
+
`${step} with:`,
|
|
768
|
+
...block(`${step} ${unit}`, "paths", filters["paths"] ?? ["**"]),
|
|
769
|
+
...filters["paths-ignore"] === void 0 ? [] : block(`${step} ${unit}`, "paths-ignore", filters["paths-ignore"]),
|
|
770
|
+
""
|
|
771
|
+
];
|
|
772
|
+
const allow = ids.filter((id) => skippable.has(id));
|
|
773
|
+
const summary = [
|
|
774
|
+
"",
|
|
775
|
+
`${jobIndent}${summaryId}:`,
|
|
776
|
+
`${job}name: ${name}`,
|
|
777
|
+
`${job}if: always()`,
|
|
778
|
+
`${job}needs: [${["changes", ...ids].join(", ")}]`,
|
|
779
|
+
`${job}runs-on: ubuntu-latest`,
|
|
780
|
+
`${job}timeout-minutes: 2`,
|
|
781
|
+
...group(summaryId),
|
|
782
|
+
`${job}permissions: {}`,
|
|
783
|
+
`${job}steps:`,
|
|
784
|
+
`${step}- uses: ${action("gate-summary")}`,
|
|
785
|
+
`${step} with:`,
|
|
786
|
+
`${step} ${unit}needs: \${{ toJSON(needs) }}`,
|
|
787
|
+
...allow.length === 0 ? [] : [`${step} ${unit}allow-skip: ${allow.join(" ")}`]
|
|
788
|
+
];
|
|
789
|
+
let last = blockEnd(lines, jobsAt);
|
|
790
|
+
while (last > jobsAt + 1 && (lines[last - 1] ?? "").trim() === "") last -= 1;
|
|
791
|
+
splices.push({
|
|
792
|
+
at: first,
|
|
793
|
+
remove: 0,
|
|
794
|
+
insert: changes
|
|
795
|
+
}, {
|
|
796
|
+
at: last,
|
|
797
|
+
remove: 0,
|
|
798
|
+
insert: summary
|
|
799
|
+
});
|
|
800
|
+
const out = [...original];
|
|
801
|
+
for (const item of splices.map((value, order) => ({
|
|
802
|
+
...value,
|
|
803
|
+
order
|
|
804
|
+
})).sort((a, b) => b.at - a.at || b.remove - a.remove || b.order - a.order)) out.splice(item.at, item.remove, ...item.insert);
|
|
805
|
+
return { text: out.join(eol) };
|
|
806
|
+
}
|
|
807
|
+
const gateTrigger = {
|
|
808
|
+
id: "gate-trigger",
|
|
809
|
+
title: "A workflow that runs on pull requests starts on each pull request: it has no on.pull_request.paths or paths-ignore.",
|
|
810
|
+
reason: "The ruleset requires the summary check \"<Name> OK\" of each gate. A workflow with a path filter does not start on a pull request that changes no file of the filter, so its check is not there, and the ruleset cannot require it. Then a pull request can merge before such a gate ends. On 2026-11-02, 19 such workflows in 11 repositories fed no required check.",
|
|
811
|
+
fix: "Remove the paths from on.pull_request. Add a job \"changes\" with the action mark1russell7/template/.github/actions/changes and the same paths, and \"if: needs.changes.outputs.match == 'true'\" on each gate job. Add a job \"<Name> OK\" with \"if: always()\", \"needs\" with each job, and the action gate-summary (CI.md, \"A gate with paths\"). Then start ruleset-ci-ok.ts again. A workflow that is not a gate can go in the option allow.",
|
|
812
|
+
sources: [{
|
|
813
|
+
repo: "fleet",
|
|
814
|
+
rule: "gate-trigger",
|
|
815
|
+
doc: "docs/STRATEGY.md (2026-11-02, a gate with paths feeds a required summary)"
|
|
816
|
+
}],
|
|
817
|
+
options: { allow: {
|
|
818
|
+
type: "strings",
|
|
819
|
+
default: [],
|
|
820
|
+
description: "The file names of the workflows that can filter pull requests by path, because they are not a gate (for example a preview)."
|
|
821
|
+
} },
|
|
822
|
+
check(context, options) {
|
|
823
|
+
const files = context.gitFiles();
|
|
824
|
+
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
825
|
+
const workflows = files.filter((path) => WORKFLOW$1.test(path)).sort(byCode);
|
|
826
|
+
if (workflows.length === 0) return { skipped: "the repository has no workflow" };
|
|
827
|
+
const allow = Array.isArray(options["allow"]) ? options["allow"] : [];
|
|
828
|
+
const breaks = [];
|
|
829
|
+
for (const file of workflows) {
|
|
830
|
+
if (allow.includes(file.slice(file.lastIndexOf("/") + 1))) continue;
|
|
831
|
+
let text;
|
|
832
|
+
try {
|
|
833
|
+
text = readFileSync(join(context.root, file), "utf8");
|
|
834
|
+
} catch {
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
const filters = prPathFilters(text);
|
|
838
|
+
const first = filters[0];
|
|
839
|
+
if (first === void 0) continue;
|
|
840
|
+
const keys = filters.map((filter) => `on.${filter.trigger}.${filter.key}`).join(" and ");
|
|
841
|
+
const converted = convertGate(text, file);
|
|
842
|
+
breaks.push({
|
|
843
|
+
file,
|
|
844
|
+
line: first.line,
|
|
845
|
+
message: `${file}: ${keys}, so the workflow does not start on each pull request, and the ruleset cannot ask for its summary check.`,
|
|
846
|
+
..."text" in converted ? { edits: [{
|
|
847
|
+
file,
|
|
848
|
+
before: text,
|
|
849
|
+
after: converted.text
|
|
850
|
+
}] } : { fix: `A person must convert it, because ${converted.reason}. ${gateTrigger.fix}` }
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
return breaks;
|
|
854
|
+
}
|
|
855
|
+
};
|
|
506
856
|
// src/rules/main-check.ts
|
|
507
857
|
/**
|
|
508
858
|
* The rule `main-check`: a script does not find out that it is the main module by a compare of `process.argv[1]` with
|
|
@@ -987,7 +1337,8 @@ function rangeOf(context) {
|
|
|
987
1337
|
]) === void 0) return { skipped: `git does not know the base ${context.base}` };
|
|
988
1338
|
return {
|
|
989
1339
|
diff: [`${context.base}...HEAD`],
|
|
990
|
-
log: [`${context.base}..HEAD`]
|
|
1340
|
+
log: [`${context.base}..HEAD`],
|
|
1341
|
+
ends: [context.base, "HEAD"]
|
|
991
1342
|
};
|
|
992
1343
|
}
|
|
993
1344
|
const event = context.env["GITHUB_EVENT_NAME"];
|
|
@@ -1006,18 +1357,24 @@ function rangeOf(context) {
|
|
|
1006
1357
|
]) === void 0) return { skipped: "the checkout has no parent of HEAD: set fetch-depth to 2 or more" };
|
|
1007
1358
|
return {
|
|
1008
1359
|
diff: ["HEAD^1", "HEAD"],
|
|
1009
|
-
log: ["HEAD^1..HEAD"]
|
|
1360
|
+
log: ["HEAD^1..HEAD"],
|
|
1361
|
+
ends: ["HEAD^1", "HEAD^2"]
|
|
1010
1362
|
};
|
|
1011
1363
|
}
|
|
1012
|
-
/** This function gives the
|
|
1013
|
-
function
|
|
1364
|
+
/** This function gives the pull request of the event file of GitHub Actions. With no event file, the body is empty. */
|
|
1365
|
+
function pullRequestOf(context) {
|
|
1014
1366
|
const file = context.env["GITHUB_EVENT_PATH"];
|
|
1015
|
-
if (file === void 0 || file === "" || !existsSync(file)) return "";
|
|
1367
|
+
if (file === void 0 || file === "" || !existsSync(file)) return { body: "" };
|
|
1016
1368
|
try {
|
|
1017
1369
|
const event = JSON.parse(readFileSync(file, "utf8"));
|
|
1018
|
-
|
|
1370
|
+
const body = typeof event.pull_request?.body === "string" ? event.pull_request.body : "";
|
|
1371
|
+
const commits = event.pull_request?.commits;
|
|
1372
|
+
return typeof commits === "number" ? {
|
|
1373
|
+
body,
|
|
1374
|
+
commits
|
|
1375
|
+
} : { body };
|
|
1019
1376
|
} catch {
|
|
1020
|
-
return "";
|
|
1377
|
+
return { body: "" };
|
|
1021
1378
|
}
|
|
1022
1379
|
}
|
|
1023
1380
|
/** This function escapes the special characters of a regular expression. */
|
|
@@ -1088,13 +1445,21 @@ const releaseFiles = {
|
|
|
1088
1445
|
if (changed.length === 0) return [];
|
|
1089
1446
|
const trailer = typeof options["trailer"] === "string" ? options["trailer"] : "Release-Edit";
|
|
1090
1447
|
const line = new RegExp(`^${escape(trailer)}:[ \\t]*\\S`, "im");
|
|
1448
|
+
const pullRequest = pullRequestOf(context);
|
|
1449
|
+
if (line.test(pullRequest.body)) return [];
|
|
1450
|
+
if (!(pullRequest.commits === 1 && context.git([
|
|
1451
|
+
"rev-parse",
|
|
1452
|
+
"--verify",
|
|
1453
|
+
"--quiet",
|
|
1454
|
+
`${range.ends[1]}^2`
|
|
1455
|
+
]) === void 0) && context.git(["merge-base", ...range.ends]) === void 0) throw new Error(`The checkout does not have the merge base of ${range.ends.join(" and ")}, so the rule cannot read each commit of the change. Use fetch-depth 0, or the CI of the template, which deepens the checkout of a pull request to its merge base.`);
|
|
1091
1456
|
const messages = context.git([
|
|
1092
1457
|
"log",
|
|
1093
1458
|
"--no-merges",
|
|
1094
1459
|
"--format=%B",
|
|
1095
1460
|
...range.log
|
|
1096
1461
|
]) ?? "";
|
|
1097
|
-
if (line.test(messages)
|
|
1462
|
+
if (line.test(messages)) return [];
|
|
1098
1463
|
const authors = new Set(Array.isArray(options["authors"]) ? options["authors"] : []);
|
|
1099
1464
|
const changers = (context.git([
|
|
1100
1465
|
"log",
|
|
@@ -1805,7 +2170,7 @@ if (board) {
|
|
|
1805
2170
|
* The rule `roadmap-parses`: each roadmap that a workflow gives to the Status page parses, on the pull request.
|
|
1806
2171
|
*/
|
|
1807
2172
|
/** A workflow file. */
|
|
1808
|
-
const WORKFLOW
|
|
2173
|
+
const WORKFLOW = /^\.github\/workflows\/[^/]+\.ya?ml$/;
|
|
1809
2174
|
/** This function tells if a line calls the Pages workflow of the template (`uses: ...reusable-pages.yml`). */
|
|
1810
2175
|
function callsPages(line) {
|
|
1811
2176
|
let text = line.trimStart();
|
|
@@ -1814,7 +2179,7 @@ function callsPages(line) {
|
|
|
1814
2179
|
const value = text.slice(5).trim();
|
|
1815
2180
|
return /(?:^|\/)reusable-pages\.ya?ml(?:@|$|\s)/.test(value);
|
|
1816
2181
|
}
|
|
1817
|
-
const indentOf
|
|
2182
|
+
const indentOf = (line) => line.length - line.trimStart().length;
|
|
1818
2183
|
/** This function tells if a line is `site-pages: false`: the site has no Status page. */
|
|
1819
2184
|
function noStatusPage(line) {
|
|
1820
2185
|
const text = line.trimStart();
|
|
@@ -1836,8 +2201,8 @@ function callsWithoutRoadmap(lines) {
|
|
|
1836
2201
|
const found = [];
|
|
1837
2202
|
lines.forEach((line, index) => {
|
|
1838
2203
|
if (!callsPages(line)) return;
|
|
1839
|
-
const indent = indentOf
|
|
1840
|
-
const inJob = (text) => text.trim() === "" || indentOf
|
|
2204
|
+
const indent = indentOf(line);
|
|
2205
|
+
const inJob = (text) => text.trim() === "" || indentOf(text) >= indent;
|
|
1841
2206
|
let first = index;
|
|
1842
2207
|
while (first > 0 && inJob(lines[first - 1] ?? "")) first -= 1;
|
|
1843
2208
|
let last = index;
|
|
@@ -1879,7 +2244,7 @@ const roadmapParses = {
|
|
|
1879
2244
|
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
1880
2245
|
const named = [];
|
|
1881
2246
|
const breaks = [];
|
|
1882
|
-
for (const file of files.filter((path) => WORKFLOW
|
|
2247
|
+
for (const file of files.filter((path) => WORKFLOW.test(path)).sort(byCode)) {
|
|
1883
2248
|
const lines = readFileSync(join(context.root, file), "utf8").split(/\r?\n/);
|
|
1884
2249
|
lines.forEach((line, index) => {
|
|
1885
2250
|
const roadmap = roadmapOfLine(line);
|
|
@@ -1934,40 +2299,6 @@ const roadmapParses = {
|
|
|
1934
2299
|
* The rule `runner-budget`: the workflows share the runners of the account. Each matrix has a `max-parallel`, each
|
|
1935
2300
|
* workflow has a concurrency group, and each schedule starts at the minute of its repository and file.
|
|
1936
2301
|
*/
|
|
1937
|
-
/** A workflow file. */
|
|
1938
|
-
const WORKFLOW = /^\.github\/workflows\/[^/]+\.ya?ml$/;
|
|
1939
|
-
const indentOf = (line) => line.length - line.trimStart().length;
|
|
1940
|
-
/** This function removes a comment at the end of a value, and the quotes around it. */
|
|
1941
|
-
function valueOf$1(raw) {
|
|
1942
|
-
const comment = raw.indexOf(" #");
|
|
1943
|
-
let value = (comment >= 0 ? raw.slice(0, comment) : raw).trim();
|
|
1944
|
-
const quote = value.charAt(0);
|
|
1945
|
-
if (value.length >= 2 && (quote === "\"" || quote === "'") && value.endsWith(quote)) value = value.slice(1, -1).trim();
|
|
1946
|
-
return value;
|
|
1947
|
-
}
|
|
1948
|
-
/** This function gives the value of the key `key` on a line, or undefined when the line has another key. */
|
|
1949
|
-
function keyValue(line, key) {
|
|
1950
|
-
let text = line.trimStart();
|
|
1951
|
-
if (text.startsWith("- ")) text = text.slice(2).trimStart();
|
|
1952
|
-
if (!text.startsWith(`${key}:`)) return void 0;
|
|
1953
|
-
return valueOf$1(text.slice(key.length + 1));
|
|
1954
|
-
}
|
|
1955
|
-
/** This function gives the lines of the block under the line `index`: the next lines with a larger indent. */
|
|
1956
|
-
function blockEnd(lines, index) {
|
|
1957
|
-
const indent = indentOf(lines[index] ?? "");
|
|
1958
|
-
let end = index + 1;
|
|
1959
|
-
while (end < lines.length) {
|
|
1960
|
-
const line = lines[end] ?? "";
|
|
1961
|
-
if (line.trim() !== "" && indentOf(line) <= indent) break;
|
|
1962
|
-
end += 1;
|
|
1963
|
-
}
|
|
1964
|
-
return end;
|
|
1965
|
-
}
|
|
1966
|
-
/** This function gives the indent of the first key of the block under the line `index`, or undefined for an empty block. */
|
|
1967
|
-
function childIndent(lines, index) {
|
|
1968
|
-
const end = blockEnd(lines, index);
|
|
1969
|
-
for (let i = index + 1; i < end; i++) if ((lines[i] ?? "").trim() !== "") return indentOf(lines[i] ?? "");
|
|
1970
|
-
}
|
|
1971
2302
|
/**
|
|
1972
2303
|
* This function gives the minute (1 to 59) of the schedules of a workflow: the FNV-1a hash of the repository and the
|
|
1973
2304
|
* file. Two repositories with the same workflow thus start at different minutes, and no schedule starts at minute 0,
|
|
@@ -2008,16 +2339,16 @@ function isShared(lines) {
|
|
|
2008
2339
|
}
|
|
2009
2340
|
/** This function gives the jobs of a workflow. */
|
|
2010
2341
|
function jobsOf(lines) {
|
|
2011
|
-
const jobs = lines.findIndex((line) => indentOf(line) === 0 && line.startsWith("jobs:"));
|
|
2342
|
+
const jobs = lines.findIndex((line) => indentOf$1(line) === 0 && line.startsWith("jobs:"));
|
|
2012
2343
|
if (jobs < 0) return [];
|
|
2013
2344
|
const jobIndent = childIndent(lines, jobs);
|
|
2014
2345
|
const end = blockEnd(lines, jobs);
|
|
2015
2346
|
const found = [];
|
|
2016
2347
|
for (let i = jobs + 1; i < end; i++) {
|
|
2017
2348
|
const line = lines[i] ?? "";
|
|
2018
|
-
if (line.trim() === "" || indentOf(line) !== jobIndent) continue;
|
|
2349
|
+
if (line.trim() === "" || indentOf$1(line) !== jobIndent) continue;
|
|
2019
2350
|
const keyIndent = childIndent(lines, i);
|
|
2020
|
-
const keys = lines.slice(i + 1, blockEnd(lines, i)).filter((text) => indentOf(text) === keyIndent);
|
|
2351
|
+
const keys = lines.slice(i + 1, blockEnd(lines, i)).filter((text) => indentOf$1(text) === keyIndent);
|
|
2021
2352
|
const uses = keys.map((text) => keyValue(text, "uses")).find((value) => value !== void 0);
|
|
2022
2353
|
const at = uses === void 0 ? -1 : uses.indexOf(".github/workflows/");
|
|
2023
2354
|
const calls = uses === void 0 || at < 0 ? void 0 : uses.slice(at + 18).split("@")[0] ?? "";
|
|
@@ -2030,13 +2361,13 @@ function jobsOf(lines) {
|
|
|
2030
2361
|
}
|
|
2031
2362
|
return found;
|
|
2032
2363
|
}
|
|
2033
|
-
const hasTopGroup = (lines) => lines.some((line) => indentOf(line) === 0 && line.startsWith("concurrency:"));
|
|
2364
|
+
const hasTopGroup = (lines) => lines.some((line) => indentOf$1(line) === 0 && line.startsWith("concurrency:"));
|
|
2034
2365
|
/**
|
|
2035
2366
|
* This function gives the edit that adds a concurrency group at the top of a workflow, before `jobs:`. A new run of a pull
|
|
2036
2367
|
* request stops the old run. A run of another event waits for the old run, so that no release or scheduled run stops.
|
|
2037
2368
|
*/
|
|
2038
2369
|
function groupEdits(file, text, lines) {
|
|
2039
|
-
const jobs = lines.findIndex((line) => indentOf(line) === 0 && line.startsWith("jobs:"));
|
|
2370
|
+
const jobs = lines.findIndex((line) => indentOf$1(line) === 0 && line.startsWith("jobs:"));
|
|
2040
2371
|
if (jobs < 0) return [];
|
|
2041
2372
|
const pad = " ".repeat(childIndent(lines, jobs) ?? 2);
|
|
2042
2373
|
const original = text.split(/\r?\n/)[jobs] ?? "jobs:";
|
|
@@ -2088,7 +2419,7 @@ function matrixBreaks(file, text, lines, limit) {
|
|
|
2088
2419
|
const keyIndent = childIndent(lines, index);
|
|
2089
2420
|
if (keyIndent === void 0) return;
|
|
2090
2421
|
const keys = [];
|
|
2091
|
-
for (let i = index + 1; i < blockEnd(lines, index); i++) if ((lines[i] ?? "").trim() !== "" && indentOf(lines[i] ?? "") === keyIndent) keys.push(i);
|
|
2422
|
+
for (let i = index + 1; i < blockEnd(lines, index); i++) if ((lines[i] ?? "").trim() !== "" && indentOf$1(lines[i] ?? "") === keyIndent) keys.push(i);
|
|
2092
2423
|
if (!keys.some((i) => keyValue(lines[i] ?? "", "matrix") !== void 0)) return;
|
|
2093
2424
|
const at = keys.find((i) => keyValue(lines[i] ?? "", "max-parallel") !== void 0);
|
|
2094
2425
|
const raw = at === void 0 ? void 0 : keyValue(lines[at] ?? "", "max-parallel");
|
|
@@ -2196,7 +2527,7 @@ const runnerBudget = {
|
|
|
2196
2527
|
check(context, options) {
|
|
2197
2528
|
const files = context.gitFiles();
|
|
2198
2529
|
if (files === void 0) return { skipped: "the root is not in a git repository" };
|
|
2199
|
-
const workflows = files.filter((path) => WORKFLOW.test(path)).sort(byCode);
|
|
2530
|
+
const workflows = files.filter((path) => WORKFLOW$1.test(path)).sort(byCode);
|
|
2200
2531
|
if (workflows.length === 0) return { skipped: "the repository has no workflow" };
|
|
2201
2532
|
const remote = context.git([
|
|
2202
2533
|
"remote",
|
|
@@ -2214,7 +2545,7 @@ const runnerBudget = {
|
|
|
2214
2545
|
} catch {
|
|
2215
2546
|
continue;
|
|
2216
2547
|
}
|
|
2217
|
-
const lines = text
|
|
2548
|
+
const lines = workflowLines(text);
|
|
2218
2549
|
breaks.push(...matrixBreaks(file, text, lines, limit), ...concurrencyBreaks(file, text, lines, grouped));
|
|
2219
2550
|
if (options["minute"] !== false) {
|
|
2220
2551
|
if (lines.some((line) => keyValue(line, "cron") !== void 0) && repository === void 0) breaks.push({
|
|
@@ -3152,7 +3483,8 @@ const RULES = [
|
|
|
3152
3483
|
mainCheck,
|
|
3153
3484
|
testsRequired,
|
|
3154
3485
|
roadmapParses,
|
|
3155
|
-
runnerBudget
|
|
3486
|
+
runnerBudget,
|
|
3487
|
+
gateTrigger
|
|
3156
3488
|
];
|
|
3157
3489
|
// src/run.ts
|
|
3158
3490
|
/**
|
|
@@ -3506,6 +3838,6 @@ function runCli(args, io) {
|
|
|
3506
3838
|
if (summary) appendFileSync(summary, summaryMarkdown(result));
|
|
3507
3839
|
return result.failed ? 1 : 0;
|
|
3508
3840
|
}
|
|
3509
|
-
export {
|
|
3841
|
+
export { hasFile as $, roadmapParses as A, REAL_COMPARE as B, isSourcePath as C, runnerBudget as D, repositoryOfRemote as E, pinnedGitDeps as F, gateTrigger as G, mainCheck as H, DEFAULT_ALLOWED as I, STRICT_OPTIONS as J, prPathFilters as K, HOME_PATTERNS as L, releaseFiles as M, isGitSpecifier as N, scheduleMinute as O, isPinned as P, codePackages as Q, noLocalPaths as R, tsconfigTest as S, sourceMain as T, ACTIONS_COMMIT as U, hasImportMetaMain as V, convertGate as W, DEPENDENCY_FIELDS as X, cuePreset as Y, cleanPath as Z, configsOfScript as _, listRules as a, readJsonc as at, testsRequired as b, runCli as c, specifiersOf as ct, RULES as d, packageFolders as dt, inFolder as et, workspaceProtocol as f, workspaceGlobs as ft, typedScripts as g, trustPolicy as h, formatResult as i, parseJsonc as it, requiredScripts as j, roadmapOfLine as k, runFix as l, globFolders as lt, TRAIN_SCOPES as m, parseConfig as mt, annotations as n, lineOf as nt, readConfig as o, replaceLine as ot, IGNORE_AFTER as p, defaultOptions as pt, summaryName as q, createContext as r, matchesAny as rt, runChecks as s, runGit as st, USAGE as t, keyLine as tt, summaryMarkdown as u, globToRegExp as ut, scriptsOf as v, pathsOf as w, hasTests as x, typedFiles as y, noBuildOutput as z };
|
|
3510
3842
|
|
|
3511
|
-
//# sourceMappingURL=run-
|
|
3843
|
+
//# sourceMappingURL=run-Dgb6gjZJ.js.map
|