@antelopejs/tooling-configs 0.2.18 → 0.2.19
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 +11 -6
- package/dist/bin/capture.mjs +1 -1
- package/dist/bin/checks.mjs +22 -4
- package/dist/bin/garden.mjs +228 -27
- package/dist/bin/lease.d.mts +1 -0
- package/dist/bin/lease.mjs +1053 -0
- package/dist/bin/sync.mjs +36 -8
- package/dist/{ci-workflow-ChW4He0r.mjs → ci-workflow-DVkpwauQ.mjs} +12 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -35,27 +35,32 @@ The AntelopeJS guardrail pack: shared lint, format and dead-code presets, the co
|
|
|
35
35
|
| bin | `antelopejs-comment-proof <base-ref>` | Compares comment-free JavaScript emit against committed HEAD |
|
|
36
36
|
| bin | `antelopejs-body-check <body.md \| -> [--head <sha>] [--base <sha>]` | Checks a PR body's proof and findings blocks against HEAD; `--findings` prints the findings block |
|
|
37
37
|
| bin | `antelopejs-check-interface-ranges` | Fails on interface ranges that break module startup |
|
|
38
|
-
| bin | `antelopejs-garden [--json] [--apply-pauses]`
|
|
38
|
+
| bin | `antelopejs-garden [--json] [--apply-pauses] [--apply] [--apply-prunes]` | The Gardener's scans of the organization through the GitHub API and npm |
|
|
39
39
|
| bin | `antelopejs-verify <command>` | The harness of the shared `verify-interface`, `verify-module` and `verify-template` skills |
|
|
40
|
+
| bin | `antelopejs-lease run \| status \| down \| gc` | Ports, a mongod, logs and tmp per worktree; see [Run a DMS from a git worktree](./docs/agent-worktrees.md) |
|
|
40
41
|
|
|
41
42
|
## antelopejs-garden
|
|
42
43
|
|
|
43
44
|
`antelopejs-garden` is the Gardener's deterministic scan. It reads the non-archived AntelopeJS repositories whose `pack` property is `full` or `template` and whose `tier` is N1 to N3, through the GitHub API and the npm registry, authenticated with the token `gh` is logged in with. It never clones.
|
|
44
45
|
|
|
45
|
-
- `--json` prints `{ generatedAt, findings, pauses, skipped }`. A finding is `{ key, repo, check, subject, severity, evidence, doneMeans }` with the key `repo|check|subject`, sorted. `skipped` lists every check whose source does not exist yet, or that could not run.
|
|
46
|
+
- `--json` prints `{ generatedAt, findings, pauses, prunes, skipped }`. A finding is `{ key, repo, check, subject, severity, evidence, doneMeans }` with the key `repo|check|subject`, sorted. `skipped` lists every check whose source does not exist yet, or that could not run.
|
|
46
47
|
- Without `--json` it prints failures only. The exit code is non-zero only when a check could not run.
|
|
47
48
|
- `--apply-pauses` sets the repository variable `NEXT_AUTOMERGE` to `shadow` on repositories where it is `on`, when `checks` is red on `next`, the ratchet file is back on a Clean repository, or governance drifted. It never sets `on` and writes nothing else.
|
|
49
|
+
- `--apply` turns `delete_branch_on_merge` on for each repository the `conformance` check reports it off on, and writes nothing else.
|
|
50
|
+
- The `stale-branches` check lists, in one finding per repository, the branches other than the default, `next` and protected ones that head a merged or closed pull request at their current commit, or have no open pull request and no commit for 30 days. A branch that heads or receives an open pull request is never listed. `prunes` holds one `{ repo, branch, reason }` per listed branch, and `--apply-prunes` deletes exactly those refs.
|
|
48
51
|
|
|
49
|
-
`antelopejs-sync` (full profile) writes the weekly mutation caller `.github/workflows/mutation.yml`, and both profiles keep the shared CI caller on the job id `ci`, so the check is reported as `ci / checks`. The `ci` job is read-only (`contents: read`) and passes `renovate-sync: false
|
|
52
|
+
`antelopejs-sync` (full profile) writes the weekly mutation caller `.github/workflows/mutation.yml`, and both profiles keep the shared CI caller on the job id `ci`, so the check is reported as `ci / checks`. The `ci` job is read-only (`contents: read`) and passes `renovate-sync: false` and `test-job: true`, which runs the tests in their own job (sync adds `test-job: true` to a caller that does not set it and keeps a value the caller set); the `contents: write` and `actions: write` grants that let the Renovate sync push its commit and dispatch the caller live on a separate `renovate-sync` job calling `ci-renovate-sync.yml`, which sync adds when it is missing and never re-pins. Under the full profile it also sets the `docs-files` input of every ci-node caller to the existing `README.md` and `docs` of the root and of each workspace package that is not private, then keeps the caller's other listed paths that still exist. Renaming a caller to `ci` also rewrites `needs:` lists and `needs.<old-id>` reads in expressions, and sync (and `--check`) fails a caller in which a job needs a job that does not exist or reads `needs.<id>` of a job missing from its own `needs:`, since GitHub evaluates that read to null and a gate like `needs.checks.result == 'skipped'` then never fails.
|
|
50
53
|
|
|
51
54
|
## Shared verification skills
|
|
52
55
|
|
|
53
|
-
`antelopejs-sync` writes one shared verification skill into a repository: `verify-interface` for an interface, `verify-module` for an implementation module (inferred from `antelopeJs.implements`) and `verify-template`
|
|
56
|
+
`antelopejs-sync` writes one shared verification skill into a repository: `verify-interface` for an interface, `verify-module` for an implementation module (inferred from `antelopeJs.implements`) and `verify-template` in a template source repository, which keeps an `.agents/skills/verify-template/` folder (bootstrap one with `--verify template`). `--profile template` infers no kind, because a scaffold ships without `.agents`: it keeps the skill that exists or the one `--verify` names. Pass `--verify interface|module|template` to choose, or `--verify custom` for a repository that keeps its own `.agents/skills/verify-<repo>/`. Sync writes `SKILL.md`, `package.json` and `tsconfig.json` in `.agents/skills/verify-<kind>/` with a `.claude/skills/verify-<kind>` link, and `--check` reports them as drift. The `tsconfig.json` extends the root one with ES module resolution and loads the Node types, so type-aware lint sees the real types of the repository's files there, Node APIs included. It never touches the repository's own layer beside them: `verify.config.ts`, `features/`, `seeded-breaks/` and `seeded-doors/`.
|
|
54
57
|
|
|
55
|
-
`antelopejs-sync` also installs the `technical-writing` and `unslop` skills in every repository
|
|
58
|
+
`antelopejs-sync` also installs the `technical-writing` and `unslop` skills in every full-profile repository and in a template source. Each is `.agents/skills/<name>/SKILL.md` with a `.claude/skills/<name>` link. The text is vendored unchanged from Upd4ting/agent-config `claude/skills/<name>/SKILL.md` at commit 4e0a848, and `--check` reports an edited file as drift. Write documentation with them: `technical-writing` picks the page's mode and sets the sentence rules, and `unslop` lists the patterns to cut.
|
|
56
59
|
|
|
57
60
|
Every deterministic step of a verification is an `antelopejs-verify` command: `map`, `plan`, `new`, `doctor`, `journey`, `formal`, `doors`, `seeded`, `seeded-doors`, `clean`, `verdict` and `publish`. The synced `SKILL.md` documents each one for the agent that verifies.
|
|
58
61
|
|
|
62
|
+
The verify skills drive a browser with `playwright-core`. [Browser driver for the verify skills](./docs/browser-driver.md) records why, with the measured speed, CPU and memory.
|
|
63
|
+
|
|
59
64
|
## Install
|
|
60
65
|
|
|
61
66
|
Node.js 24, or at least 22.18: oxlint reads `oxlint.config.ts` and loads JS plugins by executing TypeScript.
|
|
@@ -193,7 +198,7 @@ pnpm install
|
|
|
193
198
|
| `guardrails.suppressions.json` | Records the current suppression counts when the file is missing; restores the committed file instead when HEAD has one; otherwise only adds `config` and `agentFiles` at today's counts when the file predates them |
|
|
194
199
|
| `<layer>/build/backend-boundary.ts` | Where a DMS frontend layer tracks one, restores the pack's backend boundary plugin for the package that holds the layer. A formatter's rewrite is not drift; any other edit is |
|
|
195
200
|
|
|
196
|
-
`--profile template` writes only the three preset configs, a user-facing `AGENTS.md` block and the `suppressions` package scripts (plus `ratchet` once `guardrails.ratchet.json` exists) that `antelopejs-checks` requires, for template repositories. `antelopejs-sync --check` writes nothing and exits 1 on any drift; `pnpm run checks` runs it.
|
|
201
|
+
`--profile template` writes only the three preset configs, a user-facing `AGENTS.md` block and the `suppressions` package scripts (plus `ratchet` once `guardrails.ratchet.json` exists) that `antelopejs-checks` requires, for template repositories. The agent layer, `verify-template` and the writing skills under `.agents/skills/` with their `.claude/skills` links, is synced and checked only in the template source, marked by its `.agents/skills/verify-template/` folder; a project scaffolded from the template ships without it, so the template's `AGENTS.md` block links no skill under `.agents/` or `.claude/skills/`. `antelopejs-sync --check` writes nothing and exits 1 on any drift; `pnpm run checks` runs it.
|
|
197
202
|
|
|
198
203
|
`pnpm run checks` runs `typecheck`, `lint`, `format:check`, `knip`, `test`, `size`, `suppressions` and `sync:check`, plus `ratchet` when `guardrails.ratchet.json` exists. It prints only the output of the steps that failed. Sync adds the ratchet scripts and pre-commit hook only while that file exists.
|
|
199
204
|
|
package/dist/bin/capture.mjs
CHANGED
|
@@ -10,10 +10,10 @@ import { parse as parse$1, stringify } from "yaml";
|
|
|
10
10
|
import { pathToFileURL } from "node:url";
|
|
11
11
|
import { tmpdir } from "node:os";
|
|
12
12
|
import { parseArgs } from "node:util";
|
|
13
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
13
14
|
import { MongoMemoryServer } from "mongodb-memory-server";
|
|
14
15
|
import { chromium } from "playwright-core";
|
|
15
16
|
import sharp from "sharp";
|
|
16
|
-
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
17
17
|
import pixelmatch from "pixelmatch";
|
|
18
18
|
//#region src/capture/demo.ts
|
|
19
19
|
/** The instant the demo and the browser treat as now: 2026-06-15 09:00 UTC, which is 10:00 in Brussels. */
|
package/dist/bin/checks.mjs
CHANGED
|
@@ -18,11 +18,29 @@ const CHECK_STEPS = [
|
|
|
18
18
|
"suppressions",
|
|
19
19
|
"sync:check"
|
|
20
20
|
];
|
|
21
|
-
|
|
21
|
+
/** The environment variable naming, comma-separated, the steps `runChecks` leaves to another CI job. */
|
|
22
|
+
const CHECKS_SKIP_ENV = "ANTELOPEJS_CHECKS_SKIP";
|
|
23
|
+
function skippedNames(setting) {
|
|
24
|
+
return setting.split(",").map((name) => name.trim()).filter(Boolean);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Runs every check step and reports only what failed. `skipSetting` is the comma-separated value of
|
|
28
|
+
* `ANTELOPEJS_CHECKS_SKIP`: the steps it names are not run and are counted as skipped, never as passed, and a name that
|
|
29
|
+
* is not a step fails the run before any step starts so a typo cannot skip nothing.
|
|
30
|
+
*/
|
|
31
|
+
function runChecks(root, skipSetting = "") {
|
|
32
|
+
const requested = skippedNames(skipSetting);
|
|
33
|
+
const unknown = requested.filter((name) => !CHECK_STEPS.includes(name));
|
|
34
|
+
if (unknown.length) return {
|
|
35
|
+
failed: 1,
|
|
36
|
+
output: `[${CHECKS_SKIP_ENV}]\nUnknown step ${unknown.map((name) => `"${name}"`).join(", ")}. Valid steps: ${CHECK_STEPS.join(", ")}.\nChecks: 0 passed, 1 failed.\n`
|
|
37
|
+
};
|
|
22
38
|
const manifest = parseManifest(readFileSync(join(root, "package.json"), "utf8"));
|
|
23
39
|
const manager = packageManager(manifest);
|
|
24
40
|
const failures = [];
|
|
25
|
-
const
|
|
41
|
+
const present = CHECK_STEPS.filter((step) => step !== "ratchet" || existsSync(join(root, "guardrails.ratchet.json")));
|
|
42
|
+
const steps = present.filter((step) => !requested.includes(step));
|
|
43
|
+
const skipped = present.length - steps.length;
|
|
26
44
|
for (const step of steps) {
|
|
27
45
|
if (!manifest.scripts?.[step]) {
|
|
28
46
|
failures.push(`[${step}] Missing package.json script "${step}". Run antelopejs-sync.\n`);
|
|
@@ -42,13 +60,13 @@ function runChecks(root) {
|
|
|
42
60
|
}
|
|
43
61
|
return {
|
|
44
62
|
failed: failures.length,
|
|
45
|
-
output: `${failures.join("\n")}Checks: ${steps.length - failures.length} passed, ${failures.length} failed.\n`
|
|
63
|
+
output: `${failures.join("\n")}Checks: ${steps.length - failures.length} passed, ${failures.length} failed${skipped ? `, ${skipped} skipped` : ""}.\n`
|
|
46
64
|
};
|
|
47
65
|
}
|
|
48
66
|
//#endregion
|
|
49
67
|
//#region src/bin/checks.ts
|
|
50
68
|
runCli(() => {
|
|
51
|
-
const result = runChecks(repositoryRoot());
|
|
69
|
+
const result = runChecks(repositoryRoot(), process.env[CHECKS_SKIP_ENV]);
|
|
52
70
|
process.stdout.write(result.output);
|
|
53
71
|
return result.failed ? 1 : 0;
|
|
54
72
|
});
|
package/dist/bin/garden.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { a as isString, 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";
|
|
3
3
|
import { n as runCliAsync } from "../cli-4Tv71vYk.mjs";
|
|
4
|
-
import { i as CI_RENOVATE_SYNC_REF, l as ciNodeCallers, n as CI_NODE_REF, r as CI_PATH, t as CI_CONTEXT, u as ciRenovateSyncCallers } from "../ci-workflow-
|
|
4
|
+
import { i as CI_RENOVATE_SYNC_REF, l as ciNodeCallers, n as CI_NODE_REF, r as CI_PATH, t as CI_CONTEXT, u as ciRenovateSyncCallers } from "../ci-workflow-DVkpwauQ.mjs";
|
|
5
5
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
7
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
@@ -131,7 +131,7 @@ function createApi(token) {
|
|
|
131
131
|
return new Uint8Array(await (await get(path)).arrayBuffer());
|
|
132
132
|
},
|
|
133
133
|
async send(method, path, body) {
|
|
134
|
-
const response = await request(`${GITHUB}${path}`, {
|
|
134
|
+
const response = await request(`${GITHUB}${path}`, body === void 0 ? { method } : {
|
|
135
135
|
method,
|
|
136
136
|
body: JSON.stringify(body),
|
|
137
137
|
headers: { "Content-Type": "application/json" }
|
|
@@ -196,12 +196,26 @@ function checkRuns(value) {
|
|
|
196
196
|
}
|
|
197
197
|
function pullRequest(value) {
|
|
198
198
|
const source = object(value, "pull request");
|
|
199
|
+
const head = child(source, "head");
|
|
199
200
|
return {
|
|
200
201
|
number: num(source, "number"),
|
|
201
202
|
title: str(source, "title"),
|
|
202
203
|
author: optStr(child(source, "user"), "login") ?? "",
|
|
203
204
|
createdAt: time(source, "created_at"),
|
|
204
|
-
url: str(source, "html_url")
|
|
205
|
+
url: str(source, "html_url"),
|
|
206
|
+
head: optStr(head, "ref") ?? "",
|
|
207
|
+
headRepo: isObject(head.repo) ? optStr(head.repo, "full_name") : void 0,
|
|
208
|
+
headSha: optStr(head, "sha") ?? "",
|
|
209
|
+
base: optStr(child(source, "base"), "ref") ?? "",
|
|
210
|
+
merged: optStr(source, "merged_at") !== void 0
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function branch(value) {
|
|
214
|
+
const source = object(value, "branch");
|
|
215
|
+
return {
|
|
216
|
+
name: str(source, "name"),
|
|
217
|
+
protected: flag(source, "protected"),
|
|
218
|
+
sha: str(child(source, "commit"), "sha")
|
|
205
219
|
};
|
|
206
220
|
}
|
|
207
221
|
function alert(value) {
|
|
@@ -321,6 +335,10 @@ var GardenContext = class {
|
|
|
321
335
|
packuments = new Memo();
|
|
322
336
|
removals = new Memo();
|
|
323
337
|
searches = new Memo();
|
|
338
|
+
branchLists = new Memo();
|
|
339
|
+
closed = new Memo();
|
|
340
|
+
commitTimes = new Memo();
|
|
341
|
+
cleanups = new Memo();
|
|
324
342
|
constructor(api) {
|
|
325
343
|
this.api = api;
|
|
326
344
|
}
|
|
@@ -407,6 +425,29 @@ var GardenContext = class {
|
|
|
407
425
|
openPulls(repo) {
|
|
408
426
|
return this.pulls.get(repo.name, async () => (await this.api.pages(`/repos/${ORG}/${repo.name}/pulls?state=open`)).map(pullRequest));
|
|
409
427
|
}
|
|
428
|
+
/** Every branch of the repository, protected ones flagged. */
|
|
429
|
+
branchList(repo) {
|
|
430
|
+
return this.branchLists.get(repo.name, async () => (await this.api.pages(`/repos/${ORG}/${repo.name}/branches`)).map(branch));
|
|
431
|
+
}
|
|
432
|
+
/** Closed and merged pull requests whose head is the branch of this repository, not a fork's namesake. */
|
|
433
|
+
closedPulls(repo, name) {
|
|
434
|
+
return this.closed.get(`${repo.name}:${name}`, async () => (await this.api.pages(`/repos/${ORG}/${repo.name}/pulls?state=closed&head=${ORG}:${encodeURIComponent(name)}`)).map(pullRequest).filter((pull) => pull.head === name && pull.headRepo === `AntelopeJS/${repo.name}`));
|
|
435
|
+
}
|
|
436
|
+
/** When the commit was committed, in milliseconds. */
|
|
437
|
+
commitTime(repo, sha) {
|
|
438
|
+
return this.commitTimes.get(`${repo.name}:${sha}`, async () => {
|
|
439
|
+
const body = object(await this.api.json(`/repos/${ORG}/${repo.name}/commits/${sha}`), "commit");
|
|
440
|
+
return time(child(child(body, "commit"), "committer"), "date");
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
/** Whether GitHub deletes a pull request's head branch once it merges. */
|
|
444
|
+
deletesBranchOnMerge(repo) {
|
|
445
|
+
return this.cleanups.get(repo.name, async () => {
|
|
446
|
+
const body = object(await this.api.json(`/repos/${ORG}/${repo.name}`), "repository");
|
|
447
|
+
if (!Object.hasOwn(body, "delete_branch_on_merge")) throw new Error("delete_branch_on_merge is not readable; merge settings need a token with contents write access");
|
|
448
|
+
return flag(body, "delete_branch_on_merge");
|
|
449
|
+
});
|
|
450
|
+
}
|
|
410
451
|
/** Open alerts, or undefined when Dependabot alerts are disabled for the repository. */
|
|
411
452
|
alerts(repo) {
|
|
412
453
|
return this.alertLists.get(repo.name, async () => {
|
|
@@ -674,7 +715,7 @@ async function perRepo(repos, scan) {
|
|
|
674
715
|
}
|
|
675
716
|
//#endregion
|
|
676
717
|
//#region src/garden/checks/ci-health.ts
|
|
677
|
-
const DAY$
|
|
718
|
+
const DAY$4 = 864e5;
|
|
678
719
|
const WORKFLOW = "ci.yml";
|
|
679
720
|
const RECENT_RUNS = 10;
|
|
680
721
|
const MIN_BASELINE = 5;
|
|
@@ -707,7 +748,7 @@ async function red(context, repo) {
|
|
|
707
748
|
const branch = await context.targetBranch(repo);
|
|
708
749
|
const runs = await context.workflowRuns(repo, WORKFLOW, branch);
|
|
709
750
|
const since = runs === void 0 ? void 0 : redSince(runs);
|
|
710
|
-
if (since === void 0 || context.api.now().getTime() - since.createdAt <= DAY$
|
|
751
|
+
if (since === void 0 || context.api.now().getTime() - since.createdAt <= DAY$4) return [];
|
|
711
752
|
return [finding({
|
|
712
753
|
repo: repo.name,
|
|
713
754
|
check: "red-branch",
|
|
@@ -717,7 +758,7 @@ async function red(context, repo) {
|
|
|
717
758
|
async function slow(context, repo) {
|
|
718
759
|
const branch = await context.targetBranch(repo);
|
|
719
760
|
const runs = await context.workflowRuns(repo, WORKFLOW, branch);
|
|
720
|
-
const horizon = context.api.now().getTime() - 30 * DAY$
|
|
761
|
+
const horizon = context.api.now().getTime() - 30 * DAY$4;
|
|
721
762
|
const passed = (runs ?? []).filter((run) => run.conclusion === "success" && run.createdAt >= horizon);
|
|
722
763
|
const baseline = passed.slice(RECENT_RUNS).map(duration);
|
|
723
764
|
if (passed.length <= RECENT_RUNS || baseline.length < MIN_BASELINE) return [];
|
|
@@ -743,6 +784,99 @@ const ciDuration = {
|
|
|
743
784
|
}
|
|
744
785
|
};
|
|
745
786
|
//#endregion
|
|
787
|
+
//#region src/garden/checks/branches.ts
|
|
788
|
+
const CHECK$2 = "stale-branches";
|
|
789
|
+
const SUBJECT = "branches";
|
|
790
|
+
const DAY$3 = 864e5;
|
|
791
|
+
const INACTIVE_DAYS = 30;
|
|
792
|
+
function day(time) {
|
|
793
|
+
return new Date(time).toISOString().slice(0, 10);
|
|
794
|
+
}
|
|
795
|
+
function hasOpenPull(facts) {
|
|
796
|
+
const { branch, open, repo } = facts;
|
|
797
|
+
return open.some((pull) => pull.base === branch.name || pull.head === branch.name && pull.headRepo === `AntelopeJS/${repo}`);
|
|
798
|
+
}
|
|
799
|
+
/** Decides one branch: the default, `next`, protected and open-PR branches always stay. */
|
|
800
|
+
async function classify(facts) {
|
|
801
|
+
const { branch, defaultBranch, closed, now } = facts;
|
|
802
|
+
if (branch.name === defaultBranch || branch.name === "next") return { kind: "keep" };
|
|
803
|
+
if (branch.protected || hasOpenPull(facts)) return { kind: "keep" };
|
|
804
|
+
const done = (await closed()).find((pull) => pull.headSha === branch.sha);
|
|
805
|
+
if (done !== void 0) return {
|
|
806
|
+
kind: "prune",
|
|
807
|
+
reason: `${done.merged ? "merged" : "closed"} PR #${done.number}`
|
|
808
|
+
};
|
|
809
|
+
const tip = await facts.tipTime();
|
|
810
|
+
return now - tip >= INACTIVE_DAYS * DAY$3 ? {
|
|
811
|
+
kind: "prune",
|
|
812
|
+
reason: `no commit since ${day(tip)}`
|
|
813
|
+
} : { kind: "keep" };
|
|
814
|
+
}
|
|
815
|
+
async function prunable(context, repo) {
|
|
816
|
+
const [branches, open] = await Promise.all([context.branchList(repo), context.openPulls(repo)]);
|
|
817
|
+
const now = context.api.now().getTime();
|
|
818
|
+
const prunes = [];
|
|
819
|
+
for (const branch of branches) {
|
|
820
|
+
const verdict = await classify({
|
|
821
|
+
branch,
|
|
822
|
+
defaultBranch: repo.defaultBranch,
|
|
823
|
+
open,
|
|
824
|
+
closed: () => context.closedPulls(repo, branch.name),
|
|
825
|
+
tipTime: () => context.commitTime(repo, branch.sha),
|
|
826
|
+
now,
|
|
827
|
+
repo: repo.name
|
|
828
|
+
});
|
|
829
|
+
if (verdict.kind === "prune") prunes.push({
|
|
830
|
+
repo: repo.name,
|
|
831
|
+
branch: branch.name,
|
|
832
|
+
reason: verdict.reason
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
return prunes;
|
|
836
|
+
}
|
|
837
|
+
function report(repo, prunes) {
|
|
838
|
+
if (!prunes.length) return [];
|
|
839
|
+
return [finding({
|
|
840
|
+
repo: repo.name,
|
|
841
|
+
check: CHECK$2,
|
|
842
|
+
subject: SUBJECT
|
|
843
|
+
}, 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.`)];
|
|
844
|
+
}
|
|
845
|
+
/** Lists, per repository, the branches `--apply-prunes` would delete. */
|
|
846
|
+
const staleBranches = {
|
|
847
|
+
id: CHECK$2,
|
|
848
|
+
async run(context) {
|
|
849
|
+
return perRepo(await context.scope(), async (repo) => report(repo, await prunable(context, repo)));
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
/** 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. */
|
|
853
|
+
async function plannedPrunes(api, findings) {
|
|
854
|
+
const fresh = new GardenContext(api);
|
|
855
|
+
const flagged = new Set(findings.filter((entry) => entry.check === CHECK$2).map((entry) => entry.repo));
|
|
856
|
+
const prunes = [];
|
|
857
|
+
const failed = [];
|
|
858
|
+
const scope = await fresh.scope().catch((error) => {
|
|
859
|
+
failed.push(`organization listing: ${error instanceof Error ? error.message : String(error)}`);
|
|
860
|
+
return [];
|
|
861
|
+
});
|
|
862
|
+
for (const repo of scope) if (flagged.has(repo.name)) await prunable(fresh, repo).then((found) => prunes.push(...found), (error) => failed.push(`${repo.name}: ${error instanceof Error ? error.message : String(error)}`));
|
|
863
|
+
return {
|
|
864
|
+
prunes,
|
|
865
|
+
failed
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
function refPath(name) {
|
|
869
|
+
return name.split("/").map(encodeURIComponent).join("/");
|
|
870
|
+
}
|
|
871
|
+
/** Deletes each planned branch ref and nothing else; a failed deletion does not stop the rest and is returned. */
|
|
872
|
+
async function applyPrunes(api, prunes) {
|
|
873
|
+
const failed = [];
|
|
874
|
+
for (const prune of prunes) await api.send("DELETE", `/repos/${ORG}/${prune.repo}/git/refs/heads/${refPath(prune.branch)}`).catch((error) => {
|
|
875
|
+
failed.push(`${prune.repo} ${prune.branch}: ${error instanceof Error ? error.message : String(error)}`);
|
|
876
|
+
});
|
|
877
|
+
return failed;
|
|
878
|
+
}
|
|
879
|
+
//#endregion
|
|
746
880
|
//#region src/garden/npm.ts
|
|
747
881
|
const TOOLING_PACKAGE = "@antelopejs/tooling-configs";
|
|
748
882
|
function distTags(packument) {
|
|
@@ -826,6 +960,25 @@ async function cleanRatchet(context, repo) {
|
|
|
826
960
|
if (!(await context.tree(repo)).includes(GUARDRAILS_RATCHET) || !await context.removedInHistory(repo, GUARDRAILS_RATCHET)) return [];
|
|
827
961
|
return [problem(repo, "ratchet", `${GUARDRAILS_RATCHET} is back after the history deleted it.`, `${GUARDRAILS_RATCHET} is deleted again.`)];
|
|
828
962
|
}
|
|
963
|
+
const BRANCH_CLEANUP = "delete-branch-on-merge";
|
|
964
|
+
async function branchCleanup(context, repo) {
|
|
965
|
+
return await context.deletesBranchOnMerge(repo) ? [] : [problem(repo, BRANCH_CLEANUP, "delete_branch_on_merge is off, so merged head branches stay behind.", "delete_branch_on_merge is on; antelopejs-garden --apply turns it on.")];
|
|
966
|
+
}
|
|
967
|
+
/** Reported as a conformance finding, but read apart so a token that cannot see merge settings hides no other finding. */
|
|
968
|
+
const deleteBranchOnMerge = {
|
|
969
|
+
id: BRANCH_CLEANUP,
|
|
970
|
+
async run(context) {
|
|
971
|
+
return perRepo(await context.scope(), (repo) => branchCleanup(context, repo));
|
|
972
|
+
}
|
|
973
|
+
};
|
|
974
|
+
/** Turns `delete_branch_on_merge` on for each repository a finding reports it off on, and writes nothing else; returns the writes that failed. */
|
|
975
|
+
async function applySettings(api, findings) {
|
|
976
|
+
const failed = [];
|
|
977
|
+
for (const entry of findings) if (entry.check === CHECK$1 && entry.subject === BRANCH_CLEANUP) await api.send("PATCH", `/repos/${ORG}/${entry.repo}`, { delete_branch_on_merge: true }).catch((error) => {
|
|
978
|
+
failed.push(`${entry.repo}: ${error instanceof Error ? error.message : String(error)}`);
|
|
979
|
+
});
|
|
980
|
+
return failed;
|
|
981
|
+
}
|
|
829
982
|
async function scan(context, repo) {
|
|
830
983
|
return [
|
|
831
984
|
...await ciCaller(context, repo),
|
|
@@ -1319,34 +1472,48 @@ function reasons(repo, findings) {
|
|
|
1319
1472
|
const own = findings.filter((entry) => entry.repo === repo);
|
|
1320
1473
|
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"] : []];
|
|
1321
1474
|
}
|
|
1322
|
-
|
|
1475
|
+
async function pauseFor(context, repo, findings) {
|
|
1476
|
+
if (await context.variable(repo, "NEXT_AUTOMERGE") !== "on") return [];
|
|
1477
|
+
const triggers = reasons(repo.name, findings);
|
|
1478
|
+
const runs = await context.targetBranch(repo) === "next" ? await context.workflowRuns(repo, "ci.yml", "next") : void 0;
|
|
1479
|
+
if (runs !== void 0 && redSince(runs) !== void 0) triggers.unshift("checks is red on next after a merge");
|
|
1480
|
+
return triggers.length ? [{
|
|
1481
|
+
repo: repo.name,
|
|
1482
|
+
from: "on",
|
|
1483
|
+
to: PAUSED,
|
|
1484
|
+
reason: triggers.join("; ")
|
|
1485
|
+
}] : [];
|
|
1486
|
+
}
|
|
1487
|
+
/** Repositories where `NEXT_AUTOMERGE` is `on` and a stop-the-line trigger fired; a repository whose read failed is returned in `failed`, not paused. */
|
|
1323
1488
|
async function plannedPauses(context, findings) {
|
|
1324
1489
|
const pauses = [];
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
});
|
|
1336
|
-
}
|
|
1337
|
-
return pauses;
|
|
1490
|
+
const failed = [];
|
|
1491
|
+
const scope = await context.scope().catch((error) => {
|
|
1492
|
+
failed.push(`organization listing: ${error instanceof Error ? error.message : String(error)}`);
|
|
1493
|
+
return [];
|
|
1494
|
+
});
|
|
1495
|
+
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)}`));
|
|
1496
|
+
return {
|
|
1497
|
+
pauses,
|
|
1498
|
+
failed
|
|
1499
|
+
};
|
|
1338
1500
|
}
|
|
1339
|
-
/** Writes the one repository variable and nothing else. */
|
|
1501
|
+
/** Writes the one repository variable and nothing else; a refused write does not stop the rest and is returned. */
|
|
1340
1502
|
async function applyPauses(api, pauses) {
|
|
1503
|
+
const failed = [];
|
|
1341
1504
|
for (const pause of pauses) await api.send("PATCH", `/repos/${ORG}/${pause.repo}/actions/variables/${AUTOMERGE}`, {
|
|
1342
1505
|
name: AUTOMERGE,
|
|
1343
1506
|
value: pause.to
|
|
1507
|
+
}).catch((error) => {
|
|
1508
|
+
failed.push(`${pause.repo}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1344
1509
|
});
|
|
1510
|
+
return failed;
|
|
1345
1511
|
}
|
|
1346
1512
|
//#endregion
|
|
1347
1513
|
//#region src/garden/run.ts
|
|
1348
1514
|
const CHECKS = [
|
|
1349
1515
|
conformance,
|
|
1516
|
+
deleteBranchOnMerge,
|
|
1350
1517
|
redBranch,
|
|
1351
1518
|
ciDuration,
|
|
1352
1519
|
advisories,
|
|
@@ -1364,12 +1531,13 @@ const CHECKS = [
|
|
|
1364
1531
|
templateCanary,
|
|
1365
1532
|
webBuild,
|
|
1366
1533
|
linkRot,
|
|
1367
|
-
captureScenes
|
|
1534
|
+
captureScenes,
|
|
1535
|
+
staleBranches
|
|
1368
1536
|
];
|
|
1369
1537
|
function compare(a, b) {
|
|
1370
1538
|
return a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
1371
1539
|
}
|
|
1372
|
-
/** Runs every check, plans the pauses and applies
|
|
1540
|
+
/** Runs every check, plans the pauses and prunes, and applies each only when asked. */
|
|
1373
1541
|
async function garden(api, options) {
|
|
1374
1542
|
const context = new GardenContext(api);
|
|
1375
1543
|
const found = [];
|
|
@@ -1392,13 +1560,40 @@ async function garden(api, options) {
|
|
|
1392
1560
|
failures.push(failure);
|
|
1393
1561
|
}
|
|
1394
1562
|
const findings = [...new Map(found.map((entry) => [entry.key, entry])).values()].sort(compare);
|
|
1395
|
-
const
|
|
1396
|
-
|
|
1563
|
+
const planned = await plannedPauses(context, findings);
|
|
1564
|
+
const pauses = planned.pauses.sort((a, b) => a.repo < b.repo ? -1 : 1);
|
|
1565
|
+
const pauseFailures = options.applyPauses ? await applyPauses(api, pauses) : [];
|
|
1566
|
+
const { prunes, failed } = await plannedPrunes(api, findings);
|
|
1567
|
+
const late = [
|
|
1568
|
+
...planned.failed.map((reason) => ({
|
|
1569
|
+
check: "plan-pauses",
|
|
1570
|
+
reason
|
|
1571
|
+
})),
|
|
1572
|
+
...pauseFailures.map((reason) => ({
|
|
1573
|
+
check: "apply-pauses",
|
|
1574
|
+
reason
|
|
1575
|
+
})),
|
|
1576
|
+
...failed.map((reason) => ({
|
|
1577
|
+
check: "plan-prunes",
|
|
1578
|
+
reason
|
|
1579
|
+
})),
|
|
1580
|
+
...options.apply === true ? (await applySettings(api, findings)).map((reason) => ({
|
|
1581
|
+
check: "apply",
|
|
1582
|
+
reason
|
|
1583
|
+
})) : [],
|
|
1584
|
+
...options.applyPrunes === true ? (await applyPrunes(api, prunes)).map((reason) => ({
|
|
1585
|
+
check: "apply-prunes",
|
|
1586
|
+
reason
|
|
1587
|
+
})) : []
|
|
1588
|
+
];
|
|
1589
|
+
failures.push(...late);
|
|
1590
|
+
skipped.push(...late);
|
|
1397
1591
|
return {
|
|
1398
1592
|
report: {
|
|
1399
1593
|
generatedAt: api.now().toISOString(),
|
|
1400
1594
|
findings,
|
|
1401
1595
|
pauses,
|
|
1596
|
+
prunes,
|
|
1402
1597
|
skipped: skipped.sort((a, b) => a.check < b.check ? -1 : 1)
|
|
1403
1598
|
},
|
|
1404
1599
|
failures
|
|
@@ -1413,9 +1608,15 @@ function failureLines(outcome) {
|
|
|
1413
1608
|
await runCliAsync(async () => {
|
|
1414
1609
|
const { values } = parseArgs({ options: {
|
|
1415
1610
|
json: { type: "boolean" },
|
|
1416
|
-
"apply-pauses": { type: "boolean" }
|
|
1611
|
+
"apply-pauses": { type: "boolean" },
|
|
1612
|
+
apply: { type: "boolean" },
|
|
1613
|
+
"apply-prunes": { type: "boolean" }
|
|
1417
1614
|
} });
|
|
1418
|
-
const outcome = await garden(createApi(ghToken()), {
|
|
1615
|
+
const outcome = await garden(createApi(ghToken()), {
|
|
1616
|
+
applyPauses: values["apply-pauses"] === true,
|
|
1617
|
+
apply: values.apply === true,
|
|
1618
|
+
applyPrunes: values["apply-prunes"] === true
|
|
1619
|
+
});
|
|
1419
1620
|
if (values.json) process.stdout.write(`${JSON.stringify(outcome.report, null, 2)}\n`);
|
|
1420
1621
|
else for (const line of failureLines(outcome)) process.stdout.write(`${line}\n`);
|
|
1421
1622
|
return outcome.failures.length ? 1 : 0;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|