forgedock 1.60.0 → 1.61.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.
Files changed (78) hide show
  1. package/bin/config-schema.mjs +44 -1
  2. package/bin/engine/runlog.mjs +52 -0
  3. package/bin/engine-cli.mjs +9 -4
  4. package/bin/env/bench.mjs +38 -0
  5. package/bin/env/cli.mjs +134 -0
  6. package/bin/env/env.mjs +339 -0
  7. package/bin/forgedock.mjs +32 -3
  8. package/bin/help-text.mjs +2 -0
  9. package/bin/lean/ci-budget.mjs +3 -1
  10. package/bin/lean/ci-classify.mjs +74 -0
  11. package/bin/lean/ci-classify.test.mjs +147 -0
  12. package/bin/lean/ci-emit.mjs +175 -0
  13. package/bin/lean/ci-emit.test.mjs +177 -0
  14. package/bin/lean/ci-preflight.mjs +183 -0
  15. package/bin/lean/ci-preflight.test.mjs +122 -0
  16. package/bin/lean/ci-runner-health.mjs +213 -0
  17. package/bin/lean/ci-runner-health.test.mjs +113 -0
  18. package/bin/lean/ci-watch.mjs +79 -0
  19. package/bin/lean/ci-watch.test.mjs +80 -0
  20. package/bin/lean/conformance.mjs +7 -1
  21. package/bin/lean/conformance.test.mjs +7 -1
  22. package/bin/lean/depcache.mjs +38 -8
  23. package/bin/lean/deploy-stages.mjs +514 -0
  24. package/bin/lean/deploy-stages.test.mjs +580 -0
  25. package/bin/lean/effects.mjs +50 -0
  26. package/bin/lean/execution.mjs +8 -1
  27. package/bin/lean/lean.mjs +61 -12
  28. package/bin/lean/lean.test.mjs +87 -0
  29. package/bin/lean/preflight.mjs +62 -1
  30. package/bin/lean/preflight.test.mjs +30 -1
  31. package/bin/lean/release-deploy.mjs +12 -6
  32. package/bin/lean/release-flakes.mjs +16 -0
  33. package/bin/lean/release-flakes.test.mjs +15 -0
  34. package/bin/lean/release-gates.mjs +24 -1
  35. package/bin/lean/release-ledger.mjs +21 -0
  36. package/bin/lean/release-minutes-timing.test.mjs +57 -0
  37. package/bin/lean/release-minutes.mjs +98 -0
  38. package/bin/lean/release-promote.mjs +444 -0
  39. package/bin/lean/release-promote.test.mjs +470 -0
  40. package/bin/lean/release-rollback.mjs +14 -6
  41. package/bin/lean/release.mjs +31 -2
  42. package/bin/lean/sandbox-remote.mjs +11 -3
  43. package/bin/lean/testengine-recall.mjs +82 -0
  44. package/bin/lean/testengine-recall.test.mjs +103 -0
  45. package/bin/lean/testengine-shard.mjs +150 -0
  46. package/bin/lean/testengine-shard.test.mjs +111 -0
  47. package/bin/lean/testengine.mjs +486 -0
  48. package/bin/lean/testengine.test.mjs +303 -0
  49. package/bin/lean/validate-catalog.mjs +16 -0
  50. package/bin/lean/validate-catalog.test.mjs +14 -1
  51. package/bin/lean/verify-settle.test.mjs +156 -0
  52. package/bin/lean/verify.mjs +98 -3
  53. package/bin/pool/agent.mjs +65 -6
  54. package/bin/pool/ci-events.mjs +183 -0
  55. package/bin/pool/ci-events.test.mjs +143 -0
  56. package/bin/pool/docker.mjs +7 -0
  57. package/bin/pool/lane-tools.mjs +32 -0
  58. package/bin/pool/router.mjs +21 -1
  59. package/bin/pool/warm.mjs +14 -3
  60. package/bin/stats/ci-awareness.mjs +66 -0
  61. package/bin/stats/index.mjs +44 -3
  62. package/bin/stats/release-ledger.test.mjs +226 -0
  63. package/bin/stats/release.mjs +365 -1
  64. package/bin/stats/stats.test.mjs +36 -0
  65. package/docs/CI.md +31 -0
  66. package/docs/CONFIG.md +235 -2
  67. package/docs/ENV-LIBRARY.md +172 -0
  68. package/docs/STATS.md +43 -0
  69. package/docs/ci-events.md +88 -0
  70. package/docs/test-engine.md +98 -0
  71. package/package.json +1 -1
  72. package/pool/README.md +1 -0
  73. package/pool/image/entrypoint.sh +15 -3
  74. package/pool/services/docker-compose.yml +53 -0
  75. package/pool/services/git-mirror.sh +22 -0
  76. package/scripts/acceptance-red-green.sh +5 -2
  77. package/scripts/acceptance-red-green.test.sh +11 -0
  78. package/templates/github-actions/forge-env/action.yml +65 -0
