@intentius/chant 0.124.64 → 0.124.65

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 (105) hide show
  1. package/dist/cli/handlers/release.d.ts.map +1 -1
  2. package/dist/cli/handlers/release.js +20 -2
  3. package/dist/cli/handlers/run.d.ts +30 -1
  4. package/dist/cli/handlers/run.d.ts.map +1 -1
  5. package/dist/cli/handlers/run.js +108 -7
  6. package/dist/cli/main.d.ts.map +1 -1
  7. package/dist/cli/main.js +17 -2
  8. package/dist/cli/parse-args.d.ts.map +1 -1
  9. package/dist/cli/parse-args.js +7 -0
  10. package/dist/cli/registry.d.ts +5 -1
  11. package/dist/cli/registry.d.ts.map +1 -1
  12. package/dist/components/cli-support.d.ts +19 -1
  13. package/dist/components/cli-support.d.ts.map +1 -1
  14. package/dist/components/cli-support.js +11 -3
  15. package/dist/components/component.d.ts +19 -0
  16. package/dist/components/component.d.ts.map +1 -1
  17. package/dist/components/component.schema.json +17 -0
  18. package/dist/components/index.d.ts +1 -1
  19. package/dist/components/index.d.ts.map +1 -1
  20. package/dist/components/release-run.d.ts +48 -0
  21. package/dist/components/release-run.d.ts.map +1 -0
  22. package/dist/components/release-run.js +166 -0
  23. package/dist/components/starter-plugin.d.ts +1 -0
  24. package/dist/components/starter-plugin.d.ts.map +1 -1
  25. package/dist/components/starter-plugin.js +5 -1
  26. package/dist/components/unchanged-inputs.d.ts +81 -0
  27. package/dist/components/unchanged-inputs.d.ts.map +1 -0
  28. package/dist/components/unchanged-inputs.js +122 -0
  29. package/dist/components/verbs/index.d.ts +1 -0
  30. package/dist/components/verbs/index.d.ts.map +1 -1
  31. package/dist/components/verbs/index.js +1 -0
  32. package/dist/components/verbs/release-image.d.ts +36 -0
  33. package/dist/components/verbs/release-image.d.ts.map +1 -0
  34. package/dist/components/verbs/release-image.js +33 -0
  35. package/dist/lifecycle/delivery-metrics.d.ts.map +1 -1
  36. package/dist/lifecycle/delivery-metrics.js +4 -2
  37. package/dist/lifecycle/gate-statement.d.ts.map +1 -1
  38. package/dist/lifecycle/gate-statement.js +1 -2
  39. package/dist/lifecycle/git.d.ts.map +1 -1
  40. package/dist/lifecycle/git.js +6 -1
  41. package/dist/lifecycle/ledger-read.js +1 -1
  42. package/dist/lifecycle/publish-homebrew.d.ts.map +1 -1
  43. package/dist/lifecycle/publish-homebrew.js +1 -2
  44. package/dist/lifecycle/publish-marketplace.d.ts.map +1 -1
  45. package/dist/lifecycle/publish-marketplace.js +2 -3
  46. package/dist/lifecycle/query.d.ts +2 -2
  47. package/dist/lifecycle/query.d.ts.map +1 -1
  48. package/dist/lifecycle/query.js +3 -3
  49. package/dist/lifecycle/release-cut.d.ts +32 -2
  50. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  51. package/dist/lifecycle/release-cut.js +47 -7
  52. package/dist/lifecycle/release-ledger.d.ts +11 -0
  53. package/dist/lifecycle/release-ledger.d.ts.map +1 -1
  54. package/dist/lifecycle/release-store.d.ts +17 -3
  55. package/dist/lifecycle/release-store.d.ts.map +1 -1
  56. package/dist/lifecycle/release-store.js +11 -3
  57. package/dist/op/activities/activity-contracts.d.ts +4 -4
  58. package/dist/op/op-waves-run.js +5 -3
  59. package/dist/release-floors.d.ts +1 -1
  60. package/dist/release-floors.js +1 -1
  61. package/dist/wave-runtime.mjs +237 -237
  62. package/dist/workspace/delivery-metrics.schema.json +1 -1
  63. package/dist/workspace/release-candidates.d.ts.map +1 -1
  64. package/dist/workspace/release-candidates.js +1 -2
  65. package/dist/workspace/releases.schema.json +7 -2
  66. package/package.json +1 -1
  67. package/src/cli/handlers/release.ts +18 -2
  68. package/src/cli/handlers/run-unchanged.e2e.test.ts +112 -0
  69. package/src/cli/handlers/run.ts +117 -7
  70. package/src/cli/main.ts +17 -2
  71. package/src/cli/parse-args.ts +6 -0
  72. package/src/cli/registry.ts +5 -1
  73. package/src/components/cli-support.test.ts +53 -0
  74. package/src/components/cli-support.ts +26 -4
  75. package/src/components/component.schema.json +17 -0
  76. package/src/components/component.ts +20 -0
  77. package/src/components/index.ts +1 -0
  78. package/src/components/registry.test.ts +1 -1
  79. package/src/components/release-run.test.ts +127 -0
  80. package/src/components/release-run.ts +188 -0
  81. package/src/components/starter-plugin.ts +5 -0
  82. package/src/components/unchanged-inputs.test.ts +98 -0
  83. package/src/components/unchanged-inputs.ts +151 -0
  84. package/src/components/verbs/index.ts +1 -0
  85. package/src/components/verbs/release-image.ts +52 -0
  86. package/src/lifecycle/delivery-metrics.ts +4 -2
  87. package/src/lifecycle/gate-statement.ts +1 -2
  88. package/src/lifecycle/git.test.ts +15 -0
  89. package/src/lifecycle/git.ts +5 -1
  90. package/src/lifecycle/ledger-read.ts +1 -1
  91. package/src/lifecycle/publish-homebrew.ts +1 -2
  92. package/src/lifecycle/publish-marketplace.ts +2 -3
  93. package/src/lifecycle/query.ts +3 -3
  94. package/src/lifecycle/release-cut-lane.test.ts +18 -0
  95. package/src/lifecycle/release-cut-override.test.ts +12 -0
  96. package/src/lifecycle/release-cut.test.ts +45 -0
  97. package/src/lifecycle/release-cut.ts +67 -7
  98. package/src/lifecycle/release-ledger.ts +11 -0
  99. package/src/lifecycle/release-store.ts +29 -5
  100. package/src/op/op-waves-run.ts +4 -2
  101. package/src/release-floors.ts +1 -1
  102. package/src/workspace/delivery-metrics.schema.json +1 -1
  103. package/src/workspace/delivery-metrics.test.ts +8 -0
  104. package/src/workspace/release-candidates.ts +1 -2
  105. package/src/workspace/releases.schema.json +7 -2
