@antelopejs/tooling-configs 0.5.2 → 0.5.4
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 +6 -4
- package/dist/bin/api-diff.mjs +3 -3
- package/dist/bin/body-check.mjs +1 -1
- package/dist/bin/check-size.mjs +1 -1
- package/dist/bin/checks.mjs +2 -890
- package/dist/bin/comment-proof.mjs +2 -2
- package/dist/bin/garden.mjs +221 -215
- package/dist/bin/lease.mjs +1 -1
- package/dist/bin/ratchet.mjs +3 -3
- package/dist/bin/suppressions.mjs +3 -3
- package/dist/bin/sync.mjs +626 -43
- package/dist/checks-CyMCnYb4.mjs +1506 -0
- package/dist/oxc/lint.mjs +1 -1
- package/dist/{package-DxxcxOzp.mjs → package-CORwvwTw.mjs} +57 -26
- package/dist/{proof-stamp-D9yo2dxU.mjs → proof-stamp-C56iYgHa.mjs} +2 -2
- package/dist/{ratchet--WWa_w2O.mjs → ratchet-Al0XZtOz.mjs} +2 -2
- package/dist/{suppression-base-Drnl6Y7F.mjs → suppression-base-DZgUDXiI.mjs} +2 -2
- package/dist/{suppression-budget-Dvb_IqBo.mjs → suppression-budget-DgYdu6JK.mjs} +1 -1
- package/dist/{suppressions-BroaaGJ_.mjs → suppressions-CQTcKCi1.mjs} +1 -1
- package/dist/{templates-BiXgdsRN.mjs → templates-DaatyItc.mjs} +1 -1
- package/dist/{typescript-D7SaSmsl.mjs → typescript-Cw1JH8mk.mjs} +1 -1
- package/dist/{workflow-B0FmthGv.mjs → workflow-CPcNc8KL.mjs} +5 -2
- package/package.json +1 -1
- package/dist/script-steps-CgH2DSsp.mjs +0 -594
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
3
3
|
import { c as repositoryRoot } from "../files-DJ0TeaTU.mjs";
|
|
4
|
-
import { c as revisionCounts, i as stampProof, o as compareRevisions } from "../proof-stamp-
|
|
5
|
-
import { a as listsNoFiles, c as packagesAt, n as extendedConfigs, t as emitPackage } from "../typescript-
|
|
4
|
+
import { c as revisionCounts, i as stampProof, o as compareRevisions } from "../proof-stamp-C56iYgHa.mjs";
|
|
5
|
+
import { a as listsNoFiles, c as packagesAt, n as extendedConfigs, t as emitPackage } from "../typescript-Cw1JH8mk.mjs";
|
|
6
6
|
import { copyFileSync, existsSync, mkdirSync } from "node:fs";
|
|
7
7
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
8
8
|
//#region src/guardrails/comment-proof.ts
|
package/dist/bin/garden.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { t as admits } from "../semver-BDxeEcP_.mjs";
|
|
3
3
|
import { c as object, d as optTime, f as parseJson, h as time, i as isObject, l as optNum, m as strings, n as children, o as list, p as str, r as flag, s as num, t as child, u as optStr } from "../json-CG2L7YFl.mjs";
|
|
4
4
|
import { n as runCliAsync } from "../cli-4Tv71vYk.mjs";
|
|
5
|
-
import { a as RENOVATE_CONFIGS, c as CI_CONTEXT, d as CI_RENOVATE_SYNC_REF, l as CI_NODE_REF, n as ciNodeCallers, o as RENOVATE_PRESET, r as ciRenovateSyncCallers, u as CI_PATH } from "../workflow-
|
|
5
|
+
import { a as RENOVATE_CONFIGS, c as CI_CONTEXT, d as CI_RENOVATE_SYNC_REF, l as CI_NODE_REF, n as ciNodeCallers, o as RENOVATE_PRESET, r as ciRenovateSyncCallers, u as CI_PATH } from "../workflow-CPcNc8KL.mjs";
|
|
6
6
|
import { i as ghToken, n as createApi, t as ApiError } from "../api-CCOiLN3w.mjs";
|
|
7
7
|
import { parseArgs } from "node:util";
|
|
8
8
|
import { inflateRawSync } from "node:zlib";
|
|
@@ -105,6 +105,10 @@ function artifacts(value) {
|
|
|
105
105
|
function logins(value) {
|
|
106
106
|
return list(value, "members").map((entry) => str(object(entry, "member"), "login"));
|
|
107
107
|
}
|
|
108
|
+
/** The logins of a collaborator list whose role on the repository is `admin`; `maintain` is not. */
|
|
109
|
+
function adminLogins(value) {
|
|
110
|
+
return list(value, "collaborators").map((entry) => object(entry, "collaborator")).filter((entry) => str(entry, "role_name") === "admin").map((entry) => str(entry, "login"));
|
|
111
|
+
}
|
|
108
112
|
//#endregion
|
|
109
113
|
//#region src/garden/context.ts
|
|
110
114
|
const ORG = "AntelopeJS";
|
|
@@ -180,7 +184,6 @@ var GardenContext = class {
|
|
|
180
184
|
checks = new Memo();
|
|
181
185
|
pulls = new Memo();
|
|
182
186
|
alertLists = new Memo();
|
|
183
|
-
variables = new Memo();
|
|
184
187
|
packuments = new Memo();
|
|
185
188
|
removals = new Memo();
|
|
186
189
|
searches = new Memo();
|
|
@@ -325,18 +328,6 @@ var GardenContext = class {
|
|
|
325
328
|
throw error;
|
|
326
329
|
}
|
|
327
330
|
}
|
|
328
|
-
/** A repository Actions variable, or undefined when it does not exist. */
|
|
329
|
-
variable(repo, name) {
|
|
330
|
-
return this.variables.get(`${repo.name}:${name}`, async () => {
|
|
331
|
-
try {
|
|
332
|
-
const body = await this.api.json(`/repos/${ORG}/${repo.name}/actions/variables/${name}`);
|
|
333
|
-
return str(object(body, "variable"), "value");
|
|
334
|
-
} catch (error) {
|
|
335
|
-
if (error instanceof Error && isMissing(error)) return void 0;
|
|
336
|
-
throw error;
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
331
|
/** Whether a commit of the default branch history removed the file; looks at the 30 newest commits that touched it. */
|
|
341
332
|
removedInHistory(repo, path) {
|
|
342
333
|
return this.removals.get(`${repo.name}:${path}`, async () => {
|
|
@@ -364,6 +355,10 @@ var GardenContext = class {
|
|
|
364
355
|
organizationOwners() {
|
|
365
356
|
return this.api.pages(`/orgs/${ORG}/members?role=admin`).then(logins);
|
|
366
357
|
}
|
|
358
|
+
/** Logins holding the admin role on the repository, however they hold it: directly, through a team or as an organization owner. */
|
|
359
|
+
repoAdmins(repo) {
|
|
360
|
+
return this.api.pages(`/repos/${ORG}/${repo.name}/collaborators?affiliation=all`).then(adminLogins);
|
|
361
|
+
}
|
|
367
362
|
};
|
|
368
363
|
//#endregion
|
|
369
364
|
//#region src/garden/types.ts
|
|
@@ -525,19 +520,26 @@ var PartialFailure = class extends Error {
|
|
|
525
520
|
}
|
|
526
521
|
};
|
|
527
522
|
const CONCURRENCY = 6;
|
|
523
|
+
/** Runs a scan on each repository, in repository order; a failing repository is listed once in `failures`, not allowed to hide the rest. */
|
|
524
|
+
async function scanEach(repos, scan) {
|
|
525
|
+
const failures = [];
|
|
526
|
+
return {
|
|
527
|
+
results: (await mapLimit(repos, CONCURRENCY, async (repo) => {
|
|
528
|
+
try {
|
|
529
|
+
return await scan(repo);
|
|
530
|
+
} catch (error) {
|
|
531
|
+
failures.push(`${repo.name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
532
|
+
return [];
|
|
533
|
+
}
|
|
534
|
+
})).flat(),
|
|
535
|
+
failures: failures.sort()
|
|
536
|
+
};
|
|
537
|
+
}
|
|
528
538
|
/** Runs a scan on each repository; a failing repository is reported once, not allowed to hide the rest. */
|
|
529
539
|
async function perRepo(repos, scan) {
|
|
530
|
-
const failures =
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
return await scan(repo);
|
|
534
|
-
} catch (error) {
|
|
535
|
-
failures.push(`${repo.name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
536
|
-
return [];
|
|
537
|
-
}
|
|
538
|
-
})).flat();
|
|
539
|
-
if (failures.length) throw new PartialFailure(findings, failures.sort());
|
|
540
|
-
return found(findings);
|
|
540
|
+
const { results, failures } = await scanEach(repos, scan);
|
|
541
|
+
if (failures.length) throw new PartialFailure(results, failures);
|
|
542
|
+
return found(results);
|
|
541
543
|
}
|
|
542
544
|
//#endregion
|
|
543
545
|
//#region src/garden/checks/ci-health.ts
|
|
@@ -658,7 +660,7 @@ const ciDuration = {
|
|
|
658
660
|
};
|
|
659
661
|
//#endregion
|
|
660
662
|
//#region src/garden/checks/branches.ts
|
|
661
|
-
const CHECK$
|
|
663
|
+
const CHECK$1 = "stale-branches";
|
|
662
664
|
const SUBJECT = "branches";
|
|
663
665
|
const DAY$3 = 864e5;
|
|
664
666
|
const INACTIVE_DAYS = 30;
|
|
@@ -711,13 +713,13 @@ function report(repo, prunes) {
|
|
|
711
713
|
if (!prunes.length) return [];
|
|
712
714
|
return [finding({
|
|
713
715
|
repo: repo.name,
|
|
714
|
-
check: CHECK$
|
|
716
|
+
check: CHECK$1,
|
|
715
717
|
subject: SUBJECT
|
|
716
718
|
}, prunes.map(({ branch, reason }) => `${branch} (${reason})`).join(", "), `No branch other than the default, next and protected ones is the head of a merged or closed PR, or has no open PR and no commit for ${INACTIVE_DAYS} days.`)];
|
|
717
719
|
}
|
|
718
720
|
/** Lists, per repository, the branches `--apply-prunes` would delete. */
|
|
719
721
|
const staleBranches = {
|
|
720
|
-
id: CHECK$
|
|
722
|
+
id: CHECK$1,
|
|
721
723
|
async run(context) {
|
|
722
724
|
return perRepo(await context.scope(), async (repo) => report(repo, await prunable(context, repo)));
|
|
723
725
|
}
|
|
@@ -725,7 +727,7 @@ const staleBranches = {
|
|
|
725
727
|
/** The deletions behind each stale-branches finding, re-read from the API given so a branch that gained an open PR or a commit since the scan is kept; a repository whose read failed is never pruned. */
|
|
726
728
|
async function plannedPrunes(api, findings) {
|
|
727
729
|
const fresh = new GardenContext(api);
|
|
728
|
-
const flagged = new Set(findings.filter((entry) => entry.check === CHECK$
|
|
730
|
+
const flagged = new Set(findings.filter((entry) => entry.check === CHECK$1).map((entry) => entry.repo));
|
|
729
731
|
const prunes = [];
|
|
730
732
|
const failed = [];
|
|
731
733
|
const scope = await fresh.scope().catch((error) => {
|
|
@@ -767,7 +769,7 @@ async function tooling(context) {
|
|
|
767
769
|
}
|
|
768
770
|
//#endregion
|
|
769
771
|
//#region src/garden/checks/conformance.ts
|
|
770
|
-
const CHECK
|
|
772
|
+
const CHECK = "conformance";
|
|
771
773
|
const DAY$2 = 864e5;
|
|
772
774
|
const MEND_EXEMPT = /* @__PURE__ */ new Set(["k8s-gitops-infra"]);
|
|
773
775
|
/** Repositories whose ci.yml runs its own jobs: tooling-configs shards its tests and checks its docs action at HEAD, which ci-node.yml cannot do. */
|
|
@@ -775,7 +777,7 @@ const CI_CALLER_EXEMPT = /* @__PURE__ */ new Set(["tooling-configs"]);
|
|
|
775
777
|
function problem(repo, subject, evidence, doneMeans) {
|
|
776
778
|
return finding({
|
|
777
779
|
repo: repo.name,
|
|
778
|
-
check: CHECK
|
|
780
|
+
check: CHECK,
|
|
779
781
|
subject
|
|
780
782
|
}, evidence, doneMeans);
|
|
781
783
|
}
|
|
@@ -843,7 +845,7 @@ const deleteBranchOnMerge = {
|
|
|
843
845
|
/** Turns `delete_branch_on_merge` on for each repository a finding reports it off on, and writes nothing else; returns the writes that failed. */
|
|
844
846
|
async function applySettings(api, findings) {
|
|
845
847
|
const failed = [];
|
|
846
|
-
for (const entry of findings) if (entry.check === CHECK
|
|
848
|
+
for (const entry of findings) if (entry.check === CHECK && entry.subject === BRANCH_CLEANUP) await api.send("PATCH", `/repos/${ORG}/${entry.repo}`, { delete_branch_on_merge: true }).catch((error) => {
|
|
847
849
|
failed.push(`${entry.repo}: ${error instanceof Error ? error.message : String(error)}`);
|
|
848
850
|
});
|
|
849
851
|
return failed;
|
|
@@ -865,7 +867,7 @@ async function mendSelection(context) {
|
|
|
865
867
|
return (await context.repos()).filter((repo) => repo.tier !== "N4" && !MEND_EXEMPT.has(repo.name) && !active.has(repo.name)).map((repo) => problem(repo, "renovate-app", "No issue or pull request from the Renovate app: the repository is not in the app's selection.", "Antony adds the repository to the Mend Renovate app's selected repositories."));
|
|
866
868
|
}
|
|
867
869
|
const conformance = {
|
|
868
|
-
id: CHECK
|
|
870
|
+
id: CHECK,
|
|
869
871
|
async run(context) {
|
|
870
872
|
const scanned = await perRepo(await context.scope(), (repo) => scan(context, repo));
|
|
871
873
|
const extra = [...await newRepos(context), ...await mendSelection(context)];
|
|
@@ -874,134 +876,196 @@ const conformance = {
|
|
|
874
876
|
};
|
|
875
877
|
//#endregion
|
|
876
878
|
//#region src/garden/checks/governance.ts
|
|
877
|
-
const
|
|
879
|
+
const ALLOWED_OWNERS = [
|
|
878
880
|
"Upd4ting",
|
|
879
881
|
"mwesto",
|
|
880
882
|
"dada-sudo"
|
|
881
883
|
];
|
|
882
|
-
const
|
|
883
|
-
|
|
884
|
+
const ALLOWED_REPO_ADMINS = [
|
|
885
|
+
"Upd4ting",
|
|
886
|
+
"mwesto",
|
|
887
|
+
"dada-sudo",
|
|
888
|
+
"Thomasims",
|
|
889
|
+
"alessaloisio"
|
|
890
|
+
];
|
|
884
891
|
const ACTIONS_APP = 15368;
|
|
885
892
|
const ADMIN_ROLE = 5;
|
|
886
|
-
const
|
|
887
|
-
const
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
893
|
+
const DEFAULT_BRANCH_REF = "~DEFAULT_BRANCH";
|
|
894
|
+
const REQUIRED_RULES = [
|
|
895
|
+
"deletion",
|
|
896
|
+
"non_fast_forward",
|
|
897
|
+
"required_linear_history",
|
|
898
|
+
"pull_request"
|
|
899
|
+
];
|
|
900
|
+
/** Repositories the organization ruleset excludes because their own ruleset governs them, with the required rules that ruleset does not hold. */
|
|
901
|
+
const OWN_POLICY = /* @__PURE__ */ new Map([["k8s-gitops-infra", ["required_linear_history"]]]);
|
|
902
|
+
/** The packs that Required CI covers. */
|
|
903
|
+
const CI_PACKS = ["full", "template"];
|
|
904
|
+
function requiresCi(rules) {
|
|
905
|
+
return rules.some((rule) => optStr(rule, "type") === "required_status_checks" && children(child(rule, "parameters"), "required_status_checks").some((entry) => optStr(entry, "context") === CI_CONTEXT && optNum(entry, "integration_id") === ACTIONS_APP));
|
|
906
|
+
}
|
|
907
|
+
const REQUIREMENTS = [...REQUIRED_RULES.map((type) => ({
|
|
908
|
+
subject: `rule:${type}`,
|
|
909
|
+
severity: "urgent",
|
|
910
|
+
need: `a ${type} rule`,
|
|
911
|
+
applies: (repo) => !OWN_POLICY.get(repo.name)?.includes(type),
|
|
912
|
+
met: (rules) => rules.some((rule) => optStr(rule, "type") === type)
|
|
913
|
+
})), {
|
|
914
|
+
subject: "checks",
|
|
915
|
+
severity: "normal",
|
|
916
|
+
need: `${CI_CONTEXT} from GitHub Actions as a required status check`,
|
|
917
|
+
applies: (repo) => CI_PACKS.some((pack) => pack === repo.pack),
|
|
918
|
+
met: requiresCi
|
|
919
|
+
}];
|
|
920
|
+
/** Actors that may bypass a default branch ruleset, in any bypass mode: the release workflow pushes with an administrator's token. */
|
|
921
|
+
const ALLOWED_BYPASS = [{
|
|
922
|
+
type: "RepositoryRole",
|
|
923
|
+
id: ADMIN_ROLE
|
|
924
|
+
}, { type: "OrganizationAdmin" }];
|
|
925
|
+
function mayBypass(actor) {
|
|
926
|
+
const type = optStr(actor, "actor_type");
|
|
927
|
+
const id = optNum(actor, "actor_id");
|
|
928
|
+
return ALLOWED_BYPASS.some((allowed) => allowed.type === type && (allowed.id === void 0 || allowed.id === id));
|
|
929
|
+
}
|
|
930
|
+
function describeActor(actor) {
|
|
931
|
+
return `${optStr(actor, "actor_type") ?? "unknown"} ${optNum(actor, "actor_id") ?? "none"} (${optStr(actor, "bypass_mode") ?? "unknown"})`;
|
|
932
|
+
}
|
|
933
|
+
function rulesetPath(repo, rule) {
|
|
934
|
+
const id = num(rule, "ruleset_id");
|
|
935
|
+
return optStr(rule, "ruleset_source_type") === "Organization" ? `/orgs/${ORG}/rulesets/${id}` : `/repos/${ORG}/${repo.name}/rulesets/${id}`;
|
|
936
|
+
}
|
|
937
|
+
function rulesetLabel(path, name) {
|
|
938
|
+
return `${name} (${path.startsWith("/orgs/") ? "organization" : "repository"} ruleset ${path.slice(path.lastIndexOf("/") + 1)})`;
|
|
939
|
+
}
|
|
940
|
+
function rulesetReader(context) {
|
|
941
|
+
const cache = new Memo();
|
|
942
|
+
return (path) => cache.get(path, async () => object(await context.api.json(path), "ruleset"));
|
|
943
|
+
}
|
|
944
|
+
async function bypassOffenders(read, paths) {
|
|
945
|
+
const offenders = [];
|
|
946
|
+
for (const path of paths) {
|
|
947
|
+
const set = await read(path);
|
|
948
|
+
const listed = set["bypass_actors"];
|
|
949
|
+
if (listed === void 0) throw new Error(`${rulesetLabel(path, str(set, "name"))} returned no bypass list; the Gardener token must belong to an administrator.`);
|
|
950
|
+
const actors = list(listed, "bypass_actors").map((actor) => object(actor, "bypass_actors")).filter((actor) => !mayBypass(actor));
|
|
951
|
+
if (actors.length) offenders.push(`${rulesetLabel(path, str(set, "name"))}: ${actors.map(describeActor).join(", ")}`);
|
|
906
952
|
}
|
|
907
|
-
return
|
|
908
|
-
}
|
|
909
|
-
function bypassWidened(set) {
|
|
910
|
-
return set.bypass.some((actor) => {
|
|
911
|
-
const kind = optStr(actor, "actor_type");
|
|
912
|
-
return !(kind === "OrganizationAdmin" || kind === "RepositoryRole" && optNum(actor, "actor_id") === ADMIN_ROLE) || optStr(actor, "bypass_mode") !== "pull_request";
|
|
913
|
-
});
|
|
953
|
+
return offenders;
|
|
914
954
|
}
|
|
915
|
-
function
|
|
916
|
-
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
return sets.flatMap((set) => set.rules.filter((rule) => optStr(rule, "type") === "pull_request").map((rule) => child(rule, "parameters")));
|
|
920
|
-
}
|
|
921
|
-
function branchFindings(repo, branch, sets) {
|
|
922
|
-
const hit = sets.filter((set) => branchTargets(set, branch));
|
|
923
|
-
const findings = [];
|
|
924
|
-
const report = (subject, evidence, urgent) => findings.push(finding({
|
|
955
|
+
async function scanBranch(context, read, repo) {
|
|
956
|
+
const branch = repo.defaultBranch;
|
|
957
|
+
const rules = (await context.api.pages(`/repos/${ORG}/${repo.name}/rules/branches/${encodeURIComponent(branch)}`)).map((entry) => object(entry, "rule"));
|
|
958
|
+
const report = (subject, evidence, doneMeans, severity) => finding({
|
|
925
959
|
repo: repo.name,
|
|
926
|
-
check:
|
|
960
|
+
check: "branch-governance",
|
|
927
961
|
subject: `${branch}:${subject}`
|
|
928
|
-
}, evidence,
|
|
929
|
-
const
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
if (reviews.some((rule) => (optNum(rule, "required_approving_review_count") ?? 0) > 0 || flag(rule, "require_code_owner_review") || flag(rule, "require_last_push_approval"))) report("review-rule", `A ruleset on ${branch} requires a review.`, true);
|
|
933
|
-
if (!reviews.length || !reviews.every((rule) => strings(rule, "allowed_merge_methods").join() === "squash")) report("squash-only", `${branch} does not allow squash merges only.`, false);
|
|
934
|
-
if (hit.some(bypassWidened)) report("bypass", `The bypass list of ${hit.filter(bypassWidened).map((set) => set.name).join(", ")} holds more than the pull-request-only administrators.`, true);
|
|
935
|
-
return findings;
|
|
936
|
-
}
|
|
937
|
-
async function people(context, repo) {
|
|
938
|
-
const members = await context.api.pages(`/repos/${ORG}/${repo.name}/collaborators?affiliation=all`);
|
|
939
|
-
const findings = [];
|
|
940
|
-
for (const member of members.map((entry) => object(entry, "collaborator"))) {
|
|
941
|
-
const login = str(member, "login");
|
|
942
|
-
const role = optStr(member, "role_name");
|
|
943
|
-
if (role === "admin" && !ALLOWED_ADMINS.includes(login)) findings.push(finding({
|
|
944
|
-
repo: repo.name,
|
|
945
|
-
check: CHECK,
|
|
946
|
-
subject: `admin:${login}`
|
|
947
|
-
}, `${login} holds admin.`, `${login} holds write or lower.`));
|
|
948
|
-
if (login === MAINTAIN_BLOCKED && (role === "maintain" || role === "admin")) findings.push(finding({
|
|
949
|
-
repo: repo.name,
|
|
950
|
-
check: CHECK,
|
|
951
|
-
subject: `maintain:${login}`
|
|
952
|
-
}, `${login} holds ${role}.`, `${login} holds no maintain.`));
|
|
953
|
-
}
|
|
954
|
-
return findings;
|
|
955
|
-
}
|
|
956
|
-
async function scope(context, repo, value) {
|
|
957
|
-
if (value !== "on") return [];
|
|
958
|
-
const skill = (await context.tree(repo)).some((path) => VERIFICATION_SKILL.test(path));
|
|
959
|
-
return repo.tier === "N1" || repo.tier === "N2" ? skill ? [] : [finding({
|
|
960
|
-
repo: repo.name,
|
|
961
|
-
check: CHECK,
|
|
962
|
-
subject: "automerge-scope"
|
|
963
|
-
}, `${AUTOMERGE}=on without a Verification skill on ${repo.defaultBranch}.`, `${AUTOMERGE} is shadow or off, or the repository has a Verification skill.`)] : [finding({
|
|
964
|
-
repo: repo.name,
|
|
965
|
-
check: CHECK,
|
|
966
|
-
subject: "automerge-scope"
|
|
967
|
-
}, `${AUTOMERGE}=on on a ${repo.tier ?? "untiered"} repository.`, `${AUTOMERGE} is on only in N1 and N2.`)];
|
|
968
|
-
}
|
|
969
|
-
async function governed(context, repo, value) {
|
|
970
|
-
const sets = await rulesets(context, repo);
|
|
971
|
-
return [
|
|
972
|
-
...(await context.targetBranch(repo) === "next" ? ["next", repo.defaultBranch] : [repo.defaultBranch]).flatMap((branch) => branchFindings(repo, branch, sets)),
|
|
973
|
-
...await people(context, repo),
|
|
974
|
-
...await scope(context, repo, value)
|
|
975
|
-
];
|
|
962
|
+
}, evidence, doneMeans, severity);
|
|
963
|
+
const unmet = REQUIREMENTS.filter((entry) => entry.applies(repo) && !entry.met(rules)).map((entry) => report(entry.subject, `The rules in force on ${branch} hold no ${entry.need}.`, `The rules in force on ${branch} hold ${entry.need}.`, entry.severity));
|
|
964
|
+
const offenders = await bypassOffenders(read, [...new Set(rules.map((rule) => rulesetPath(repo, rule)))]);
|
|
965
|
+
return offenders.length ? [...unmet, report("bypass", `Rulesets on ${branch} let actors other than administrators bypass them: ${offenders.join("; ")}.`, `Only the admin role and organization administrators can bypass the rulesets on ${branch}.`, "urgent")] : unmet;
|
|
976
966
|
}
|
|
977
|
-
const
|
|
978
|
-
id:
|
|
967
|
+
const branchGovernance = {
|
|
968
|
+
id: "branch-governance",
|
|
979
969
|
async run(context) {
|
|
980
|
-
const
|
|
981
|
-
|
|
982
|
-
await perRepo(repos, async (repo) => {
|
|
983
|
-
const value = await context.variable(repo, AUTOMERGE);
|
|
984
|
-
if (value !== void 0) values.set(repo.name, value);
|
|
985
|
-
return [];
|
|
986
|
-
});
|
|
987
|
-
if (!values.size) return skip(`${AUTOMERGE} exists on no repository yet.`);
|
|
988
|
-
return perRepo(repos.filter((repo) => values.has(repo.name)), (repo) => governed(context, repo, values.get(repo.name) ?? ""));
|
|
970
|
+
const read = rulesetReader(context);
|
|
971
|
+
return perRepo(await context.repos(), (repo) => scanBranch(context, read, repo));
|
|
989
972
|
}
|
|
990
973
|
};
|
|
991
974
|
const governanceDrift = {
|
|
992
975
|
id: "governance-drift",
|
|
993
976
|
async run(context) {
|
|
994
|
-
return found((await context.organizationOwners()).filter((login) => !
|
|
977
|
+
return found((await context.organizationOwners()).filter((login) => !ALLOWED_OWNERS.includes(login)).map((login) => finding({
|
|
995
978
|
repo: ORG,
|
|
996
979
|
check: "governance-drift",
|
|
997
980
|
subject: `org-admin:${login}`
|
|
998
981
|
}, `${login} is an organization owner.`, `${login} is a member, or the allowed administrators change.`)));
|
|
999
982
|
}
|
|
1000
983
|
};
|
|
984
|
+
/** One finding per login that holds `admin` on a repository and is not an allowed repo administrator, listing the repositories; `maintain` has no bypass and is not read. */
|
|
985
|
+
const repoAdmins = {
|
|
986
|
+
id: "repo-admins",
|
|
987
|
+
async run(context) {
|
|
988
|
+
const { results, failures } = await scanEach(await context.repos(), async (repo) => (await context.repoAdmins(repo)).filter((login) => !ALLOWED_REPO_ADMINS.includes(login)).map((login) => ({
|
|
989
|
+
login,
|
|
990
|
+
repo: repo.name
|
|
991
|
+
})));
|
|
992
|
+
const held = /* @__PURE__ */ new Map();
|
|
993
|
+
for (const { login, repo } of results) held.set(login, [...held.get(login) ?? [], repo]);
|
|
994
|
+
const findings = [...held].map(([login, repos]) => finding({
|
|
995
|
+
repo: ORG,
|
|
996
|
+
check: "repo-admins",
|
|
997
|
+
subject: `repo-admin:${login}`
|
|
998
|
+
}, `${login} holds admin on ${repos.length} ${repos.length === 1 ? "repository" : "repositories"}: ${repos.join(", ")}.`, `${login} holds no admin role on those repositories, or the allowed repository administrators change.`));
|
|
999
|
+
if (failures.length) throw new PartialFailure(findings, failures);
|
|
1000
|
+
return found(findings);
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
const ACTIVE = {
|
|
1004
|
+
what: "enforcement active",
|
|
1005
|
+
holds: (set) => optStr(set, "enforcement") === "active"
|
|
1006
|
+
};
|
|
1007
|
+
const ON_BRANCHES = {
|
|
1008
|
+
what: "target branch",
|
|
1009
|
+
holds: (set) => optStr(set, "target") === "branch"
|
|
1010
|
+
};
|
|
1011
|
+
function condition(set, name, key) {
|
|
1012
|
+
return strings(child(child(set, "conditions"), name), key);
|
|
1013
|
+
}
|
|
1014
|
+
function sameNames(actual, wanted) {
|
|
1015
|
+
return [...actual].sort().join() === [...wanted].sort().join();
|
|
1016
|
+
}
|
|
1017
|
+
const ON_DEFAULT_BRANCH = {
|
|
1018
|
+
what: `ref ${DEFAULT_BRANCH_REF} with no ref excluded`,
|
|
1019
|
+
holds: (set) => condition(set, "ref_name", "include").some((ref) => ref === DEFAULT_BRANCH_REF || ref === "~ALL") && !condition(set, "ref_name", "exclude").length
|
|
1020
|
+
};
|
|
1021
|
+
const ORG_RULESETS = [{
|
|
1022
|
+
name: "Default branch protection",
|
|
1023
|
+
expects: [
|
|
1024
|
+
ACTIVE,
|
|
1025
|
+
ON_BRANCHES,
|
|
1026
|
+
ON_DEFAULT_BRANCH,
|
|
1027
|
+
{
|
|
1028
|
+
what: `repository_name include ~ALL, exclude only ${[...OWN_POLICY.keys()].join(", ")}`,
|
|
1029
|
+
holds: (set) => condition(set, "repository_name", "include").includes("~ALL") && sameNames(condition(set, "repository_name", "exclude"), [...OWN_POLICY.keys()])
|
|
1030
|
+
}
|
|
1031
|
+
]
|
|
1032
|
+
}, {
|
|
1033
|
+
name: "Required CI",
|
|
1034
|
+
expects: [
|
|
1035
|
+
ACTIVE,
|
|
1036
|
+
ON_BRANCHES,
|
|
1037
|
+
ON_DEFAULT_BRANCH,
|
|
1038
|
+
{
|
|
1039
|
+
what: "repository property pack in full and template",
|
|
1040
|
+
holds: (set) => children(child(child(set, "conditions"), "repository_property"), "include").some((entry) => optStr(entry, "name") === "pack" && CI_PACKS.every((value) => strings(entry, "property_values").includes(value)))
|
|
1041
|
+
},
|
|
1042
|
+
{
|
|
1043
|
+
what: `required status check ${CI_CONTEXT} from integration ${ACTIONS_APP}`,
|
|
1044
|
+
holds: (set) => requiresCi(children(set, "rules"))
|
|
1045
|
+
}
|
|
1046
|
+
]
|
|
1047
|
+
}];
|
|
1048
|
+
async function orgDrift(context, summaries, policy) {
|
|
1049
|
+
const make = (evidence) => finding({
|
|
1050
|
+
repo: ORG,
|
|
1051
|
+
check: "org-checks-ruleset",
|
|
1052
|
+
subject: `ruleset:${policy.name}`
|
|
1053
|
+
}, evidence, `The organization ruleset "${policy.name}" is back to its policy.`, "urgent");
|
|
1054
|
+
const named = summaries.filter((entry) => optStr(entry, "name") === policy.name);
|
|
1055
|
+
const [summary] = named;
|
|
1056
|
+
if (summary === void 0) return [make(`The organization has no ruleset named "${policy.name}".`)];
|
|
1057
|
+
if (named.length > 1) return [make(`${named.length} organization rulesets are named "${policy.name}": ${named.map((entry) => num(entry, "id")).join(", ")}.`)];
|
|
1058
|
+
const detail = object(await context.api.json(`/orgs/${ORG}/rulesets/${num(summary, "id")}`), "ruleset");
|
|
1059
|
+
const unmet = policy.expects.filter((entry) => !entry.holds(detail));
|
|
1060
|
+
return unmet.length ? [make(`"${policy.name}" lacks: ${unmet.map((entry) => entry.what).join(", ")}.`)] : [];
|
|
1061
|
+
}
|
|
1001
1062
|
const orgChecksRuleset = {
|
|
1002
1063
|
id: "org-checks-ruleset",
|
|
1003
|
-
async run() {
|
|
1004
|
-
|
|
1064
|
+
async run(context) {
|
|
1065
|
+
const summaries = (await context.api.pages(`/orgs/${ORG}/rulesets`)).map((entry) => object(entry, "ruleset"));
|
|
1066
|
+
const findings = [];
|
|
1067
|
+
for (const policy of ORG_RULESETS) findings.push(...await orgDrift(context, summaries, policy));
|
|
1068
|
+
return found(findings);
|
|
1005
1069
|
}
|
|
1006
1070
|
};
|
|
1007
1071
|
//#endregion
|
|
@@ -1259,68 +1323,6 @@ const staleRegistry = {
|
|
|
1259
1323
|
}
|
|
1260
1324
|
};
|
|
1261
1325
|
const CANARY = "template-canary.yml";
|
|
1262
|
-
const templateCanary = {
|
|
1263
|
-
id: "template-canary",
|
|
1264
|
-
async run(context) {
|
|
1265
|
-
let wired = 0;
|
|
1266
|
-
const result = await perRepo(await templates(context), async (repo) => {
|
|
1267
|
-
const runs = await context.workflowRuns(repo, CANARY, repo.defaultBranch, "");
|
|
1268
|
-
if (runs === void 0) return [];
|
|
1269
|
-
wired++;
|
|
1270
|
-
const latest = runs[0];
|
|
1271
|
-
return latest?.conclusion === "failure" ? [finding({
|
|
1272
|
-
repo: repo.name,
|
|
1273
|
-
check: "template-canary",
|
|
1274
|
-
subject: "canary"
|
|
1275
|
-
}, `The latest ${CANARY} run is red: ${latest.url}`, `${CANARY} is green with every @antelopejs/* dependency on next.`)] : [];
|
|
1276
|
-
});
|
|
1277
|
-
return wired ? result : skip(`no template runs ${CANARY} yet`);
|
|
1278
|
-
}
|
|
1279
|
-
};
|
|
1280
|
-
//#endregion
|
|
1281
|
-
//#region src/garden/pauses.ts
|
|
1282
|
-
const PAUSED = "shadow";
|
|
1283
|
-
function reasons(repo, findings) {
|
|
1284
|
-
const own = findings.filter((entry) => entry.repo === repo);
|
|
1285
|
-
return [...own.some((entry) => entry.check === "conformance" && entry.subject === "ratchet") ? ["the ratchet file is back on a Clean repository"] : [], ...own.some((entry) => entry.check === "next-governance") ? ["governance drift"] : []];
|
|
1286
|
-
}
|
|
1287
|
-
async function pauseFor(context, repo, findings) {
|
|
1288
|
-
if (await context.variable(repo, "NEXT_AUTOMERGE") !== "on") return [];
|
|
1289
|
-
const triggers = reasons(repo.name, findings);
|
|
1290
|
-
const runs = await context.targetBranch(repo) === "next" ? await context.workflowRuns(repo, "ci.yml", "next") : void 0;
|
|
1291
|
-
if (runs !== void 0 && redSince(runs) !== void 0) triggers.unshift("checks is red on next after a merge");
|
|
1292
|
-
return triggers.length ? [{
|
|
1293
|
-
repo: repo.name,
|
|
1294
|
-
from: "on",
|
|
1295
|
-
to: PAUSED,
|
|
1296
|
-
reason: triggers.join("; ")
|
|
1297
|
-
}] : [];
|
|
1298
|
-
}
|
|
1299
|
-
/** Repositories where `NEXT_AUTOMERGE` is `on` and a stop-the-line trigger fired; a repository whose read failed is returned in `failed`, not paused. */
|
|
1300
|
-
async function plannedPauses(context, findings) {
|
|
1301
|
-
const pauses = [];
|
|
1302
|
-
const failed = [];
|
|
1303
|
-
const scope = await context.scope().catch((error) => {
|
|
1304
|
-
failed.push(`organization listing: ${error instanceof Error ? error.message : String(error)}`);
|
|
1305
|
-
return [];
|
|
1306
|
-
});
|
|
1307
|
-
for (const repo of scope) await pauseFor(context, repo, findings).then((found) => pauses.push(...found), (error) => failed.push(`${repo.name}: ${error instanceof Error ? error.message : String(error)}`));
|
|
1308
|
-
return {
|
|
1309
|
-
pauses,
|
|
1310
|
-
failed
|
|
1311
|
-
};
|
|
1312
|
-
}
|
|
1313
|
-
/** Writes the one repository variable and nothing else; a refused write does not stop the rest and is returned. */
|
|
1314
|
-
async function applyPauses(api, pauses) {
|
|
1315
|
-
const failed = [];
|
|
1316
|
-
for (const pause of pauses) await api.send("PATCH", `/repos/${ORG}/${pause.repo}/actions/variables/${AUTOMERGE}`, {
|
|
1317
|
-
name: AUTOMERGE,
|
|
1318
|
-
value: pause.to
|
|
1319
|
-
}).catch((error) => {
|
|
1320
|
-
failed.push(`${pause.repo}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1321
|
-
});
|
|
1322
|
-
return failed;
|
|
1323
|
-
}
|
|
1324
1326
|
//#endregion
|
|
1325
1327
|
//#region src/garden/run.ts
|
|
1326
1328
|
const CHECKS = [
|
|
@@ -1331,7 +1333,8 @@ const CHECKS = [
|
|
|
1331
1333
|
advisories,
|
|
1332
1334
|
stuckRenovate,
|
|
1333
1335
|
governanceDrift,
|
|
1334
|
-
|
|
1336
|
+
repoAdmins,
|
|
1337
|
+
branchGovernance,
|
|
1335
1338
|
orgChecksRuleset,
|
|
1336
1339
|
aiApps,
|
|
1337
1340
|
orbSecrets,
|
|
@@ -1339,7 +1342,24 @@ const CHECKS = [
|
|
|
1339
1342
|
templateBehindLatest,
|
|
1340
1343
|
templateMembership,
|
|
1341
1344
|
staleRegistry,
|
|
1342
|
-
|
|
1345
|
+
{
|
|
1346
|
+
id: "template-canary",
|
|
1347
|
+
async run(context) {
|
|
1348
|
+
let wired = 0;
|
|
1349
|
+
const result = await perRepo(await templates(context), async (repo) => {
|
|
1350
|
+
const runs = await context.workflowRuns(repo, CANARY, repo.defaultBranch, "");
|
|
1351
|
+
if (runs === void 0) return [];
|
|
1352
|
+
wired++;
|
|
1353
|
+
const latest = runs[0];
|
|
1354
|
+
return latest?.conclusion === "failure" ? [finding({
|
|
1355
|
+
repo: repo.name,
|
|
1356
|
+
check: "template-canary",
|
|
1357
|
+
subject: "canary"
|
|
1358
|
+
}, `The latest ${CANARY} run is red: ${latest.url}`, `${CANARY} is green with every @antelopejs/* dependency on next.`)] : [];
|
|
1359
|
+
});
|
|
1360
|
+
return wired ? result : skip(`no template runs ${CANARY} yet`);
|
|
1361
|
+
}
|
|
1362
|
+
},
|
|
1343
1363
|
webBuild,
|
|
1344
1364
|
linkRot,
|
|
1345
1365
|
captureScenes,
|
|
@@ -1348,7 +1368,7 @@ const CHECKS = [
|
|
|
1348
1368
|
function compare(a, b) {
|
|
1349
1369
|
return a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
1350
1370
|
}
|
|
1351
|
-
/** Runs every check, plans the
|
|
1371
|
+
/** Runs every check, plans the prunes, and applies the writes only when asked. */
|
|
1352
1372
|
async function garden(api, options) {
|
|
1353
1373
|
const context = new GardenContext(api);
|
|
1354
1374
|
const found = [];
|
|
@@ -1371,19 +1391,8 @@ async function garden(api, options) {
|
|
|
1371
1391
|
failures.push(failure);
|
|
1372
1392
|
}
|
|
1373
1393
|
const findings = [...new Map(found.map((entry) => [entry.key, entry])).values()].sort(compare);
|
|
1374
|
-
const planned = await plannedPauses(context, findings);
|
|
1375
|
-
const pauses = planned.pauses.sort((a, b) => a.repo < b.repo ? -1 : 1);
|
|
1376
|
-
const pauseFailures = options.applyPauses ? await applyPauses(api, pauses) : [];
|
|
1377
1394
|
const { prunes, failed } = await plannedPrunes(api, findings);
|
|
1378
1395
|
const late = [
|
|
1379
|
-
...planned.failed.map((reason) => ({
|
|
1380
|
-
check: "plan-pauses",
|
|
1381
|
-
reason
|
|
1382
|
-
})),
|
|
1383
|
-
...pauseFailures.map((reason) => ({
|
|
1384
|
-
check: "apply-pauses",
|
|
1385
|
-
reason
|
|
1386
|
-
})),
|
|
1387
1396
|
...failed.map((reason) => ({
|
|
1388
1397
|
check: "plan-prunes",
|
|
1389
1398
|
reason
|
|
@@ -1403,7 +1412,6 @@ async function garden(api, options) {
|
|
|
1403
1412
|
report: {
|
|
1404
1413
|
generatedAt: api.now().toISOString(),
|
|
1405
1414
|
findings,
|
|
1406
|
-
pauses,
|
|
1407
1415
|
prunes,
|
|
1408
1416
|
skipped: skipped.sort((a, b) => a.check < b.check ? -1 : 1)
|
|
1409
1417
|
},
|
|
@@ -1419,12 +1427,10 @@ function failureLines(outcome) {
|
|
|
1419
1427
|
await runCliAsync(async () => {
|
|
1420
1428
|
const { values } = parseArgs({ options: {
|
|
1421
1429
|
json: { type: "boolean" },
|
|
1422
|
-
"apply-pauses": { type: "boolean" },
|
|
1423
1430
|
apply: { type: "boolean" },
|
|
1424
1431
|
"apply-prunes": { type: "boolean" }
|
|
1425
1432
|
} });
|
|
1426
1433
|
const outcome = await garden(createApi(ghToken()), {
|
|
1427
|
-
applyPauses: values["apply-pauses"] === true,
|
|
1428
1434
|
apply: values.apply === true,
|
|
1429
1435
|
applyPrunes: values["apply-prunes"] === true
|
|
1430
1436
|
});
|
package/dist/bin/lease.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { n as runCliAsync } from "../cli-4Tv71vYk.mjs";
|
|
3
|
-
import { a as isServerRole, l as unmarked, o as leaseEnv, s as leaseMarker } from "../env-DT0UJNeL.mjs";
|
|
4
3
|
import { a as closeServer, c as LOCK_PORT, d as isRole, f as leaseHome, i as claimPort, l as PORT_ROLES, m as parseRecord, n as bindable, o as listenerPids, p as leaseId, r as chooseBlock, s as listensOn, t as accepting, u as isLeaseId } from "../ports-DGP6bPJy.mjs";
|
|
4
|
+
import { a as isServerRole, l as unmarked, o as leaseEnv, s as leaseMarker } from "../env-DT0UJNeL.mjs";
|
|
5
5
|
import { accessSync, closeSync, constants, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, utimesSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { delimiter, join } from "node:path";
|
|
7
7
|
import { execFileSync, spawn } from "node:child_process";
|
package/dist/bin/ratchet.mjs
CHANGED
|
@@ -3,10 +3,10 @@ import { c as parseCeilings, l as readCeilings, t as CEILINGS_FILE } from "../ce
|
|
|
3
3
|
import { n as renamedPaths } from "../renames-L2owF5GD.mjs";
|
|
4
4
|
import { t as runCli } from "../cli-4Tv71vYk.mjs";
|
|
5
5
|
import { c as repositoryRoot, l as resolveRevision, t as LINT_CONFIG } from "../files-DJ0TeaTU.mjs";
|
|
6
|
-
import { n as ratchet, r as withPreviousTree } from "../ratchet
|
|
6
|
+
import { n as ratchet, r as withPreviousTree } from "../ratchet-Al0XZtOz.mjs";
|
|
7
7
|
import { t as lintDiagnostics } from "../oxlint-BbpTFFmf.mjs";
|
|
8
|
-
import { d as stagedAdditions, f as stagedChanges, u as previousLine } from "../suppression-budget-
|
|
9
|
-
import { n as suppressionBase } from "../suppression-base-
|
|
8
|
+
import { d as stagedAdditions, f as stagedChanges, u as previousLine } from "../suppression-budget-DgYdu6JK.mjs";
|
|
9
|
+
import { n as suppressionBase } from "../suppression-base-DZgUDXiI.mjs";
|
|
10
10
|
import { existsSync } from "node:fs";
|
|
11
11
|
import { join } from "node:path";
|
|
12
12
|
import { execFileSync, spawnSync } from "node:child_process";
|