@@ -7,6 +7,8 @@
7
7
  * last `gates.demote_window` runs exceeds `gates.demote_fb_rate` percent is demoted to warn through `runControl("demote")`
8
8
  * with an expiry and an issue, unless it is on the safety allowlist. `release gates` reports runs/fails/FB share/minutes
9
9
  * (FB share = FB runs / runs, the same rate the demotion uses). No catalogue file: every entry point is a no-op, zero writes.
10
+ * CI evidence (#5711): a gate that re-runs work a required check already did names it in `evidence_check`; `evidenceSkips`
11
+ * says which of those gates an accepted attestation covers. A safety gate is never covered.
10
12
  */
11
13
  import { existsSync, readFileSync } from "node:fs";
12
14
  import { join } from "node:path";
@@ -24,7 +26,7 @@ export const DEMOTE_MODES = ["warn", "inconclusive"];
24
26
  export const SAFETY_DEFAULT = ["migration-immutability", "identity-preflight", "backup-freshness", "health-auto-restore"];
25
27
  export const GATE_PATHS_DEFAULT = ["scripts/deploy/**", "scripts/lib/**", "scripts/prod-smoke-test.sh", "**/gate-fixtures/**", "tests/gates/**"];
26
28
  export const REQUIRED = ["id", "protects_against", "where", "determinism", "pre_merge_artifact", "version", "mode", "owner", "review_by"];
27
- const OPTIONAL = ["on_uncertainty", "failure_triggers", "proportionality"];
29
+ const OPTIONAL = ["on_uncertainty", "failure_triggers", "proportionality", "evidence_check"];
28
30
  const DAY_MS = 86_400_000;
29
31
 
30
32
  /** @returns {string[]} findings for a parsed catalogue `{schema: 1, gates: [...]}`; empty when valid. */
@@ -81,6 +83,27 @@ export function parseGatesConfig(policy) {
81
83
  export const isSafetyGate = (gate, safety = SAFETY_DEFAULT) =>
82
84
  isUnskippable(String(gate)) || safety.some((s) => gate === s || String(gate).startsWith(`${s}:`) || String(gate).startsWith(`${s}/`));
83
85
 
86
+ /**
87
+ * CI-evidence side (#5711, release-promote.mjs): for every catalogue gate with an `evidence_check`, whether the attestation
88
+ * `evidence` ({commit, checks: [{name, conclusion}]}) covers it. `ok` is the promote verdict (`canPromote`): without it nothing
89
+ * is skipped. A safety gate always runs, whatever the evidence says. The catalogue mode of a gate is not changed.
90
+ * @returns {{gate: string, check: string, skip: boolean, why: string, record?: object}[]} `record` is the telemetry record of a skipped gate.
91
+ */
92
+ export function evidenceSkips(catalogue, evidence, { ok = false, safety = SAFETY_DEFAULT } = {}) {
93
+ const out = [];
94
+ for (const g of catalogue?.gates ?? []) {
95
+ const check = typeof g?.evidence_check === "string" ? g.evidence_check.trim() : "";
96
+ if (!g?.id || !check) continue;
97
+ const keep = (why) => out.push({ gate: String(g.id), check, skip: false, why });
98
+ if (isSafetyGate(String(g.id), safety)) { keep("safety gate: always runs"); continue; }
99
+ if (!ok) { keep("the evidence was not accepted"); continue; }
100
+ if (!(evidence?.checks ?? []).some((c) => c?.name === check && c.conclusion === "success")) { keep(`${check} is not in the attestation as success`); continue; }
101
+ const why = `${check} passed on ${String(evidence.commit).slice(0, 12)}`;
102
+ out.push({ gate: String(g.id), check, skip: true, why, record: gateRecord({ gate: g.id, outcome: "skip", evidence: `promote: ${why}` }) });
103
+ }
104
+ return out;
105
+ }
106
+
84
107
  /** One telemetry record, or null for an unknown gate or outcome. A TP/FB class needs a non-empty `evidence`, else `unknown`. */
85
108
  export function gateRecord({ gate, outcome, class: cls, evidence, minutes = 0, gate_sha: gateSha }) {
86
109
  if (!gate || !OUTCOMES.includes(outcome)) return null;
@@ -220,3 +220,24 @@ export async function recordTrain(ctx, rec, now = Date.now()) {
220
220
  const at = new Date(now).toISOString();
221
221
  return updateActive(ctx, ["train"], (active) => ({ patch: { train: { ...(active.train ?? {}), [rec.release ?? "-"]: { ...rec, lane: "train", rollout_invalidated: true, at } } }, control: { at, verb: "train", lane: "train", release: rec.release ?? null, state: rec.state ?? null, units: rec.units?.length ?? 0, rollout_invalidated: true } }));
222
222
  }
223
+
224
+ /**
225
+ * #5718: release state for `forgedock stats --release-ledger`. One record per managed release started at or after `sinceMs`:
226
+ * `{id, pr, startedAt, status, live, deployAttempts}` (read-only; a release without a readable state is skipped). The id
227
+ * carries the start time (`rYYYYMMDD-HHMMSS-n`), so older releases cost no read.
228
+ */
229
+ export async function releaseRecords(ctx, { sinceMs = 0 } = {}) {
230
+ const out = [];
231
+ for (const id of await listLedgers(ctx)) {
232
+ const m = /^r(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2})-/.exec(id);
233
+ if (m && Date.UTC(+m[1], +m[2] - 1, +m[3], +m[4], +m[5], +m[6]) < sinceMs) continue;
234
+ let s = null;
235
+ try { s = (await readLedger(ctx, id))?.state ?? null; } catch { s = null; }
236
+ if (!s) continue;
237
+ const pr = s.steps?.["release-pr"]?.result?.pr ?? s.pr ?? null;
238
+ const phase = String(s.deploy?.phase ?? "");
239
+ out.push({ id, pr: pr == null ? null : Number(pr), startedAt: s.startedAt ?? null, status: s.status ?? null,
240
+ live: ["live", "done"].includes(String(s.status ?? "").toLowerCase()) || phase.startsWith("LIVE"), deployAttempts: Number(s.deploy?.attempts) || 0 });
241
+ }
242
+ return out;
243
+ }
@@ -0,0 +1,57 @@
1
+ // SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
2
+ // SPDX-License-Identifier: AGPL-3.0-or-later
3
+ // #5718: Actions timing primitives of the release ledger (pure).
4
+ import { describe, it } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { classifyStep, criticalJob, firstFailedStep, isSelfHosted, jobRan, jobSeconds, jobSetup, minuteShares, queueSeconds } from "./release-minutes.mjs";
7
+
8
+ const T = (s) => `2026-03-01T10:${s}Z`;
9
+ const job = (o = {}) => ({ name: "test", conclusion: "success", created_at: T("00:00"), started_at: T("00:30"), completed_at: T("05:30"), labels: ["ubuntu-latest"], runner_group_name: "GitHub Actions", steps: [], ...o });
10
+ const step = (name, a, b, conclusion = "success") => ({ name, conclusion, started_at: T(a), completed_at: T(b) });
11
+
12
+ describe("step classes (#5718)", () => {
13
+ it("classifies checkout, toolchain and dependency steps of every ecosystem by name", () => {
14
+ const want = {
15
+ checkout: ["Run actions/checkout@v4", "Checkout", "Checkout repository", "git clone the sources"],
16
+ toolchain: ["Run actions/setup-node@v4", "Run actions/setup-python@v5", "Run actions/setup-go@v5", "Set up Python", "Setup Node.js", "Set up Docker Buildx", "Run pnpm/action-setup@v4", "Install Rust toolchain", "rustup update stable", "Run astral-sh/setup-uv@v3"],
17
+ deps: ["Install dependencies", "npm ci", "Run npm install", "pnpm install --frozen-lockfile", "yarn install --immutable", "Run yarn", "pip install -r requirements.txt", "poetry install --no-root", "uv sync --frozen", "uv pip install -e .", "bundle install", "composer install", "go mod download", "cargo fetch", "dotnet restore", "Install Python dependencies", "Restore dependency cache", "Run actions/cache@v4"],
18
+ "image-build": ["Build and push image", "Run docker/build-push-action@v6", "docker build -t app .", "Build web image", "docker buildx bake"],
19
+ lint: ["Run lint", "eslint", "ruff check", "Check formatting", "Typecheck", "Lockfile is up to date", "Generated files drift"],
20
+ };
21
+ for (const [cls, names] of Object.entries(want)) for (const n of names) assert.equal(classifyStep(n), cls, n);
22
+ });
23
+ it("the runner's own steps, post steps and work steps are not setup", () => {
24
+ for (const n of ["Set up job", "Complete job", "Post Run actions/checkout@v4", "Post Install dependencies", "Run tests", "Roll out", "Smoke", "", null]) assert.equal(classifyStep(n), null, String(n));
25
+ });
26
+ it("jobSetup sums the seconds of each setup class", () => {
27
+ const j = job({ steps: [step("Set up job", "00:30", "00:32"), step("Run actions/checkout@v4", "00:32", "00:40"), step("Run actions/setup-node@v4", "00:40", "01:00"), step("npm ci", "01:00", "01:45"), step("Run actions/cache@v4", "01:45", "01:50"), step("Run tests", "01:50", "05:30")] });
28
+ assert.deepEqual(jobSetup(j), { checkout: 8, toolchain: 20, deps: 50, total: 78 });
29
+ assert.deepEqual(jobSetup(job()), { checkout: 0, toolchain: 0, deps: 0, total: 0 });
30
+ });
31
+ });
32
+
33
+ describe("job timing (#5718)", () => {
34
+ it("seconds, queue and self-hosted detection", () => {
35
+ assert.equal(jobSeconds(job()), 300); assert.equal(queueSeconds(job()), 30);
36
+ const skipped = job({ conclusion: "skipped", started_at: T("00:00"), completed_at: T("00:00") });
37
+ assert.equal(jobRan(skipped), false); assert.equal(queueSeconds(skipped), null); assert.equal(jobSeconds({}), 0);
38
+ assert.equal(isSelfHosted(job()), false);
39
+ assert.equal(isSelfHosted(job({ labels: ["self-hosted", "linux"] })), true);
40
+ assert.equal(isSelfHosted(job({ labels: ["big"], runner_group_name: "Default" })), true);
41
+ assert.equal(isSelfHosted(job({ labels: ["ubuntu-latest-8-cores"], runner_group_name: "Default Larger Runners" })), false);
42
+ });
43
+ it("minute shares split failed and cancelled job time", () => {
44
+ const s = minuteShares([job(), job({ conclusion: "failure" }), job({ conclusion: "cancelled", completed_at: T("10:30") }), job({ conclusion: "timed_out", completed_at: T("03:00") })]);
45
+ assert.deepEqual([s.seconds, s.failed, s.cancelled], [1350, 450, 600]);
46
+ assert.equal(s.failedShare, 450 / 1350); assert.equal(s.cancelledShare, 600 / 1350);
47
+ assert.deepEqual(minuteShares([]), { seconds: 0, failed: 0, cancelled: 0, failedShare: null, cancelledShare: null });
48
+ });
49
+ it("the critical job ends last; the first failed step is the earliest one", () => {
50
+ const a = job({ name: "lint", completed_at: T("02:00"), conclusion: "failure", steps: [step("Run lint", "00:40", "02:00", "failure")] });
51
+ const b = job({ name: "restore", completed_at: T("25:00"), conclusion: "failure", steps: [step("Run restore", "01:00", "25:00", "failure")] });
52
+ assert.equal(criticalJob([a, b, job({ conclusion: "skipped", started_at: T("30:00"), completed_at: T("30:00") })]).name, "restore");
53
+ assert.equal(criticalJob([]), null);
54
+ assert.deepEqual(firstFailedStep([b, a]), { job: "lint", step: "Run lint", cls: "lint", at: T("02:00") });
55
+ assert.equal(firstFailedStep([job()]), null);
56
+ });
57
+ });
@@ -100,3 +100,101 @@ export function waveReport(records, cfg = parseBudgetConfig(null)) {
100
100
  const verdict = waves.length < 3 ? `${waves.length}/3 waves measured` : m.within ? "within 25% of the model" : "OUTSIDE 25% of the model: tune budget.on_exceed and the nightly cadence";
101
101
  return { ...m, waves: waves.length, lines: [...m.lines, `total: model ${m.model} min, measured ${m.measured} min (${verdict})`] };
102
102
  }
103
+
104
+ // ---- Actions timing primitives (#5718, Forge CI W8): pure readers of runs/jobs/steps payloads, shared by `forgedock stats --release-ledger`. ----
105
+
106
+ const spanMs = (a, b) => { const d = Date.parse(b) - Date.parse(a); return Number.isFinite(d) && d > 0 ? d : 0; };
107
+ const FAILED = ["failure", "timed_out", "startup_failure"];
108
+ const lc = (v) => String(v ?? "").toLowerCase();
109
+ /** A job that ran (skipped jobs carry no time and no queue). */
110
+ export const jobRan = (j) => lc(j?.conclusion) !== "skipped" && spanMs(j?.started_at, j?.completed_at) > 0;
111
+ export const jobSeconds = (j) => spanMs(j?.started_at, j?.completed_at) / 1000;
112
+ /** Seconds a job waited for a runner (created -> started); null when the job never ran or the API gave no `created_at`. */
113
+ export const queueSeconds = (j) => (jobRan(j) && j.created_at ? spanMs(j.created_at, j.started_at) / 1000 : null);
114
+ /** Self-hosted by its labels, else by a runner group that is not GitHub's own. */
115
+ export function isSelfHosted(j) {
116
+ if ((j?.labels ?? []).some((l) => lc(l) === "self-hosted")) return true;
117
+ const g = lc(j?.runner_group_name);
118
+ return Boolean(g) && !/github actions|larger runners/.test(g);
119
+ }
120
+
121
+ /**
122
+ * Step classes, by step name only (the jobs API has no `uses`), ecosystem-neutral. Order matters: dependency installs are
123
+ * tested before toolchains so "Install Python dependencies" is `deps`. `Post ...` steps and the runner's own
124
+ * "Set up job" / "Complete job" are never setup.
125
+ */
126
+ export const STEP_CLASSES = Object.freeze([
127
+ ["checkout", /(^|[\s/])checkout(@|\s|$)|\bgit clone\b|\bfetch (the )?(repo|repository|sources?)\b/i],
128
+ ["deps", /\bnpm (ci|install|i)\b|\bpnpm (install|i)\b|\byarn( install)?\s*(--|$)|\bpip3? install\b|\bpoetry install\b|\buv (sync|pip install)\b|\bpipenv (install|sync)\b|\bbundle install\b|\bcomposer install\b|\bgo mod download\b|\bcargo fetch\b|\bdotnet restore\b|\binstall (\w+ )?(dependencies|deps|packages|requirements|modules)\b|\brestore (\w+ )?(dependencies|deps|cache)\b|actions\/cache|^cache\b|\bdependency cache\b/i],
129
+ ["image-build", /docker\/build-push-action|\bdocker (buildx )?build\b|\bbuildx bake\b|\bbuild (and push )?(the )?(\S+ )?(docker )?images?\b|\bimage build\b/i],
130
+ ["toolchain", /setup-[a-z0-9-]+(@|\s|$)|\baction-setup\b|^(run )?set ?up (?!job\b)\S+|\binstall (node|python|rust|go|java|ruby|php|deno|bun|toolchain)\b|\brustup\b|\bnvm (install|use)\b|\bpyenv\b|\basdf install\b|\btoolchain\b/i],
131
+ ["lint", /\b(lint\w*|eslint|ruff|flake8|prettier|format(ting)?( check)?|typecheck|type-check|tsc|mypy|lockfile|generated|drift|shellcheck)\b/i],
132
+ ]);
133
+ export const SETUP_CLASSES = Object.freeze(["checkout", "toolchain", "deps"]);
134
+ /** Failures of these classes are mechanical: no test ran, the fix is deterministic. */
135
+ export const MECHANICAL_CLASSES = Object.freeze(["checkout", "toolchain", "deps", "lint"]);
136
+ export function classifyStep(name) {
137
+ const n = String(name ?? "").trim();
138
+ if (!n || /^post\b/i.test(n) || /^(set up|complete) job$/i.test(n)) return null;
139
+ for (const [cls, re] of STEP_CLASSES) if (re.test(n)) return cls;
140
+ return null;
141
+ }
142
+ /** Seconds one job spent per setup class: {checkout, toolchain, deps, total}. */
143
+ export function jobSetup(j) {
144
+ const out = { checkout: 0, toolchain: 0, deps: 0, total: 0 };
145
+ for (const s of j?.steps ?? []) {
146
+ const cls = classifyStep(s?.name);
147
+ if (!SETUP_CLASSES.includes(cls)) continue;
148
+ const sec = spanMs(s.started_at, s.completed_at) / 1000;
149
+ out[cls] += sec; out.total += sec;
150
+ }
151
+ return out;
152
+ }
153
+ /** Job seconds by outcome: {seconds, failed, cancelled, failedShare, cancelledShare}; shares are null with no time. */
154
+ export function minuteShares(jobs) {
155
+ let seconds = 0, failed = 0, cancelled = 0;
156
+ for (const j of jobs ?? []) {
157
+ const s = jobSeconds(j), c = lc(j?.conclusion);
158
+ seconds += s;
159
+ if (FAILED.includes(c)) failed += s; else if (c === "cancelled") cancelled += s;
160
+ }
161
+ return { seconds, failed, cancelled, failedShare: seconds ? failed / seconds : null, cancelledShare: seconds ? cancelled / seconds : null };
162
+ }
163
+ /** The job that ends last: it sets the wall time of its run. Null when no job ran. */
164
+ export function criticalJob(jobs) {
165
+ let best = null;
166
+ for (const j of jobs ?? []) if (jobRan(j) && (!best || Date.parse(j.completed_at) > Date.parse(best.completed_at))) best = j;
167
+ return best;
168
+ }
169
+ /** The earliest failed step over `jobs`: {job, step, cls, at} (`cls` from classifyStep), or null. */
170
+ export function firstFailedStep(jobs) {
171
+ let best = null;
172
+ for (const j of jobs ?? []) for (const s of j?.steps ?? []) {
173
+ if (!FAILED.includes(lc(s?.conclusion)) || !s.completed_at) continue;
174
+ if (!best || Date.parse(s.completed_at) < Date.parse(best.at)) best = { job: j.name, step: s.name, cls: classifyStep(s.name), at: s.completed_at };
175
+ }
176
+ return best;
177
+ }
178
+ export const isFailedConclusion = (c) => FAILED.includes(lc(c));
179
+
180
+ const lines = (out) => String(out ?? "").split("\n").filter((l) => l.trim()).map((l) => JSON.parse(l));
181
+ const RUN_JQ = ".workflow_runs[] | {id, name, path, event, status, conclusion, head_sha, head_branch, run_attempt, created_at, run_started_at, updated_at, prs: [.pull_requests[]?.number], actor: (.triggering_actor.login // .actor.login // null)} | @json";
182
+ const JOB_JQ = ".jobs[] | {id, name, run_attempt, status, conclusion, created_at, started_at, completed_at, labels, runner_group_name, steps: [.steps[]? | {name, status, conclusion, started_at, completed_at}]} | @json";
183
+ /** The runs list API returns at most this many results per query; a fuller window is split in two. */
184
+ export const RUNS_QUERY_CAP = 1000;
185
+ const iso = (ms) => new Date(ms).toISOString().replace(/\.\d{3}Z$/, "Z");
186
+ /**
187
+ * Workflow runs created in [sinceMs, untilMs], optionally one branch and one event, paginated (`gh api --paginate`, so the
188
+ * caller's retry helper covers each page). A window that hits the API's 1000-result cap is halved and fetched again, so
189
+ * nothing is silently dropped. The runs API is slow (seconds per page): callers scope by branch and event.
190
+ */
191
+ export async function listRuns({ gh, repo, sinceMs, untilMs = Date.now(), branch = null, event = null, cap = RUNS_QUERY_CAP }) {
192
+ const q = `repos/${repo}/actions/runs?per_page=100&created=${iso(sinceMs)}..${iso(untilMs)}${branch ? `&branch=${encodeURIComponent(branch)}` : ""}${event ? `&event=${encodeURIComponent(event)}` : ""}`;
193
+ const runs = lines(await gh(["api", "--paginate", q, "--jq", RUN_JQ]));
194
+ if (runs.length < cap || untilMs - sinceMs < 2000) return runs;
195
+ const mid = Math.floor((sinceMs + untilMs) / 2000) * 1000;
196
+ const [a, b] = [await listRuns({ gh, repo, sinceMs, untilMs: mid, branch, event, cap }), await listRuns({ gh, repo, sinceMs: mid + 1000, untilMs, branch, event, cap })];
197
+ return [...b, ...a];
198
+ }
199
+ /** Jobs (with steps) of one run, every attempt, paginated. */
200
+ export const listRunJobs = async ({ gh, repo, runId }) => lines(await gh(["api", "--paginate", `repos/${repo}/actions/runs/${runId}/jobs?per_page=100&filter=all`, "--jq", JOB_JQ]));