@@ -0,0 +1,151 @@
1
+ /**
2
+ * A component a release leaves alone (#4695): one whose declared inputs are
3
+ * the same as in the release the environment runs it from.
4
+ *
5
+ * Some deploys cost something even when nothing changed. Arugula's hub drops
6
+ * every relayed terminal when it restarts, and `fly-release` stamps each
7
+ * release's commit on the Machine, so every release would restart it. A
8
+ * component declares what it is made from (`inputs` on the component):
9
+ *
10
+ * ```ts
11
+ * inputs: {
12
+ * paths: ["../crates/control", "../web", ":(exclude)../web/e2e", "../Cargo.lock", "src/control.component.ts", "src/control.fly.ts"],
13
+ * params: ["region"],
14
+ * }
15
+ * ```
16
+ *
17
+ * and a run under a release (`chant run --components --release`) compares
18
+ * them with the release named by the environment's latest record of the
19
+ * component. The component is unchanged when:
20
+ *
21
+ * - git sees no change between the two releases' commits to a file the
22
+ * `paths` match, read as pathspecs from the member's directory;
23
+ * - each of the `params` has the same value in the two releases' targets for
24
+ * the environment;
25
+ * - the deploy files the two targets record for the component
26
+ * (`releaseTemplatesDigest`) are the same, so a change to what the
27
+ * component deploys is never skipped for want of a listed path.
28
+ *
29
+ * Anything that can't be compared deploys: no record of the component in the
30
+ * environment, a record made from no release, a release that isn't stored, a
31
+ * commit git doesn't have. `--deploy-unchanged` deploys it anyway.
32
+ *
33
+ * A skip is recorded ({@link unchangedRecord}): a release record of this
34
+ * release for the component that repeats the digest of the deploy it keeps
35
+ * and names that deploy in `unchangedSince`.
36
+ */
37
+
38
+ import { execFileSync } from "node:child_process";
39
+ import type { ComponentInputs } from "./component";
40
+ import type { Release } from "../lifecycle/release-store";
41
+ import type { ReleaseRecord, ReleaseRecordInput, RunOrigin } from "../lifecycle/release-ledger";
42
+ import { releaseTemplatesDigest } from "./release-promote";
43
+ import { NEXT_RELEASE } from "../release-floors";
44
+
45
+ /** The first chant that reads a component's `inputs` and writes `unchangedSince` on a release record (#4695). */
46
+ export const UNCHANGED_INPUTS_FLOOR = NEXT_RELEASE;
47
+
48
+ /** Whether a component's inputs are the same as in the release the environment runs it from. */
49
+ export type InputsVerdict =
50
+ | {
51
+ unchanged: true;
52
+ /** The environment's record of the deploy that stays. */
53
+ since: ReleaseRecord;
54
+ /** The environment's record already names this release: there is nothing new to record. */
55
+ recorded: boolean;
56
+ }
57
+ | { unchanged: false; reason: string };
58
+
59
+ /** The files `paths` match that differ between two commits, or null when git can't tell. */
60
+ export type ChangedPaths = (from: string, to: string, paths: readonly string[]) => string[] | null;
61
+
62
+ /** {@link ChangedPaths} through `git diff`, with the pathspecs read from `memberDir`. */
63
+ export function gitChangedPaths(memberDir: string): ChangedPaths {
64
+ return (from, to, paths) => {
65
+ try {
66
+ const out = execFileSync("git", ["diff", "--name-only", "--no-renames", from, to, "--", ...paths], {
67
+ cwd: memberDir,
68
+ encoding: "utf-8",
69
+ stdio: ["ignore", "pipe", "pipe"],
70
+ });
71
+ return out.split("\n").filter((l) => l !== "");
72
+ } catch {
73
+ return null;
74
+ }
75
+ };
76
+ }
77
+
78
+ const shortDigest = (d: string): string => d.replace(/^jcs1-sha256:/, "").slice(0, 12);
79
+
80
+ /** Compare `component`'s declared inputs in `release` with the release the environment's `current` record names. */
81
+ export async function compareInputs(input: {
82
+ component: string;
83
+ inputs: ComponentInputs;
84
+ env: string;
85
+ release: Release;
86
+ /** The environment's latest record of the component, if it has one. */
87
+ current: ReleaseRecord | undefined;
88
+ readRelease: (digest: string) => Promise<Release | null>;
89
+ changedPaths: ChangedPaths;
90
+ }): Promise<InputsVerdict> {
91
+ const { component, inputs, env, release, current } = input;
92
+ const paths = inputs.paths ?? [];
93
+ const params = inputs.params ?? [];
94
+ if (paths.length === 0 && params.length === 0) return { unchanged: false, reason: "it declares no paths or params in inputs" };
95
+ if (!current) return { unchanged: false, reason: `"${env}" has no deploy of it` };
96
+ if (current.releaseDigest === undefined) return { unchanged: false, reason: `the deploy "${env}" runs (run ${current.runId}) was not made from a release` };
97
+ if (current.releaseDigest === release.releaseDigest) return { unchanged: true, since: current, recorded: true };
98
+
99
+ const prior = await input.readRelease(current.releaseDigest).catch(() => null);
100
+ if (!prior) return { unchanged: false, reason: `release ${shortDigest(current.releaseDigest)}, which "${env}" runs it from, is not stored here` };
101
+ const before = prior.targets.find((t) => t.env === env);
102
+ const now = release.targets.find((t) => t.env === env);
103
+ if (!before || !now) return { unchanged: false, reason: `release ${shortDigest((before ? release : prior).releaseDigest)} has no target for "${env}"` };
104
+
105
+ for (const name of params) {
106
+ const a = before.params.find((p) => p.name === name)?.value;
107
+ const b = now.params.find((p) => p.name === name)?.value;
108
+ if (a !== b) return { unchanged: false, reason: `param ${name} is ${JSON.stringify(b)}, was ${JSON.stringify(a)}` };
109
+ }
110
+ if (releaseTemplatesDigest(before, component) !== releaseTemplatesDigest(now, component)) {
111
+ return { unchanged: false, reason: `the files its deploy reads in the "${env}" target changed` };
112
+ }
113
+ if (paths.length > 0 && prior.commit !== release.commit) {
114
+ const changed = input.changedPaths(prior.commit, release.commit, paths);
115
+ if (changed === null) {
116
+ return { unchanged: false, reason: `git can't compare ${prior.commit.slice(0, 12)} and ${release.commit.slice(0, 12)} here; fetch the history between them` };
117
+ }
118
+ if (changed.length > 0) {
119
+ return { unchanged: false, reason: `${changed.length} input file(s) changed since ${prior.commit.slice(0, 12)}, such as ${changed[0]}` };
120
+ }
121
+ }
122
+ return { unchanged: true, since: current, recorded: false };
123
+ }
124
+
125
+ /**
126
+ * The record of a skip (#4695): this release, for `since`'s component in its
127
+ * environment, repeating what that deploy recorded of its artifact and naming
128
+ * it in `unchangedSince`. Who approved that deploy is not repeated, since
129
+ * nothing was approved now.
130
+ */
131
+ export function unchangedRecord(
132
+ since: ReleaseRecord,
133
+ run: { releaseDigest: string; runId: string; runOrigin?: RunOrigin; timestamp: string; actor: string },
134
+ ): ReleaseRecordInput {
135
+ return {
136
+ component: since.component,
137
+ env: since.env,
138
+ digest: since.digest,
139
+ gitSha: since.gitSha,
140
+ ...(since.manifestDigest !== undefined ? { manifestDigest: since.manifestDigest } : {}),
141
+ ...(since.inputDigest !== undefined ? { inputDigest: since.inputDigest } : {}),
142
+ ...(since.digestKind !== undefined ? { digestKind: since.digestKind } : {}),
143
+ ...(since.releaseVersion !== undefined ? { releaseVersion: since.releaseVersion } : {}),
144
+ runId: run.runId,
145
+ ...(run.runOrigin ? { runOrigin: run.runOrigin } : {}),
146
+ timestamp: run.timestamp,
147
+ actor: run.actor,
148
+ releaseDigest: run.releaseDigest,
149
+ unchangedSince: { env: since.env, runId: since.runId, timestamp: since.timestamp },
150
+ };
151
+ }
@@ -54,6 +54,7 @@ export * from "./run-agent";
54
54
  export * from "./wrangler";
