@intentius/chant-lexicon-pulumi 0.124.77 → 0.124.78

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.
@@ -1,3 +1,5 @@
1
+ /** The first chant with `link: false` and {@link ciFetchScript} (#4814). It is core's floor, so it freezes with chant's release. */
2
+ export declare const PULUMI_CI_SETUP_FLOOR: string;
1
3
  export type CiEngine = "pulumi" | "plunge";
2
4
  /** The Pulumi release the default lines install: the plunge corpus's, which plunge 0.1.0 is built from. */
3
5
  export declare const PULUMI_CI_VERSION = "3.272.0";
@@ -21,6 +23,12 @@ export interface CiInstallOptions {
21
23
  root?: string;
22
24
  /** Recorded sums by architecture, in place of {@link PINNED_SHA256}'s for this release. */
23
25
  sha256?: Partial<Record<CiArch, string>>;
26
+ /**
27
+ * Link the binary into /usr/local/bin (default true). `false` (#4814)
28
+ * leaves PATH alone and skips only on the versioned directory, for a pin
29
+ * a step runs by its path.
30
+ */
31
+ link?: boolean;
24
32
  }
25
33
  /** One release's download: the base URL, the archive per architecture, and its checksums file. */
26
34
  export interface CiRelease {
@@ -34,9 +42,38 @@ export declare function ciRelease(engine: CiEngine, version: string): CiRelease;
34
42
  export declare function ciEngineDir(engine: CiEngine, version: string, root?: string): string;
35
43
  /** The recorded sums for `version`, by architecture: the caller's, else {@link PINNED_SHA256}'s. */
36
44
  export declare function recordedSums(engine: CiEngine, version: string, given?: Partial<Record<CiArch, string>>): Partial<Record<CiArch, string>>;
45
+ /** A shell expression giving the job's architecture as x64 or arm64. */
46
+ export declare const CI_JOB_ARCH = "\"$(uname -m | sed 's/x86_64/x64/;s/aarch64/arm64/')\"";
47
+ /**
48
+ * A shell expression giving a Docker build's target architecture
49
+ * (`ARG TARGETARCH`) as x64 or arm64. Each case pattern opens with "(":
50
+ * bash 3.2 (macOS sh) cannot parse a bare `arm64)` inside `$(...)`.
51
+ */
52
+ export declare const CI_DOCKER_ARCH = "\"$(case \"$TARGETARCH\" in (arm64) echo arm64 ;; (*) echo x64 ;; esac)\"";
53
+ /** Where {@link ciFetchScript} puts a release and what it checks it against. */
54
+ export interface CiFetchOptions {
55
+ /** The directory the archive unpacks into, an absolute path: `/out/opt/plywood/pulumi-3.272.0` in an image's fetch stage. */
56
+ dir: string;
57
+ /** A shell expression giving x64 or arm64. Default {@link CI_JOB_ARCH}; an image build passes {@link CI_DOCKER_ARCH}. */
58
+ arch?: string;
59
+ /** A shell word for the checksums file's URL, such as `"$CHECKSUMS_URL"`. Default the release's own. */
60
+ checksumsUrl?: string;
61
+ /** Recorded sums by architecture, in place of {@link PINNED_SHA256}'s for this release. */
62
+ sha256?: Partial<Record<CiArch, string>>;
63
+ }
64
+ /**
65
+ * Shell that downloads one release into `dir` and checks it against the
66
+ * release's checksums file and, when recorded, the sum per architecture
67
+ * (#4814). Run it under `set -e`. Both archives unpack a top directory named
68
+ * after the engine, which `--strip-components=1` drops. `arch` and
69
+ * `checksumsUrl` go onto the line as they are, so they are the caller's
70
+ * shell, never a value from outside.
71
+ */
72
+ export declare function ciFetchScript(engine: CiEngine, version: string, options: CiFetchOptions): string;
37
73
  /**
38
74
  * Pulumi at `version` under `<root>/pulumi-<version>/`, checked against the
39
- * release checksums. Skips when the `pulumi` on PATH is that version.
75
+ * release checksums. Linked, it skips when the `pulumi` on PATH is that
76
+ * version; with `link: false` only when the versioned directory holds it.
40
77
  */
41
78
  export declare function pulumiInstallLine(version?: string, options?: CiInstallOptions): string;
42
79
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ci-setup.d.ts","sourceRoot":"","sources":["../src/ci-setup.ts"],"names":[],"mappings":"AA6BA,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE3C,2GAA2G;AAC3G,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,mIAAmI;AACnI,eAAO,MAAM,iBAAiB,UAAU,CAAC;AAEzC,uDAAuD;AACvD,eAAO,MAAM,cAAc,eAAe,CAAC;AAE3C,iFAAi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25
25
  * A product with images of its own (plywood keeps its engines under
26
26
  * /opt/plywood) passes `root`, so the lines find what its image carries.
27
+ *
28
+ * `link: false` (#4814) installs a second release beside the linked one, for
29
+ * a step that runs `<root>/<engine>-<version>/<engine>` itself (pulumi-up's
30
+ * `engineVersion` and `engineRoot`): the line skips only when that directory
31
+ * holds the binary, and never touches PATH. {@link ciFetchScript} is the
32
+ * download and check alone, for an image build's `RUN` with the arch from
33
+ * `$TARGETARCH` ({@link CI_DOCKER_ARCH}) and the checksums URL from a build
34
+ * argument, so a tampered checksums file can be shown to fail the build.
27
35
  */
36
+ import { CI_SETUP_UNLINKED_FLOOR } from "@intentius/chant/lexicon";
28
37
  import { pulumiMemberEngine } from "./member-engine.js";
38
+ /** The first chant with `link: false` and {@link ciFetchScript} (#4814). It is core's floor, so it freezes with chant's release. */
39
+ export const PULUMI_CI_SETUP_FLOOR = CI_SETUP_UNLINKED_FLOOR;
29
40
  /** The Pulumi release the default lines install: the plunge corpus's, which plunge 0.1.0 is built from. */
30
41
  export const PULUMI_CI_VERSION = "3.272.0";
31
42
  /** The plunge release the default lines install (INTENTIUS/plunge, tag plunge-v<ver>), not the Pulumi version it is built from. */
@@ -85,25 +96,38 @@ export function recordedSums(engine, version, given) {
85
96
  }
86
97
  return out;
87
98
  }
88
- /** The job's architecture as x64 or arm64. */
89
- const JOB_ARCH = `"$(uname -m | sed 's/x86_64/x64/;s/aarch64/arm64/')"`;
99
+ /** A shell expression giving the job's architecture as x64 or arm64. */
100
+ export const CI_JOB_ARCH = `"$(uname -m | sed 's/x86_64/x64/;s/aarch64/arm64/')"`;
101
+ /**
102
+ * A shell expression giving a Docker build's target architecture
103
+ * (`ARG TARGETARCH`) as x64 or arm64. Each case pattern opens with "(":
104
+ * bash 3.2 (macOS sh) cannot parse a bare `arm64)` inside `$(...)`.
105
+ */
106
+ export const CI_DOCKER_ARCH = `"$(case "$TARGETARCH" in (arm64) echo arm64 ;; (*) echo x64 ;; esac)"`;
90
107
  /**
91
108
  * Shell that downloads one release into `dir` and checks it against the
92
- * release's checksums file and, when recorded, the sum per architecture.
93
- * Both archives unpack a top directory named after the engine, which
94
- * `--strip-components=1` drops.
109
+ * release's checksums file and, when recorded, the sum per architecture
110
+ * (#4814). Run it under `set -e`. Both archives unpack a top directory named
111
+ * after the engine, which `--strip-components=1` drops. `arch` and
112
+ * `checksumsUrl` go onto the line as they are, so they are the caller's
113
+ * shell, never a value from outside.
95
114
  */
96
- function fetchScript(engine, version, dir, sums) {
115
+ export function ciFetchScript(engine, version, options) {
116
+ if (!ROOT.test(options.dir))
117
+ throw new Error(`a fetch directory is an absolute path of letters, digits and ._/-, not ${JSON.stringify(options.dir)}`);
118
+ return fetchScript(engine, version, options.dir, recordedSums(engine, version, options.sha256), options.arch ?? CI_JOB_ARCH, options.checksumsUrl);
119
+ }
120
+ function fetchScript(engine, version, dir, sums, arch, checksumsUrl) {
97
121
  const r = ciRelease(engine, version);
98
122
  const recorded = CI_ARCHES.filter((a) => sums[a]);
99
123
  const pinCase = recorded.length > 0 ? `case "$a" in ${recorded.map((a) => `${a}) want=${sums[a]} ;;`).join(" ")} *) want= ;; esac` : "want=";
100
124
  const file = r.archive("x64").replace("-x64.", "-$a.");
101
125
  return [
102
- `a=${JOB_ARCH}`,
126
+ `a=${arch}`,
103
127
  `f="${file}"`,
104
128
  `t="$(mktemp -d)"`,
105
129
  `curl -fsSLo "$t/$f" "${r.base}/$f"`,
106
- `curl -fsSLo "$t/sums" "${r.base}/${r.checksums}"`,
130
+ `curl -fsSLo "$t/sums" ${checksumsUrl ?? `"${r.base}/${r.checksums}"`}`,
107
131
  // The archive's line, with any ./ or * before the name taken off.
108
132
  `line="$(sed -n "s#^\\([0-9a-f]\\{64\\}\\) *[*.]*/*$f\\$#\\1#p" "$t/sums")"`,
109
133
  `{ [ -n "$line" ] || { echo "${engine} ${version}: $f is not in ${r.checksums}" >&2; exit 1; }; }`,
@@ -114,17 +138,21 @@ function fetchScript(engine, version, dir, sums) {
114
138
  `tar -xzf "$t/$f" -C "${dir}" --strip-components=1`,
115
139
  ].join(" && ");
116
140
  }
117
- /** The line for one engine: skip when present, else fetch and check, then link into /usr/local/bin. */
141
+ /** The line for one engine: skip when present, else fetch and check, then link into /usr/local/bin unless `link` is false. */
118
142
  function installLine(engine, version, options, present) {
119
143
  const dir = ciEngineDir(engine, version, options.root);
120
- const install = `(set -e; ${fetchScript(engine, version, dir, recordedSums(engine, version, options.sha256))})`;
144
+ const install = `(set -e; ${fetchScript(engine, version, dir, recordedSums(engine, version, options.sha256), CI_JOB_ARCH)})`;
145
+ // Unlinked: the versioned directory alone says whether this release is there.
146
+ if (options.link === false)
147
+ return `[ -x "${dir}/${engine}" ] || ${install}`;
121
148
  const link = `ln -sf "${dir}/${engine}" /usr/local/bin/${engine}`;
122
149
  const inDir = `[ -x "${dir}/${engine}" ]`;
123
150
  return present ? `${present} || { { ${inDir} || ${install}; } && ${link}; }` : `{ ${inDir} || ${install}; } && ${link}`;
124
151
  }
125
152
  /**
126
153
  * Pulumi at `version` under `<root>/pulumi-<version>/`, checked against the
127
- * release checksums. Skips when the `pulumi` on PATH is that version.
154
+ * release checksums. Linked, it skips when the `pulumi` on PATH is that
155
+ * version; with `link: false` only when the versioned directory holds it.
128
156
  */
129
157
  export function pulumiInstallLine(version = PULUMI_CI_VERSION, options = {}) {
130
158
  ciRelease("pulumi", version);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "algorithm": "sha256",
3
3
  "artifacts": {
4
- "manifest.json": "2fa60d02dd777d4354d62208875a4350eb14a8144609b50625a9df414565e795",
4
+ "manifest.json": "dd5c57a82a0caba7be924c8717a872c97b7dad4ffb3d2d995b1bd522f2c81210",
5
5
  "meta.json": "ca3d163bab055381827226140568f3bef7eaac187cebd76878e0b63e9e442356",
6
6
  "types/index.d.ts": "883bcdf6a960e21360e79df010ca2087719fffec60fc39541c5ecd32d661e328",
7
7
  "rules/member-dir-absolute.ts": "4805d5e247ad544f942e1b2c36fc15a5087ca0aacaf804183a269021bd60e276",
@@ -25,5 +25,5 @@
25
25
  "skills/chant-pulumi-stack-export.md": "aadd67f5e067de61dfda43d57492bca08bd22429e4baf314d6856a810dc0e8dc",
26
26
  "skills/chant-pulumi-plunge.md": "8a7f2f9f1124744dee9645905f141057ca01f5a88e34e1bc3858d69406d7ff3a"
27
27
  },
28
- "composite": "1d542b54cd5a8f5807c7c9f961becd0650dd7c4841efd84bb62e79961e783197"
28
+ "composite": "4478559916bc27e26c9ecd8da5720945095ebd991fedada35187abe96bdd4e09"
29
29
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pulumi",
3
- "version": "0.124.77",
3
+ "version": "0.124.78",
4
4
  "chantVersion": ">=0.1.0",
5
5
  "namespace": "Pulumi"
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intentius/chant-lexicon-pulumi",
3
- "version": "0.124.77",
3
+ "version": "0.124.78",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/",
@@ -54,7 +54,7 @@
54
54
  "access": "public"
55
55
  },
56
56
  "peerDependencies": {
57
- "@intentius/chant": "^0.124.77",
57
+ "@intentius/chant": "^0.124.78",
58
58
  "zod": "^4.3.6"
59
59
  },
60
60
  "description": "pulumi lexicon for chant: a Pulumi program as a workspace member, its preview in the change set and its refresh as drift records",
@@ -5,11 +5,22 @@
5
5
  * only; nothing is downloaded.
6
6
  */
7
7
 
8
+ import { execFileSync, spawnSync } from "node:child_process";
9
+ import { createHash } from "node:crypto";
10
+ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
8
13
  import { describe, expect, test } from "vitest";
14
+ import { CI_SETUP_UNLINKED_FLOOR } from "@intentius/chant/lexicon";
15
+ import { NEXT_RELEASE } from "@intentius/chant/release-floors";
9
16
  import {
10
17
  ciEngineDir,
18
+ ciFetchScript,
11
19
  ciRelease,
20
+ CI_DOCKER_ARCH,
12
21
  CI_ENGINE_ROOT,
22
+ CI_JOB_ARCH,
23
+ PULUMI_CI_SETUP_FLOOR,
13
24
  PINNED_SHA256,
14
25
  PLUNGE_CI_VERSION,
15
26
  plungeInstallLine,
@@ -121,3 +132,89 @@ describe("pulumi-up's pinned binary (#4592)", () => {
121
132
  expect(() => engineRunnerAt("pulumi")).toThrow(/absolute/);
122
133
  });
123
134
  });
135
+
136
+ // #4814: a second release beside the linked one, and the fetch script for image builds.
137
+ describe("an unlinked install line (#4814)", () => {
138
+ test("installs under the versioned path and never touches PATH", () => {
139
+ for (const line of [pulumiInstallLine("3.250.0", { root: "/opt/plywood", link: false }), plungeInstallLine("0.2.0", { root: "/opt/plywood", link: false })]) {
140
+ expect(line).not.toContain("/usr/local/bin");
141
+ expect(line).not.toContain("ln -s");
142
+ }
143
+ });
144
+
145
+ test("skips on the versioned directory alone, not on the pulumi that PATH finds", () => {
146
+ const line = pulumiInstallLine("3.250.0", { root: "/opt/plywood", link: false });
147
+ expect(line.startsWith('[ -x "/opt/plywood/pulumi-3.250.0/pulumi" ] || (set -e; ')).toBe(true);
148
+ expect(line).not.toContain("command -v pulumi");
149
+ expect(line).not.toContain("pulumi version");
150
+ expect(line.endsWith(")")).toBe(true);
151
+ });
152
+
153
+ test("is the fetch script under the job's architecture, so plywood's unlinkedInstallLine is this call", () => {
154
+ const sums = { x64: "c".repeat(64), arm64: "d".repeat(64) };
155
+ expect(plungeInstallLine("0.2.0", { root: "/opt/plywood", sha256: sums, link: false })).toBe(
156
+ `[ -x "/opt/plywood/plunge-0.2.0/plunge" ] || (set -e; ${ciFetchScript("plunge", "0.2.0", { dir: "/opt/plywood/plunge-0.2.0", sha256: sums })})`,
157
+ );
158
+ });
159
+
160
+ test("a linked line is the one it was", () => {
161
+ expect(pulumiInstallLine()).toBe(pulumiInstallLine(PULUMI_CI_VERSION, { link: true }));
162
+ expect(pulumiInstallLine().startsWith("{ command -v pulumi")).toBe(true);
163
+ });
164
+ });
165
+
166
+ describe("ciFetchScript (#4814)", () => {
167
+ test("takes the target directory, an arch expression and a checksums URL word", () => {
168
+ const s = ciFetchScript("pulumi", "3.272.0", { dir: "/out/opt/plywood/pulumi-3.272.0", arch: CI_DOCKER_ARCH, checksumsUrl: '"$CHECKSUMS_URL"' });
169
+ expect(s.startsWith(`a=${CI_DOCKER_ARCH} && `)).toBe(true);
170
+ expect(CI_DOCKER_ARCH).toBe(`"$(case "$TARGETARCH" in (arm64) echo arm64 ;; (*) echo x64 ;; esac)"`);
171
+ expect(s).toContain('curl -fsSLo "$t/sums" "$CHECKSUMS_URL"');
172
+ expect(s).toContain('tar -xzf "$t/$f" -C "/out/opt/plywood/pulumi-3.272.0" --strip-components=1');
173
+ expect(s).toContain(`x64) want=${PINNED_SHA256["pulumi-v3.272.0-linux-x64.tar.gz"]} ;;`);
174
+ });
175
+
176
+ test("defaults to the job's architecture and the release's own checksums file", () => {
177
+ const s = ciFetchScript("plunge", "0.1.0", { dir: "/opt/chant/plunge-0.1.0" });
178
+ expect(s.startsWith(`a=${CI_JOB_ARCH} && `)).toBe(true);
179
+ expect(s).toContain('curl -fsSLo "$t/sums" "https://github.com/INTENTIUS/plunge/releases/download/plunge-v0.1.0/plunge-v0.1.0-checksums.txt"');
180
+ expect(() => ciFetchScript("plunge", "0.1.0", { dir: "relative" })).toThrow(/absolute/);
181
+ });
182
+
183
+ test.skipIf(!["sha256sum", "tar", "sh"].every((b) => spawnSync("sh", ["-c", `command -v ${b}`]).status === 0))(
184
+ "run: installs a release whose sum matches, and refuses a tampered checksums file",
185
+ () => {
186
+ const work = mkdtempSync(join(tmpdir(), "chant-ci-fetch-"));
187
+ const served = join(work, "served");
188
+ mkdirSync(join(served, "src", "pulumi"), { recursive: true });
189
+ writeFileSync(join(served, "src", "pulumi", "pulumi"), "#!/bin/sh\necho v3.272.0\n");
190
+ chmodSync(join(served, "src", "pulumi", "pulumi"), 0o755);
191
+ const archive = "pulumi-v3.272.0-linux-x64.tar.gz";
192
+ execFileSync("tar", ["-czf", join(served, archive), "-C", join(served, "src"), "pulumi"]);
193
+ const sum = createHash("sha256").update(readFileSync(join(served, archive))).digest("hex");
194
+ writeFileSync(join(served, "pulumi-3.272.0-checksums.txt"), `${sum} ${archive}\n`);
195
+ writeFileSync(join(served, "tampered.txt"), `${"0".repeat(64)} ${archive}\n`);
196
+ // curl -fsSLo <out> <url>: serve the file the URL names from the served directory.
197
+ const bin = join(work, "bin");
198
+ mkdirSync(bin);
199
+ writeFileSync(join(bin, "curl"), `#!/bin/sh\ncp "${served}/$(basename "$3")" "$2"\n`);
200
+ chmodSync(join(bin, "curl"), 0o755);
201
+ const env = { ...process.env, PATH: `${bin}:${process.env.PATH}` };
202
+ const run = (script: string) => spawnSync("sh", ["-c", `set -e; ${script}`], { env, encoding: "utf8" });
203
+
204
+ const dir = join(work, "opt", "pulumi-3.272.0");
205
+ const ok = run(ciFetchScript("pulumi", "3.272.0", { dir, arch: '"x64"', sha256: { x64: sum } }));
206
+ expect(ok.stderr).toBe("");
207
+ expect(ok.status).toBe(0);
208
+ expect(existsSync(join(dir, "pulumi"))).toBe(true);
209
+
210
+ const tampered = run(ciFetchScript("pulumi", "3.272.0", { dir: join(work, "t"), arch: '"x64"', checksumsUrl: '"https://example.test/tampered.txt"', sha256: { x64: sum } }));
211
+ expect(tampered.status).not.toBe(0);
212
+ expect(tampered.stderr).toContain(`lists ${"0".repeat(64)} for ${archive}; chant records ${sum}`);
213
+ },
214
+ );
215
+
216
+ test("the floor names the next release", () => {
217
+ expect(PULUMI_CI_SETUP_FLOOR).toBe(CI_SETUP_UNLINKED_FLOOR);
218
+ expect(CI_SETUP_UNLINKED_FLOOR).toBe(NEXT_RELEASE);
219
+ });
220
+ });
package/src/ci-setup.ts CHANGED
@@ -24,9 +24,21 @@
24
24
  *
25
25
  * A product with images of its own (plywood keeps its engines under
26
26
  * /opt/plywood) passes `root`, so the lines find what its image carries.
27
+ *
28
+ * `link: false` (#4814) installs a second release beside the linked one, for
29
+ * a step that runs `<root>/<engine>-<version>/<engine>` itself (pulumi-up's
30
+ * `engineVersion` and `engineRoot`): the line skips only when that directory
31
+ * holds the binary, and never touches PATH. {@link ciFetchScript} is the
32
+ * download and check alone, for an image build's `RUN` with the arch from
33
+ * `$TARGETARCH` ({@link CI_DOCKER_ARCH}) and the checksums URL from a build
34
+ * argument, so a tampered checksums file can be shown to fail the build.
27
35
  */
36
+ import { CI_SETUP_UNLINKED_FLOOR } from "@intentius/chant/lexicon";
28
37
  import { pulumiMemberEngine } from "./member-engine";
29
38
 
39
+ /** The first chant with `link: false` and {@link ciFetchScript} (#4814). It is core's floor, so it freezes with chant's release. */
40
+ export const PULUMI_CI_SETUP_FLOOR: string = CI_SETUP_UNLINKED_FLOOR;
41
+
30
42
  export type CiEngine = "pulumi" | "plunge";
31
43
 
32
44
  /** The Pulumi release the default lines install: the plunge corpus's, which plunge 0.1.0 is built from. */
@@ -61,6 +73,12 @@ export interface CiInstallOptions {
61
73
  root?: string;
62
74
  /** Recorded sums by architecture, in place of {@link PINNED_SHA256}'s for this release. */
63
75
  sha256?: Partial<Record<CiArch, string>>;
76
+ /**
77
+ * Link the binary into /usr/local/bin (default true). `false` (#4814)
78
+ * leaves PATH alone and skips only on the versioned directory, for a pin
79
+ * a step runs by its path.
80
+ */
81
+ link?: boolean;
64
82
  }
65
83
 
66
84
  /** One release's download: the base URL, the archive per architecture, and its checksums file. */
@@ -110,26 +128,52 @@ export function recordedSums(engine: CiEngine, version: string, given?: Partial<
110
128
  return out;
111
129
  }
112
130
 
113
- /** The job's architecture as x64 or arm64. */
114
- const JOB_ARCH = `"$(uname -m | sed 's/x86_64/x64/;s/aarch64/arm64/')"`;
131
+ /** A shell expression giving the job's architecture as x64 or arm64. */
132
+ export const CI_JOB_ARCH = `"$(uname -m | sed 's/x86_64/x64/;s/aarch64/arm64/')"`;
133
+
134
+ /**
135
+ * A shell expression giving a Docker build's target architecture
136
+ * (`ARG TARGETARCH`) as x64 or arm64. Each case pattern opens with "(":
137
+ * bash 3.2 (macOS sh) cannot parse a bare `arm64)` inside `$(...)`.
138
+ */
139
+ export const CI_DOCKER_ARCH = `"$(case "$TARGETARCH" in (arm64) echo arm64 ;; (*) echo x64 ;; esac)"`;
140
+
141
+ /** Where {@link ciFetchScript} puts a release and what it checks it against. */
142
+ export interface CiFetchOptions {
143
+ /** The directory the archive unpacks into, an absolute path: `/out/opt/plywood/pulumi-3.272.0` in an image's fetch stage. */
144
+ dir: string;
145
+ /** A shell expression giving x64 or arm64. Default {@link CI_JOB_ARCH}; an image build passes {@link CI_DOCKER_ARCH}. */
146
+ arch?: string;
147
+ /** A shell word for the checksums file's URL, such as `"$CHECKSUMS_URL"`. Default the release's own. */
148
+ checksumsUrl?: string;
149
+ /** Recorded sums by architecture, in place of {@link PINNED_SHA256}'s for this release. */
150
+ sha256?: Partial<Record<CiArch, string>>;
151
+ }
115
152
 
116
153
  /**
117
154
  * Shell that downloads one release into `dir` and checks it against the
118
- * release's checksums file and, when recorded, the sum per architecture.
119
- * Both archives unpack a top directory named after the engine, which
120
- * `--strip-components=1` drops.
155
+ * release's checksums file and, when recorded, the sum per architecture
156
+ * (#4814). Run it under `set -e`. Both archives unpack a top directory named
157
+ * after the engine, which `--strip-components=1` drops. `arch` and
158
+ * `checksumsUrl` go onto the line as they are, so they are the caller's
159
+ * shell, never a value from outside.
121
160
  */
122
- function fetchScript(engine: CiEngine, version: string, dir: string, sums: Partial<Record<CiArch, string>>): string {
161
+ export function ciFetchScript(engine: CiEngine, version: string, options: CiFetchOptions): string {
162
+ if (!ROOT.test(options.dir)) throw new Error(`a fetch directory is an absolute path of letters, digits and ._/-, not ${JSON.stringify(options.dir)}`);
163
+ return fetchScript(engine, version, options.dir, recordedSums(engine, version, options.sha256), options.arch ?? CI_JOB_ARCH, options.checksumsUrl);
164
+ }
165
+
166
+ function fetchScript(engine: CiEngine, version: string, dir: string, sums: Partial<Record<CiArch, string>>, arch: string, checksumsUrl?: string): string {
123
167
  const r = ciRelease(engine, version);
124
168
  const recorded = CI_ARCHES.filter((a) => sums[a]);
125
169
  const pinCase = recorded.length > 0 ? `case "$a" in ${recorded.map((a) => `${a}) want=${sums[a]} ;;`).join(" ")} *) want= ;; esac` : "want=";
126
170
  const file = r.archive("x64").replace("-x64.", "-$a.");
127
171
  return [
128
- `a=${JOB_ARCH}`,
172
+ `a=${arch}`,
129
173
  `f="${file}"`,
130
174
  `t="$(mktemp -d)"`,
131
175
  `curl -fsSLo "$t/$f" "${r.base}/$f"`,
132
- `curl -fsSLo "$t/sums" "${r.base}/${r.checksums}"`,
176
+ `curl -fsSLo "$t/sums" ${checksumsUrl ?? `"${r.base}/${r.checksums}"`}`,
133
177
  // The archive's line, with any ./ or * before the name taken off.
134
178
  `line="$(sed -n "s#^\\([0-9a-f]\\{64\\}\\) *[*.]*/*$f\\$#\\1#p" "$t/sums")"`,
135
179
  `{ [ -n "$line" ] || { echo "${engine} ${version}: $f is not in ${r.checksums}" >&2; exit 1; }; }`,
@@ -141,10 +185,12 @@ function fetchScript(engine: CiEngine, version: string, dir: string, sums: Parti
141
185
  ].join(" && ");
142
186
  }
143
187
 
144
- /** The line for one engine: skip when present, else fetch and check, then link into /usr/local/bin. */
188
+ /** The line for one engine: skip when present, else fetch and check, then link into /usr/local/bin unless `link` is false. */
145
189
  function installLine(engine: CiEngine, version: string, options: CiInstallOptions, present?: string): string {
146
190
  const dir = ciEngineDir(engine, version, options.root);
147
- const install = `(set -e; ${fetchScript(engine, version, dir, recordedSums(engine, version, options.sha256))})`;
191
+ const install = `(set -e; ${fetchScript(engine, version, dir, recordedSums(engine, version, options.sha256), CI_JOB_ARCH)})`;
192
+ // Unlinked: the versioned directory alone says whether this release is there.
193
+ if (options.link === false) return `[ -x "${dir}/${engine}" ] || ${install}`;
148
194
  const link = `ln -sf "${dir}/${engine}" /usr/local/bin/${engine}`;
149
195
  const inDir = `[ -x "${dir}/${engine}" ]`;
150
196
  return present ? `${present} || { { ${inDir} || ${install}; } && ${link}; }` : `{ ${inDir} || ${install}; } && ${link}`;
@@ -152,7 +198,8 @@ function installLine(engine: CiEngine, version: string, options: CiInstallOption
152
198
 
153
199
  /**
154
200
  * Pulumi at `version` under `<root>/pulumi-<version>/`, checked against the
155
- * release checksums. Skips when the `pulumi` on PATH is that version.
201
+ * release checksums. Linked, it skips when the `pulumi` on PATH is that
202
+ * version; with `link: false` only when the versioned directory holds it.
156
203
  */
157
204
  export function pulumiInstallLine(version = PULUMI_CI_VERSION, options: CiInstallOptions = {}): string {
158
205
  ciRelease("pulumi", version);