forgedock 1.60.1 → 1.61.1
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/bin/config-schema.mjs +44 -1
- package/bin/engine/runlog.mjs +52 -0
- package/bin/engine-cli.mjs +9 -4
- package/bin/env/bench.mjs +38 -0
- package/bin/env/cli.mjs +134 -0
- package/bin/env/env.mjs +339 -0
- package/bin/forgedock.mjs +32 -3
- package/bin/help-text.mjs +2 -0
- package/bin/lean/ci-budget.mjs +3 -1
- package/bin/lean/ci-classify.mjs +74 -0
- package/bin/lean/ci-classify.test.mjs +147 -0
- package/bin/lean/ci-emit.mjs +175 -0
- package/bin/lean/ci-emit.test.mjs +177 -0
- package/bin/lean/ci-preflight.mjs +183 -0
- package/bin/lean/ci-preflight.test.mjs +122 -0
- package/bin/lean/ci-runner-health.mjs +213 -0
- package/bin/lean/ci-runner-health.test.mjs +113 -0
- package/bin/lean/ci-watch.mjs +79 -0
- package/bin/lean/ci-watch.test.mjs +80 -0
- package/bin/lean/depcache.mjs +38 -8
- package/bin/lean/deploy-stages.mjs +514 -0
- package/bin/lean/deploy-stages.test.mjs +580 -0
- package/bin/lean/effects.mjs +50 -0
- package/bin/lean/execution.mjs +8 -1
- package/bin/lean/lean.mjs +38 -6
- package/bin/lean/lean.test.mjs +61 -0
- package/bin/lean/release-deploy.mjs +12 -6
- package/bin/lean/release-flakes.mjs +16 -0
- package/bin/lean/release-flakes.test.mjs +15 -0
- package/bin/lean/release-gates.mjs +24 -1
- package/bin/lean/release-ledger.mjs +21 -0
- package/bin/lean/release-minutes-timing.test.mjs +57 -0
- package/bin/lean/release-minutes.mjs +98 -0
- package/bin/lean/release-promote.mjs +444 -0
- package/bin/lean/release-promote.test.mjs +470 -0
- package/bin/lean/release-rollback.mjs +14 -6
- package/bin/lean/release.mjs +31 -2
- package/bin/lean/sandbox-remote.mjs +11 -3
- package/bin/lean/testengine-recall.mjs +82 -0
- package/bin/lean/testengine-recall.test.mjs +103 -0
- package/bin/lean/testengine-shard.mjs +150 -0
- package/bin/lean/testengine-shard.test.mjs +111 -0
- package/bin/lean/testengine.mjs +486 -0
- package/bin/lean/testengine.test.mjs +303 -0
- package/bin/lean/verify-settle.test.mjs +156 -0
- package/bin/lean/verify.mjs +98 -3
- package/bin/pool/agent.mjs +57 -6
- package/bin/pool/ci-events.mjs +189 -0
- package/bin/pool/ci-events.test.mjs +143 -0
- package/bin/pool/docker.mjs +7 -0
- package/bin/pool/lane-tools.mjs +1 -0
- package/bin/pool/router.mjs +25 -1
- package/bin/pool/warm.mjs +1 -1
- package/bin/stats/ci-awareness.mjs +66 -0
- package/bin/stats/index.mjs +44 -3
- package/bin/stats/release-ledger.test.mjs +226 -0
- package/bin/stats/release.mjs +365 -1
- package/bin/stats/stats.test.mjs +36 -0
- package/docs/CI.md +31 -0
- package/docs/CONFIG.md +235 -2
- package/docs/ENV-LIBRARY.md +172 -0
- package/docs/STATS.md +43 -0
- package/docs/ci-events.md +88 -0
- package/docs/test-engine.md +98 -0
- package/package.json +1 -1
- package/pool/README.md +1 -0
- package/pool/image/entrypoint.sh +15 -3
- package/pool/services/docker-compose.yml +53 -0
- package/pool/services/git-mirror.sh +22 -0
- package/templates/github-actions/forge-env/action.yml +65 -0
package/bin/stats/release.mjs
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
* forge#4628: per-release regression rule over the `aggregate()` groups. Each metric is null when its own sample is
|
|
5
5
|
* below minN; a verdict is null when either side is null. There is no "pass" value, only regressed|improved|flat|null.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { DEFAULT_MIN_N, UNKNOWN, compareVersions, percentile } from "./aggregate.mjs";
|
|
10
|
+
import { cacheDir } from "./cache.mjs";
|
|
11
|
+
import * as M from "../lean/release-minutes.mjs";
|
|
8
12
|
|
|
9
13
|
export const METRICS_MARKER = "<!-- FORGE:METRICS v1 -->";
|
|
10
14
|
const isNum = (x) => typeof x === "number" && Number.isFinite(x);
|
|
@@ -73,3 +77,363 @@ export async function postMetrics({ gh, repo, pr, body }) {
|
|
|
73
77
|
else await gh(["api", "-X", "POST", `repos/${repo}/issues/${pr}/comments`, "-f", `body=${body}`]);
|
|
74
78
|
return mine ? "updated" : "created";
|
|
75
79
|
}
|
|
80
|
+
|
|
81
|
+
// ---- Release ledger (#5718, Forge CI W8): the plan's "Today (measured)" numbers from the Actions runs/jobs/steps API plus release state. ----
|
|
82
|
+
|
|
83
|
+
const CI_EVENTS = ["pull_request", "pull_request_target", "merge_group"];
|
|
84
|
+
const DEPLOY_EVENTS = ["push", "workflow_dispatch", "release", "workflow_run"];
|
|
85
|
+
const DEPLOY_NAME_RE = /deploy|rollout|publish|release|ship/i;
|
|
86
|
+
const t = (s) => Date.parse(s);
|
|
87
|
+
const p50 = (v) => percentile(v, 50), p90 = (v) => percentile(v, 90);
|
|
88
|
+
const lcs = (v) => String(v ?? "").toLowerCase();
|
|
89
|
+
const list = (v) => (Array.isArray(v) ? v : String(v ?? "").split(",")).map((x) => String(x).trim()).filter(Boolean);
|
|
90
|
+
const re = (s) => { try { return s ? new RegExp(s, "i") : null; } catch { return null; } };
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The plan's Targets table: today vs phase 1 vs end. `higherBetter` flips the verdict; a metric without targets is
|
|
94
|
+
* reported and compared against a baseline only. Units: s, min, h, n (a count), pct (a 0..1 share).
|
|
95
|
+
*/
|
|
96
|
+
export const LEDGER_METRICS = Object.freeze([
|
|
97
|
+
{ key: "mechanical_failure_surfaced_s", label: "Mechanical failure surfaced (run start -> run end)", unit: "s", phase1: 60, end: 30 },
|
|
98
|
+
{ key: "setup_self_hosted_s", label: "Job setup, self-hosted (checkout + toolchain + dependencies)", unit: "s", phase1: 30, end: 10 },
|
|
99
|
+
{ key: "setup_hosted_s", label: "Job setup, hosted (checkout + toolchain + dependencies)", unit: "s" },
|
|
100
|
+
{ key: "ci_round_wall_min_p50", label: "CI wall time per round (p50)", unit: "min", phase1: 10, end: 4 },
|
|
101
|
+
{ key: "pushes_per_release_pr_p50", label: "Pushes per release PR (p50)", unit: "n", phase1: 1.5, end: 1 },
|
|
102
|
+
{ key: "deploy_pregate_min_p50", label: "Deploy pre-gate (run start -> deploy job start)", unit: "min", phase1: 5, end: 1 },
|
|
103
|
+
{ key: "image_build_min_p50", label: "Image build (p50 per job)", unit: "min", phase1: 4, end: 1.5 },
|
|
104
|
+
{ key: "deploy_job_min_p50", label: "Deploy job (rollout)", unit: "min", phase1: 15, end: 5 },
|
|
105
|
+
{ key: "pr_to_live_clean_h_median", label: "Release PR opened -> live (clean, median)", unit: "h", phase1: 1, end: 0.5 },
|
|
106
|
+
{ key: "pr_to_live_h_median", label: "Release PR opened -> live (all, median)", unit: "h" },
|
|
107
|
+
{ key: "pr_to_live_h_p90", label: "Release PR opened -> live (all, p90)", unit: "h" },
|
|
108
|
+
{ key: "queue_s_p90", label: "Queue time (p90)", unit: "s", phase1: 30, end: 30 },
|
|
109
|
+
{ key: "failed_minute_share", label: "CI minutes in failed jobs", unit: "pct" },
|
|
110
|
+
{ key: "cancelled_minute_share", label: "CI minutes in cancelled jobs", unit: "pct" },
|
|
111
|
+
{ key: "ci_round_fail_rate", label: "CI rounds that fail", unit: "pct" },
|
|
112
|
+
{ key: "deploy_live_rate", label: "Deploy attempts that reached live", unit: "pct", higherBetter: true },
|
|
113
|
+
]);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* forge.yaml `stats:` keys of the ledger (all optional) -> config. `ledger_release_base` (default: the repo's default
|
|
117
|
+
* branch), `ledger_release_head` (default: `branches.staging` when set, else any head), `ledger_ci_workflows` (names or
|
|
118
|
+
* file names; default every workflow), `ledger_deploy_workflow` (name or file; default: detected), `ledger_deploy_job`
|
|
119
|
+
* (regex on the job name; default: detected).
|
|
120
|
+
*/
|
|
121
|
+
export function parseLedgerConfig(stats, branches) {
|
|
122
|
+
const s = stats && typeof stats === "object" ? stats : {};
|
|
123
|
+
const str = (k) => String(s[k] ?? "").trim() || null;
|
|
124
|
+
return { releaseBase: str("ledger_release_base"), releaseHead: str("ledger_release_head") ?? (String(branches?.staging ?? "").trim() || null),
|
|
125
|
+
ciWorkflows: list(s.ledger_ci_workflows), deployWorkflow: str("ledger_deploy_workflow"), deployJob: str("ledger_deploy_job") };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const wfMatch = (run, name) => { const n = lcs(name), p = lcs(run.path); return lcs(run.name) === n || p === n || p.endsWith(`/${n}`); };
|
|
129
|
+
const ranRun = (r) => r.status === "completed" && !["skipped", "action_required", "stale"].includes(lcs(r.conclusion));
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Which runs belong to the ledger (pure): the CI runs of each release PR and the deploy runs. A release PR is a PR into
|
|
133
|
+
* `base` (from `cfg.releaseHead` when set) opened in the window. Its CI runs are the PR-event runs that name it (or, for
|
|
134
|
+
* runs that name no PR, its head branch while it was open); a repo whose CI only runs on push falls back to the push runs
|
|
135
|
+
* of the head branch while the PR was open. The deploy workflow is `cfg.deployWorkflow`, else the non-PR workflow on `base`
|
|
136
|
+
* whose name or file says deploy/publish/release with the most runs.
|
|
137
|
+
* @returns {{releases: {pr: object, ci: object[]}[], deploy: object[], deployWorkflow: string|null, need: number[]}}
|
|
138
|
+
*/
|
|
139
|
+
export function planLedger({ prs = [], runs = [], base, cfg = {}, untilMs = Date.now() }) {
|
|
140
|
+
const wanted = (r) => !cfg.ciWorkflows?.length || cfg.ciWorkflows.some((n) => wfMatch(r, n));
|
|
141
|
+
const nonPr = runs.filter((r) => DEPLOY_EVENTS.includes(r.event));
|
|
142
|
+
let deployWorkflow = cfg.deployWorkflow ?? null;
|
|
143
|
+
if (!deployWorkflow) {
|
|
144
|
+
const counts = new Map();
|
|
145
|
+
for (const r of nonPr) if ((r.head_branch === base || r.event !== "push") && (DEPLOY_NAME_RE.test(r.name ?? "") || DEPLOY_NAME_RE.test(r.path ?? "")) && ranRun(r)) counts.set(r.path ?? r.name, (counts.get(r.path ?? r.name) ?? 0) + 1);
|
|
146
|
+
deployWorkflow = [...counts].sort((a, b) => b[1] - a[1] || String(a[0]).localeCompare(String(b[0])))[0]?.[0] ?? null;
|
|
147
|
+
}
|
|
148
|
+
const isDeploy = (r) => Boolean(deployWorkflow) && wfMatch(r, deployWorkflow);
|
|
149
|
+
const deploy = nonPr.filter(isDeploy).sort((a, b) => t(a.created_at) - t(b.created_at));
|
|
150
|
+
const rel = prs.filter((p) => p.base_ref === base && (!cfg.releaseHead || p.head_ref === cfg.releaseHead)).sort((a, b) => t(a.created_at) - t(b.created_at));
|
|
151
|
+
const releases = rel.map((pr) => {
|
|
152
|
+
const from = t(pr.created_at), to = t(pr.closed_at ?? pr.merged_at) || untilMs;
|
|
153
|
+
const open = (r) => r.head_branch === pr.head_ref && t(r.created_at) >= from && t(r.created_at) <= to;
|
|
154
|
+
let ci = runs.filter((r) => CI_EVENTS.includes(r.event) && wanted(r) && ((r.prs ?? []).includes(pr.number) || (!(r.prs ?? []).length && open(r))));
|
|
155
|
+
if (!ci.length) ci = runs.filter((r) => r.event === "push" && wanted(r) && !isDeploy(r) && open(r));
|
|
156
|
+
return { pr, ci };
|
|
157
|
+
});
|
|
158
|
+
const need = [...new Set([...releases.flatMap((x) => x.ci), ...deploy].filter(ranRun).map((r) => r.id))];
|
|
159
|
+
return { releases, deploy, deployWorkflow, need };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const round1 = (x, d = 1) => (x == null ? null : Math.round(x * 10 ** d) / 10 ** d);
|
|
163
|
+
const latest = (run, jobs) => (jobs ?? []).filter((j) => (j.run_attempt ?? 1) === (run.run_attempt ?? 1));
|
|
164
|
+
const first = (jobs) => (jobs ?? []).filter((j) => (j.run_attempt ?? 1) === 1);
|
|
165
|
+
/** Wall span of a run's first attempt: created -> the end of its first-attempt jobs (a later rerun must not stretch the round). */
|
|
166
|
+
function runSpan(run, jobs) {
|
|
167
|
+
const start = t(run.created_at);
|
|
168
|
+
const ends = (run.run_attempt ?? 1) > 1 ? first(jobs).filter(M.jobRan).map((j) => t(j.completed_at)) : [t(run.updated_at)];
|
|
169
|
+
const end = ends.length ? Math.max(...ends) : t(run.updated_at);
|
|
170
|
+
return { start, end };
|
|
171
|
+
}
|
|
172
|
+
/** The job that rolls out: `cfg.deployJob` (regex), else the longest ran job whose name says deploy, else the longest ran job. */
|
|
173
|
+
export function deployJobOf(jobs, cfg = {}) {
|
|
174
|
+
const ran = (jobs ?? []).filter(M.jobRan).sort((a, b) => M.jobSeconds(b) - M.jobSeconds(a));
|
|
175
|
+
const want = re(cfg.deployJob);
|
|
176
|
+
if (want) return ran.find((j) => want.test(j.name)) ?? null;
|
|
177
|
+
return ran.find((j) => DEPLOY_NAME_RE.test(j.name)) ?? ran[0] ?? null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The ledger report (pure). `data`: {repo, sinceMs, untilMs, base, prs, runs, jobs: {<run id>: job[]}, ledger?: [{pr, deployAttempts, live}]}.
|
|
182
|
+
* Every metric is null without a sample; `n` carries each sample size. Nothing is estimated.
|
|
183
|
+
*/
|
|
184
|
+
export function computeReleaseLedger(data, cfg = {}) {
|
|
185
|
+
const { repo, sinceMs, untilMs, base, jobs = {} } = data;
|
|
186
|
+
const plan = planLedger({ prs: data.prs, runs: data.runs, base, cfg, untilMs });
|
|
187
|
+
const jobsOf = (r) => jobs[r.id] ?? [];
|
|
188
|
+
const n = {}, m = {}, notes = [];
|
|
189
|
+
const ciRuns = [...new Map(plan.releases.flatMap((x) => x.ci).filter(ranRun).map((r) => [r.id, r])).values()];
|
|
190
|
+
const ciJobs = ciRuns.flatMap(jobsOf);
|
|
191
|
+
|
|
192
|
+
// rounds: one per (release PR, head sha)
|
|
193
|
+
const rounds = [], pushes = [];
|
|
194
|
+
for (const { pr, ci } of plan.releases) {
|
|
195
|
+
const bySha = new Map();
|
|
196
|
+
for (const r of ci) { if (!bySha.has(r.head_sha)) bySha.set(r.head_sha, []); bySha.get(r.head_sha).push(r); }
|
|
197
|
+
if (bySha.size) pushes.push({ pr: pr.number, pushes: bySha.size });
|
|
198
|
+
for (const [sha, rs] of bySha) {
|
|
199
|
+
const done = rs.filter(ranRun);
|
|
200
|
+
if (!done.length || rs.some((r) => r.status !== "completed")) continue;
|
|
201
|
+
const spans = done.map((r) => runSpan(r, jobsOf(r)));
|
|
202
|
+
const outcome = done.some((r) => M.isFailedConclusion(r.conclusion)) ? "fail" : done.some((r) => lcs(r.conclusion) === "cancelled") ? "cancelled" : "pass";
|
|
203
|
+
rounds.push({ pr: pr.number, sha, outcome, runs: done, wallMin: (Math.max(...spans.map((s) => s.end)) - Math.min(...spans.map((s) => s.start))) / 60000,
|
|
204
|
+
jobMin: done.flatMap((r) => first(jobsOf(r))).reduce((a, j) => a + M.jobSeconds(j), 0) / 60 });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const judged = rounds.filter((r) => r.outcome !== "cancelled");
|
|
208
|
+
m.ci_round_wall_min_p50 = round1(p50(judged.map((r) => r.wallMin))); m.ci_round_wall_min_p90 = round1(p90(judged.map((r) => r.wallMin)));
|
|
209
|
+
m.ci_round_job_min_p50 = round1(p50(judged.map((r) => r.jobMin)));
|
|
210
|
+
m.ci_round_fail_rate = judged.length ? round1(judged.filter((r) => r.outcome === "fail").length / judged.length, 3) : null;
|
|
211
|
+
n.rounds = judged.length;
|
|
212
|
+
m.pushes_per_release_pr_p50 = round1(p50(pushes.map((x) => x.pushes))); m.pushes_per_release_pr_max = pushes.length ? Math.max(...pushes.map((x) => x.pushes)) : null;
|
|
213
|
+
n.release_prs = plan.releases.length; n.release_prs_with_ci = pushes.length;
|
|
214
|
+
|
|
215
|
+
const sh = M.minuteShares(ciJobs);
|
|
216
|
+
m.failed_minute_share = round1(sh.failedShare, 3); m.cancelled_minute_share = round1(sh.cancelledShare, 3); m.ci_job_minutes = round1(sh.seconds / 60, 0);
|
|
217
|
+
n.ci_runs = ciRuns.length; n.ci_jobs = ciJobs.filter(M.jobRan).length;
|
|
218
|
+
|
|
219
|
+
// critical path: the job that ends last in each judged round (latest attempt of every run of that head)
|
|
220
|
+
const crit = new Map(), byName = new Map();
|
|
221
|
+
for (const r of ciRuns) for (const j of latest(r, jobsOf(r)).filter(M.jobRan)) { if (!byName.has(j.name)) byName.set(j.name, []); byName.get(j.name).push(j); }
|
|
222
|
+
let critRuns = 0;
|
|
223
|
+
for (const rd of judged) {
|
|
224
|
+
const c = M.criticalJob(rd.runs.flatMap((r) => latest(r, jobsOf(r))));
|
|
225
|
+
if (c) { critRuns++; crit.set(c.name, (crit.get(c.name) ?? 0) + 1); }
|
|
226
|
+
}
|
|
227
|
+
const critical_path = [...crit].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, 5).map(([job, runs]) => {
|
|
228
|
+
const js = byName.get(job) ?? [];
|
|
229
|
+
return { job, rounds: runs, of: critRuns, min_p50: round1(p50(js.map((j) => M.jobSeconds(j) / 60))), fail_rate: js.length ? round1(js.filter((j) => M.isFailedConclusion(j.conclusion)).length / js.length, 3) : null };
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// deploy
|
|
233
|
+
const deployRuns = plan.deploy.filter(ranRun).filter((r) => jobsOf(r).some(M.jobRan));
|
|
234
|
+
const attempts = deployRuns.map((r) => {
|
|
235
|
+
const js = latest(r, jobsOf(r)), dj = deployJobOf(js, cfg);
|
|
236
|
+
const live = lcs(r.conclusion) === "success" && Boolean(dj) && lcs(dj.conclusion) === "success";
|
|
237
|
+
return { run: r, jobs: js, dj, live, liveAt: live ? t(dj.completed_at) : null };
|
|
238
|
+
});
|
|
239
|
+
const liveAttempts = attempts.filter((a) => a.live);
|
|
240
|
+
n.deploy_attempts = attempts.length; n.deploy_live = liveAttempts.length;
|
|
241
|
+
m.deploy_live_rate = attempts.length ? round1(liveAttempts.length / attempts.length, 3) : null;
|
|
242
|
+
m.deploy_pregate_min_p50 = round1(p50(liveAttempts.map((a) => (t(a.dj.started_at) - t(a.run.run_started_at ?? a.run.created_at)) / 60000)));
|
|
243
|
+
m.deploy_job_min_p50 = round1(p50(liveAttempts.map((a) => M.jobSeconds(a.dj) / 60)));
|
|
244
|
+
m.deploy_run_min_p50 = round1(p50(liveAttempts.map((a) => (t(a.run.updated_at) - t(a.run.run_started_at ?? a.run.created_at)) / 60000)));
|
|
245
|
+
const stepSecs = new Map();
|
|
246
|
+
for (const a of liveAttempts) for (const s of a.dj.steps ?? []) {
|
|
247
|
+
const sec = (t(s.completed_at) - t(s.started_at)) / 1000;
|
|
248
|
+
if (!(sec > 0)) continue;
|
|
249
|
+
if (!stepSecs.has(s.name)) stepSecs.set(s.name, []);
|
|
250
|
+
stepSecs.get(s.name).push(sec);
|
|
251
|
+
}
|
|
252
|
+
const deploy_steps = [...stepSecs].map(([step, v]) => ({ step, min_p50: round1(p50(v) / 60, 2), n: v.length })).sort((a, b) => b.min_p50 - a.min_p50).slice(0, 10);
|
|
253
|
+
|
|
254
|
+
// setup, queue, image build: over every ledger job that ran
|
|
255
|
+
const allJobs = [...ciJobs, ...deployRuns.flatMap(jobsOf)].filter(M.jobRan);
|
|
256
|
+
m.queue_s_p90 = round1(p90(allJobs.map(M.queueSeconds).filter((x) => x != null)), 0); m.queue_s_p50 = round1(p50(allJobs.map(M.queueSeconds).filter((x) => x != null)), 0);
|
|
257
|
+
const setup = {};
|
|
258
|
+
for (const [kind, js] of [["self_hosted", allJobs.filter(M.isSelfHosted)], ["hosted", allJobs.filter((j) => !M.isSelfHosted(j))]]) {
|
|
259
|
+
const per = js.map(M.jobSetup).filter((s) => s.total > 0);
|
|
260
|
+
const cls = (k) => round1(p50(per.map((s) => s[k]).filter((x) => x > 0)), 0);
|
|
261
|
+
setup[kind] = { jobs: per.length, checkout_s: cls("checkout"), toolchain_s: cls("toolchain"), deps_s: cls("deps"), };
|
|
262
|
+
setup[kind].total_s = per.length ? (setup[kind].checkout_s ?? 0) + (setup[kind].toolchain_s ?? 0) + (setup[kind].deps_s ?? 0) : null; // the sum of the three class medians, as the plan states it
|
|
263
|
+
m[`setup_${kind}_s`] = setup[kind].total_s;
|
|
264
|
+
}
|
|
265
|
+
const img = allJobs.map((j) => (j.steps ?? []).filter((s) => M.classifyStep(s.name) === "image-build").reduce((a, s) => a + Math.max(0, t(s.completed_at) - t(s.started_at)) / 60000, 0)).filter((x) => x > 0);
|
|
266
|
+
m.image_build_min_p50 = round1(p50(img)); n.image_build_jobs = img.length;
|
|
267
|
+
|
|
268
|
+
// failure surfacing: when a failed run ends (what an agent sees today) vs when its first failed step ended
|
|
269
|
+
const surfaced = [], firstStep = [], mech = [];
|
|
270
|
+
for (const r of ciRuns.filter((x) => M.isFailedConclusion(x.conclusion))) {
|
|
271
|
+
const ff = M.firstFailedStep(latest(r, jobsOf(r)));
|
|
272
|
+
if (!ff) continue;
|
|
273
|
+
const start = t(r.run_started_at ?? r.created_at), end = (t(r.updated_at) - start) / 1000;
|
|
274
|
+
surfaced.push(end); firstStep.push((t(ff.at) - start) / 1000);
|
|
275
|
+
if (M.MECHANICAL_CLASSES.includes(ff.cls)) mech.push(end);
|
|
276
|
+
}
|
|
277
|
+
m.failure_surfaced_s_p50 = round1(p50(surfaced), 0); m.first_failed_step_s_p50 = round1(p50(firstStep), 0);
|
|
278
|
+
m.mechanical_failure_surfaced_s = round1(p50(mech), 0); n.failed_runs = surfaced.length; n.mechanical_failures = mech.length;
|
|
279
|
+
|
|
280
|
+
// releases: opened -> live
|
|
281
|
+
const merged = plan.releases.map((x) => x.pr).filter((p) => p.merged_at);
|
|
282
|
+
const ledgerBy = new Map((data.ledger ?? []).filter((l) => l?.pr != null).map((l) => [Number(l.pr), l]));
|
|
283
|
+
const releases = merged.map((pr, i) => {
|
|
284
|
+
const next = merged[i + 1] ? t(merged[i + 1].merged_at) : Infinity;
|
|
285
|
+
let own = attempts.filter((a) => a.run.head_sha === pr.merge_commit_sha);
|
|
286
|
+
if (!own.length) own = attempts.filter((a) => t(a.run.created_at) >= t(pr.merged_at) && t(a.run.created_at) < next);
|
|
287
|
+
const firstLive = own.find((a) => a.live);
|
|
288
|
+
const liveAt = plan.deployWorkflow ? firstLive?.liveAt ?? null : t(pr.merged_at);
|
|
289
|
+
const led = ledgerBy.get(pr.number);
|
|
290
|
+
const tries = Math.max(own.length, Number(led?.deployAttempts) || 0);
|
|
291
|
+
return { pr: pr.number, opened: pr.created_at, merged: pr.merged_at, live: liveAt ? new Date(liveAt).toISOString() : null, hours: liveAt ? round1((liveAt - t(pr.created_at)) / 3600000, 2) : null,
|
|
292
|
+
pushes: pushes.find((x) => x.pr === pr.number)?.pushes ?? null, deploy_attempts: tries, clean: Boolean(liveAt) && tries <= 1 && (!own.length || own[0].live) };
|
|
293
|
+
});
|
|
294
|
+
if (!plan.deployWorkflow) notes.push("no deploy workflow found: live = the release PR's merge time (set stats.ledger_deploy_workflow)");
|
|
295
|
+
else if (!cfg.deployWorkflow) notes.push(`deploy workflow detected: ${plan.deployWorkflow} (set stats.ledger_deploy_workflow to pin it)`);
|
|
296
|
+
const wentLive = releases.filter((r) => r.hours != null), clean = wentLive.filter((r) => r.clean);
|
|
297
|
+
m.pr_to_live_h_median = round1(p50(wentLive.map((r) => r.hours)), 2); m.pr_to_live_h_p90 = round1(p90(wentLive.map((r) => r.hours)), 2);
|
|
298
|
+
m.pr_to_live_clean_h_median = round1(p50(clean.map((r) => r.hours)), 2); m.pr_to_live_clean_h_p90 = round1(p90(clean.map((r) => r.hours)), 2);
|
|
299
|
+
n.live_releases = wentLive.length; n.clean_releases = clean.length;
|
|
300
|
+
const missing = plan.need.filter((id) => !jobs[id]).length;
|
|
301
|
+
if (missing) notes.push(`${missing} run(s) without job data (not fetched): job-level metrics exclude them`);
|
|
302
|
+
|
|
303
|
+
return { v: 1, repo, base, window: { since: new Date(sinceMs).toISOString(), until: new Date(untilMs).toISOString(), days: round1((untilMs - sinceMs) / 86400000) },
|
|
304
|
+
deploy_workflow: plan.deployWorkflow, n, metrics: m, table: ledgerTable(m), critical_path, setup, deploy_steps, releases, notes };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const fmtVal = (unit, v) => (v == null ? "n/a" : unit === "pct" ? `${(v * 100).toFixed(1)}%` : unit === "n" ? String(v) : `${v} ${unit}`);
|
|
308
|
+
/** Rows of the Targets table: today vs phase 1 vs end, with `status` end-met | phase1-met | not-met | no-target | n/a. */
|
|
309
|
+
export function ledgerTable(metrics, defs = LEDGER_METRICS) {
|
|
310
|
+
return defs.map((d) => {
|
|
311
|
+
const v = metrics[d.key] ?? null;
|
|
312
|
+
const meets = (target) => (d.higherBetter ? v >= target : v <= target);
|
|
313
|
+
const status = d.end == null ? "no-target" : v == null ? "n/a" : meets(d.end) ? "end-met" : meets(d.phase1) ? "phase1-met" : "not-met";
|
|
314
|
+
return { key: d.key, label: d.label, unit: d.unit, today: v, phase1: d.phase1 ?? null, end: d.end ?? null, status };
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const mdTable = (head, rows) => { const line = (r) => `| ${r.join(" | ")} |`; return [line(head), line(head.map(() => "---")), ...rows.map(line)]; };
|
|
319
|
+
const tgt = (unit, v, hb) => (v == null ? "-" : `${hb ? ">=" : "<="} ${fmtVal(unit, v)}`);
|
|
320
|
+
export function renderReleaseLedger(r) {
|
|
321
|
+
const defs = new Map(LEDGER_METRICS.map((d) => [d.key, d]));
|
|
322
|
+
const out = [`Release ledger: ${r.repo}, ${r.window.since.slice(0, 10)} to ${r.window.until.slice(0, 10)} (${r.window.days} days), release base ${r.base}`,
|
|
323
|
+
`${r.n.release_prs} release PR(s), ${r.n.live_releases} live (${r.n.clean_releases} clean); ${r.n.ci_runs} CI run(s), ${r.n.ci_jobs} job(s), ${r.n.rounds} round(s); ${r.n.deploy_attempts} deploy attempt(s), ${r.n.deploy_live} reached live`, "",
|
|
324
|
+
...mdTable(["Stage", "Today (measured)", "Phase 1 target", "End target", "Status"], r.table.map((x) => { const hb = defs.get(x.key)?.higherBetter; return [x.label, fmtVal(x.unit, x.today), tgt(x.unit, x.phase1, hb), tgt(x.unit, x.end, hb), x.status]; }))];
|
|
325
|
+
const s = r.setup;
|
|
326
|
+
out.push("", "Job setup p50 (checkout + toolchain + dependencies):");
|
|
327
|
+
for (const k of ["self_hosted", "hosted"]) out.push(` ${k.replace("_", "-")}: ${s[k].jobs ? `${s[k].checkout_s ?? "n/a"} s + ${s[k].toolchain_s ?? "n/a"} s + ${s[k].deps_s ?? "n/a"} s (total ${s[k].total_s} s, ${s[k].jobs} job(s))` : "n/a"}`);
|
|
328
|
+
out.push(`CI round: wall p50 ${fmtVal("min", r.metrics.ci_round_wall_min_p50)}, p90 ${fmtVal("min", r.metrics.ci_round_wall_min_p90)}, ${fmtVal("min", r.metrics.ci_round_job_min_p50)} of jobs p50; pushes per release PR p50 ${r.metrics.pushes_per_release_pr_p50 ?? "n/a"} (max ${r.metrics.pushes_per_release_pr_max ?? "n/a"})`);
|
|
329
|
+
out.push(`Failures: surfaced at run end p50 ${fmtVal("s", r.metrics.failure_surfaced_s_p50)}; the first failed step ended at p50 ${fmtVal("s", r.metrics.first_failed_step_s_p50)} (${r.n.failed_runs} failed run(s), ${r.n.mechanical_failures} mechanical)`);
|
|
330
|
+
out.push(`Queue: p50 ${fmtVal("s", r.metrics.queue_s_p50)}, p90 ${fmtVal("s", r.metrics.queue_s_p90)}`);
|
|
331
|
+
if (r.critical_path.length) out.push("", "Critical path (the job that ends last):", ...mdTable(["Job", "Rounds", "p50", "Fails"], r.critical_path.map((c) => [c.job, `${c.rounds} of ${c.of}`, fmtVal("min", c.min_p50), fmtVal("pct", c.fail_rate)])));
|
|
332
|
+
if (r.deploy_steps.length) out.push("", `Deploy job by step (p50 over ${r.n.deploy_live} live deploy(s); run p50 ${fmtVal("min", r.metrics.deploy_run_min_p50)}):`, ...mdTable(["Step", "p50"], r.deploy_steps.map((d) => [d.step, fmtVal("min", d.min_p50)])));
|
|
333
|
+
for (const note of r.notes) out.push("", `note: ${note}`);
|
|
334
|
+
return out.join("\n");
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** Baseline record of a report: what `--baseline compare` reads back. */
|
|
338
|
+
export const baselineOf = (r, now = Date.now()) => ({ v: 1, saved_at: new Date(now).toISOString(), repo: r.repo, window: r.window, n: r.n, metrics: r.metrics });
|
|
339
|
+
/** Before/after per metric, measured the same way: verdict improved | regressed | flat (within 5%, or 2 points for a share) | null when either side is missing. */
|
|
340
|
+
export function compareBaseline(base, r, defs = LEDGER_METRICS) {
|
|
341
|
+
const rows = defs.map((d) => {
|
|
342
|
+
const before = base?.metrics?.[d.key] ?? null, after = r.metrics[d.key] ?? null;
|
|
343
|
+
let verdict = null, delta = null;
|
|
344
|
+
if (before != null && after != null) {
|
|
345
|
+
delta = round1(after - before, 3);
|
|
346
|
+
const rel = d.unit === "pct" ? Math.abs(delta) <= 0.02 : before === 0 ? after === 0 : Math.abs(delta / before) <= 0.05;
|
|
347
|
+
verdict = rel ? "flat" : (delta < 0) === !d.higherBetter ? "improved" : "regressed";
|
|
348
|
+
}
|
|
349
|
+
return { key: d.key, label: d.label, unit: d.unit, before, after, delta, verdict };
|
|
350
|
+
});
|
|
351
|
+
return { baseline: { saved_at: base?.saved_at ?? null, window: base?.window ?? null, n: base?.n ?? null }, rows };
|
|
352
|
+
}
|
|
353
|
+
export function renderBaselineCompare(c, r) {
|
|
354
|
+
const w = (x) => (x ? `${x.since.slice(0, 10)} to ${x.until.slice(0, 10)}` : "n/a");
|
|
355
|
+
return [`Release ledger before/after: ${r.repo}`, `before: ${w(c.baseline.window)} (saved ${c.baseline.saved_at ?? "n/a"}); after: ${w(r.window)}`, "",
|
|
356
|
+
...mdTable(["Stage", "Before", "After", "Verdict"], c.rows.map((x) => [x.label, fmtVal(x.unit, x.before), fmtVal(x.unit, x.after), x.verdict ?? "n/a"]))].join("\n");
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const PR_JQ = ".[] | {number, title, state, created_at, merged_at, closed_at, merge_commit_sha, head_ref: .head.ref, head_sha: .head.sha, base_ref: .base.ref} | @json";
|
|
360
|
+
const jsonLines = (out) => String(out ?? "").split("\n").filter((l) => l.trim()).map((l) => JSON.parse(l));
|
|
361
|
+
/** PRs into `base` opened since `sinceMs`, newest first; stops paging at the first page that reaches the window's start. */
|
|
362
|
+
export async function listReleasePrs({ gh, repo, base, sinceMs }) {
|
|
363
|
+
const out = [];
|
|
364
|
+
for (let page = 1; page <= 50; page++) {
|
|
365
|
+
const rows = jsonLines(await gh(["api", `repos/${repo}/pulls?state=all&base=${encodeURIComponent(base)}&sort=created&direction=desc&per_page=100&page=${page}`, "--jq", PR_JQ]));
|
|
366
|
+
out.push(...rows.filter((p) => t(p.created_at) >= sinceMs));
|
|
367
|
+
if (rows.length < 100 || t(rows[rows.length - 1].created_at) < sinceMs) break;
|
|
368
|
+
}
|
|
369
|
+
return out;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const JOBS_CACHE = "actions-jobs.json";
|
|
373
|
+
function loadJobsCache(repo, env) { try { const c = JSON.parse(readFileSync(join(cacheDir(repo, env), JOBS_CACHE), "utf8")); return c?.v === 1 && c.runs ? c : { v: 1, runs: {} }; } catch { return { v: 1, runs: {} }; } }
|
|
374
|
+
function saveJobsCache(repo, cache, env) { try { const dir = cacheDir(repo, env); mkdirSync(dir, { recursive: true }); const tmp = join(dir, `${JOBS_CACHE}.${process.pid}.tmp`); writeFileSync(tmp, JSON.stringify(cache)); renameSync(tmp, join(dir, JOBS_CACHE)); } catch { /* the cache is optional */ } }
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Reads everything the ledger needs: the release PRs, the runs of the release head branches and of the base (paginated, one
|
|
378
|
+
* query per branch and event) and the jobs of the ledger's runs only (4 at a time). Jobs of a completed run never change, so they are cached per (run, attempt) next to the stats cache;
|
|
379
|
+
* `maxRuns` bounds the job fetches of one call (newest first) and the report notes what was left out.
|
|
380
|
+
*/
|
|
381
|
+
export async function gatherReleaseLedger({ gh, repo, sinceMs, untilMs = Date.now(), cfg = {}, env = process.env, useCache = true, maxRuns = 600, onProgress = () => {}, ledger = [] }) {
|
|
382
|
+
const base = cfg.releaseBase ?? String(await gh(["api", `repos/${repo}`, "--jq", ".default_branch"])).trim();
|
|
383
|
+
const prs = await listReleasePrs({ gh, repo, base, sinceMs });
|
|
384
|
+
// Scoped reads: PR-event runs of each release head branch (push runs only where a head has none) and the non-PR runs of the base.
|
|
385
|
+
const heads = [...new Set(prs.filter((p) => !cfg.releaseHead || p.head_ref === cfg.releaseHead).map((p) => p.head_ref))], seen = new Map();
|
|
386
|
+
const read = async (branch, event) => { for (const r of await M.listRuns({ gh, repo, sinceMs, untilMs, branch, event })) seen.set(r.id, r); };
|
|
387
|
+
for (const head of heads) {
|
|
388
|
+
const before = seen.size;
|
|
389
|
+
for (const e of CI_EVENTS) await read(head, e);
|
|
390
|
+
if (seen.size === before) await read(head, "push");
|
|
391
|
+
}
|
|
392
|
+
for (const e of DEPLOY_EVENTS) await read(base, e);
|
|
393
|
+
const runs = [...seen.values()];
|
|
394
|
+
const plan = planLedger({ prs, runs, base, cfg, untilMs });
|
|
395
|
+
const byId = new Map(runs.map((r) => [r.id, r]));
|
|
396
|
+
const cache = useCache ? loadJobsCache(repo, env) : { v: 1, runs: {} };
|
|
397
|
+
const key = (r) => `${r.id}:${r.run_attempt ?? 1}`;
|
|
398
|
+
const jobs = {}, todo = [];
|
|
399
|
+
for (const id of plan.need) { const r = byId.get(id), hit = cache.runs[key(r)]; if (hit) jobs[id] = hit; else todo.push(r); }
|
|
400
|
+
todo.sort((a, b) => t(b.created_at) - t(a.created_at));
|
|
401
|
+
const batch = todo.slice(0, maxRuns);
|
|
402
|
+
let done = 0;
|
|
403
|
+
const worker = async () => { for (let r; (r = batch.shift());) { jobs[r.id] = await M.listRunJobs({ gh, repo, runId: r.id }); cache.runs[key(r)] = jobs[r.id]; onProgress({ done: ++done, total: done + batch.length }); } };
|
|
404
|
+
await Promise.all(Array.from({ length: 4 }, worker));
|
|
405
|
+
if (useCache && done) saveJobsCache(repo, cache, env);
|
|
406
|
+
return { repo, sinceMs, untilMs, base, prs, runs, jobs, ledger };
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** `--since` of the ledger: a date (YYYY-MM-DD[T...]) or a window (`21d`, `36h`); default 21 days. */
|
|
410
|
+
export function ledgerSince(since, now = Date.now()) {
|
|
411
|
+
if (!since) return now - 21 * 86400000;
|
|
412
|
+
const w = /^(\d+)([dh])$/.exec(since);
|
|
413
|
+
if (w) return now - Number(w[1]) * (w[2] === "d" ? 86400000 : 3600000);
|
|
414
|
+
const ms = /^\d{4}-\d{2}-\d{2}/.test(since) ? Date.parse(since) : NaN;
|
|
415
|
+
if (Number.isNaN(ms)) throw new Error(`--since must be a date (YYYY-MM-DD) or a window (21d, 36h) with --release-ledger: ${since}`);
|
|
416
|
+
return ms;
|
|
417
|
+
}
|
|
418
|
+
export const baselinePath = (repo, file, env = process.env) => file ?? join(cacheDir(repo, env), "release-ledger-baseline.json");
|
|
419
|
+
|
|
420
|
+
/** `forgedock stats --release-ledger`: 0, 1 on a read failure, 2 when `--baseline compare` has no baseline. */
|
|
421
|
+
export async function runReleaseLedger(opts, deps = {}) {
|
|
422
|
+
const now = deps.now?.() ?? Date.now(), env = deps.env ?? process.env, write = deps.write ?? ((s) => process.stdout.write(s));
|
|
423
|
+
const cfg = { ...(deps.config ?? {}), ...(opts.deployWorkflow ? { deployWorkflow: opts.deployWorkflow } : {}), ...(opts.releaseHead ? { releaseHead: opts.releaseHead === "any" ? null : opts.releaseHead } : {}) };
|
|
424
|
+
const data = await gatherReleaseLedger({ gh: deps.gh, repo: opts.repo, sinceMs: ledgerSince(opts.since, now), untilMs: now, cfg, env, useCache: opts.cache !== false, onProgress: deps.onProgress, ledger: deps.ledger ?? [] });
|
|
425
|
+
const report = computeReleaseLedger(data, cfg);
|
|
426
|
+
const file = baselinePath(opts.repo, opts.baselineFile, env);
|
|
427
|
+
if (opts.baseline === "compare") {
|
|
428
|
+
let base = null;
|
|
429
|
+
try { base = JSON.parse(readFileSync(file, "utf8")); } catch { /* reported below */ }
|
|
430
|
+
if (!base?.metrics) { process.stderr.write(`forgedock stats: no baseline at ${file} (run --release-ledger --baseline save first)\n`); return 2; }
|
|
431
|
+
const cmp = compareBaseline(base, report);
|
|
432
|
+
write(`${opts.json ? JSON.stringify({ ...report, compare: cmp }, null, 2) : `${renderBaselineCompare(cmp, report)}\n\n${renderReleaseLedger(report)}`}\n`);
|
|
433
|
+
return 0;
|
|
434
|
+
}
|
|
435
|
+
if (opts.baseline === "save") { mkdirSync(dirname(file), { recursive: true }); writeFileSync(file, `${JSON.stringify(baselineOf(report, now), null, 2)}\n`); }
|
|
436
|
+
write(`${opts.json ? JSON.stringify(report, null, 2) : renderReleaseLedger(report)}\n`);
|
|
437
|
+
if (opts.baseline === "save" && !opts.json) write(`\nbaseline saved: ${file}\n`);
|
|
438
|
+
return 0;
|
|
439
|
+
}
|
package/bin/stats/stats.test.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { cacheDir } from "./cache.mjs";
|
|
|
13
13
|
import { fetchGithubRecords, parseTelemetryComments, runsFromRecords, toModel } from "./github-source.mjs";
|
|
14
14
|
import { buildReport, makeProgressPrinter, parseArgs, parseSince, readAlertConfig, runStats, sinceToTimestamp } from "./index.mjs";
|
|
15
15
|
import { lanesOfLog, readLanes, readLocalLaneRuns, readLocalRuns, summariseLog } from "./local-source.mjs";
|
|
16
|
+
import { ciAwarenessReport, lanesOf, readCiLogs, renderCiAwareness } from "./ci-awareness.mjs";
|
|
16
17
|
import { renderAlerts, renderCompact, renderJson, renderMarkdown } from "./render.mjs";
|
|
17
18
|
import { edgeQuery, parseEdge, verdictMix, contextPackAb, renderContextAb, builderTierReport, renderTiers, exploreAb, renderExploreAb, laneProfileReport, renderLaneProfiles } from "./query.mjs";
|
|
18
19
|
|
|
@@ -1081,3 +1082,38 @@ describe("merged vs verified (#5339)", () => {
|
|
|
1081
1082
|
assert.deepEqual(g.flow.milestones, [{ milestone: "M1", merged: 2, verified: 1 }, { milestone: "M2", merged: 1, verified: 1 }]);
|
|
1082
1083
|
});
|
|
1083
1084
|
});
|
|
1085
|
+
|
|
1086
|
+
describe("stats --ci-awareness (#5692)", () => {
|
|
1087
|
+
const T = (sec) => new Date(Date.UTC(2026, 10, 15, 10, 0, sec)).toISOString();
|
|
1088
|
+
const lane = (version, aware, rounds) => [
|
|
1089
|
+
{ event: "RUN_START", version, ts: T(0) },
|
|
1090
|
+
...aware.map((s, i) => ({ event: "CI_AWARE", event_ts: T(100 + i), aware_ts: T(100 + i + s), ts: T(100 + i + s) })),
|
|
1091
|
+
...rounds.map(([pr, at]) => ({ event: "CI_FIX_ROUND", pr, ts: T(at) })),
|
|
1092
|
+
{ event: "RUN_TERMINAL", ts: T(1000) },
|
|
1093
|
+
];
|
|
1094
|
+
it("per version: median/p90 awareness, rounds per PR and wall per round", () => {
|
|
1095
|
+
const r = ciAwarenessReport([lane("1.59.0", [], [[7, 100]]), lane("1.60.0", [10, 20, 30, 40, 50], [[8, 100], [8, 400]])]);
|
|
1096
|
+
const old = r.versions.find((v) => v.version === "1.59.0"), cur = r.versions.find((v) => v.version === "1.60.0");
|
|
1097
|
+
assert.equal(old.event_driven, false); assert.equal(old.awareness_s.n, 0); assert.equal(old.rounds_per_pr.median, 1);
|
|
1098
|
+
assert.equal(cur.event_driven, true); assert.deepEqual([cur.awareness_s.median, cur.awareness_s.p90, cur.awareness_s.n], [30, 50, 5]);
|
|
1099
|
+
assert.equal(cur.rounds_per_pr.median, 2); assert.deepEqual(cur.round_wall_s.n, 2); assert.equal(cur.round_wall_s.median, 300);
|
|
1100
|
+
assert.equal(r.total.lanes, 2);
|
|
1101
|
+
});
|
|
1102
|
+
it("lanesOf splits RUN_START slices; render and the CLI read local logs", () => {
|
|
1103
|
+
assert.equal(lanesOf([...lane("a", [], []), ...lane("b", [], [])]).length, 2);
|
|
1104
|
+
const dir = tmpDir("ci-aware-"); mkdirSync(dir, { recursive: true });
|
|
1105
|
+
writeFileSync(join(dir, "o__r__7.jsonl"), `${lane("1.60.0", [12], [[7, 100]]).map((e) => JSON.stringify(e)).join("\n")}\n{broken\n`);
|
|
1106
|
+
writeFileSync(join(dir, "x__y__8.jsonl"), `${lane("1.60.0", [99], []).map((e) => JSON.stringify(e)).join("\n")}\n`);
|
|
1107
|
+
assert.equal(readCiLogs(dir, "o/r").length, 1);
|
|
1108
|
+
const text = renderCiAwareness(ciAwarenessReport(readCiLogs(dir)));
|
|
1109
|
+
assert.match(text, /awareness latency: median 12s, p90 99s \(n=2\)/); assert.match(text, /event-driven/);
|
|
1110
|
+
assert.equal(parseArgs(["--ci-awareness"]).ciAwareness, true);
|
|
1111
|
+
});
|
|
1112
|
+
it("--since <date> keeps only the lanes started on/after it", () => {
|
|
1113
|
+
const logs = [lane("1.59.0", [], [[7, 100]]), lane("1.60.0", [10], [[8, 100]])];
|
|
1114
|
+
assert.equal(ciAwarenessReport(logs, { sinceMs: Date.parse(T(0)) }).total.lanes, 2);
|
|
1115
|
+
assert.equal(ciAwarenessReport(logs, { sinceMs: Date.parse(T(1)) }).total.lanes, 0);
|
|
1116
|
+
assert.equal(ciAwarenessReport([[{ event: "RUN_START", version: "x" }]], { sinceMs: 1 }).total.lanes, 0); // no start time
|
|
1117
|
+
assert.equal(ciAwarenessReport(logs).total.lanes, 2);
|
|
1118
|
+
});
|
|
1119
|
+
});
|
package/docs/CI.md
CHANGED
|
@@ -204,6 +204,37 @@ Uncomment the `Set Commit Status` step in the workflow template to add a pass/fa
|
|
|
204
204
|
|
|
205
205
|
---
|
|
206
206
|
|
|
207
|
+
## Superseded runs
|
|
208
|
+
|
|
209
|
+
A push to a PR branch makes the runs of the previous head useless, but GitHub lets them finish. On ForgeDock's own
|
|
210
|
+
release PRs, 39% of CI job minutes over 7 days (2026-11-08 to 2026-11-15) went to jobs that were then cancelled. Two ways to stop paying for it:
|
|
211
|
+
|
|
212
|
+
**In the workflow (preferred, no API calls).** Add a `concurrency` block to every workflow that only verifies a head:
|
|
213
|
+
|
|
214
|
+
```yaml
|
|
215
|
+
concurrency:
|
|
216
|
+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
|
217
|
+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
The group is per workflow and per PR, so a new push cancels only the older run of the same workflow on the same PR.
|
|
221
|
+
`cancel-in-progress` is limited to pull-request events: a push or dispatch run on a protected branch may be a deploy, and
|
|
222
|
+
a deploy must never be cancelled half way. Do not add the block to a deploy workflow; give that one a group with
|
|
223
|
+
`cancel-in-progress: false` so deploys queue instead.
|
|
224
|
+
|
|
225
|
+
**From ForgeDock (when the workflow cannot be edited).** `verify.cancel_superseded: own` in forge.yaml makes a lane cancel
|
|
226
|
+
the pull-request runs of its own branch for an older head right after it pushes (default `off`; see
|
|
227
|
+
[CONFIG.md](CONFIG.md#verify-optional)). For any branch or PR, by hand or from a hook:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
npx forgedock ci cancel-superseded --pr 123 --dry-run # list what would be cancelled
|
|
231
|
+
npx forgedock ci cancel-superseded --pr 123 --mode own # cancel the runs this actor triggered
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
It cancels only queued or running `pull_request` / `pull_request_target` runs whose head sha is not the branch's current
|
|
235
|
+
head. The checks of the current head are untouched, so no gate gets weaker. Measure the effect with
|
|
236
|
+
`forgedock stats --release-ledger` (row "CI minutes in cancelled jobs").
|
|
237
|
+
|
|
207
238
|
## Troubleshooting
|
|
208
239
|
|
|
209
240
|
**Review job fails immediately with `ANTHROPIC_API_KEY not set`**
|