55
55
  export * from "./r2-sync";
56
56
  export * from "./member-outputs";
57
+ export * from "./release-image";
57
58
  export * from "./vuln-scan";
58
59
  export * from "./vex";
59
60
  export * from "./license-policy";
@@ -0,0 +1,52 @@
1
+ /**
2
+ * `release-image`: the image a release recorded for this component (#4694).
3
+ *
4
+ * A component whose image is built elsewhere, as by a CI job with a toolchain
5
+ * the deploy machine lacks, declares no build and no publish. The image is
6
+ * handed to the cut by digest (`chant release cut --image
7
+ * <component>=<repository>@sha256:<hex>`), and the step stands where a publish
8
+ * step would, so the steps after it read the image as they would a publish's:
9
+ *
10
+ * ```ts
11
+ * phase("Image", [{ kind: "release-image" }]),
12
+ * phase("Release", [{ kind: "fly-release", plan: "dist/fly.json", image: "@Image.uri", digest: "@Image.digest" }]),
13
+ * ```
14
+ *
15
+ * The step has nothing of its own to give. A run under a release
16
+ * (`chant run --components <c> --env <e> --release <label>`) fills in the
17
+ * image the release recorded (../release-run.ts), and a run of a release
18
+ * that recorded none is refused before anything runs. Outside a release the
19
+ * step fails, so a deploy never runs an image no release named.
20
+ */
21
+
22
+ import type { Capability } from "../capability";
23
+
24
+ export interface ReleaseImageInput {
25
+ /** The image, `<repository>@sha256:<hex>`. Filled in by a run under a release; not written by the component. */
26
+ uri?: string;
27
+ /** The image's digest. Filled in with `uri`. */
28
+ digest?: string;
29
+ }
30
+
31
+ export interface ReleaseImageOutput {
32
+ /** The image reference a deploy step runs. */
33
+ uri: string;
34
+ digest: string;
35
+ }
36
+
37
+ /** The kind of the step. */
38
+ export const RELEASE_IMAGE_KIND = "release-image";
39
+
40
+ export const releaseImageCapability: Capability<ReleaseImageInput, ReleaseImageOutput> = {
41
+ kind: RELEASE_IMAGE_KIND,
42
+ rollbackPolicy: "none-by-design",
43
+ async run(ctx, input) {
44
+ if (typeof input?.uri !== "string" || typeof input.digest !== "string") {
45
+ throw new Error(
46
+ `release-image: "${ctx.component}" deploys the image a release recorded for it, and this run names no release. ` +
47
+ `Run it under one: chant run --components ${ctx.component} --env ${ctx.env} --release <label>`,
48
+ );
49
+ }
50
+ return { uri: input.uri, digest: input.digest };
51
+ },
52
+ };
@@ -169,8 +169,10 @@ export function environmentMetrics(
169
169
  window: MetricsWindow,
170
170
  failureWindowDays: number = DEFAULT_FAILURE_WINDOW_DAYS,
171
171
  ): EnvironmentMetrics {
172
- // Ledger order breaks timestamp ties, as `latestPerComponent` does.
173
- const sorted = records.map((r, i) => ({ r, i })).sort((a, b) => at(a.r.timestamp) - at(b.r.timestamp) || a.i - b.i).map((x) => x.r);
172
+ // Ledger order breaks timestamp ties, as `latestPerComponent` does. A
173
+ // release that skipped a component (#4695) deployed nothing: its record is
174
+ // in no metric.
175
+ const sorted = records.filter((r) => r.unchangedSince === undefined).map((r, i) => ({ r, i })).sort((a, b) => at(a.r.timestamp) - at(b.r.timestamp) || a.i - b.i).map((x) => x.r);
174
176
  const since = at(window.since);
175
177
  const until = at(window.until);
176
178
  const failureMs = failureWindowDays * DAY_MS;
@@ -19,7 +19,6 @@
19
19
  */
20
20
 
21
21
  import { createHash } from "node:crypto";
22
- import { NEXT_RELEASE } from "../release-floors";
23
22
  import { GATE_SEAL_NAMESPACE, gateSealPayload, gateSealVersion, isWebAuthnAssertion, webAuthnChallenge, type SealedGateApproval, type WebAuthnAssertion } from "./gate-seal";
24
23
 
25
24
  /**
@@ -37,7 +36,7 @@ export const GATE_EXTERNAL_SIGNATURE_FLOOR = "0.124.63";
37
36
  * checks, so it finds a version 3 seal doesn't verify and counts nothing for
38
37
  * it, whatever the gate.
39
38
  */
40
- export const GATE_BINDING_FLOOR = NEXT_RELEASE;
39
+ export const GATE_BINDING_FLOOR = "0.124.64";
41
40
 
42
41
  /** The longest binding `--binding` takes, in UTF-8 bytes (#4697). */
43
42
  export const GATE_BINDING_MAX_BYTES = 512;
@@ -587,6 +587,21 @@ describe("lifecycle/git", () => {
587
587
  }
588
588
  });
