forgedock 1.52.0 → 1.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +51 -0
- package/README.md +8 -2
- package/bin/auth/app-manifest.mjs +89 -0
- package/bin/auth/app-manifest.test.mjs +75 -0
- package/bin/auth/app-token.mjs +256 -0
- package/bin/auth/app-token.test.mjs +232 -0
- package/bin/brand.mjs +7 -0
- package/bin/config-history.mjs +151 -0
- package/bin/config-schema.mjs +115 -0
- package/bin/demo.mjs +65 -11
- package/bin/engine/outcome-codes.mjs +9 -3
- package/bin/engine/telemetry-seam.mjs +11 -3
- package/bin/engine/telemetry-seam.test.mjs +17 -0
- package/bin/engine-cli.mjs +110 -36
- package/bin/experiment.mjs +58 -6
- package/bin/first-run.mjs +122 -0
- package/bin/forge-utils.mjs +6 -2
- package/bin/forgedock.mjs +138 -142
- package/bin/help-text.mjs +144 -0
- package/bin/hooks/pre-tool-use.mjs +7 -0
- package/bin/journey.mjs +82 -83
- package/bin/lean/acceptance.mjs +313 -0
- package/bin/lean/acceptance.test.mjs +215 -0
- package/bin/lean/account-watch.mjs +28 -0
- package/bin/lean/account-watch.test.mjs +30 -0
- package/bin/lean/activation.mjs +38 -0
- package/bin/lean/activation.test.mjs +36 -1
- package/bin/lean/basered.mjs +115 -0
- package/bin/lean/basered.test.mjs +66 -0
- package/bin/lean/batch-health.mjs +114 -7
- package/bin/lean/batch-health.test.mjs +87 -1
- package/bin/lean/batch.mjs +41 -2
- package/bin/lean/batch.test.mjs +115 -11
- package/bin/lean/branchlock.mjs +54 -0
- package/bin/lean/branchlock.test.mjs +49 -0
- package/bin/lean/ceiling.mjs +72 -0
- package/bin/lean/ceiling.test.mjs +54 -0
- package/bin/lean/checkpoint-reconcile.mjs +43 -0
- package/bin/lean/checkpoint-reconcile.test.mjs +95 -0
- package/bin/lean/ci-budget.mjs +366 -0
- package/bin/lean/ci-budget.test.mjs +167 -0
- package/bin/lean/conformance.e2e.test.mjs +8 -1
- package/bin/lean/conformance.mjs +269 -38
- package/bin/lean/conformance.test.mjs +280 -7
- package/bin/lean/context.mjs +35 -6
- package/bin/lean/context.test.mjs +27 -1
- package/bin/lean/depcache.mjs +25 -1
- package/bin/lean/depcache.test.mjs +26 -0
- package/bin/lean/e2e.mjs +18 -2
- package/bin/lean/e2e.test.mjs +26 -1
- package/bin/lean/effects.mjs +47 -14
- package/bin/lean/execution.mjs +19 -3
- package/bin/lean/execution.test.mjs +63 -0
- package/bin/lean/facts.mjs +3 -3
- package/bin/lean/facts.test.mjs +5 -0
- package/bin/lean/findinglabel.mjs +16 -0
- package/bin/lean/findinglabel.test.mjs +39 -0
- package/bin/lean/fixround.mjs +14 -0
- package/bin/lean/fixround.test.mjs +25 -2
- package/bin/lean/gh-assoc.test.mjs +2 -1
- package/bin/lean/integration.mjs +100 -9
- package/bin/lean/integration.test.mjs +98 -0
- package/bin/lean/issuewatch-parity.mjs +64 -0
- package/bin/lean/issuewatch-parity.test.mjs +127 -0
- package/bin/lean/issuewatch-release.mjs +6 -2
- package/bin/lean/issuewatch-release.test.mjs +17 -1
- package/bin/lean/issuewatch.mjs +45 -6
- package/bin/lean/issuewatch.test.mjs +3 -2
- package/bin/lean/lanelock.mjs +14 -0
- package/bin/lean/lean.mjs +473 -100
- package/bin/lean/lean.test.mjs +686 -33
- package/bin/lean/light.mjs +48 -7
- package/bin/lean/light.test.mjs +37 -3
- package/bin/lean/limits.test.mjs +142 -9
- package/bin/lean/mechfix.mjs +124 -0
- package/bin/lean/mechfix.test.mjs +75 -0
- package/bin/lean/orchestrate-cancel.test.mjs +143 -0
- package/bin/lean/orchestrate.mjs +116 -28
- package/bin/lean/phaseledger.mjs +47 -5
- package/bin/lean/phaseledger.test.mjs +30 -1
- package/bin/lean/postdeploy-check.test.mjs +39 -0
- package/bin/lean/precheck.mjs +23 -4
- package/bin/lean/precheck.test.mjs +14 -1
- package/bin/lean/prereq.mjs +28 -0
- package/bin/lean/prereq.test.mjs +20 -0
- package/bin/lean/probe.mjs +4 -2
- package/bin/lean/prodparity.mjs +52 -0
- package/bin/lean/prodparity.test.mjs +67 -0
- package/bin/lean/prompts.mjs +77 -19
- package/bin/lean/quota.mjs +39 -0
- package/bin/lean/recovery.test.mjs +11 -1
- package/bin/lean/relaxation.mjs +73 -0
- package/bin/lean/relaxation.test.mjs +54 -0
- package/bin/lean/release-io.test.mjs +42 -0
- package/bin/lean/release-postmerge.mjs +125 -0
- package/bin/lean/release-preflight.mjs +58 -0
- package/bin/lean/release-preflight.test.mjs +114 -0
- package/bin/lean/release-rehearsal.mjs +64 -0
- package/bin/lean/release-rehearsal.test.mjs +93 -0
- package/bin/lean/release-review.e2e.test.mjs +77 -0
- package/bin/lean/release-review.mjs +254 -0
- package/bin/lean/release-review.test.mjs +307 -0
- package/bin/lean/release-snapshot.mjs +188 -0
- package/bin/lean/release-snapshot.test.mjs +190 -0
- package/bin/lean/release.mjs +296 -0
- package/bin/lean/release.test.mjs +387 -0
- package/bin/lean/render.mjs +1 -1
- package/bin/lean/replan.mjs +184 -0
- package/bin/lean/replan.test.mjs +110 -0
- package/bin/lean/resume.mjs +9 -7
- package/bin/lean/resume.test.mjs +16 -0
- package/bin/lean/rotator.mjs +150 -31
- package/bin/lean/rotator.test.mjs +105 -2
- package/bin/lean/sandbox-remote.mjs +9 -2
- package/bin/lean/schedd.mjs +83 -5
- package/bin/lean/schedd.test.mjs +108 -7
- package/bin/lean/selfreview.mjs +94 -0
- package/bin/lean/selfreview.test.mjs +58 -1
- package/bin/lean/selftest-gate.mjs +22 -0
- package/bin/lean/selftest-gate.test.mjs +18 -1
- package/bin/lean/selftest-journey.mjs +234 -0
- package/bin/lean/selftest-journey.test.mjs +130 -0
- package/bin/lean/selftest-live.mjs +2 -1
- package/bin/lean/seqlease.mjs +35 -1
- package/bin/lean/seqlease.test.mjs +15 -0
- package/bin/lean/seqreserve.e2e.test.mjs +135 -0
- package/bin/lean/seqreserve.mjs +73 -0
- package/bin/lean/seqreserve.test.mjs +134 -0
- package/bin/lean/sequence.mjs +35 -6
- package/bin/lean/seqversioned.mjs +147 -0
- package/bin/lean/stagestamp.mjs +28 -0
- package/bin/lean/stagestamp.test.mjs +32 -0
- package/bin/lean/surfaces.mjs +75 -0
- package/bin/lean/surfaces.test.mjs +59 -0
- package/bin/lean/toolplace.mjs +28 -0
- package/bin/lean/toolplace.test.mjs +24 -0
- package/bin/lean/toolstats.mjs +3 -1
- package/bin/lean/toolstats.test.mjs +11 -0
- package/bin/lean/validatebest.mjs +28 -0
- package/bin/lean/validatebest.test.mjs +27 -0
- package/bin/lean/verifier.mjs +3 -2
- package/bin/lean/verify.mjs +2 -1
- package/bin/lean/verify.test.mjs +6 -0
- package/bin/pool/agent.mjs +27 -4
- package/bin/pool/docker.mjs +5 -0
- package/bin/pool/router.mjs +74 -28
- package/bin/prereqs.mjs +111 -0
- package/bin/replay-timelapse.mjs +149 -0
- package/bin/review-staging.mjs +123 -16
- package/bin/review-staging.test.mjs +18 -0
- package/bin/runner.mjs +43 -6
- package/bin/splash-install.mjs +157 -0
- package/bin/stats/aggregate.mjs +8 -1
- package/bin/stats/conformance-outcomes.mjs +289 -0
- package/bin/stats/conformance-outcomes.test.mjs +274 -0
- package/bin/stats/depth.mjs +275 -0
- package/bin/stats/depth.test.mjs +158 -0
- package/bin/stats/efficiency.mjs +26 -5
- package/bin/stats/efficiency.test.mjs +45 -1
- package/bin/stats/experiment.mjs +7 -5
- package/bin/stats/first-review.mjs +77 -0
- package/bin/stats/first-review.test.mjs +36 -0
- package/bin/stats/firstmerge.mjs +40 -0
- package/bin/stats/firstmerge.test.mjs +41 -0
- package/bin/stats/github-source.mjs +53 -15
- package/bin/stats/index.mjs +147 -9
- package/bin/stats/local-source.mjs +12 -0
- package/bin/stats/origin.mjs +80 -0
- package/bin/stats/origin.test.mjs +58 -0
- package/bin/stats/query.mjs +69 -0
- package/bin/stats/render.mjs +3 -1
- package/bin/stats/scoreboard.mjs +137 -0
- package/bin/stats/scoreboard.test.mjs +87 -0
- package/bin/stats/selffiled.mjs +52 -0
- package/bin/stats/selffiled.test.mjs +71 -0
- package/bin/stats/stats.test.mjs +80 -0
- package/bin/tui.mjs +3 -2
- package/commands/bootstrap.md +15 -14
- package/commands/deploy-pr.md +18 -3
- package/commands/forge-stats.md +1 -1
- package/commands/forgedock-ci-setup.md +28 -0
- package/commands/forgedock-init.md +4 -5
- package/commands/issue.md +2 -0
- package/commands/milestone.md +9 -1
- package/commands/orchestrate.md +1 -1
- package/commands/replay.md +2 -0
- package/commands/review-pr-agents/security.md +4 -0
- package/commands/review-pr-staging.md +6 -1
- package/commands/work-on/build.md +4 -6
- package/commands/work-on/close.md +8 -0
- package/docs/CONFIG.md +170 -18
- package/docs/ISSUE-WATCH.md +25 -0
- package/docs/OUTCOME-CODES.md +4 -0
- package/docs/REPLAY.md +9 -0
- package/docs/SELFTEST.md +11 -0
- package/docs/STATS.md +61 -0
- package/docs/TELEMETRY.md +1 -1
- package/docs/eval/README.md +6 -0
- package/docs/eval/adversarial-bench.md +68 -0
- package/docs/eval/corpus/adversarial-v1.json +285 -0
- package/docs/eval/feature-bench.md +42 -0
- package/docs/eval/feature-specs/crud-auth/journeys/notes-crud-isolated.mjs +21 -0
- package/docs/eval/feature-specs/crud-auth/journeys/register-login.mjs +12 -0
- package/docs/eval/feature-specs/crud-auth/spec.md +15 -0
- package/docs/site/start-a-new-project.md +2 -1
- package/package.json +5 -2
- package/plugins/forgedock-splash/.claude-plugin/plugin.json +10 -0
- package/plugins/forgedock-splash/README.md +27 -0
- package/plugins/forgedock-splash/hooks/hooks.json +1 -0
- package/plugins/forgedock-splash/hooks/register.tsx +74 -0
- package/plugins/forgedock-splash/hooks/scene.ts +222 -0
- package/plugins/forgedock-splash/types/index.d.ts +10 -0
- package/pool/README.md +1 -1
- package/pool/image/cs-cred +14 -1
- package/scripts/backfill-finding-labels.mjs +50 -0
- package/scripts/backfill-finding-labels.test.mjs +36 -0
- package/scripts/bench-adversarial.mjs +216 -0
- package/scripts/bench-feature.mjs +170 -0
- package/scripts/bench-lightlane.mjs +2 -2
- package/scripts/bootstrap-create.mjs +2 -2
- package/scripts/bootstrap-validate.mjs +35 -2
- package/scripts/check-spec-size.sh +4 -3
- package/scripts/check-spec-size.test.sh +3 -0
- package/scripts/doctor-pipeline-state.sh +21 -6
- package/scripts/file-deferred-followups.sh +59 -251
- package/scripts/file-deferred-followups.test.sh +85 -206
- package/scripts/followup-route.mjs +12 -0
- package/scripts/owner-route-parity.test.sh +17 -1
- package/scripts/plan-validate-live.mjs +40 -6
- package/scripts/review-pr-side-effects.test.sh +40 -0
- package/scripts/review-pr-staging-scope.test.sh +1 -1
- package/scripts/review-staging-post.sh +23 -0
- package/scripts/review-staging-post.test.sh +8 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
|
|
2
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
3
|
+
/**
|
|
4
|
+
* `forgedock release [--repo R] [--merge] [--watch] [--resume <id>]` (#5208): the staging -> default release as one durable,
|
|
5
|
+
* resumable job. State lives in `~/.forge/releases/<id>/state.json` (or `FORGEDOCK_RELEASE_DIR`), written like a batch
|
|
6
|
+
* (tmp + fsync + rename, never tmpfs). Steps run in order and each completed step is recorded, so `--resume <id>` continues
|
|
7
|
+
* from the last completed one. Every effect goes through `io`, so the steps are unit-testable. Review, fixes and post-merge
|
|
8
|
+
* live in release-review.mjs / release-postmerge.mjs (stubs that block until their parts land). Promotion is opt-in: without
|
|
9
|
+
* `--merge` or forge.yaml `release.auto_merge: true` the job stops at GATE_PASS and prints the merge command.
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
12
|
+
import { execFileSync } from "node:child_process";
|
|
13
|
+
import { homedir } from "node:os";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { writeAtomic, assertDiskPath, batchRoot, listBatches, openBatch, isLaneAlive } from "./batch.mjs";
|
|
16
|
+
import { readBranches, DEFAULT_STAGING_BRANCH } from "./lane.mjs";
|
|
17
|
+
import { ghRunner } from "./issuewatch.mjs";
|
|
18
|
+
import { parseForgeYaml } from "../forge-utils.mjs";
|
|
19
|
+
import { reviewStep, fixStep } from "./release-review.mjs";
|
|
20
|
+
import { postMergeStep } from "./release-postmerge.mjs";
|
|
21
|
+
import { rehearsalStep, parseRehearsalConfig } from "./release-rehearsal.mjs";
|
|
22
|
+
import { budgetReportLine, releaseRuns } from "./ci-budget.mjs";
|
|
23
|
+
import { cutSnapshot, writeRecord, checkChain, verifyRelease, DEFAULT_PATTERN } from "./release-snapshot.mjs";
|
|
24
|
+
import { hostPreflightStep, markReadyStep, parsePreflightConfig } from "./release-preflight.mjs";
|
|
25
|
+
|
|
26
|
+
export const RELEASE_STEPS = ["preflight", "host-preflight", "release-pr", "review", "fixes", "mark-ready", "rehearsal", "promotion", "post-merge"];
|
|
27
|
+
const ID_RE = /^r\d{8}-\d{6}-\d+$/;
|
|
28
|
+
const BLOCKED_EXIT = 3;
|
|
29
|
+
|
|
30
|
+
export function releaseRoot(env = process.env) {
|
|
31
|
+
return env.FORGEDOCK_RELEASE_DIR || join(homedir(), ".forge", "releases");
|
|
32
|
+
}
|
|
33
|
+
export function newReleaseId(now = Date.now(), pid = process.pid) {
|
|
34
|
+
return `r${new Date(now).toISOString().replace(/[-:]/g, "").replace("T", "-").slice(0, 15)}-${pid}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Handle on one release directory; every write is atomic. */
|
|
38
|
+
export function openRelease(root, id, mounts) {
|
|
39
|
+
if (!ID_RE.test(String(id ?? ""))) throw new Error(`invalid release id ${JSON.stringify(id)}`);
|
|
40
|
+
const file = join(root, id, "state.json");
|
|
41
|
+
return {
|
|
42
|
+
id, file,
|
|
43
|
+
exists: () => existsSync(file),
|
|
44
|
+
load: () => { try { return JSON.parse(readFileSync(file, "utf8")); } catch { return null; } },
|
|
45
|
+
save: (state) => { assertDiskPath(root, mounts); mkdirSync(join(root, id), { recursive: true }); writeAtomic(file, JSON.stringify(state, null, 2) + "\n", { private: true }); },
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** forge.yaml `release.*` of `raw`: `{autoMerge, artifactCheck, versionSync, publishWorkflow, rehearsal, preflight, mode, branchPattern, fixMode}` (#5253, #5276, #5277). */
|
|
50
|
+
export function readReleaseConfig(raw) {
|
|
51
|
+
let r = {};
|
|
52
|
+
try { r = parseForgeYaml(String(raw ?? ""))?.release ?? {}; } catch { r = {}; }
|
|
53
|
+
const off = (v) => ["false", "off", "no", "0", ""].includes(String(v ?? "").trim().toLowerCase());
|
|
54
|
+
return { autoMerge: !off(r.auto_merge), artifactCheck: r.artifact_check || null, versionSync: !off(r.version_sync), publishWorkflow: r.publish_workflow || null, ...optKeys(r), ...snapshotKeys(r) };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `{mode, branchPattern, fixMode}` only when configured (#5276): mode `snapshot` cuts release/<id>; anything else is `freeze`. */
|
|
58
|
+
const snapshotKeys = (r) => {
|
|
59
|
+
const pick = (v, ok, dflt) => (ok.includes(String(v).trim().toLowerCase()) ? String(v).trim().toLowerCase() : dflt);
|
|
60
|
+
return {
|
|
61
|
+
...(r.mode ? { mode: pick(r.mode, ["snapshot", "freeze"], "freeze") } : {}),
|
|
62
|
+
...(r.branch_pattern ? { branchPattern: String(r.branch_pattern) } : {}),
|
|
63
|
+
...(r.fix_mode ? { fixMode: pick(r.fix_mode, ["cherry-pick", "recut"], "cherry-pick") } : {}),
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export const isSnapshot = (config) => config?.mode === "snapshot";
|
|
67
|
+
|
|
68
|
+
/** `{rehearsal}` / `{preflight}` only when configured, so the config of a repo without them keeps its shape. */
|
|
69
|
+
const optKeys = (r) => { const rehearsal = parseRehearsalConfig(r), preflight = parsePreflightConfig(r); return { ...(rehearsal ? { rehearsal } : {}), ...(preflight ? { preflight } : {}) }; };
|
|
70
|
+
|
|
71
|
+
const json = (s) => JSON.parse(String(s || "null"));
|
|
72
|
+
|
|
73
|
+
/** The bundle list of PRs merged into `base` since the last release PR (the newest merged head->base PR). */
|
|
74
|
+
export async function bundleList({ io, repo, head, base }) {
|
|
75
|
+
const last = json(await io.gh(["pr", "list", "--repo", repo, "--base", base, "--head", head, "--state", "merged", "--limit", "1", "--json", "mergedAt"]))?.[0]?.mergedAt;
|
|
76
|
+
const merged = json(await io.gh(["pr", "list", "--repo", repo, "--base", head, "--state", "merged", "--limit", "200", "--json", "number,title,mergedAt,closingIssuesReferences"])) ?? [];
|
|
77
|
+
return merged.filter((p) => !last || p.mergedAt > last).sort((a, b) => a.number - b.number);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const bundleBody = (list) => `## Release bundle\n\n${list.length ? list.map((p) => `- #${p.number} ${p.title}`).join("\n") : "_No merged PRs found since the last release._"}\n`;
|
|
81
|
+
|
|
82
|
+
async function preflightStep(ctx) {
|
|
83
|
+
const { io, repo, state, staging } = ctx;
|
|
84
|
+
// Snapshot mode: lanes keep merging to staging; the release is cut from a fixed SHA, so nothing is refused or held (#5276).
|
|
85
|
+
if (isSnapshot(ctx.config)) return { snapshot: true, held: 0 };
|
|
86
|
+
const lanes = await io.runningLanes(repo);
|
|
87
|
+
if (lanes.length) return { refused: `lanes of ${repo} are running (${lanes.map((l) => `${l.batch}#${l.issue}`).join(", ")}); wait or cancel them` };
|
|
88
|
+
const open = json(await io.gh(["pr", "list", "--repo", repo, "--base", staging, "--state", "open", "--json", "number"])) ?? [];
|
|
89
|
+
if (open.length) return { refused: `open PRs target ${staging}: ${open.map((p) => `#${p.number}`).join(", ")}; merge or close them first` };
|
|
90
|
+
// Hold: K=1 on every unfinished batch of the repo; the previous K is recorded so it can be restored, also after a kill.
|
|
91
|
+
state.held ??= [];
|
|
92
|
+
for (const b of await io.batches(repo)) {
|
|
93
|
+
if (state.held.some((h) => h.batch === b.id)) continue;
|
|
94
|
+
state.held.push({ batch: b.id, k: b.k });
|
|
95
|
+
ctx.save();
|
|
96
|
+
await io.setParallel(b.id, 1);
|
|
97
|
+
}
|
|
98
|
+
return { held: state.held.length };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Restore every held batch to its recorded K; best effort, recorded as it goes. */
|
|
102
|
+
export async function restoreBatches(ctx) {
|
|
103
|
+
const { io, state } = ctx;
|
|
104
|
+
for (const h of state.held ?? []) {
|
|
105
|
+
if (h.restored) continue;
|
|
106
|
+
try { await io.setParallel(h.batch, h.k ?? 1); h.restored = true; } catch (e) { io.print(`release: could not restore K=${h.k} on batch ${h.batch}: ${e.message}`); }
|
|
107
|
+
}
|
|
108
|
+
ctx.save();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Snapshot mode: cut release/<id> (once; a resume reuses the recorded branch) and open release/<id> -> default. */
|
|
112
|
+
async function snapshotPrStep(ctx) {
|
|
113
|
+
const { io, repo, staging, def, state } = ctx;
|
|
114
|
+
if (!io.git) throw new Error("snapshot releases need io.git");
|
|
115
|
+
if (!state.release) {
|
|
116
|
+
const bundle = await bundleList({ io, repo, head: staging, base: def });
|
|
117
|
+
const cut = await cutSnapshot({ io, git: io.git, repo, staging, def, pattern: ctx.config.branchPattern ?? DEFAULT_PATTERN, id: state.id, bundle });
|
|
118
|
+
if (cut.refused) return { refused: cut.refused };
|
|
119
|
+
state.release = cut.record; state.releaseBundle = bundle;
|
|
120
|
+
ctx.save();
|
|
121
|
+
}
|
|
122
|
+
const { branch } = state.release;
|
|
123
|
+
const found = json(await io.gh(["pr", "list", "--repo", repo, "--base", def, "--head", branch, "--state", "open", "--json", "number,headRefOid,url"]))?.[0];
|
|
124
|
+
if (found) return { pr: found.number, head: found.headRefOid, url: found.url, reused: true, branch };
|
|
125
|
+
const list = state.releaseBundle ?? [];
|
|
126
|
+
const url = String(await io.gh(["pr", "create", "--repo", repo, "--base", def, "--head", branch, "--title", `Release: ${branch} -> ${def}`, "--body", bundleBody(list)])).trim();
|
|
127
|
+
const n = Number(/\/pull\/(\d+)/.exec(url)?.[1]);
|
|
128
|
+
if (!Number.isSafeInteger(n)) throw new Error(`gh pr create returned no PR url: ${url}`);
|
|
129
|
+
state.steps["release-pr"] = { done: false, result: { pr: n } }; // writeRecord reads the PR number from here
|
|
130
|
+
await writeRecord(ctx);
|
|
131
|
+
const v = json(await io.gh(["pr", "view", String(n), "--repo", repo, "--json", "headRefOid"]));
|
|
132
|
+
return { pr: n, head: v?.headRefOid, url, reused: false, bundle: list.length, branch };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function releasePrStep(ctx) {
|
|
136
|
+
if (isSnapshot(ctx.config)) return snapshotPrStep(ctx);
|
|
137
|
+
const { io, repo, staging, def } = ctx;
|
|
138
|
+
const found = json(await io.gh(["pr", "list", "--repo", repo, "--base", def, "--head", staging, "--state", "open", "--json", "number,headRefOid,url"]))?.[0];
|
|
139
|
+
if (found) return { pr: found.number, head: found.headRefOid, url: found.url, reused: true };
|
|
140
|
+
const list = await bundleList({ io, repo, head: staging, base: def });
|
|
141
|
+
const url = String(await io.gh(["pr", "create", "--repo", repo, "--base", def, "--head", staging, "--title", `Release: ${staging} -> ${def}`, "--body", bundleBody(list), ...(ctx.config.preflight ? ["--draft"] : [])])).trim();
|
|
142
|
+
const n = Number(/\/pull\/(\d+)/.exec(url)?.[1]);
|
|
143
|
+
if (!Number.isSafeInteger(n)) throw new Error(`gh pr create returned no PR url: ${url}`);
|
|
144
|
+
const v = json(await io.gh(["pr", "view", String(n), "--repo", repo, "--json", "headRefOid"]));
|
|
145
|
+
return { pr: n, head: v?.headRefOid, url, reused: false, bundle: list.length };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** GATE_PASS marker on the PR and the `forge/deploy-gate` conclusion at `head`. */
|
|
149
|
+
export async function gateState({ io, repo, pr, head }) {
|
|
150
|
+
const comments = json(await io.gh(["pr", "view", String(pr), "--repo", repo, "--json", "comments"]))?.comments ?? [];
|
|
151
|
+
const bodies = comments.map((c) => String(c.body ?? ""));
|
|
152
|
+
let marker = null;
|
|
153
|
+
for (const b of bodies) { if (b.includes("FORGE:GATE_PASS")) marker = "pass"; else if (b.includes("FORGE:GATE_FAILURE")) marker = "failure"; }
|
|
154
|
+
const checks = json(await io.gh(["api", `repos/${repo}/commits/${head}/check-runs`, "--jq", "[.check_runs[] | {name, conclusion}]"])) ?? [];
|
|
155
|
+
const gate = checks.find((c) => c.name === "forge/deploy-gate");
|
|
156
|
+
return { marker, deployGate: gate?.conclusion ?? null };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function promotionStep(ctx) {
|
|
160
|
+
const { io, repo, state, opts } = ctx;
|
|
161
|
+
const { pr } = state.steps["release-pr"].result;
|
|
162
|
+
const view = json(await io.gh(["pr", "view", String(pr), "--repo", repo, "--json", "state,mergeCommit,headRefOid"]));
|
|
163
|
+
const head = view?.headRefOid;
|
|
164
|
+
// Already merged (by hand, or by a crashed --merge run): hand the merge sha to post-merge; never gate or merge again.
|
|
165
|
+
if (view?.state === "MERGED" && view?.mergeCommit?.oid) return { merged: true, alreadyMerged: true, mergeCommit: view.mergeCommit.oid, head };
|
|
166
|
+
if (view?.state === "CLOSED") return { stopped: true, why: `release PR #${pr} was closed without merging`, head };
|
|
167
|
+
if (state.release) {
|
|
168
|
+
const chain = checkChain({ git: io.git, record: state.release, sha: head, staging: ctx.staging, exact: true });
|
|
169
|
+
if (!chain.ok) return { stopped: true, why: `release head ${head} is not snapshot + recorded cherry-picks: ${chain.why}`, head };
|
|
170
|
+
}
|
|
171
|
+
const gate = await gateState({ io, repo, pr, head });
|
|
172
|
+
if (gate.marker !== "pass") return { stopped: true, why: `no FORGE:GATE_PASS on #${pr} (last marker: ${gate.marker ?? "none"})`, head };
|
|
173
|
+
const cmd = `gh pr merge ${pr} --repo ${repo} --merge --match-head-commit ${head}`;
|
|
174
|
+
if (!opts.merge && !ctx.config.autoMerge) { io.print(`GATE_PASS on #${pr}. Merge when ready:\n ${cmd}`); return { stopped: true, why: "GATE_PASS; promotion is opt-in (--merge or release.auto_merge)", cmd, head, gate }; }
|
|
175
|
+
if (gate.deployGate !== "success") return { stopped: true, why: `forge/deploy-gate is ${gate.deployGate ?? "absent"}, not success`, head, gate };
|
|
176
|
+
await io.gh(["pr", "merge", String(pr), "--repo", repo, "--merge", "--match-head-commit", head]);
|
|
177
|
+
return { merged: true, head, gate };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const OPTIONAL_STEPS = ["host-preflight", "mark-ready"];
|
|
181
|
+
|
|
182
|
+
const STEP_FNS = {
|
|
183
|
+
preflight: preflightStep,
|
|
184
|
+
"host-preflight": hostPreflightStep,
|
|
185
|
+
"release-pr": releasePrStep,
|
|
186
|
+
review: (ctx) => reviewStep(ctx),
|
|
187
|
+
fixes: (ctx) => fixStep(ctx),
|
|
188
|
+
"mark-ready": markReadyStep,
|
|
189
|
+
rehearsal: (ctx) => rehearsalStep(ctx),
|
|
190
|
+
promotion: promotionStep,
|
|
191
|
+
"post-merge": (ctx) => postMergeStep(ctx),
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/** The step table with `over` replacing steps by name (tests stub the steps that need a real repo). */
|
|
195
|
+
export const withStubs = (over = {}) => ({ ...STEP_FNS, ...over });
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Run the job: each step not yet done, in order. A step result with `refused`, `blocked` or `stopped` ends the run and is not
|
|
199
|
+
* marked done (the next resume retries it). Batches are restored on every exit that ends the job (finished, refused, thrown).
|
|
200
|
+
* @returns {{id, status: "done"|"refused"|"blocked"|"stopped", step?, reason?}}
|
|
201
|
+
*/
|
|
202
|
+
export async function runRelease({ io, repo, opts = {}, config = {}, branches = {}, root, id, steps = STEP_FNS, mounts }) {
|
|
203
|
+
const rel = openRelease(root, id, mounts);
|
|
204
|
+
const state = rel.load() ?? { v: 1, id, repo, startedAt: new Date(io.now()).toISOString(), steps: {}, held: [] };
|
|
205
|
+
state.opts = { merge: !!(opts.merge || state.opts?.merge) };
|
|
206
|
+
const ctx = { io, repo, opts: state.opts, config, state, staging: branches.staging || DEFAULT_STAGING_BRANCH, def: branches.default || "main", git: io.git, save: () => rel.save(state) };
|
|
207
|
+
ctx.save();
|
|
208
|
+
let out;
|
|
209
|
+
try {
|
|
210
|
+
for (const step of RELEASE_STEPS) {
|
|
211
|
+
if (state.steps[step]?.done) continue;
|
|
212
|
+
const result = await steps[step](ctx);
|
|
213
|
+
if (result?.refused) { out = { id, status: "refused", step, reason: result.refused }; break; }
|
|
214
|
+
if (result?.blocked) { out = { id, status: "blocked", step, reason: result.reason }; break; }
|
|
215
|
+
if (result?.skipped && OPTIONAL_STEPS.includes(step)) continue; // unconfigured: leaves no trace in the state
|
|
216
|
+
if (result?.stopped) { state.steps[step] = { done: false, at: new Date(io.now()).toISOString(), result }; out = { id, status: "stopped", step, reason: result.why }; break; }
|
|
217
|
+
state.steps[step] = { done: true, at: new Date(io.now()).toISOString(), result };
|
|
218
|
+
ctx.save();
|
|
219
|
+
}
|
|
220
|
+
out ??= { id, status: "done" };
|
|
221
|
+
} finally {
|
|
222
|
+
// A stop at GATE_PASS ends the release hold as well: nothing else is waiting on the batches.
|
|
223
|
+
await restoreBatches(ctx);
|
|
224
|
+
}
|
|
225
|
+
state.status = out.status; ctx.save();
|
|
226
|
+
return out;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Real effects. `runningLanes`/`batches` read the batch dirs of `repo` (a plan without `repo` is taken as this repo's). */
|
|
230
|
+
export function realReleaseIo({ env = process.env, exec = execFileSync, print = (l) => console.log(l), cwd = process.cwd() } = {}) {
|
|
231
|
+
const gh = ghRunner(exec, print);
|
|
232
|
+
const root = batchRoot(env);
|
|
233
|
+
const mine = (b, repo) => { const r = b.readPlan()?.repo; return !r || r === repo; };
|
|
234
|
+
const unfinished = (repo) => listBatches(root).map((id) => openBatch(root, id)).filter((b) => !b.readReport() && mine(b, repo));
|
|
235
|
+
return {
|
|
236
|
+
gh: (args) => gh(args), print, now: () => Date.now(),
|
|
237
|
+
git: (args, { env: extra, input } = {}) => exec("git", args, { cwd, encoding: "utf8", input, env: { ...env, ...extra }, maxBuffer: 64 << 20, stdio: ["pipe", "pipe", "pipe"] }),
|
|
238
|
+
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
239
|
+
run: async (cmd) => { try { exec("sh", ["-c", cmd], { stdio: "ignore", timeout: 120_000 }); return { ok: true }; } catch { return { ok: false }; } },
|
|
240
|
+
rehearse: async (cmd, { timeout } = {}) => {
|
|
241
|
+
try { return { ok: true, code: 0, output: String(exec("sh", ["-c", cmd], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout, maxBuffer: 16 << 20 })) }; }
|
|
242
|
+
catch (e) { return { ok: false, code: e.status ?? null, timedOut: e.code === "ETIMEDOUT", output: `${e.stdout ?? ""}${e.stderr ?? ""}` || String(e.message) }; }
|
|
243
|
+
},
|
|
244
|
+
runningLanes: (repo) => unfinished(repo).flatMap((b) => Object.entries(b.store.load()?.lanes ?? {})
|
|
245
|
+
.filter(([n, rec]) => rec?.pid && isLaneAlive(rec.pid, b.resultFile(n)) && !existsSync(b.resultFile(n)))
|
|
246
|
+
.map(([n]) => ({ batch: b.id, issue: n }))),
|
|
247
|
+
batches: (repo) => unfinished(repo).map((b) => ({ id: b.id, k: b.readParallel() ?? 1 })),
|
|
248
|
+
setParallel: async (id, k) => {
|
|
249
|
+
const { orchestrateFromCli } = await import("../engine-cli.mjs");
|
|
250
|
+
await orchestrateFromCli(["--set-parallel", id, String(k)]);
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const flag = (argv, f) => { const i = argv.indexOf(f); return i >= 0 ? argv[i + 1] : null; };
|
|
256
|
+
export const RELEASE_USAGE = "usage: forgedock release [--repo owner/repo] [--merge] [--watch] [--resume <id>] | forgedock release verify <sha> [--repo owner/repo]";
|
|
257
|
+
|
|
258
|
+
/** `forgedock release ...`; @returns the process exit code (0 done or stopped at GATE_PASS, 1 refused, 3 blocked on a manual step). */
|
|
259
|
+
export async function releaseFromCli(argv, deps = {}) {
|
|
260
|
+
const cwd = deps.cwd ?? process.cwd(), env = deps.env ?? process.env;
|
|
261
|
+
const io = deps.io ?? realReleaseIo({ env, cwd });
|
|
262
|
+
if (argv[0] === "verify") return verifyFromCli(argv.slice(1), { io, cwd });
|
|
263
|
+
const unknown = argv.filter((a, i) => a.startsWith("--") && !["--repo", "--merge", "--watch", "--resume"].includes(a) && !(argv[i - 1] === "--resume" || argv[i - 1] === "--repo"));
|
|
264
|
+
if (unknown.length) throw new Error(`unknown option ${unknown[0]}; ${RELEASE_USAGE}`);
|
|
265
|
+
const root = releaseRoot(env);
|
|
266
|
+
const resume = flag(argv, "--resume");
|
|
267
|
+
let id = resume ?? newReleaseId(io.now());
|
|
268
|
+
let repo = flag(argv, "--repo");
|
|
269
|
+
if (resume) {
|
|
270
|
+
const st = openRelease(root, resume).load();
|
|
271
|
+
if (!st) throw new Error(`no release ${resume} in ${root}`);
|
|
272
|
+
repo ??= st.repo;
|
|
273
|
+
}
|
|
274
|
+
repo ??= JSON.parse(String(await io.gh(["repo", "view", "--json", "nameWithOwner"]))).nameWithOwner;
|
|
275
|
+
let raw = ""; try { raw = readFileSync(join(cwd, "forge.yaml"), "utf8"); } catch { /* no forge.yaml: defaults */ }
|
|
276
|
+
const budget = async (since) => { // #5278: the Actions-minutes line (and any auto switch to local-first); never fails the job
|
|
277
|
+
try { io.print(await budgetReportLine({ cwd, repo, gh: (a) => io.gh(a), now: io.now(), release: since ? await releaseRuns({ gh: (a) => io.gh(a), repo, sinceMs: since }) : null })); } catch { /* best effort */ }
|
|
278
|
+
};
|
|
279
|
+
await budget(null);
|
|
280
|
+
const r = await runRelease({ io, repo, opts: { merge: argv.includes("--merge") }, config: readReleaseConfig(raw), branches: readBranches(cwd), root, id, mounts: deps.mounts });
|
|
281
|
+
const line = r.status === "done" ? `release ${id}: done` : `release ${id}: ${r.status} at ${r.step}: ${r.reason} (resume: forgedock release --resume ${id})`;
|
|
282
|
+
io.print(line);
|
|
283
|
+
try { await budget(Date.parse(openRelease(root, id).load()?.startedAt) || null); } catch { /* best effort */ }
|
|
284
|
+
return r.status === "refused" ? 1 : r.status === "blocked" ? BLOCKED_EXIT : 0;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** `forgedock release verify <sha> [--repo R]`: exit 0 when the release head is the snapshot plus its recorded cherry-picks of staging commits, else 1. */
|
|
288
|
+
async function verifyFromCli(argv, { io, cwd }) {
|
|
289
|
+
const sha = argv.find((a, i) => !a.startsWith("--") && argv[i - 1] !== "--repo");
|
|
290
|
+
if (!sha || !/^[0-9a-f]{7,40}$/i.test(sha)) throw new Error(`release verify needs a commit sha; ${RELEASE_USAGE}`);
|
|
291
|
+
const repo = flag(argv, "--repo") ?? JSON.parse(String(await io.gh(["repo", "view", "--json", "nameWithOwner"]))).nameWithOwner;
|
|
292
|
+
const full = io.git(["rev-parse", sha]).trim();
|
|
293
|
+
const r = await verifyRelease({ io, git: io.git, repo, staging: readBranches(cwd).staging || DEFAULT_STAGING_BRANCH, sha: full });
|
|
294
|
+
io.print(r.ok ? `release verify ${full}: ok (snapshot + ${r.picks} cherry-pick(s), PR #${r.pr})` : `release verify ${full}: FAILED: ${r.why}`);
|
|
295
|
+
return r.ok ? 0 : 1;
|
|
296
|
+
}
|