@intentius/chant 0.124.87 → 0.124.88
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/dist/action-pins.d.ts +1 -0
- package/dist/action-pins.d.ts.map +1 -1
- package/dist/action-pins.js +2 -0
- package/dist/actor.d.ts +12 -0
- package/dist/actor.d.ts.map +1 -0
- package/dist/actor.js +18 -0
- package/dist/bundle-check.d.ts +20 -5
- package/dist/bundle-check.d.ts.map +1 -1
- package/dist/bundle-check.js +20 -5
- package/dist/chant-install.d.ts +98 -0
- package/dist/chant-install.d.ts.map +1 -1
- package/dist/chant-install.js +204 -2
- package/dist/ci-commit.d.ts +1 -1
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +1 -2
- package/dist/ci-control.d.ts +1 -1
- package/dist/ci-control.d.ts.map +1 -1
- package/dist/ci-control.js +1 -1
- package/dist/ci-evidence-claims.d.ts +59 -0
- package/dist/ci-evidence-claims.d.ts.map +1 -0
- package/dist/ci-evidence-claims.js +87 -0
- package/dist/ci-evidence-from-job.d.ts +103 -0
- package/dist/ci-evidence-from-job.d.ts.map +1 -0
- package/dist/ci-evidence-from-job.js +162 -0
- package/dist/ci-evidence-jobs.d.ts +39 -4
- package/dist/ci-evidence-jobs.d.ts.map +1 -1
- package/dist/ci-evidence-jobs.js +38 -4
- package/dist/ci-handover.d.ts +12 -0
- package/dist/ci-handover.d.ts.map +1 -1
- package/dist/ci-handover.js +15 -3
- package/dist/ci-identity.d.ts +32 -6
- package/dist/ci-identity.d.ts.map +1 -1
- package/dist/ci-identity.js +40 -8
- package/dist/ci-image.d.ts +47 -9
- package/dist/ci-image.d.ts.map +1 -1
- package/dist/ci-image.js +45 -18
- package/dist/ci-jobs.d.ts +1 -1
- package/dist/ci-jobs.d.ts.map +1 -1
- package/dist/ci-jobs.js +7 -2
- package/dist/ci-login.d.ts +75 -13
- package/dist/ci-login.d.ts.map +1 -1
- package/dist/ci-login.js +89 -37
- package/dist/ci-product-words.d.ts +20 -1
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +27 -1
- package/dist/ci-product.d.ts +21 -2
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +21 -2
- package/dist/cli/handlers/approve-confirm.d.ts +14 -0
- package/dist/cli/handlers/approve-confirm.d.ts.map +1 -1
- package/dist/cli/handlers/approve-confirm.js +46 -0
- package/dist/cli/handlers/build.d.ts +1 -1
- package/dist/cli/handlers/build.d.ts.map +1 -1
- package/dist/cli/handlers/build.js +22 -1
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +21 -1
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
- package/dist/cli/handlers/ci-evidence.js +227 -18
- package/dist/cli/handlers/ci-forge-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-forge-check.js +34 -17
- package/dist/cli/handlers/generated-check.d.ts +3 -0
- package/dist/cli/handlers/generated-check.d.ts.map +1 -0
- package/dist/cli/handlers/generated-check.js +41 -0
- package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle.js +3 -0
- package/dist/cli/handlers/local-chant.d.ts +13 -0
- package/dist/cli/handlers/local-chant.d.ts.map +1 -1
- package/dist/cli/handlers/local-chant.js +42 -1
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +42 -5
- package/dist/cli/handlers/run-wave.js +8 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +38 -4
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +66 -0
- package/dist/cli/registry.d.ts +24 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/check-hooks.d.ts +10 -0
- package/dist/components/check-hooks.d.ts.map +1 -1
- package/dist/components/check-hooks.js +18 -0
- package/dist/components/pr-checks.d.ts +105 -0
- package/dist/components/pr-checks.d.ts.map +1 -0
- package/dist/components/pr-checks.js +119 -0
- package/dist/components/pr-pipeline.d.ts +34 -0
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +14 -1
- package/dist/components/product-pipeline.d.ts +16 -1
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +17 -2
- package/dist/components/product-plan.d.ts +257 -4
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +241 -11
- package/dist/config.d.ts +10 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +11 -6
- package/dist/control/consumers.d.ts +6 -0
- package/dist/control/consumers.d.ts.map +1 -1
- package/dist/control/consumers.js +6 -0
- package/dist/dead-guards.d.ts.map +1 -1
- package/dist/dead-guards.js +9 -6
- package/dist/discovery/files.d.ts +1 -1
- package/dist/discovery/files.js +1 -1
- package/dist/drift-issue.d.ts +20 -3
- package/dist/drift-issue.d.ts.map +1 -1
- package/dist/drift-issue.js +16 -0
- package/dist/drift-record.d.ts +45 -5
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/drift-record.js +27 -6
- package/dist/floor-table.d.ts +6 -6
- package/dist/floor-table.d.ts.map +1 -1
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +58 -21
- package/dist/floor-table.js +10 -7
- package/dist/forge-check/contract.d.ts +8 -0
- package/dist/forge-check/contract.d.ts.map +1 -1
- package/dist/forge-check/contract.js +4 -1
- package/dist/forge-check/index.d.ts +2 -0
- package/dist/forge-check/index.d.ts.map +1 -1
- package/dist/forge-check/index.js +2 -0
- package/dist/forge-flags.d.ts +10 -0
- package/dist/forge-flags.d.ts.map +1 -1
- package/dist/forge-flags.js +31 -0
- package/dist/forge-remote.d.ts +47 -0
- package/dist/forge-remote.d.ts.map +1 -0
- package/dist/forge-remote.js +69 -0
- package/dist/generated-check.d.ts +74 -0
- package/dist/generated-check.d.ts.map +1 -0
- package/dist/generated-check.js +216 -0
- package/dist/lexicon.d.ts +16 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.d.ts +15 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +49 -3
- package/dist/lifecycle/release-images.d.ts +22 -1
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +27 -3
- package/dist/lifecycle/release-ledger.d.ts +4 -3
- package/dist/lifecycle/release-ledger.d.ts.map +1 -1
- package/dist/lifecycle/release-ledger.js +3 -2
- package/dist/local-chant.d.ts +57 -3
- package/dist/local-chant.d.ts.map +1 -1
- package/dist/local-chant.js +122 -13
- package/dist/op/op-waves-evidence-jobs.d.ts +92 -0
- package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -0
- package/dist/op/op-waves-evidence-jobs.js +112 -0
- package/dist/op/op-waves-evidence.d.ts +12 -1
- package/dist/op/op-waves-evidence.d.ts.map +1 -1
- package/dist/op/op-waves-evidence.js +23 -2
- package/dist/op/op-waves-run.d.ts +12 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +54 -3
- package/dist/op/op-waves.d.ts +8 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +10 -0
- package/dist/op/schedule-overdue.d.ts +39 -2
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +89 -7
- package/dist/pr-forge-reads.d.ts +21 -1
- package/dist/pr-forge-reads.d.ts.map +1 -1
- package/dist/pr-forge-reads.js +19 -1
- package/dist/pr-forge.d.ts +7 -1
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +7 -2
- package/dist/pr-plan-note.d.ts +24 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +11 -1
- package/dist/pr-plan-record.d.ts +47 -0
- package/dist/pr-plan-record.d.ts.map +1 -0
- package/dist/pr-plan-record.js +89 -0
- package/dist/pr-post.d.ts +40 -0
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +79 -6
- package/dist/pr-requires.d.ts +8 -0
- package/dist/pr-requires.d.ts.map +1 -1
- package/dist/pr-requires.js +3 -1
- package/dist/ref-gate-init.d.ts +76 -0
- package/dist/ref-gate-init.d.ts.map +1 -0
- package/dist/ref-gate-init.js +144 -0
- package/dist/ref-gate-rules.d.ts +19 -0
- package/dist/ref-gate-rules.d.ts.map +1 -0
- package/dist/ref-gate-rules.js +17 -0
- package/dist/release-floors.d.ts +64 -16
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +65 -17
- package/dist/state-migration.d.ts +24 -1
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +39 -3
- package/dist/state-unlock.d.ts +32 -1
- package/dist/state-unlock.d.ts.map +1 -1
- package/dist/state-unlock.js +31 -0
- package/dist/wave-runtime.mjs +292 -285
- package/dist/workspace/ci-green-cli.d.ts.map +1 -1
- package/dist/workspace/ci-green-cli.js +13 -7
- package/dist/workspace/drift-cli.d.ts +1 -1
- package/dist/workspace/drift-cli.d.ts.map +1 -1
- package/dist/workspace/drift-cli.js +5 -12
- package/dist/workspace/forge-work.d.ts +3 -2
- package/dist/workspace/forge-work.d.ts.map +1 -1
- package/dist/workspace/forge-work.js +7 -17
- package/dist/workspace/lexicon-outputs.js +2 -2
- package/dist/workspace/release-workflow.d.ts +26 -3
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +48 -6
- package/dist/workspace/trust/check-evidence-report.d.ts +18 -0
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.js +13 -0
- package/dist/workspace/trust/check-evidence.d.ts +13 -1
- package/dist/workspace/trust/check-evidence.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence.js +8 -3
- package/dist/workspace/trust/evidence.d.ts +5 -0
- package/dist/workspace/trust/evidence.d.ts.map +1 -1
- package/dist/workspace/trust/evidence.js +5 -0
- package/dist/workspace/trust/open-evidence.d.ts +67 -0
- package/dist/workspace/trust/open-evidence.d.ts.map +1 -0
- package/dist/workspace/trust/open-evidence.js +92 -0
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate-cli.js +65 -3
- package/dist/workspace/trust/ref-gate.d.ts +61 -2
- package/dist/workspace/trust/ref-gate.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate.js +72 -7
- package/package.json +1 -1
- package/src/action-pins.ts +2 -0
- package/src/actor.test.ts +12 -0
- package/src/actor.ts +19 -0
- package/src/bundle-check.test.ts +22 -0
- package/src/bundle-check.ts +33 -5
- package/src/chant-install.test.ts +109 -1
- package/src/chant-install.ts +243 -2
- package/src/ci-commit.test.ts +51 -5
- package/src/ci-commit.ts +1 -2
- package/src/ci-control.ts +1 -0
- package/src/ci-evidence-claims.ts +102 -0
- package/src/ci-evidence-from-job.test.ts +147 -0
- package/src/ci-evidence-from-job.ts +195 -0
- package/src/ci-evidence-jobs.ts +41 -4
- package/src/ci-handover.ts +16 -3
- package/src/ci-identity.test.ts +3 -3
- package/src/ci-identity.ts +51 -11
- package/src/ci-image.test.ts +60 -10
- package/src/ci-image.ts +78 -19
- package/src/ci-jobs.ts +7 -2
- package/src/ci-login.test.ts +131 -3
- package/src/ci-login.token-drop.test.ts +204 -0
- package/src/ci-login.ts +137 -39
- package/src/ci-product-words.ts +30 -0
- package/src/ci-product.ts +26 -1
- package/src/cli/commands/__fixtures__/source-dir-root/migrations/0001-init/backfill.ts +3 -0
- package/src/cli/handlers/approve-confirm.test.ts +35 -0
- package/src/cli/handlers/approve-confirm.ts +44 -0
- package/src/cli/handlers/build-source-dir.test.ts +4 -0
- package/src/cli/handlers/build.ts +20 -2
- package/src/cli/handlers/ci-check.ts +19 -1
- package/src/cli/handlers/ci-evidence-open.test.ts +164 -0
- package/src/cli/handlers/ci-evidence.ts +210 -16
- package/src/cli/handlers/ci-forge-check.ts +22 -9
- package/src/cli/handlers/generated-check.ts +39 -0
- package/src/cli/handlers/lifecycle.test.ts +20 -0
- package/src/cli/handlers/lifecycle.ts +4 -0
- package/src/cli/handlers/local-chant.ts +39 -1
- package/src/cli/handlers/pr.ts +43 -5
- package/src/cli/handlers/run-wave.ts +7 -0
- package/src/cli/main.ts +38 -4
- package/src/cli/parse-args.ts +46 -0
- package/src/cli/registry.ts +24 -0
- package/src/components/check-hooks.ts +22 -0
- package/src/components/check-report-summary.test.ts +78 -0
- package/src/components/pr-checks.ts +159 -0
- package/src/components/pr-pipeline.ts +41 -1
- package/src/components/product-pipeline.ts +25 -3
- package/src/components/product-plan.test.ts +102 -1
- package/src/components/product-plan.ts +416 -15
- package/src/config.ts +13 -8
- package/src/control/consumers.ts +7 -0
- package/src/dead-guards.test.ts +27 -5
- package/src/dead-guards.ts +9 -6
- package/src/discovery/files.ts +1 -1
- package/src/drift-issue.test.ts +29 -1
- package/src/drift-issue.ts +28 -3
- package/src/drift-record.test.ts +25 -0
- package/src/drift-record.ts +55 -6
- package/src/floor-table.data.ts +58 -21
- package/src/floor-table.ts +12 -9
- package/src/forge-check/contract.ts +11 -1
- package/src/forge-check/forge-check.test.ts +8 -0
- package/src/forge-check/index.ts +2 -0
- package/src/forge-flags.test.ts +25 -1
- package/src/forge-flags.ts +34 -0
- package/src/forge-remote.test.ts +37 -0
- package/src/forge-remote.ts +79 -0
- package/src/generated-check.e2e.test.ts +98 -0
- package/src/generated-check.test.ts +104 -0
- package/src/generated-check.ts +269 -0
- package/src/lexicon.ts +17 -0
- package/src/lifecycle/publish-npm.ts +56 -3
- package/src/lifecycle/release-catalog.test.ts +2 -2
- package/src/lifecycle/release-images-dockerfile.test.ts +20 -0
- package/src/lifecycle/release-images.test.ts +44 -0
- package/src/lifecycle/release-images.ts +39 -3
- package/src/lifecycle/release-ledger.ts +4 -3
- package/src/local-chant.e2e.test.ts +81 -6
- package/src/local-chant.test.ts +22 -3
- package/src/local-chant.ts +130 -13
- package/src/op/op-waves-evidence-jobs.ts +134 -0
- package/src/op/op-waves-evidence.test.ts +36 -3
- package/src/op/op-waves-evidence.ts +23 -3
- package/src/op/op-waves-run.ts +57 -2
- package/src/op/op-waves.ts +11 -0
- package/src/op/schedule-overdue.test.ts +83 -1
- package/src/op/schedule-overdue.ts +107 -9
- package/src/pr-forge-reads-compare.test.ts +2 -1
- package/src/pr-forge-reads.ts +37 -1
- package/src/pr-forge.ts +14 -3
- package/src/pr-plan-note.ts +32 -3
- package/src/pr-plan-record.test.ts +75 -0
- package/src/pr-plan-record.ts +101 -0
- package/src/pr-post-plan-note.test.ts +60 -0
- package/src/pr-post.test.ts +30 -0
- package/src/pr-post.ts +110 -6
- package/src/pr-requires.test.ts +20 -0
- package/src/pr-requires.ts +10 -1
- package/src/ref-gate-init.ts +189 -0
- package/src/ref-gate-rules.ts +26 -0
- package/src/release-floors.ts +86 -17
- package/src/state-migration-record.test.ts +90 -0
- package/src/state-migration.test.ts +1 -1
- package/src/state-migration.ts +52 -3
- package/src/state-unlock.test.ts +33 -1
- package/src/state-unlock.ts +49 -1
- package/src/workspace/ci-green-cli.ts +12 -6
- package/src/workspace/drift-cli.ts +6 -18
- package/src/workspace/forge-work.ts +7 -14
- package/src/workspace/lexicon-outputs.ts +2 -2
- package/src/workspace/release-workflow.test.ts +70 -0
- package/src/workspace/release-workflow.ts +56 -8
- package/src/workspace/trust/check-evidence-report.ts +24 -0
- package/src/workspace/trust/check-evidence.ts +17 -5
- package/src/workspace/trust/evidence.ts +5 -0
- package/src/workspace/trust/open-evidence.ts +129 -0
- package/src/workspace/trust/ref-gate-cli.ts +59 -3
- package/src/workspace/trust/ref-gate-pieces.test.ts +175 -0
- package/src/workspace/trust/ref-gate.e2e.test.ts +17 -0
- package/src/workspace/trust/ref-gate.ts +87 -6
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@intentius/chant/generated-check` (#4909): the check that a product's
|
|
3
|
+
* committed generated files are what their sources render.
|
|
4
|
+
*
|
|
5
|
+
* A product commits files that chant or its own scripts render from
|
|
6
|
+
* TypeScript: workflows GitHub reads, Dockerfiles, a JSON Schema, a stack's
|
|
7
|
+
* configs. Each product carried its own drift check for them: terragucci's
|
|
8
|
+
* `just ci-check` rendered every one into a `mktemp -d` dir, compared it with
|
|
9
|
+
* `diff -u` and cleaned up with `rm -rf`, and plywood's `build-images.mjs
|
|
10
|
+
* --check` and `build-schema.mjs --check` compared in memory. Here a product
|
|
11
|
+
* declares its renders in `chantGenerated` in its root package.json, and
|
|
12
|
+
* `chant dev generated-check` runs them:
|
|
13
|
+
*
|
|
14
|
+
* 1. make one directory under the OS temp directory, the render tree;
|
|
15
|
+
* 2. run every render's command in the product root at once, with `{out}`
|
|
16
|
+
* in the command and `CHANT_GENERATED_OUT` in its environment naming that
|
|
17
|
+
* tree, so each writes its files at their committed paths below it;
|
|
18
|
+
* 3. compare each declared file with its render, in declaration order, and
|
|
19
|
+
* fail naming every file that differs, is missing on either side, or a
|
|
20
|
+
* render that failed.
|
|
21
|
+
*
|
|
22
|
+
* The render tree is never removed: it is left for the OS to clear, and the
|
|
23
|
+
* check prints where it is, so a failure can be read there.
|
|
24
|
+
*
|
|
25
|
+
* chant's own writers read `CHANT_GENERATED_OUT` too ({@link renderPathOf},
|
|
26
|
+
* {@link committedPathOf}): under a check, `chant ci workflow` and `chant
|
|
27
|
+
* release workflow` write every file into the render tree, the trigger edits
|
|
28
|
+
* to other workflows included, and name the committed path in their header,
|
|
29
|
+
* so the render matches the file that was written without `--output`.
|
|
30
|
+
*
|
|
31
|
+
* This module imports only Node's own modules.
|
|
32
|
+
*/
|
|
33
|
+
import { spawn } from "node:child_process";
|
|
34
|
+
import { existsSync, mkdtempSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
35
|
+
import { tmpdir } from "node:os";
|
|
36
|
+
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
37
|
+
|
|
38
|
+
/** The render tree of the running check, for chant's own writers and a product's scripts. */
|
|
39
|
+
export const GENERATED_OUT_ENV = "CHANT_GENERATED_OUT";
|
|
40
|
+
/** The product root the check renders for: the committed paths are relative to it. */
|
|
41
|
+
export const GENERATED_ROOT_ENV = "CHANT_GENERATED_ROOT";
|
|
42
|
+
|
|
43
|
+
/** One render: a command that writes some of the product's generated files. */
|
|
44
|
+
export interface GeneratedRender {
|
|
45
|
+
/** A short name, in the output: `ci`, `images`. */
|
|
46
|
+
name: string;
|
|
47
|
+
/**
|
|
48
|
+
* A shell command run in the product root. `{out}` is the render tree,
|
|
49
|
+
* quoted for the shell; the command writes each file at its committed path
|
|
50
|
+
* below it (`npx chant build ci -o {out}/.github/workflows/ci.yml`).
|
|
51
|
+
*/
|
|
52
|
+
run: string;
|
|
53
|
+
/**
|
|
54
|
+
* The committed files it renders, relative to the product root. A `*` in a
|
|
55
|
+
* path's last segment matches within it (`images/Dockerfile.*`), and then
|
|
56
|
+
* every match on either side must have its twin. A render with no files
|
|
57
|
+
* passes when its command exits 0 (a script with a check of its own).
|
|
58
|
+
*/
|
|
59
|
+
files?: string[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** `chantGenerated` in a product's root package.json (#4909). */
|
|
63
|
+
export interface GeneratedCheckConfig {
|
|
64
|
+
/** The command that writes the committed files, named in a failure: `just ci`. */
|
|
65
|
+
regenerate?: string;
|
|
66
|
+
renders: GeneratedRender[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface GeneratedRenderResult {
|
|
70
|
+
name: string;
|
|
71
|
+
/** The command as run, `{out}` filled in. */
|
|
72
|
+
command: string;
|
|
73
|
+
exitCode: number;
|
|
74
|
+
/** Its stdout and stderr, together. */
|
|
75
|
+
output: string;
|
|
76
|
+
/** The committed files compared, relative to the product root. */
|
|
77
|
+
files: string[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface GeneratedCheckResult {
|
|
81
|
+
ok: boolean;
|
|
82
|
+
/** The render tree, left in place. */
|
|
83
|
+
out: string;
|
|
84
|
+
problems: string[];
|
|
85
|
+
renders: GeneratedRenderResult[];
|
|
86
|
+
/** Each committed file that matched its render. */
|
|
87
|
+
matched: string[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The `chantGenerated` field of the package.json in `productDir`, or undefined. Throws on a malformed one. */
|
|
91
|
+
export function readGeneratedCheckConfig(productDir: string): GeneratedCheckConfig | undefined {
|
|
92
|
+
const f = join(productDir, "package.json");
|
|
93
|
+
if (!existsSync(f)) return undefined;
|
|
94
|
+
const raw = (JSON.parse(readFileSync(f, "utf8")) as { chantGenerated?: unknown }).chantGenerated;
|
|
95
|
+
if (raw === undefined) return undefined;
|
|
96
|
+
const c = raw as Partial<GeneratedCheckConfig>;
|
|
97
|
+
if (!c || typeof c !== "object" || !Array.isArray(c.renders)) throw new Error(`${f}: chantGenerated needs a renders list`);
|
|
98
|
+
const names = new Set<string>();
|
|
99
|
+
for (const [i, r] of c.renders.entries()) {
|
|
100
|
+
if (!r || typeof r.name !== "string" || !r.name || typeof r.run !== "string" || !r.run) throw new Error(`${f}: chantGenerated.renders[${i}] needs a name and a run command`);
|
|
101
|
+
if (names.has(r.name)) throw new Error(`${f}: chantGenerated.renders names '${r.name}' twice`);
|
|
102
|
+
names.add(r.name);
|
|
103
|
+
if (r.files !== undefined && (!Array.isArray(r.files) || r.files.some((p) => typeof p !== "string" || p.startsWith("/") || p.split("/").includes("..")))) {
|
|
104
|
+
throw new Error(`${f}: chantGenerated.renders[${i}].files must be paths inside the product`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (c.regenerate !== undefined && typeof c.regenerate !== "string") throw new Error(`${f}: chantGenerated.regenerate must be a command`);
|
|
108
|
+
return c as GeneratedCheckConfig;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Quote one argument for `sh`. */
|
|
112
|
+
const shellQuote = (s: string) => (/^[A-Za-z0-9._\/=:@%+,-]+$/.test(s) ? s : `'${s.replace(/'/g, `'\\''`)}'`);
|
|
113
|
+
|
|
114
|
+
/** The render tree and product root of the running check, or undefined outside one. */
|
|
115
|
+
function renderEnv(): { out: string; root: string } | undefined {
|
|
116
|
+
const out = process.env[GENERATED_OUT_ENV];
|
|
117
|
+
const root = process.env[GENERATED_ROOT_ENV];
|
|
118
|
+
return out && root ? { out: resolve(out), root: resolve(root) } : undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Whether `path` is `dir` or below it. */
|
|
122
|
+
const within = (dir: string, path: string) => {
|
|
123
|
+
const r = relative(dir, resolve(path));
|
|
124
|
+
return !r.startsWith("..") && !isAbsolute(r);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Where a chant writer puts `path` (absolute): under a check, a path inside
|
|
129
|
+
* the product root moves to the same place in the render tree, so a check
|
|
130
|
+
* never writes the product's files. Outside a check, `path` itself.
|
|
131
|
+
*/
|
|
132
|
+
export function renderPathOf(path: string): string {
|
|
133
|
+
const env = renderEnv();
|
|
134
|
+
if (!env || within(env.out, path) || !within(env.root, path)) return path;
|
|
135
|
+
return join(env.out, relative(env.root, path));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The committed path a render-tree path stands for, so a header names it; any other path is itself. */
|
|
139
|
+
export function committedPathOf(path: string): string {
|
|
140
|
+
const env = renderEnv();
|
|
141
|
+
if (!env || !within(env.out, path)) return path;
|
|
142
|
+
return join(env.root, relative(env.out, path));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Whether `path` (absolute) is in the render tree of a running check. */
|
|
146
|
+
export function isRenderPath(path: string): boolean {
|
|
147
|
+
const env = renderEnv();
|
|
148
|
+
return env !== undefined && within(env.out, path);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The files a declared path names under `base`, relative to it: the path itself, or a last-segment `*` pattern's matches. */
|
|
152
|
+
function expand(base: string, path: string): string[] {
|
|
153
|
+
const last = path.lastIndexOf("/");
|
|
154
|
+
const dir = last < 0 ? "" : path.slice(0, last);
|
|
155
|
+
const name = path.slice(last + 1);
|
|
156
|
+
if (!name.includes("*")) return existsSync(join(base, path)) ? [path] : [];
|
|
157
|
+
const re = new RegExp(`^${name.split("*").map((p) => p.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join("[^/]*")}$`);
|
|
158
|
+
const at = join(base, dir);
|
|
159
|
+
if (!existsSync(at) || !statSync(at).isDirectory()) return [];
|
|
160
|
+
return readdirSync(at)
|
|
161
|
+
.filter((f) => re.test(f) && statSync(join(at, f)).isFile())
|
|
162
|
+
.sort()
|
|
163
|
+
.map((f) => (dir ? `${dir}/${f}` : f));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** A short line diff of two texts: the first lines that differ, with a little context. */
|
|
167
|
+
export function diffLines(committed: string, rendered: string, max = 12): string[] {
|
|
168
|
+
const a = committed.split("\n");
|
|
169
|
+
const b = rendered.split("\n");
|
|
170
|
+
let start = 0;
|
|
171
|
+
while (start < a.length && start < b.length && a[start] === b[start]) start++;
|
|
172
|
+
let endA = a.length;
|
|
173
|
+
let endB = b.length;
|
|
174
|
+
while (endA > start && endB > start && a[endA - 1] === b[endB - 1]) {
|
|
175
|
+
endA--;
|
|
176
|
+
endB--;
|
|
177
|
+
}
|
|
178
|
+
const out = [`@@ line ${start + 1} @@`];
|
|
179
|
+
for (const l of a.slice(Math.max(0, start - 2), start)) out.push(` ${l}`);
|
|
180
|
+
const removed = a.slice(start, endA).map((l) => `- ${l}`);
|
|
181
|
+
const added = b.slice(start, endB).map((l) => `+ ${l}`);
|
|
182
|
+
const body = [...removed, ...added];
|
|
183
|
+
out.push(...body.slice(0, max));
|
|
184
|
+
if (body.length > max) out.push(` ... ${body.length - max} more changed lines`);
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Run one render; resolves with its exit code and output. */
|
|
189
|
+
function runRender(command: string, cwd: string, env: NodeJS.ProcessEnv): Promise<{ exitCode: number; output: string }> {
|
|
190
|
+
return new Promise((done) => {
|
|
191
|
+
const child = spawn("sh", ["-c", command], { cwd, env, stdio: ["ignore", "pipe", "pipe"] });
|
|
192
|
+
const chunks: Buffer[] = [];
|
|
193
|
+
child.stdout.on("data", (c: Buffer) => chunks.push(c));
|
|
194
|
+
child.stderr.on("data", (c: Buffer) => chunks.push(c));
|
|
195
|
+
child.on("error", (err) => done({ exitCode: 127, output: String(err) }));
|
|
196
|
+
child.on("close", (code, signal) => done({ exitCode: code ?? (signal ? 128 : 1), output: Buffer.concat(chunks).toString("utf8") }));
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface GeneratedCheckOptions {
|
|
201
|
+
/** Only these renders, by name. */
|
|
202
|
+
only?: string[];
|
|
203
|
+
/** The render tree's parent directory (default: the OS temp directory). */
|
|
204
|
+
tmpDir?: string;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Render the product's declared generated files into a fresh directory under
|
|
209
|
+
* the OS temp directory and compare each with the committed file (#4909).
|
|
210
|
+
* The directory is left in place and named in the result.
|
|
211
|
+
*/
|
|
212
|
+
export async function checkGenerated(productDir: string, config: GeneratedCheckConfig, opts: GeneratedCheckOptions = {}): Promise<GeneratedCheckResult> {
|
|
213
|
+
const root = realpathSync(resolve(productDir));
|
|
214
|
+
const out = realpathSync(mkdtempSync(join(opts.tmpDir ?? tmpdir(), "chant-generated-")));
|
|
215
|
+
const problems: string[] = [];
|
|
216
|
+
let renders = config.renders;
|
|
217
|
+
if (opts.only?.length) {
|
|
218
|
+
const unknown = opts.only.filter((n) => !renders.some((r) => r.name === n));
|
|
219
|
+
if (unknown.length) problems.push(`chantGenerated has no render named ${unknown.map((n) => `'${n}'`).join(", ")}`);
|
|
220
|
+
renders = renders.filter((r) => opts.only!.includes(r.name));
|
|
221
|
+
}
|
|
222
|
+
const env = { ...process.env, [GENERATED_OUT_ENV]: out, [GENERATED_ROOT_ENV]: root };
|
|
223
|
+
const ran = await Promise.all(
|
|
224
|
+
renders.map(async (r) => {
|
|
225
|
+
const command = r.run.split("{out}").join(shellQuote(out));
|
|
226
|
+
return { r, command, ...(await runRender(command, root, env)) };
|
|
227
|
+
}),
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
const results: GeneratedRenderResult[] = [];
|
|
231
|
+
const matched: string[] = [];
|
|
232
|
+
const hint = config.regenerate ? ` Run '${config.regenerate}' and commit the result.` : "";
|
|
233
|
+
for (const { r, command, exitCode, output } of ran) {
|
|
234
|
+
const files: string[] = [];
|
|
235
|
+
results.push({ name: r.name, command, exitCode, output, files });
|
|
236
|
+
if (exitCode !== 0) {
|
|
237
|
+
problems.push(`render '${r.name}' exited ${exitCode}: ${command}${output.trim() ? `\n${output.trimEnd().split("\n").map((l) => ` ${l}`).join("\n")}` : ""}`);
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
for (const path of r.files ?? []) {
|
|
241
|
+
const committed = expand(root, path);
|
|
242
|
+
const rendered = expand(out, path);
|
|
243
|
+
if (!path.includes("*") && rendered.length === 0) {
|
|
244
|
+
problems.push(`render '${r.name}' wrote no ${path} under the render tree`);
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (path.includes("*") && committed.length === 0 && rendered.length === 0) {
|
|
248
|
+
problems.push(`${path} matches no file, committed or rendered by '${r.name}'`);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
for (const f of [...new Set([...committed, ...rendered])].sort()) {
|
|
252
|
+
files.push(f);
|
|
253
|
+
if (!rendered.includes(f)) {
|
|
254
|
+
problems.push(`${f} is committed, but '${r.name}' no longer renders it.${hint}`);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (!committed.includes(f)) {
|
|
258
|
+
problems.push(`${f} is what '${r.name}' renders, but it is not committed.${hint}`);
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
const a = readFileSync(join(root, f), "utf8");
|
|
262
|
+
const b = readFileSync(join(out, f), "utf8");
|
|
263
|
+
if (a === b) matched.push(f);
|
|
264
|
+
else problems.push(`${f} is not what '${r.name}' renders.${hint}\n${diffLines(a, b).map((l) => ` ${l}`).join("\n")}`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return { ok: problems.length === 0, out, problems, renders: results, matched };
|
|
269
|
+
}
|
package/src/lexicon.ts
CHANGED
|
@@ -793,6 +793,8 @@ export interface OpSetupUsesStep {
|
|
|
793
793
|
* `assertSetupSteps`, which refuses both at build time.
|
|
794
794
|
*/
|
|
795
795
|
uses: string;
|
|
796
|
+
/** The step's name on GitHub and Forgejo, such as "Log in to AWS" (#4932). GitLab script lines have none. Absent: the forge names it from the action. */
|
|
797
|
+
name?: string;
|
|
796
798
|
/** The action's inputs, emitted as the step's `with:` mapping. */
|
|
797
799
|
with?: Record<string, string | number | boolean>;
|
|
798
800
|
/** Environment for this step alone, emitted as the step's `env:` mapping. */
|
|
@@ -803,6 +805,8 @@ export interface OpSetupUsesStep {
|
|
|
803
805
|
export interface OpSetupRunStep {
|
|
804
806
|
/** The shell line, emitted as the step's `run:`. */
|
|
805
807
|
run: string;
|
|
808
|
+
/** The step's name on GitHub and Forgejo, such as "Log in to AWS" (#4932). GitLab script lines have none. Absent: the forge shows the line. */
|
|
809
|
+
name?: string;
|
|
806
810
|
/** Environment for this step alone, emitted as the step's `env:` mapping. */
|
|
807
811
|
env?: Record<string, string>;
|
|
808
812
|
}
|
|
@@ -1936,6 +1940,19 @@ export interface LexiconPlugin {
|
|
|
1936
1940
|
migrationSource?(from: string, to?: string): MigrationSource | undefined;
|
|
1937
1941
|
|
|
1938
1942
|
// State
|
|
1943
|
+
/**
|
|
1944
|
+
* What a declared entity {@link describeResources} confirmed absent is,
|
|
1945
|
+
* when no snapshot says it was deployed (#4896). Left out, it is
|
|
1946
|
+
* `pending`: not deployed yet, the right reading for a cloud stack. A
|
|
1947
|
+
* lexicon whose environments always hold what is declared once they are
|
|
1948
|
+
* set up says `missing`, gone: the sql lexicon does, since a server that
|
|
1949
|
+
* lacks a declared table lost it. `chant lifecycle diff --live --json`
|
|
1950
|
+
* writes it as the lexicon section's `absent`, and the drift records
|
|
1951
|
+
* (`lexiconDriftRecords` on `@intentius/chant/drift-record`) read it from
|
|
1952
|
+
* there. The live diff's own `missing` list is unchanged.
|
|
1953
|
+
*/
|
|
1954
|
+
liveAbsentStatus?: "pending" | "missing";
|
|
1955
|
+
|
|
1939
1956
|
/**
|
|
1940
1957
|
* Query deployed resources and return API metadata. Opt-in.
|
|
1941
1958
|
*
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
import { execFileSync, spawn } from "node:child_process";
|
|
56
56
|
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
57
57
|
import { tmpdir } from "node:os";
|
|
58
|
-
import { join } from "node:path";
|
|
58
|
+
import { join, relative, resolve, sep } from "node:path";
|
|
59
59
|
import { packageSbom } from "./publish-attachments";
|
|
60
60
|
import type { NpmPublishDeclaration } from "./publish-declaration";
|
|
61
61
|
import { checkReleaseDigest, fileDigest, isDir, memberFile, publishTargetKey } from "./publish-targets";
|
|
@@ -194,6 +194,53 @@ export function checkPackagePins(decl: Pick<NpmPublishDeclaration, "pins">, rele
|
|
|
194
194
|
if (found === 0) throw new PublishTargetError("publish-npm-pins-missing", `no package of the npm target holds ${decl.pins}, which pins names`, "Build the package so it carries the file, or remove pins.");
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
/** The output of `npm pack --dry-run --json`: one entry per package, with the files it would carry. */
|
|
198
|
+
type NpmPackListing = Array<{ files?: Array<{ path?: unknown }> }>;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* #4934: refuse a package that would carry an image archive the release
|
|
202
|
+
* records (`release.images`). In a dispatched release the publish job takes
|
|
203
|
+
* the cut's archives into their directory under the checkout, as the tag
|
|
204
|
+
* workflow's `release images` and a workstation cut write them there, so a
|
|
205
|
+
* package whose `files` takes that directory packs the image and the registry
|
|
206
|
+
* refuses it (413) after the other targets published. For each package that
|
|
207
|
+
* an archive lies inside, `npm pack --dry-run --json --ignore-scripts` lists
|
|
208
|
+
* what `npm publish` would send, and an archive among it, or a file under an
|
|
209
|
+
* archive that is a layout directory, is refused at the plan, before any
|
|
210
|
+
* target publishes, naming the file and the `files` entry that leaves it out.
|
|
211
|
+
* A package no archive lies inside runs no npm, and a packed `.tgz` holds
|
|
212
|
+
* what it was packed with, which the plan reads as it is.
|
|
213
|
+
*/
|
|
214
|
+
export function checkPackageImages(release: PublishContext["release"], cwd: string, pkgs: ReadonlyArray<Pick<NpmPackage, "path" | "abs" | "name">>, bin = "npm", env: NodeJS.ProcessEnv = process.env): void {
|
|
215
|
+
const archives = release.artifactDigests.filter((a) => a.kind === "image" && a.path !== "").map((a) => ({ component: a.component, abs: resolve(cwd, a.path) }));
|
|
216
|
+
if (archives.length === 0) return;
|
|
217
|
+
for (const pkg of pkgs) {
|
|
218
|
+
if (!isDir(pkg.abs)) continue;
|
|
219
|
+
const inside = archives.map((a) => ({ ...a, rel: relative(pkg.abs, a.abs).split(sep).join("/") })).filter((a) => a.rel !== "" && a.rel !== ".." && !a.rel.startsWith("../"));
|
|
220
|
+
if (inside.length === 0) continue;
|
|
221
|
+
let files: string[];
|
|
222
|
+
try {
|
|
223
|
+
const out = execFileSync(bin, ["pack", "--dry-run", "--json", "--ignore-scripts"], { cwd: pkg.abs, env, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 256 * 1024 * 1024 });
|
|
224
|
+
files = (JSON.parse(out.slice(out.indexOf("["))) as NpmPackListing).flatMap((e) => (e.files ?? []).map((f) => String(f.path)));
|
|
225
|
+
} catch (err) {
|
|
226
|
+
throw new PublishTargetError(
|
|
227
|
+
"publish-npm-pack-failed",
|
|
228
|
+
`npm pack --dry-run --json could not list what ${pkg.name} (${pkg.path}) carries, so whether it packs the image archive ${inside[0]!.rel} is not known: ${err instanceof Error ? err.message.split("\n")[0] : String(err)}`,
|
|
229
|
+
"Run npm pack --dry-run in the package to see why it fails.",
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
for (const a of inside) {
|
|
233
|
+
const carried = files.find((f) => f === a.rel || f.startsWith(`${a.rel}/`));
|
|
234
|
+
if (carried === undefined) continue;
|
|
235
|
+
throw new PublishTargetError(
|
|
236
|
+
"publish-npm-carries-image",
|
|
237
|
+
`${pkg.name} (${pkg.path}) would carry ${carried}, the archive of image "${a.component}" that release.images names; the image goes to its own target, and npmjs refuses a package that size (413)`,
|
|
238
|
+
`Add "!${a.rel}" to "files" in ${pkg.path === "." ? "" : `${pkg.path}/`}package.json (or ${a.rel} to its .npmignore when it has no "files"), so the package leaves the image out.`,
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
197
244
|
export function npmTarget(decl: NpmPublishDeclaration, deps: PublishDeps): PublishTarget {
|
|
198
245
|
const bin = deps.npm ?? "npm";
|
|
199
246
|
const sleep = deps.sleep ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)));
|
|
@@ -249,8 +296,14 @@ export function npmTarget(decl: NpmPublishDeclaration, deps: PublishDeps): Publi
|
|
|
249
296
|
return pkgs;
|
|
250
297
|
};
|
|
251
298
|
const extra = (pkg: NpmPackage) => ({ ...(pkg.digest ? { digest: pkg.digest } : {}), ...(pkg.sbom ? { sbom: pkg.sbom } : {}) });
|
|
299
|
+
/** #4934: what plan and stage read, with the image archives a package would carry refused. */
|
|
300
|
+
const readChecked = (ctx: PublishContext) => {
|
|
301
|
+
const pkgs = read(ctx);
|
|
302
|
+
checkPackageImages(ctx.release, ctx.cwd, pkgs, bin, ctx.env);
|
|
303
|
+
return pkgs;
|
|
304
|
+
};
|
|
252
305
|
const plan = async (ctx: PublishContext): Promise<PublishItem[]> =>
|
|
253
|
-
|
|
306
|
+
readChecked(ctx).map((pkg) => ({ name: `${pkg.name}@${pkg.version}`, destination: staging ? `${shown(NPM_STAGE_TAG)}, then ${revealTag(ctx)}` : shown(revealTag(ctx)), ...extra(pkg) }));
|
|
254
307
|
/**
|
|
255
308
|
* In CI, install what was published into an empty directory and run
|
|
256
309
|
* `npm audit signatures` there (#4049), which checks each package's
|
|
@@ -343,7 +396,7 @@ export function npmTarget(decl: NpmPublishDeclaration, deps: PublishDeps): Publi
|
|
|
343
396
|
key: publishTargetKey(decl),
|
|
344
397
|
plan,
|
|
345
398
|
async stage(ctx) {
|
|
346
|
-
const pkgs =
|
|
399
|
+
const pkgs = readChecked(ctx);
|
|
347
400
|
const items: PublishItem[] = [];
|
|
348
401
|
for (const pkg of pkgs) {
|
|
349
402
|
const item: PublishItem = { name: `${pkg.name}@${pkg.version}`, destination: shown(stageTag(ctx)), ...extra(pkg) };
|
|
@@ -11,7 +11,7 @@ import { spawnSync } from "node:child_process";
|
|
|
11
11
|
import { writeFileSync } from "node:fs";
|
|
12
12
|
import { join } from "node:path";
|
|
13
13
|
import schema from "../workspace/release-catalog.schema.json";
|
|
14
|
-
import { appendReleaseRecord, InvalidReleaseRecordError, readReleaseLedger,
|
|
14
|
+
import { appendReleaseRecord, InvalidReleaseRecordError, readReleaseLedger, RELEASE_RECORD_VERSION_FLOOR, type ReleaseRecord } from "./release-ledger";
|
|
15
15
|
import { parseReleaseLedger } from "./release-read";
|
|
16
16
|
import {
|
|
17
17
|
buildReleaseCatalog,
|
|
@@ -46,7 +46,7 @@ describe("release catalog schema", () => {
|
|
|
46
46
|
|
|
47
47
|
test("its floors shipped in 0.124.55", () => {
|
|
48
48
|
expect(RELEASE_CATALOG_FLOOR).toBe("0.124.55");
|
|
49
|
-
expect(
|
|
49
|
+
expect(RELEASE_RECORD_VERSION_FLOOR).toBe("0.124.55");
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
52
|
|
|
@@ -54,6 +54,26 @@ describe("a release.images entry that names a Dockerfile (#4819)", () => {
|
|
|
54
54
|
);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
+
test("args go to the build as build arguments, so sql-yodeler's release-image.sh is a Dockerfile entry (#4908)", () => {
|
|
58
|
+
const entry = {
|
|
59
|
+
name: "sql-yodeler",
|
|
60
|
+
dockerfile: ".github/image/Dockerfile",
|
|
61
|
+
context: "dist/image-context",
|
|
62
|
+
prepare: "mkdir -p dist/image-context && npm pack --pack-destination dist/image-context",
|
|
63
|
+
args: { YODEL_PACKAGE: "/ctx/intentius-sql-yodeler-0.14.0.tgz", CHANT_PINS: "@intentius/chant@0.124.87 @intentius/chant-lexicon-sql@0.124.87" },
|
|
64
|
+
};
|
|
65
|
+
expect(releaseImageBuildCommand(entry, { versionArg: true })).toContain(
|
|
66
|
+
`--build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH" --build-arg CHANT_RELEASE_LABEL="$CHANT_RELEASE_LABEL" --build-arg YODEL_PACKAGE=/ctx/intentius-sql-yodeler-0.14.0.tgz --build-arg 'CHANT_PINS=@intentius/chant@0.124.87 @intentius/chant-lexicon-sql@0.124.87' --output`,
|
|
67
|
+
);
|
|
68
|
+
expect(releaseImageBuildCommand(entry)).toContain(" -f .github/image/Dockerfile dist/image-context >&2");
|
|
69
|
+
expect(() => checkReleaseImages([entry])).not.toThrow();
|
|
70
|
+
expect(() => checkReleaseImages([{ ...entry, args: { "BAD-NAME": "x" } }])).toThrow(/not a build argument name/);
|
|
71
|
+
expect(() => checkReleaseImages([{ ...entry, args: { SOURCE_DATE_EPOCH: "0" } }])).toThrow(/chant passes itself/);
|
|
72
|
+
expect(() => checkReleaseImages([{ ...entry, args: { A: "x\ny" } }])).toThrow(/one-line/);
|
|
73
|
+
const parsed = ChantConfigSchema.safeParse({ release: { images: [entry] } });
|
|
74
|
+
expect(parsed.success).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
|
|
57
77
|
test("the archive defaults to dist/images/<name>.tar, and a build entry is as it was", () => {
|
|
58
78
|
const images: ReleaseImageDeclaration[] = [
|
|
59
79
|
{ name: "pulumi", dockerfile: "images/plywood-pulumi/Dockerfile" },
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
pinnedDigests,
|
|
22
22
|
readPins,
|
|
23
23
|
releaseImageDigests,
|
|
24
|
+
releaseImagePlatforms,
|
|
24
25
|
ReleaseImageError,
|
|
25
26
|
unknownPins,
|
|
26
27
|
writeReleaseDigests,
|
|
@@ -45,6 +46,13 @@ describe("release.images (#4657)", () => {
|
|
|
45
46
|
expect(() => checkReleaseImages([{ name: "a", build: "x", archive: "../a.tar" }])).toThrow(/not a path inside the member/);
|
|
46
47
|
});
|
|
47
48
|
|
|
49
|
+
test("the platforms the images build: a Dockerfile entry's or the default, and a command entry's own (#4876)", () => {
|
|
50
|
+
expect(releaseImagePlatforms([{ name: "a", dockerfile: "Dockerfile" }])).toEqual(["linux/amd64", "linux/arm64"]);
|
|
51
|
+
expect(releaseImagePlatforms([{ name: "a", dockerfile: "Dockerfile", platforms: ["linux/amd64"] }, { name: "b", build: "x", archive: "b.tar" }])).toEqual(["linux/amd64"]);
|
|
52
|
+
expect(releaseImagePlatforms([{ name: "b", build: "x", archive: "b.tar", platforms: ["linux/arm64", "linux/amd64"] }])).toEqual(["linux/amd64", "linux/arm64"]);
|
|
53
|
+
expect(() => checkReleaseImages([{ name: "b", build: "x", archive: "b.tar", platforms: ["arm64"] }])).toThrow(/os\/arch/);
|
|
54
|
+
});
|
|
55
|
+
|
|
48
56
|
test("each build runs with SOURCE_DATE_EPOCH and the label, and its archive's top manifest digest is recorded", () => {
|
|
49
57
|
const r = new TestRepo("release-images-build");
|
|
50
58
|
repos.push(r);
|
|
@@ -240,3 +248,39 @@ test("the digests file is sorted JSON of name to digest", () => {
|
|
|
240
248
|
expect(readFileSync(file, "utf-8")).toBe(`{\n "a": "${D("2")}",\n "z": "${D("1")}"\n}\n`);
|
|
241
249
|
writeFileSync(file, "");
|
|
242
250
|
});
|
|
251
|
+
|
|
252
|
+
describe("an npm package that would carry an image archive (#4934)", () => {
|
|
253
|
+
/** A member that is itself the package, as sql-yodeler's is, with the image archive under dist/images and `files` as given. */
|
|
254
|
+
const fixture = (name: string, files: string[]): { dir: string; release: Release } => {
|
|
255
|
+
const r = new TestRepo(name);
|
|
256
|
+
repos.push(r);
|
|
257
|
+
writePackage(r.dir, "@acme/app", "2.0.0");
|
|
258
|
+
const pkg = JSON.parse(readFileSync(join(r.dir, "package.json"), "utf-8")) as Record<string, unknown>;
|
|
259
|
+
writeFileSync(join(r.dir, "package.json"), JSON.stringify({ ...pkg, files }, null, 2));
|
|
260
|
+
mkdirSync(join(r.dir, "dist", "images"), { recursive: true });
|
|
261
|
+
writeFileSync(join(r.dir, "dist", "index.js"), "export {};\n");
|
|
262
|
+
writeFileSync(join(r.dir, "dist", "images", "app.tar"), "image bytes");
|
|
263
|
+
const image: ReleaseArtifact = { component: "app", kind: "image", path: "dist/images/app.tar", digest: D("a") };
|
|
264
|
+
return { dir: r.dir, release: { artifactDigests: [image] } as unknown as Release };
|
|
265
|
+
};
|
|
266
|
+
const planOf = async (dir: string, release: Release) => {
|
|
267
|
+
const [target] = await createPublishTargets([PublishDeclarationSchema.parse({ type: "npm", packages: ["."] })], {});
|
|
268
|
+
const env = { PATH: process.env.PATH ?? "", HOME: process.env.HOME ?? "" };
|
|
269
|
+
const ctx: PublishContext = { release, label: "v2", releaseTag: "release/v2", provenance: NO_OIDC, cwd: dir, tag: null, env, redactor: createRedactor(env), log: () => {} };
|
|
270
|
+
return target!.plan(ctx);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
test("a package whose files takes the archive's directory is refused at plan time, naming the file and the files entry to add", async () => {
|
|
274
|
+
const { dir, release } = fixture("npm-carries-image", ["dist", "sbom.spdx.json"]);
|
|
275
|
+
const err = await planOf(dir, release).catch((e: unknown) => e);
|
|
276
|
+
expect(err).toBeInstanceOf(PublishTargetError);
|
|
277
|
+
expect((err as PublishTargetError).code).toBe("publish-npm-carries-image");
|
|
278
|
+
expect((err as PublishTargetError).message).toContain("would carry dist/images/app.tar");
|
|
279
|
+
expect((err as PublishTargetError).fix).toContain('Add "!dist/images/app.tar" to "files" in package.json');
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test("the same package with the archive left out plans", async () => {
|
|
283
|
+
const { dir, release } = fixture("npm-leaves-image-out", ["dist", "!dist/images/app.tar", "sbom.spdx.json"]);
|
|
284
|
+
expect((await planOf(dir, release)).map((i) => i.name)).toEqual(["@acme/app@2.0.0"]);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* the reproducible build itself ({@link releaseImageBuildCommand}), a
|
|
27
27
|
* `docker-container` buildx builder writing an OCI archive with timestamps
|
|
28
28
|
* rewritten from `SOURCE_DATE_EPOCH` and no attestations, for every
|
|
29
|
-
* platform. Its `prepare` command (the bundle the image carries, a packed
|
|
29
|
+
* platform, with the entry's own build arguments (`args`, #4908). Its `prepare` command (the bundle the image carries, a packed
|
|
30
30
|
* package) runs first with no digests file named, so the image is the same
|
|
31
31
|
* in the cut and the publish job. A product's package build turns the
|
|
32
32
|
* digests file and its `{ name: reference }` into the table it bakes in with
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
import { spawnSync } from "node:child_process";
|
|
39
39
|
import { existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
40
40
|
import { dirname, isAbsolute, posix, relative, resolve } from "node:path";
|
|
41
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
41
42
|
import type { PublishDeclaration } from "./publish-declaration";
|
|
42
43
|
import type { Release, ReleaseArtifact } from "./release-store";
|
|
43
44
|
|
|
@@ -54,6 +55,9 @@ export const RELEASE_IMAGES_FLOOR = "0.124.71";
|
|
|
54
55
|
*/
|
|
55
56
|
export const RELEASE_IMAGE_DOCKERFILE_FLOOR = "0.124.78";
|
|
56
57
|
|
|
58
|
+
/** The first chant whose Dockerfile entry in `release.images` takes `args`, build arguments beside the two chant passes (#4908). */
|
|
59
|
+
export const RELEASE_IMAGE_ARGS_FLOOR = NEXT_RELEASE;
|
|
60
|
+
|
|
57
61
|
/** One image a release builds in its cut with a command of the product's. */
|
|
58
62
|
export interface ReleaseImageBuild {
|
|
59
63
|
/** The image's name: its key in the digests file, and its artifact's `component` in the release. */
|
|
@@ -62,6 +66,12 @@ export interface ReleaseImageBuild {
|
|
|
62
66
|
build: string;
|
|
63
67
|
/** The OCI archive the command writes, a layout directory or a tar file, relative to the member. The `oci` target's `image`. */
|
|
64
68
|
archive: string;
|
|
69
|
+
/**
|
|
70
|
+
* The platforms the command builds, such as `["linux/amd64", "linux/arm64"]`
|
|
71
|
+
* (#4876). chant does not pass them to the command; `chant release workflow`
|
|
72
|
+
* reads them to set up QEMU for those the runner can't run. Unset: none.
|
|
73
|
+
*/
|
|
74
|
+
platforms?: string[];
|
|
65
75
|
}
|
|
66
76
|
|
|
67
77
|
/** One image chant builds from a Dockerfile (#4819). */
|
|
@@ -77,6 +87,13 @@ export interface ReleaseImageDockerfile {
|
|
|
77
87
|
archive?: string;
|
|
78
88
|
/** A command run once before the builds, with `CHANT_RELEASE_DIGESTS` unset: what the image copies in, such as the bundle or a packed package. */
|
|
79
89
|
prepare?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Build arguments beside `SOURCE_DATE_EPOCH` and `CHANT_RELEASE_LABEL`
|
|
92
|
+
* (#4908), such as the packed package's file and the chant packages the
|
|
93
|
+
* image installs beside it, as sql-yodeler's `release-image.sh` passed
|
|
94
|
+
* them. Values are literal; the config computes them.
|
|
95
|
+
*/
|
|
96
|
+
args?: Record<string, string>;
|
|
80
97
|
}
|
|
81
98
|
|
|
82
99
|
/** One image a release builds in its cut. */
|
|
@@ -112,7 +129,9 @@ export function releaseImageBuildCommand(i: ReleaseImageDockerfile, o: { version
|
|
|
112
129
|
`mkdir -p ${sh(posix.dirname(archive))}`,
|
|
113
130
|
[
|
|
114
131
|
`docker buildx build --builder ${b} --no-cache --platform ${sh((i.platforms ?? RELEASE_IMAGE_PLATFORMS).join(","))}`,
|
|
115
|
-
`--provenance=false --sbom=false --build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH"${o.versionArg ? ' --build-arg CHANT_RELEASE_LABEL="$CHANT_RELEASE_LABEL"' : ""}
|
|
132
|
+
`--provenance=false --sbom=false --build-arg SOURCE_DATE_EPOCH="$SOURCE_DATE_EPOCH"${o.versionArg ? ' --build-arg CHANT_RELEASE_LABEL="$CHANT_RELEASE_LABEL"' : ""}${Object.entries(i.args ?? {})
|
|
133
|
+
.map(([k, v]) => ` --build-arg ${sh(`${k}=${v}`)}`)
|
|
134
|
+
.join("")}`,
|
|
116
135
|
`--output ${sh(`type=oci,dest=${archive},rewrite-timestamp=true`)} -f ${sh(i.dockerfile)} ${sh(i.context ?? ".")} >&2`,
|
|
117
136
|
].join(" "),
|
|
118
137
|
].join(" && ");
|
|
@@ -123,6 +142,15 @@ export function resolveReleaseImages(images: readonly ReleaseImageDeclaration[],
|
|
|
123
142
|
return images.map((i) => (isDockerfile(i) ? { name: i.name, build: releaseImageBuildCommand(i, o), archive: archiveOf(i) } : i));
|
|
124
143
|
}
|
|
125
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Every platform the images build (#4876): a Dockerfile entry's, or
|
|
147
|
+
* {@link RELEASE_IMAGE_PLATFORMS} when it names none, and a command entry's
|
|
148
|
+
* `platforms`. Sorted, each once.
|
|
149
|
+
*/
|
|
150
|
+
export function releaseImagePlatforms(images: readonly ReleaseImageDeclaration[]): string[] {
|
|
151
|
+
return [...new Set(images.flatMap((i) => (isDockerfile(i) ? (i.platforms ?? RELEASE_IMAGE_PLATFORMS) : (i.platforms ?? []))))].sort();
|
|
152
|
+
}
|
|
153
|
+
|
|
126
154
|
export class ReleaseImageError extends Error {
|
|
127
155
|
constructor(
|
|
128
156
|
readonly code: string,
|
|
@@ -135,6 +163,9 @@ export class ReleaseImageError extends Error {
|
|
|
135
163
|
}
|
|
136
164
|
|
|
137
165
|
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
166
|
+
const BUILD_ARG = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
167
|
+
/** The build arguments chant passes itself, which an entry's `args` cannot set. */
|
|
168
|
+
const CHANT_BUILD_ARGS = ["SOURCE_DATE_EPOCH", "CHANT_RELEASE_LABEL"];
|
|
138
169
|
|
|
139
170
|
const outside = (p: string): boolean => isAbsolute(p) || p.split(/[\\/]/).includes("..");
|
|
140
171
|
|
|
@@ -150,7 +181,12 @@ export function checkReleaseImages(images: readonly ReleaseImageDeclaration[]):
|
|
|
150
181
|
for (const [what, p] of paths) {
|
|
151
182
|
if (p !== undefined && outside(p)) throw new ReleaseImageError("release-image-archive-outside", `release.images "${i.name}": ${what} ${p} is not a path inside the member`);
|
|
152
183
|
}
|
|
153
|
-
|
|
184
|
+
for (const [k, v] of Object.entries((isDockerfile(i) && i.args) || {})) {
|
|
185
|
+
if (!BUILD_ARG.test(k)) throw new ReleaseImageError("release-image-invalid", `release.images "${i.name}": args names ${JSON.stringify(k)}, which is not a build argument name`);
|
|
186
|
+
if (CHANT_BUILD_ARGS.includes(k)) throw new ReleaseImageError("release-image-invalid", `release.images "${i.name}": args sets ${k}, which chant passes itself`);
|
|
187
|
+
if (typeof v !== "string" || /[\r\n]/.test(v)) throw new ReleaseImageError("release-image-invalid", `release.images "${i.name}": args.${k} is not a one-line string`);
|
|
188
|
+
}
|
|
189
|
+
if (i.platforms !== undefined && (i.platforms.length === 0 || !i.platforms.every((p) => PLATFORM.test(p)))) {
|
|
154
190
|
throw new ReleaseImageError("release-image-invalid", `release.images "${i.name}": platforms is a list of os/arch such as linux/amd64, not ${JSON.stringify(i.platforms)}`);
|
|
155
191
|
}
|
|
156
192
|
}
|
|
@@ -78,9 +78,10 @@ export const RUN_ORIGIN_JOB_FLOOR = "0.124.32";
|
|
|
78
78
|
/**
|
|
79
79
|
* The first chant that writes and reads `releaseVersion` on a release record
|
|
80
80
|
* (#4595). A record from an older chant has none, and a reader lists it by
|
|
81
|
-
* digest.
|
|
81
|
+
* digest. It was named `RELEASE_VERSION_FLOOR` until #4916 gave that name to
|
|
82
|
+
* ./release-version.ts alone, the floor of `release.version`.
|
|
82
83
|
*/
|
|
83
|
-
export const
|
|
84
|
+
export const RELEASE_RECORD_VERSION_FLOOR = "0.124.55";
|
|
84
85
|
|
|
85
86
|
/**
|
|
86
87
|
* The gate resolution that admitted a deploy (#4020): the gate's address in the
|
|
@@ -291,7 +292,7 @@ export interface ReleaseRecord {
|
|
|
291
292
|
* Optional: the version the publish gave this release (#4595), such as a
|
|
292
293
|
* module's `1.4.0` or a package's `2.0.0-rc.1`, when the component has
|
|
293
294
|
* versions of its own. `version` is taken by the record's schema version,
|
|
294
|
-
* so the field has this name. Written from {@link
|
|
295
|
+
* so the field has this name. Written from {@link RELEASE_RECORD_VERSION_FLOOR};
|
|
295
296
|
* absent on older records and on deploys that name no version. The
|
|
296
297
|
* release catalog (./release-catalog.ts) lists a version by it, and a
|
|
297
298
|
* record without one by its digest.
|