589
589
 
590
+ test("a change set the other writer stored under the same digest stays as it is there, and the rest of the commit lands", async () => {
591
+ const { a, b, remotePath, done } = await twoWriters();
592
+ try {
593
+ await advance(a, "_change-sets/jcs1-sha256_abc.json", '{"digest":"abc","graph":"theirs"}');
594
+ await writeBlobToPath("_change-sets", "jcs1-sha256_abc.json", '{"digest":"abc","graph":"ours"}', "Change set abc", { cwd: b });
595
+ await writeBlobToPath("prod", "release.jsonl", '{"released":1}\n', "Release record", { cwd: b });
596
+
597
+ expect(await pushLifecycleRebasing({ cwd: b })).toEqual({ pushed: true });
598
+ const tip = git(["rev-parse", "refs/heads/chant/lifecycle"], remotePath).stdout.trim();
599
+ expect(git(["show", `${tip}:prod/_change-sets/jcs1-sha256_abc.json`], remotePath).stdout).toBe('{"digest":"abc","graph":"theirs"}');
600
+ } finally {
601
+ await done();
602
+ }
603
+ });
604
+
590
605
  test("a commit that changes the file the other writer changed is refused by name, and the local write is kept", async () => {
591
606
  const { a, b, done } = await twoWriters();
592
607
  try {
@@ -1018,7 +1018,9 @@ async function rebaseLifecycleOnRemote(remote: string, cwd?: string): Promise<{
1018
1018
  * line `onto` already holds. A run record, a release record and a gate line
1019
1019
  * are such appends, so two writers to one environment's file no longer lose
1020
1020
  * one of them on a replay. Any other change, or a file the commit rewrote
1021
- * rather than appended to, returns why, and the replay stops as before.
1021
+ * rather than appended to, returns why, and the replay stops as before. A
1022
+ * change set the other writer already stored under the same digest stays as
1023
+ * it is there.
1022
1024
  */
1023
1025
  async function replayAppends(parent: string, commit: string, onto: string, cwd?: string): Promise<{ tree: string } | { error: string }> {
1024
1026
  const rt = getRuntime();
@@ -1036,6 +1038,8 @@ async function replayAppends(parent: string, commit: string, onto: string, cwd?:
1036
1038
  };
1037
1039
  const files: Array<{ path: string; content: string }> = [];
1038
1040
  for (const { status, path } of changes) {
1041
+ // #4022: a stored change set is written once under its digest, so a copy already there is the same document, whatever graph it carries.
1042
+ if (status === "A" && /(^|\/)_change-sets\/[^/]+\.json$/.test(path) && (await blob(onto, path)) !== null) continue;
1039
1043
  if (!path.endsWith(".jsonl") || (status !== "M" && status !== "A")) return { error: `${path} is not a ledger line file this replay appends to` };
1040
1044
  const ours = (await blob(commit, path)) ?? "";
1041
1045
  const base = status === "M" ? ((await blob(parent, path)) ?? "") : "";
@@ -47,7 +47,7 @@ export const LEDGER_TIME_COLUMN: Record<QueryTable, string | null> = {
47
47
  };
48
48
 
49
49
  /** The columns that hold JSON, which this read prints parsed. */
50
- const JSON_COLUMNS = new Set(["attributes", "labels", "outcomes", "promoted_from", "restores", "redeploys", "artifacts", "wave", "request", "detail", "components", "approvers", "settings", "estates"]);
50
+ const JSON_COLUMNS = new Set(["attributes", "labels", "outcomes", "promoted_from", "restores", "redeploys", "unchanged_since", "artifacts", "wave", "request", "detail", "components", "approvers", "settings", "estates"]);
51
51
  /** The columns that hold an ISO instant. */
52
52
  const TIME_COLUMNS = new Set(["last_updated", "observed_at", "started", "ended", "timestamp", "expires_at", "approved_at", "finished_at"]);
53
53
  /** INTEGER columns that hold 0 or 1, which this read prints as booleans. */
@@ -56,13 +56,12 @@ import { SshGitRepo } from "./publish-git-ssh";
56
56
  import { GitHubRepo, githubApi } from "./publish-github";
57
57
  import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets";
58
58
  import { PublishTargetError, type PublishContext, type PublishDeps, type PublishFetch, type PublishItem, type PublishTarget } from "./release-publish";
59
- import { NEXT_RELEASE } from "../release-floors";
60
59
 
61
60
  /** The first chant that publishes a `homebrew` target (#4676). */
62
61
  export const PUBLISH_HOMEBREW_FLOOR = "0.124.63";
63
62
 
64
63
  /** The first chant that reads a homebrew target's `sshKeyEnv` (#4699). */
65
- export const PUBLISH_HOMEBREW_SSH_KEY_FLOOR = NEXT_RELEASE;
64
+ export const PUBLISH_HOMEBREW_SSH_KEY_FLOOR = "0.124.64";
66
65
 
67
66
  /** The variable the tap token is read from when the declaration names none. */
68
67
  export const HOMEBREW_TOKEN_ENV = "HOMEBREW_TAP_TOKEN";
@@ -73,16 +73,15 @@ import {
73
73
  type PublishTarget,
74
74
  type StagedTarget,
75
75
  } from "./release-publish";
76
- import { NEXT_RELEASE } from "../release-floors";
77
76
 
78
77
  /** The first chant that publishes a `marketplace` target (#4676). */
79
78
  export const PUBLISH_MARKETPLACE_FLOOR = "0.124.63";
80
79
 
81
80
  /** The first chant that reads a marketplace target's `auth` (#4698). */
82
- export const PUBLISH_MARKETPLACE_AUTH_FLOOR = NEXT_RELEASE;
81
+ export const PUBLISH_MARKETPLACE_AUTH_FLOOR = "0.124.64";
83
82
 
84
83
  /** The first chant that reads a marketplace target's `onRefusal` (#4698). */
85
- export const PUBLISH_MARKETPLACE_ON_REFUSAL_FLOOR = NEXT_RELEASE;
84
+ export const PUBLISH_MARKETPLACE_ON_REFUSAL_FLOOR = "0.124.64";
86
85
 
87
86
  export const OPEN_VSX_REGISTRY = "https://open-vsx.org";
88
87
  export const VSCODE_GALLERY = "https://marketplace.visualstudio.com";
@@ -90,8 +90,8 @@ export const QUERY_TABLES = {
90
90
  * request a pending fact asks for, as JSON.
91
91
  */
92
92
  gates: [["member", "TEXT"], ["op", "TEXT"], ["gate", "TEXT"], ["kind", "TEXT"], ["timestamp", "TEXT"], ["resolved_by", "TEXT"], ["relayed_by", "TEXT"], ["approver_kind", "TEXT"], ["plan_digest", "TEXT"], ["environment", "TEXT"], ["release_digest", "TEXT"], ["git_sha", "TEXT"], ["run_id", "TEXT"], ["url", "TEXT"], ["note", "TEXT"], ["expires_at", "TEXT"], ["origin", "TEXT"], ["empty", "INTEGER"], ["signed", "INTEGER"], ["change_set", "TEXT"], ["request", "TEXT"]],
93
- /** One row per deploy record in `<env>/releases.jsonl`. `promoted_from`, `restores` and `redeploys` are JSON. */
94
- deploys: [["member", "TEXT"], ["env", "TEXT"], ["component", "TEXT"], ["digest", "TEXT"], ["git_sha", "TEXT"], ["run_id", "TEXT"], ["forge", "TEXT"], ["run_url", "TEXT"], ["timestamp", "TEXT"], ["actor", "TEXT"], ["approver", "TEXT"], ["release_digest", "TEXT"], ["digest_kind", "TEXT"], ["promoted_from", "TEXT"], ["restores", "TEXT"], ["redeploys", "TEXT"]],
93
+ /** One row per deploy record in `<env>/releases.jsonl`. `promoted_from`, `restores`, `redeploys` and `unchanged_since` (#4695) are JSON. */
94
+ deploys: [["member", "TEXT"], ["env", "TEXT"], ["component", "TEXT"], ["digest", "TEXT"], ["git_sha", "TEXT"], ["run_id", "TEXT"], ["forge", "TEXT"], ["run_url", "TEXT"], ["timestamp", "TEXT"], ["actor", "TEXT"], ["approver", "TEXT"], ["release_digest", "TEXT"], ["digest_kind", "TEXT"], ["promoted_from", "TEXT"], ["restores", "TEXT"], ["redeploys", "TEXT"], ["unchanged_since", "TEXT"]],
95
95
  /** One row per release file whose content hashes to its digest. `envs` joins its targets' environments with commas; `artifacts` is JSON. */
96
96
  releases: [["member", "TEXT"], ["release_digest", "TEXT"], ["release_member", "TEXT"], ["git_sha", "TEXT"], ["envs", "TEXT"], ["artifacts", "TEXT"]],
97
97
  /** One row per line of `_releases/cuts.jsonl`. `signed` is 1 for a signed cut. */
@@ -336,7 +336,7 @@ export async function loadQueryData(ledgers: readonly QueryLedger[]): Promise<Qu
336
336
  const { records, malformed: bad } = parseReleaseLedger(releaseLedgerLines(await port.read(env, file)));
337
337
  malformed.deploys += bad;
338
338
  for (const d of records) {
339
- data.deploys.push({ member, env: d.env, component: d.component, digest: d.digest, git_sha: d.gitSha, run_id: d.runId, forge: str(d.runOrigin?.forge), run_url: str(d.runOrigin?.url), timestamp: d.timestamp, actor: d.actor, approver: str(d.approver), release_digest: str(d.releaseDigest), digest_kind: str(d.digestKind), promoted_from: json(d.promotedFrom), restores: json(d.restores), redeploys: json(d.redeploys) });
339
+ data.deploys.push({ member, env: d.env, component: d.component, digest: d.digest, git_sha: d.gitSha, run_id: d.runId, forge: str(d.runOrigin?.forge), run_url: str(d.runOrigin?.url), timestamp: d.timestamp, actor: d.actor, approver: str(d.approver), release_digest: str(d.releaseDigest), digest_kind: str(d.digestKind), promoted_from: json(d.promotedFrom), restores: json(d.restores), redeploys: json(d.redeploys), unchanged_since: json(d.unchangedSince) });
340
340
  }
341
341
  continue;
342
342
  }
@@ -100,6 +100,24 @@ describe("a cut from a lane (#4692)", () => {
100
100
  });
101
101
  });
102
102
 
103
+ test("an image handed to a cut from a lane is recorded, and nothing is built (#4694)", async () => {
104
+ await withTestDir(async (dir) => {
105
+ const sha = workspace(dir);
106
+ git(dir, "tag", `ci/green-server/${sha}`, sha);
107
+ const images = { api: `registry.fly.io/api@sha256:${"c".repeat(64)}` };
108
+ const plan = await planRelease({ cwd: dir, compiler: compiler(), label: "v1.0.0", actor: "alice", env: {}, lane: "server", images });
109
+ expect(plan.build).toEqual([]);
110
+ expect(plan.handed.map((h) => h.ref)).toEqual([images.api]);
111
+ const result = await cutRelease({ cwd: dir, compiler: compiler(), label: "v1.0.0", actor: "alice", env: {}, now: NOW, lane: "server", images });
112
+ expect(result.cut?.lane).toBe("server");
113
+ expect(result.release.artifactDigests.map((a) => a.ref)).toEqual([images.api]);
114
+ expect(result.release.releaseDigest).toBe(plan.releaseDigest);
115
+ const doc = await releasesDocument({ cwd: dir });
116
+ if ("error" in doc) throw new Error(doc.error.message);
117
+ contract(releasesSchema).expectValid(doc);
118
+ });
119
+ });
120
+
103
121
  test("a cut without a lane writes no lane, and a full green commit is cut as before", async () => {
104
122
  await withTestDir(async (dir) => {
105
123
  const sha = workspace(dir);
@@ -155,6 +155,18 @@ describe("a cut of a commit that is not green, under an override (#4693)", () =>
155
155
  });
156
156
  });
157
157
 
158
+ test("an image handed to the cut is recorded under an override, and nothing is built (#4694)", async () => {
159
+ await withTestDir(async (dir) => {
160
+ const sha = project(dir);
161
+ await refusal(cutRelease(request(dir, T0)));
162
+ await override(dir, sha, "github:alice");
163
+ const result = await cutRelease({ ...request(dir, T2), images: { api: `registry.fly.io/api@sha256:${"c".repeat(64)}` } });
164
+ expect(result.cut?.override?.by).toBe("github:alice");
165
+ expect(result.handed).toEqual([{ component: "api", ref: `registry.fly.io/api@sha256:${"c".repeat(64)}`, digest: `sha256:${"c".repeat(64)}` }]);
166
+ expect(result.release.artifactDigests).toEqual([{ component: "api", kind: "image", path: "", digest: `sha256:${"c".repeat(64)}`, ref: `registry.fly.io/api@sha256:${"c".repeat(64)}` }]);
167
+ });
168
+ });
169
+
158
170
  test("an override counts only from a listed person, with a reason, and not from an agent", async () => {
159
171
  await withTestDir(async (dir) => {
160
172
  const sha = project(dir);
@@ -123,6 +123,14 @@ describe("the release digest", () => {
123
123
  expect(computeReleaseDigest({ ...subject, targets: [{ ...t, templates: [{ ...t.templates[0], encoding: "base64" as const }] }] })).not.toBe(digest);
124
124
  });
125
125
 
126
+ test("an artifact without a ref hashes as before #4694; a handed image's ref is in the digest", () => {
127
+ const digest = computeReleaseDigest(subject);
128
+ expect(computeReleaseDigest({ ...subject, artifactDigests: subject.artifactDigests.map((a) => ({ ...a, ref: undefined })) })).toBe(digest);
129
+ const handed = { ...subject, artifactDigests: [{ component: "api", kind: "image" as const, path: "", digest: "sha256:1", ref: "r.io/api@sha256:1" }] };
130
+ expect(computeReleaseDigest(handed)).not.toBe(computeReleaseDigest({ ...handed, artifactDigests: [{ ...handed.artifactDigests[0], ref: "r.io/other@sha256:1" }] }));
131
+ expect(makeRelease(handed).artifactDigests[0].ref).toBe("r.io/api@sha256:1");
132
+ });
133
+
126
134
  test("verifyReleaseDigest catches a release whose content no longer matches its digest", () => {
127
135
  const release = makeRelease(subject);
128
136
  expect(verifyReleaseDigest(release)).toBe(true);
@@ -307,6 +315,43 @@ describe("cutRelease", () => {
307
315
  });
308
316
  });
309
317
 
318
+ test("an image handed to the cut is recorded by its reference, and the component is not built (#4694)", async () => {
319
+ await withTestDir(async (dir) => {
320
+ const sha = initRepo(dir);
321
+ green(dir, sha);
322
+ const ref = `registry.fly.io/api@sha256:${"b".repeat(64)}`;
323
+ const compiler = fixtureCompiler();
324
+ const plan = await planRelease({ cwd: dir, compiler: fixtureCompiler(), label: "v1", actor: "a", env: {}, images: { api: ref } });
325
+ expect(plan.build).toEqual([]);
326
+ expect(plan.handed).toEqual([{ component: "api", ref, digest: `sha256:${"b".repeat(64)}` }]);
327
+
328
+ const result = await cutRelease({ cwd: dir, compiler, label: "v1", actor: "a", env: {}, images: { api: ref } });
329
+ expect(compiler.built).toEqual([]);
330
+ expect(result.release.artifactDigests).toEqual([{ component: "api", kind: "image", path: "", digest: `sha256:${"b".repeat(64)}`, ref }]);
331
+ expect(plan.releaseDigest).toBe(result.release.releaseDigest);
332
+ expect(await readRelease(result.release.releaseDigest, { cwd: dir })).toEqual(result.release);
333
+
334
+ // The next cut hands another image; nothing is carried from the first.
335
+ const next = commitFile(dir, "flags.json", "{}\n");
336
+ green(dir, next);
337
+ const r2 = await cutRelease({ cwd: dir, compiler, label: "v2", actor: "a", env: {}, images: { api: `registry.fly.io/api@sha256:${"c".repeat(64)}` } });
338
+ expect(r2.reused).toEqual([]);
339
+ expect(r2.release.artifactDigests.map((a) => a.digest)).toEqual([`sha256:${"c".repeat(64)}`]);
340
+ });
341
+ });
342
+
343
+ test("refuses an image handed by tag, or for a component that isn't enabled (#4694)", async () => {
344
+ await withTestDir(async (dir) => {
345
+ const sha = initRepo(dir);
346
+ green(dir, sha);
347
+ const byTag = await planRelease({ cwd: dir, compiler: fixtureCompiler(), label: null, actor: "a", env: {}, images: { api: "registry.fly.io/api:latest" } }).catch((e: unknown) => e);
348
+ expect((byTag as ReleaseCutError).code).toBe("release-image-invalid");
349
+ const unknown = await planRelease({ cwd: dir, compiler: fixtureCompiler(), label: null, actor: "a", env: {}, images: { web: `r.io/web@sha256:${"b".repeat(64)}` } }).catch((e: unknown) => e);
350
+ expect((unknown as ReleaseCutError).code).toBe("release-image-unknown-component");
351
+ expect((unknown as ReleaseCutError).fix).toMatch(/api/);
352
+ });
353
+ });
354
+
310
355
  test("refuses a member that declares no environments", async () => {
311
356
  await withTestDir(async (dir) => {
312
357
  const sha = initRepo(dir);
@@ -17,6 +17,14 @@
17
17
  * component's own file, the member's `chant.config.ts` and the paths its
18
18
  * build steps read.
19
19
  *
20
+ * An image built elsewhere, as by a CI job that builds what the cut's machine
21
+ * can't, is handed to the cut by digest (#4694, `--image
22
+ * <component>=<repository>@sha256:<hex>`). The release records it with its
23
+ * reference in `ref`, and the cut builds nothing for that component: its
24
+ * archive steps, if it has any, don't run, and no earlier release's entry is
25
+ * carried. A deploy under the release runs that image
26
+ * (../components/release-run.ts).
27
+ *
20
28
  * A project with no components (#4046) needs no special case here: its
21
29
  * targets hold the files `chant build --env <env>` writes, each with
22
30
  * `component: null`, and `artifactDigests` is empty.
@@ -74,12 +82,11 @@ import {
74
82
  type TemplateContent,
75
83
  } from "./release-store";
76
84
  import type { CompiledTarget, TargetCompiler } from "../components/release-compile";
77
- import { NEXT_RELEASE } from "../release-floors";
78
85
 
79
86
  /** The first chant that cuts from a lane's green tag and writes `lane` on the cut line (#4692). */
80
- export const RELEASE_CUT_LANE_FLOOR = NEXT_RELEASE;
87
+ export const RELEASE_CUT_LANE_FLOOR = "0.124.64";
81
88
  /** The first chant that cuts a commit that is not green under an override and writes `override` on the cut line (#4693). */
82
- export const RELEASE_CUT_OVERRIDE_FLOOR = NEXT_RELEASE;
89
+ export const RELEASE_CUT_OVERRIDE_FLOOR = "0.124.64";
83
90
 
84
91
  /** The override gate's subject for a cut of `commit` (#4693): `release-<sha12>`. */
85
92
  export function greenOverrideSubject(commit: string): string {
@@ -103,6 +110,8 @@ export type ReleaseCutCode =
103
110
  | "release-no-environments"
104
111
  | "release-no-components"
105
112
  | "release-build-inputs-differ"
113
+ | "release-image-invalid"
114
+ | "release-image-unknown-component"
106
115
  | "release-unsigned"
107
116
  | "release-signer-refused"
108
117
  | "declaration-invalid";
@@ -156,6 +165,12 @@ export interface CutRequest {
156
165
  * refused, and a cut that is not a dry run records the request for one.
157
166
  */
158
167
  overrideGreen?: boolean;
168
+ /**
169
+ * Images built elsewhere and handed to the cut (#4694), by component: each
170
+ * `<repository>@sha256:<hex>`. The release records each as the component's
171
+ * image, and the cut builds nothing for it.
172
+ */
173
+ images?: Readonly<Record<string, string>>;
159
174
  }
160
175
 
161
176
  export interface CutResult {
@@ -168,6 +183,26 @@ export interface CutResult {
168
183
  stored: boolean;
169
184
  /** The components whose artifacts were taken from an earlier release, and that release's digest. */
170
185
  reused: Array<{ component: string; from: string }>;
186
+ /** The images handed to the cut (#4694), by component, as recorded. */
187
+ handed: Array<{ component: string; ref: string; digest: string }>;
188
+ }
189
+
190
+ /** An image reference by digest: `<repository>@sha256:<64 hex>`, the repository without a tag. */
191
+ const IMAGE_BY_DIGEST = /^([a-z0-9]+(?:[._-][a-z0-9]+)*(?::[0-9]+)?(?:\/[a-z0-9]+(?:[._-]+[a-z0-9]+)*)*)@(sha256:[0-9a-f]{64})$/;
192
+
193
+ /**
194
+ * The release artifact for an image handed to the cut (#4694), or why the
195
+ * reference can't be one: it must name its repository and its digest, and no
196
+ * tag, since a tag can move after the cut.
197
+ */
198
+ export function handedImage(component: string, ref: string): ReleaseArtifact | { error: string } {
199
+ const m = IMAGE_BY_DIGEST.exec(ref);
200
+ if (!m) {
201
+ return {
202
+ error: `--image ${component}=${ref}: an image is handed to the cut by digest, as <repository>@sha256:<64 hex digits> with no tag, such as registry.fly.io/app@sha256:${"0".repeat(64)}`,
203
+ };
204
+ }
205
+ return { component, kind: "image", path: "", digest: m[2]!, ref };
171
206
  }
172
207
 
173
208
  function git(top: string, args: string[]): string {
@@ -249,9 +284,10 @@ interface Prepared {
249
284
  releaseRule: ReturnType<typeof import("../workspace/identity").releaseRuleFrom>;
250
285
  /** The components to build, by the environment they are built in. */
251
286
  toBuild: Map<string, string[]>;
252
- /** The artifacts carried from an earlier release. */
287
+ /** The artifacts carried from an earlier release, and the images handed to the cut. */
253
288
  carried: ReleaseArtifact[];
254
289
  reused: CutResult["reused"];
290
+ handed: CutResult["handed"];
255
291
  member: string | null;
256
292
  /** The lane the commit was checked in, or null for the full green tag. */
257
293
  lane: string | null;
@@ -447,15 +483,34 @@ async function prepare(req: CutRequest, record = false): Promise<Prepared> {
447
483
  );
448
484
  }
449
485
 
486
+ // #4694: an image handed to the cut is the component's, in place of a build.
487
+ const enabled = new Set(compiled.flatMap((t) => t.components));
488
+ const handedArtifacts: ReleaseArtifact[] = [];
489
+ for (const [component, ref] of Object.entries(req.images ?? {})) {
490
+ if (!enabled.has(component)) {
491
+ throw new ReleaseCutError(
492
+ "release-image-unknown-component",
493
+ `--image names "${component}", which is not a component enabled in any environment of this member`,
494
+ enabled.size > 0 ? `The components are: ${[...enabled].sort().join(", ")}` : undefined,
495
+ );
496
+ }
497
+ const artifact = handedImage(component, ref);
498
+ if ("error" in artifact) throw new ReleaseCutError("release-image-invalid", artifact.error);
499
+ handedArtifacts.push(artifact);
500
+ }
501
+ const handedTo = new Set(handedArtifacts.map((a) => a.component));
502
+
450
503
  // Which environment each component's artifacts are built in: the first one it is enabled in.
451
504
  const firstEnv = new Map<string, CompiledTarget>();
452
- for (const t of compiled) for (const c of t.components) if (!firstEnv.has(c) && (t.buildSteps[c]?.length ?? 0) > 0) firstEnv.set(c, t);
505
+ for (const t of compiled) {
506
+ for (const c of t.components) if (!firstEnv.has(c) && !handedTo.has(c) && (t.buildSteps[c]?.length ?? 0) > 0) firstEnv.set(c, t);
507
+ }
453
508
 
454
509
  // git names paths from its top with symlinks resolved (/private/var on macOS).
455
510
  const realCwd = realpathSync(cwd);
456
511
  const previous = firstEnv.size > 0 ? await previousRelease(top, commit, cwd) : undefined;
457
512
  const reused: CutResult["reused"] = [];
458
- const artifacts: ReleaseArtifact[] = [];
513
+ const artifacts: ReleaseArtifact[] = [...handedArtifacts];
459
514
  const toBuild = new Map<string, string[]>();
460
515
  for (const [component, target] of firstEnv) {
461
516
  const prior = previous?.artifactDigests.filter((a) => a.component === component) ?? [];
@@ -484,6 +539,7 @@ async function prepare(req: CutRequest, record = false): Promise<Prepared> {
484
539
  toBuild,
485
540
  carried: artifacts,
486
541
  reused,
542
+ handed: handedArtifacts.map((a) => ({ component: a.component, ref: a.ref!, digest: a.digest })),
487
543
  member: ledger.members.length > 0 ? ledger.members.join("/") : null,
488
544
  lane,
489
545
  override,
@@ -531,6 +587,8 @@ export interface CutPlan {
531
587
  build: Array<{ component: string; env: string }>;
532
588
  /** The components whose artifacts would be carried from an earlier release. */
533
589
  reused: CutResult["reused"];
590
+ /** The images handed to the cut (#4694), by component. */
591
+ handed: CutResult["handed"];
534
592
  /** Each component's publish steps, with the environments whose deploy runs them. */
535
593
  publishSteps: Array<{ component: string; kind: string; to: string | null; envs: string[] }>;
536
594
  /** Whether the release gate in identity.gates requires a signed cut. */
@@ -605,6 +663,7 @@ export async function planRelease(req: CutRequest): Promise<CutPlan> {
605
663
  targets: targets.map((t) => ({ env: t.env, params: t.params, templates: t.templates.map(({ component, path }) => ({ component, path })), ...(t.trees ? { trees: t.trees } : {}) })),
606
664
  build,
607
665
  reused: p.reused,
666
+ handed: p.handed,
608
667
  publishSteps: [...steps.values()],
609
668
  signatureRequired: p.releaseRule.requirement !== null,
610
669
  lane: p.lane,
@@ -628,7 +687,7 @@ export async function planRelease(req: CutRequest): Promise<CutPlan> {
628
687
  */
629
688
  export async function cutRelease(req: CutRequest): Promise<CutResult> {
630
689
  const p = await prepare(req, true);
631
- const { cwd, commit, compiled, releaseRule, reused } = p;
690
+ const { cwd, commit, compiled, releaseRule, reused, handed } = p;
632
691
  const artifacts = [...p.carried];
633
692
  for (const env of p.envs) {
634
693
  const names = p.toBuild.get(env);
@@ -697,5 +756,6 @@ export async function cutRelease(req: CutRequest): Promise<CutResult> {
697
756
  label: outcome.appended ? outcome.cut.label : outcome.label,
698
757
  stored: stored.written,
699
758
  reused,
759
+ handed,
700
760
  };
701
761
  }