@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
package/src/floor-table.ts
CHANGED
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
* feature-detect on, as one table, and the version compare a product asks it
|
|
4
4
|
* with.
|
|
5
5
|
*
|
|
6
|
-
* A floor is a constant `<NAME>_FLOOR` in chant core
|
|
7
|
-
*
|
|
6
|
+
* A floor is a constant `<NAME>_FLOOR` in chant core, or in a lexicon's
|
|
7
|
+
* src/chant-floors.ts (#4916), naming the first chant release with a part
|
|
8
|
+
* (an export, a field chant writes, a flag). Lexicons release with chant at
|
|
9
|
+
* the same version, so a lexicon's floor is a chant version too. A product
|
|
8
10
|
* that runs on several chant releases checks one before it calls the part. The
|
|
9
11
|
* rows are written by scripts/floor-table.ts from the constants themselves
|
|
10
12
|
* (./floor-table.data.ts), and scripts/release-floors.ts fails while a floor
|
|
11
13
|
* is missing from them. A floor added since the last release has the version
|
|
12
|
-
* of the next one, NEXT_RELEASE, which the release moves on.
|
|
14
|
+
* of the next one, NEXT_RELEASE, which the release moves on. Each name is
|
|
15
|
+
* declared once (#4916), and scripts/floor-table.ts fails on a second.
|
|
13
16
|
*
|
|
14
17
|
* `chant dev dead-guards` (./dead-guards.ts) reads this table against a
|
|
15
18
|
* product's chant pin and names each check the pin already meets.
|
|
@@ -26,24 +29,24 @@ export interface FloorRow {
|
|
|
26
29
|
gates: string;
|
|
27
30
|
/** The issue that added it, `#4784`, or a product's (`terragucci issue 1303`). */
|
|
28
31
|
issue?: string;
|
|
29
|
-
/** The file under packages/core/src that declares it. */
|
|
32
|
+
/** The file under packages/core/src that declares it, or a lexicon's floors file from the repository root (`lexicons/terraform/src/chant-floors.ts`). */
|
|
30
33
|
file: string;
|
|
31
|
-
/** The
|
|
34
|
+
/** The subpaths a product can import the constant from: `@intentius/chant/...`, or the lexicon's own. */
|
|
32
35
|
modules: readonly string[];
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
/** Every floor, in the order
|
|
38
|
+
/** Every floor, core's in the order its files declare them, then each lexicon's. */
|
|
36
39
|
export const FLOOR_TABLE: readonly FloorRow[] = FLOOR_ROWS;
|
|
37
40
|
|
|
38
|
-
/** The rows named `name`: one, or
|
|
41
|
+
/** The rows named `name`: one, or none. A table a caller builds may hold more. */
|
|
39
42
|
export function floorRows(name: string): FloorRow[] {
|
|
40
43
|
return FLOOR_TABLE.filter((r) => r.name === name);
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
/**
|
|
44
47
|
* The version a product must reach for the floor `name`, or undefined when no
|
|
45
|
-
* file declares it.
|
|
46
|
-
* check that passes holds for either.
|
|
48
|
+
* file declares it. Should a name ever have two rows, the higher version, so
|
|
49
|
+
* a check that passes holds for either.
|
|
47
50
|
*/
|
|
48
51
|
export function floorVersion(name: string): string | undefined {
|
|
49
52
|
const rows = floorRows(name);
|
|
@@ -174,6 +174,14 @@ export interface PipelineContractInput {
|
|
|
174
174
|
protectedBranches?: string[];
|
|
175
175
|
/** Default: each pipeline's plan status, such as `chant/plan` or `plywood/preview/<member>`. */
|
|
176
176
|
requiredStatuses?: string[];
|
|
177
|
+
/**
|
|
178
|
+
* The ref gate's status (#4913), added to the required statuses: the one
|
|
179
|
+
* the generated `ref-gate` job sets when the pipeline renders it
|
|
180
|
+
* (`refGateStatus`, `--ref-gate-status`). Read it with `refGateRulesAt`
|
|
181
|
+
* (`@intentius/chant/ref-gate-rules`): its `status` for the default branch,
|
|
182
|
+
* by default `chant/ref-gate`.
|
|
183
|
+
*/
|
|
184
|
+
refGateStatus?: string;
|
|
177
185
|
gitlabVariables?: string[];
|
|
178
186
|
}
|
|
179
187
|
|
|
@@ -204,12 +212,14 @@ export function pipelineContract(input: PipelineContractInput): ForgeCheckContra
|
|
|
204
212
|
const ctx = productStatusContext(words, "plan", p.member);
|
|
205
213
|
if (!statuses.includes(ctx)) statuses.push(ctx);
|
|
206
214
|
}
|
|
215
|
+
const required = [...(input.requiredStatuses ?? statuses)];
|
|
216
|
+
if (input.refGateStatus && !required.includes(input.refGateStatus)) required.push(input.refGateStatus);
|
|
207
217
|
return {
|
|
208
218
|
forge,
|
|
209
219
|
repository,
|
|
210
220
|
jobs,
|
|
211
221
|
protectedBranches: input.protectedBranches ?? [repository.defaultBranch],
|
|
212
|
-
requiredStatuses:
|
|
222
|
+
requiredStatuses: required,
|
|
213
223
|
...(input.gitlabVariables ? { gitlabVariables: input.gitlabVariables } : {}),
|
|
214
224
|
};
|
|
215
225
|
}
|
|
@@ -165,6 +165,14 @@ describe("the contract chant's pipelines make (#4608)", () => {
|
|
|
165
165
|
expect(c.jobs[2]!.pulumi).toEqual({ organization: "acme", tokens: ["team:deployers"], audience: "urn:pulumi:org:acme", apiUrl: PULUMI_API });
|
|
166
166
|
});
|
|
167
167
|
|
|
168
|
+
test("the ref gate's status is required beside the plan status when the pipeline sets it (#4913)", () => {
|
|
169
|
+
const c = pipelineContract({ forge: "github", repository: repo(), pipelines: [{ name: "production", identity: awsIdentity }], refGateStatus: "chant/ref-gate" });
|
|
170
|
+
expect(c.requiredStatuses).toEqual(["chant/plan", "chant/ref-gate"]);
|
|
171
|
+
const given = pipelineContract({ forge: "github", repository: repo(), pipelines: [{ name: "production", identity: awsIdentity }], requiredStatuses: ["acme/ci", "acme/gate"], refGateStatus: "acme/gate" });
|
|
172
|
+
expect(given.requiredStatuses).toEqual(["acme/ci", "acme/gate"]);
|
|
173
|
+
expect(pipelineContract({ forge: "github", repository: repo(), pipelines: [{ name: "production", identity: awsIdentity }] }).requiredStatuses).toEqual(["chant/plan"]);
|
|
174
|
+
});
|
|
175
|
+
|
|
168
176
|
test("Forgejo has no environments, so an apply environment is left out", () => {
|
|
169
177
|
const c = pipelineContract({ forge: "forgejo", repository: { ...repo(), host: "code.example.com" }, pipelines: [{ name: "p", identity: awsIdentity, forgeEnvironment: "prod" }] });
|
|
170
178
|
expect(c.jobs[2]!.forgeEnvironment).toBeUndefined();
|
package/src/forge-check/index.ts
CHANGED
|
@@ -40,4 +40,6 @@ export {
|
|
|
40
40
|
type FederatedCredential,
|
|
41
41
|
} from "./trust";
|
|
42
42
|
export { pulumiRows, policyGrants, PULUMI_TOKEN_ENV } from "./pulumi";
|
|
43
|
+
/** `refGateStatus` in `pipelineContract` (#4913). */
|
|
44
|
+
export { REF_GATE_PIECES_FLOOR } from "../release-floors";
|
|
43
45
|
export { forgeCheck, forgeCheckExit, describeForgeCheck, countRows, forgeCheckCommand, forgeCheckSchema, forgeCheckTarget, uncheckedClouds, ForgeCheckTargetError, type ForgeCheckInput } from "./check";
|
package/src/forge-flags.test.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { describe, expect, test } from "vitest";
|
|
8
|
-
import { apiBaseOf, ForgeFlagError, forgeFlagHints, forgeTargetFromFlags, forgeTargetOptionsFromFlags, forgeTargetWith } from "./forge-flags";
|
|
8
|
+
import { apiBaseOf, ForgeFlagError, forgeFlagHints, forgeTargetFromFlags, forgeTargetOptionsFromFlags, forgeTargetWith, jobForgeTarget } from "./forge-flags";
|
|
9
9
|
import { ForgeEnvironmentError } from "./pr-forge";
|
|
10
10
|
|
|
11
11
|
const SHA = "a".repeat(40);
|
|
@@ -108,3 +108,27 @@ describe("forgeTargetFromFlags (#4800)", () => {
|
|
|
108
108
|
expect(forgeFlagHints(missing as ForgeEnvironmentError, { requirePr: true })).toEqual(["outside CI pass --repo, --pr and --api-url", "name another token variable with --token-env"]);
|
|
109
109
|
});
|
|
110
110
|
});
|
|
111
|
+
|
|
112
|
+
// #4888: the one target type terragucci needs: the web origin on it, and undefined where the job cannot reach the forge.
|
|
113
|
+
describe("the target's web origin and jobForgeTarget (#4888)", () => {
|
|
114
|
+
test("the origin is --url, else the job's server, else https on the host", () => {
|
|
115
|
+
expect(forgeTargetWith({ FORGEJO_TOKEN: "f" }, { kind: "forgejo", repo: "a/b", url: "http://forgejo:3000/" }).origin).toBe("http://forgejo:3000");
|
|
116
|
+
expect(forgeTargetWith({ GITHUB_ACTIONS: "true", GITHUB_REPOSITORY: "a/b", GITHUB_SERVER_URL: "https://ghe.example", GITHUB_API_URL: "https://ghe.example/api/v3", GITHUB_TOKEN: "t" }).origin).toBe("https://ghe.example");
|
|
117
|
+
expect(forgeTargetWith({ GITLAB_CI: "true", CI_SERVER_URL: "https://gl.example", CI_API_V4_URL: "https://gl.example/api/v4", CI_PROJECT_ID: "7", GITLAB_TOKEN: "g" }).origin).toBe("https://gl.example");
|
|
118
|
+
expect(forgeTargetWith({ GITHUB_TOKEN: "t" }, { kind: "github", repo: "a/b", apiUrl: "https://api.github.com" }).origin).toBe("https://github.com");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const job = { GITHUB_ACTIONS: "true", GITHUB_REPOSITORY: "acme/infra", GITHUB_SERVER_URL: "https://github.com", TG_TOKEN: "tg" };
|
|
122
|
+
|
|
123
|
+
test("a job's target with the token the product holds, or with none for a read", () => {
|
|
124
|
+
expect(jobForgeTarget({ token: "given" }, job)).toMatchObject({ kind: "github", repo: "acme/infra", token: "given", origin: "https://github.com" });
|
|
125
|
+
expect(jobForgeTarget({ tokenEnv: "TG_TOKEN" }, job)).toMatchObject({ token: "tg", tokenSource: "TG_TOKEN" });
|
|
126
|
+
expect(jobForgeTarget({ tokenEnv: "TG_TOKEN" }, { ...job, TG_TOKEN: "" }, { tokenOptional: true })).toMatchObject({ token: "", repo: "acme/infra" });
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("undefined where the job names no forge or lacks a piece, and a bad flag still throws", () => {
|
|
130
|
+
expect(jobForgeTarget({ tokenEnv: "TG_TOKEN" }, {})).toBeUndefined();
|
|
131
|
+
expect(jobForgeTarget({ tokenEnv: "TG_TOKEN" }, { ...job, TG_TOKEN: "" })).toBeUndefined();
|
|
132
|
+
expect(() => jobForgeTarget({ forge: "svn" }, job)).toThrow(ForgeFlagError);
|
|
133
|
+
});
|
|
134
|
+
});
|
package/src/forge-flags.ts
CHANGED
|
@@ -34,6 +34,15 @@ export interface ForgeOverrides {
|
|
|
34
34
|
|
|
35
35
|
const trimUrl = (u: string | undefined): string | undefined => u?.trim().replace(/\/+$/, "") || undefined;
|
|
36
36
|
|
|
37
|
+
/** `scheme://host[:port]` of a URL, the path dropped. */
|
|
38
|
+
const originOf = (url: string): string => {
|
|
39
|
+
try {
|
|
40
|
+
return new URL(url).origin;
|
|
41
|
+
} catch {
|
|
42
|
+
return url;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
37
46
|
const hostOf = (url: string): string | undefined => {
|
|
38
47
|
try {
|
|
39
48
|
return new URL(url).host.toLowerCase();
|
|
@@ -102,6 +111,9 @@ export function forgeTargetWith(env: Record<string, string | undefined> = proces
|
|
|
102
111
|
const out: ForgeTarget = { ...t };
|
|
103
112
|
if (noToken) Object.assign(out, { token: "", tokenSource: "" });
|
|
104
113
|
if (kind !== "gitlab" && apiUrl && !url) out.host = hostOf(apiUrl)!.replace(/^api\.github\.com$/, "github.com");
|
|
114
|
+
// #4888: the web origin, for a product's links and messages: `url`, else the job's server when it is the target's host, else https on the host.
|
|
115
|
+
const server = url ?? trimUrl(kind === "gitlab" ? e.CI_SERVER_URL : ((fj ? e.FORGEJO_SERVER_URL : undefined) ?? e.GITHUB_SERVER_URL));
|
|
116
|
+
out.origin = server && /^https?:\/\//i.test(server) && hostOf(server) === out.host ? originOf(server) : `https://${out.host}`;
|
|
105
117
|
if (kind !== "gitlab" && (repo || url)) {
|
|
106
118
|
const server = trimUrl(job("SERVER_URL"));
|
|
107
119
|
const jobRepo = job("REPOSITORY");
|
|
@@ -193,6 +205,28 @@ export function forgeTargetFromFlags(
|
|
|
193
205
|
return { ...t, tokenSource: "the token given" };
|
|
194
206
|
}
|
|
195
207
|
|
|
208
|
+
/**
|
|
209
|
+
* {@link forgeTargetFromFlags}, or undefined where it would throw
|
|
210
|
+
* {@link ForgeEnvironmentError} (#4888): the environment names no forge, or
|
|
211
|
+
* lacks the repository or the token. For a product step that does its
|
|
212
|
+
* forge work only when the job can, as terragucci's own `targetFromEnv`
|
|
213
|
+
* did: give the token the product holds as `token`, the one variable to
|
|
214
|
+
* read as `tokenEnv`, and `tokenOptional` for a read a public repository
|
|
215
|
+
* answers with none.
|
|
216
|
+
*/
|
|
217
|
+
export function jobForgeTarget(
|
|
218
|
+
flags: ForgeFlags,
|
|
219
|
+
env: Record<string, string | undefined> = process.env,
|
|
220
|
+
opts: Pick<ForgeTargetOptions, "requirePr" | "readFile"> & Pick<ForgeOverrides, "tokenOptional"> = {},
|
|
221
|
+
): ForgeTarget | undefined {
|
|
222
|
+
try {
|
|
223
|
+
return forgeTargetFromFlags(flags, env, opts);
|
|
224
|
+
} catch (err) {
|
|
225
|
+
if (err instanceof ForgeEnvironmentError) return undefined;
|
|
226
|
+
throw err;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
196
230
|
/**
|
|
197
231
|
* The flags that would supply what a {@link ForgeEnvironmentError} says is
|
|
198
232
|
* missing, for a product's message: `outside CI pass --repo, --pr and
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4920: the forge a checkout's origin remote names, public, so a laptop
|
|
3
|
+
* command needs no repository setting.
|
|
4
|
+
*/
|
|
5
|
+
import { execFileSync } from "node:child_process";
|
|
6
|
+
import { mkdtempSync } from "node:fs";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { describe, expect, test } from "vitest";
|
|
10
|
+
import { forgeKindOfHost, forgeOfCheckout, forgeOfRemote } from "./forge-remote";
|
|
11
|
+
|
|
12
|
+
describe("forgeOfRemote (#4920)", () => {
|
|
13
|
+
test("https, ssh and scp remotes on each forge", () => {
|
|
14
|
+
expect(forgeOfRemote("https://github.com/acme/infra.git")).toEqual({ kind: "github", host: "github.com", url: "https://github.com", repo: "acme/infra" });
|
|
15
|
+
expect(forgeOfRemote("git@gitlab.com:group/sub/proj.git")).toEqual({ kind: "gitlab", host: "gitlab.com", url: "https://gitlab.com", repo: "group/sub/proj" });
|
|
16
|
+
expect(forgeOfRemote("ssh://git@codeberg.org:22/acme/infra")).toEqual({ kind: "forgejo", host: "codeberg.org", url: "https://codeberg.org", repo: "acme/infra" });
|
|
17
|
+
expect(forgeOfRemote("http://forgejo.lan:3000/acme/infra.git")).toEqual({ kind: "forgejo", host: "forgejo.lan:3000", url: "http://forgejo.lan:3000", repo: "acme/infra" });
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("a host no forge is named for, unless the kind is given; no repository path is none", () => {
|
|
21
|
+
expect(forgeOfRemote("git@git.corp.example:acme/infra.git")).toBeUndefined();
|
|
22
|
+
expect(forgeOfRemote("git@git.corp.example:acme/infra.git", { kind: "gitlab" })).toMatchObject({ kind: "gitlab", repo: "acme/infra", url: "https://git.corp.example" });
|
|
23
|
+
expect(forgeOfRemote("https://github.com/")).toBeUndefined();
|
|
24
|
+
expect(forgeOfRemote(undefined)).toBeUndefined();
|
|
25
|
+
expect(forgeKindOfHost("GitHub.example.com")).toBe("github");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("a checkout's origin, read with git", () => {
|
|
29
|
+
// A temporary checkout, left for the OS to clear.
|
|
30
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-forge-remote-"));
|
|
31
|
+
execFileSync("git", ["-C", dir, "init", "-q"]);
|
|
32
|
+
expect(forgeOfCheckout(dir)).toBeUndefined();
|
|
33
|
+
execFileSync("git", ["-C", dir, "remote", "add", "origin", "git@github.com:acme/infra.git"]);
|
|
34
|
+
expect(forgeOfCheckout(dir)).toMatchObject({ kind: "github", repo: "acme/infra" });
|
|
35
|
+
expect(forgeOfCheckout(dir, { remote: "upstream" })).toBeUndefined();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The forge a checkout's origin remote names (#4920): its kind, host, web
|
|
3
|
+
* origin and repository, for a command run on a laptop with no CI variables
|
|
4
|
+
* and no repository setting, such as plywood's `cancel`.
|
|
5
|
+
*
|
|
6
|
+
* It is the reading chant's own laptop paths make when the environment
|
|
7
|
+
* names no forge (`forgeWorkReader` in ./workspace/forge-work.ts): the
|
|
8
|
+
* host from the remote's URL, the kind from the host's name, and the
|
|
9
|
+
* repository path. Kept out of `pr-forge.ts`, which is in the pr-forge and
|
|
10
|
+
* pr-loop bundles.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { execFileSync } from "node:child_process";
|
|
14
|
+
import type { ForgeKind } from "./pr-forge";
|
|
15
|
+
import { remoteRepoPath } from "./op/activities/forge-pull-request";
|
|
16
|
+
import { remoteHost } from "./op/activities/gh-host";
|
|
17
|
+
|
|
18
|
+
export { remoteRepoPath, remoteHost };
|
|
19
|
+
|
|
20
|
+
/** The forge kind a remote host is: github.com and hosts named for GitHub, GitLab, or Forgejo and Gitea (codeberg.org too). Null for any other. */
|
|
21
|
+
export function forgeKindOfHost(host: string): ForgeKind | null {
|
|
22
|
+
const h = host.toLowerCase().replace(/:\d+$/, "");
|
|
23
|
+
if (h === "github.com" || /(^|[.-])github([.-]|$)/.test(h)) return "github";
|
|
24
|
+
if (h === "gitlab.com" || /(^|[.-])gitlab([.-]|$)/.test(h)) return "gitlab";
|
|
25
|
+
if (h === "codeberg.org" || /(^|[.-])(forgejo|gitea)([.-]|$)/.test(h)) return "forgejo";
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The forge a git remote names. */
|
|
30
|
+
export interface RemoteForge {
|
|
31
|
+
kind: ForgeKind;
|
|
32
|
+
/** Lower-cased, with an http(s) remote's port. */
|
|
33
|
+
host: string;
|
|
34
|
+
/** The web origin, `https://host` (an http remote keeps its scheme and port), as `--url` takes it. */
|
|
35
|
+
url: string;
|
|
36
|
+
/** `owner/name`, or a GitLab group path and name. */
|
|
37
|
+
repo: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The forge a remote URL names (`https://host/o/r.git`, `ssh://git@host/o/r`,
|
|
42
|
+
* `git@host:o/r`), or undefined when it names no repository path or its host
|
|
43
|
+
* is none {@link forgeKindOfHost} knows. `kind` stands in for the host's
|
|
44
|
+
* guess, for a self-hosted forge whose name says nothing.
|
|
45
|
+
*/
|
|
46
|
+
export function forgeOfRemote(remoteUrl: string | undefined, opts: { kind?: ForgeKind } = {}): RemoteForge | undefined {
|
|
47
|
+
const host = remoteHost(remoteUrl);
|
|
48
|
+
const repo = remoteRepoPath(remoteUrl);
|
|
49
|
+
if (!host || !repo) return undefined;
|
|
50
|
+
const kind = opts.kind ?? forgeKindOfHost(host);
|
|
51
|
+
if (!kind) return undefined;
|
|
52
|
+
let url = `https://${host.replace(/:\d+$/, "")}`;
|
|
53
|
+
try {
|
|
54
|
+
const u = new URL(remoteUrl!.trim());
|
|
55
|
+
if (u.protocol === "http:" || u.protocol === "https:") url = `${u.protocol}//${u.host.toLowerCase()}`;
|
|
56
|
+
} catch {
|
|
57
|
+
// An scp-style remote is ssh, whose port is not the web's.
|
|
58
|
+
}
|
|
59
|
+
return { kind, host, url, repo };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** `git remote get-url <remote>` in `cwd`, or undefined when there is none. */
|
|
63
|
+
function gitRemoteUrl(cwd: string, remote: string): string | undefined {
|
|
64
|
+
try {
|
|
65
|
+
return execFileSync("git", ["remote", "get-url", remote], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim() || undefined;
|
|
66
|
+
} catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The forge the checkout at `cwd` names by its `origin` remote (or
|
|
73
|
+
* `remote`), as {@link forgeOfRemote} reads it. Undefined outside a
|
|
74
|
+
* checkout, with no such remote, or for a host no forge kind is known for.
|
|
75
|
+
*/
|
|
76
|
+
export function forgeOfCheckout(cwd: string, opts: { remote?: string; kind?: ForgeKind; remoteUrl?: (cwd: string, remote: string) => string | undefined } = {}): RemoteForge | undefined {
|
|
77
|
+
const url = (opts.remoteUrl ?? gitRemoteUrl)(cwd, opts.remote ?? "origin");
|
|
78
|
+
return forgeOfRemote(url, opts.kind ? { kind: opts.kind } : {});
|
|
79
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* #4909 end to end: `chant dev generated-check` through the real CLI, on a
|
|
10
|
+
* product whose release workflow `chant release workflow` writes, the render
|
|
11
|
+
* terragucci's `just ci-check` had to strip `--output` from with sed; and
|
|
12
|
+
* `chant dev local-image` on a pinned and a local chant.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const mainTs = resolve(here, "cli/main.ts");
|
|
17
|
+
const tsxLoader = pathToFileURL(resolve(here, "../../../node_modules/tsx/dist/loader.mjs")).href;
|
|
18
|
+
const chantCommand = `${JSON.stringify(process.execPath)} --import ${tsxLoader} ${JSON.stringify(mainTs)}`;
|
|
19
|
+
|
|
20
|
+
const write = (file: string, body: string | object) => {
|
|
21
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
22
|
+
writeFileSync(file, typeof body === "string" ? body : JSON.stringify(body, null, 2) + "\n");
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const chant = (cwd: string, ...args: string[]) => spawnSync(process.execPath, ["--import", tsxLoader, mainTs, ...args], { cwd, encoding: "utf8", env: { ...process.env, NO_COLOR: "1" }, timeout: 110_000 });
|
|
26
|
+
|
|
27
|
+
/** A git repository holding a chant workspace with a committed release workflow. */
|
|
28
|
+
function product(): string {
|
|
29
|
+
const dir = realpathSync(mkdtempSync(join(tmpdir(), "chant-4909-e2e-")));
|
|
30
|
+
write(join(dir, "chant.workspace.json"), { name: "product", schema: 1, members: [] });
|
|
31
|
+
write(join(dir, "chant.config.json"), { lexicons: [] });
|
|
32
|
+
write(join(dir, "package.json"), {
|
|
33
|
+
name: "product",
|
|
34
|
+
private: true,
|
|
35
|
+
chantGenerated: {
|
|
36
|
+
regenerate: "chant release workflow --forge github",
|
|
37
|
+
renders: [{ name: "release", run: `${chantCommand} release workflow --forge github --output {out}/.github/workflows/chant-release.yml`, files: [".github/workflows/chant-release.yml"] }],
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
mkdirSync(join(dir, ".github/workflows"), { recursive: true });
|
|
41
|
+
expect(spawnSync("git", ["init", "-q"], { cwd: dir }).status).toBe(0);
|
|
42
|
+
return dir;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe("chant dev generated-check (#4909)", () => {
|
|
46
|
+
it("passes on the committed release workflow, then fails a hand edit and leaves the render tree", () => {
|
|
47
|
+
const dir = product();
|
|
48
|
+
const written = chant(dir, "release", "workflow", "--forge", "github");
|
|
49
|
+
expect(written.status).toBe(0);
|
|
50
|
+
const committed = readFileSync(join(dir, ".github/workflows/chant-release.yml"), "utf8");
|
|
51
|
+
expect(committed.split("\n")[0]).not.toContain("--output");
|
|
52
|
+
|
|
53
|
+
const ok = chant(dir, "dev", "generated-check", "--json");
|
|
54
|
+
expect(ok.status).toBe(0);
|
|
55
|
+
const result = JSON.parse(ok.stdout);
|
|
56
|
+
expect(result.matched).toEqual([".github/workflows/chant-release.yml"]);
|
|
57
|
+
// The check rendered beside the product and wrote nothing in it.
|
|
58
|
+
expect(readFileSync(join(dir, ".github/workflows/chant-release.yml"), "utf8")).toBe(committed);
|
|
59
|
+
expect(readFileSync(join(result.out, ".github/workflows/chant-release.yml"), "utf8")).toBe(committed);
|
|
60
|
+
|
|
61
|
+
writeFileSync(join(dir, ".github/workflows/chant-release.yml"), committed.replace("name: chant release", "name: hand edited"));
|
|
62
|
+
const bad = chant(dir, "dev", "generated-check");
|
|
63
|
+
expect(bad.status).toBe(1);
|
|
64
|
+
expect(bad.stderr).toContain(".github/workflows/chant-release.yml is not what 'release' renders. Run 'chant release workflow --forge github' and commit the result.");
|
|
65
|
+
expect(bad.stderr).toContain("+ name: chant release");
|
|
66
|
+
expect(bad.stderr).toMatch(/the renders are in .*chant-generated-/);
|
|
67
|
+
}, 120_000);
|
|
68
|
+
|
|
69
|
+
it("refuses a product with no chantGenerated", () => {
|
|
70
|
+
const dir = realpathSync(mkdtempSync(join(tmpdir(), "chant-4909-e2e-none-")));
|
|
71
|
+
write(join(dir, "package.json"), { name: "none" });
|
|
72
|
+
const r = chant(dir, "dev", "generated-check");
|
|
73
|
+
expect(r.status).toBe(2);
|
|
74
|
+
expect(r.stderr).toContain("declares no chantGenerated");
|
|
75
|
+
}, 60_000);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("chant dev local-image (#4909)", () => {
|
|
79
|
+
it("names the pin, then the local build and its build context, and refuses a missing tarball", () => {
|
|
80
|
+
const dir = realpathSync(mkdtempSync(join(tmpdir(), "chant-4909-e2e-image-")));
|
|
81
|
+
write(join(dir, "package.json"), { name: "product", private: true, devDependencies: { "@intentius/chant": "1.2.3" } });
|
|
82
|
+
write(join(dir, "node_modules/@intentius/chant/package.json"), { name: "@intentius/chant", version: "1.2.3" });
|
|
83
|
+
const pinned = chant(dir, "dev", "local-image");
|
|
84
|
+
expect(pinned.status).toBe(0);
|
|
85
|
+
expect(pinned.stdout.trim()).toBe("1.2.3");
|
|
86
|
+
|
|
87
|
+
write(join(dir, "node_modules/@intentius/chant/package.json"), { name: "@intentius/chant", version: "1.3.0", chantLocal: { commit: "abc123", dir: "/chant" } });
|
|
88
|
+
write(join(dir, ".chant-local/commit"), "abc123\n");
|
|
89
|
+
write(join(dir, ".chant-local/intentius-chant.tgz"), "tgz");
|
|
90
|
+
const local = chant(dir, "dev", "local-image", "--json");
|
|
91
|
+
expect(local.status).toBe(0);
|
|
92
|
+
expect(JSON.parse(local.stdout).args).toEqual(["--build-context", `chant-local=${join(dir, ".chant-local")}`, "--build-arg", "CHANT_VERSION=local-abc123"]);
|
|
93
|
+
|
|
94
|
+
const missing = chant(dir, "dev", "local-image", "--with", "@intentius/chant-lexicon-fountain");
|
|
95
|
+
expect(missing.status).toBe(1);
|
|
96
|
+
expect(missing.stderr).toContain("no tarball for @intentius/chant-lexicon-fountain; run chant dev local again with --with @intentius/chant-lexicon-fountain");
|
|
97
|
+
}, 60_000);
|
|
98
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { checkGenerated, committedPathOf, diffLines, GENERATED_OUT_ENV, GENERATED_ROOT_ENV, isRenderPath, readGeneratedCheckConfig, renderPathOf, type GeneratedCheckConfig } from "./generated-check";
|
|
6
|
+
|
|
7
|
+
/** #4909: a product's generated files checked by chant instead of terragucci's `just ci-check` and plywood's `--check` scripts. */
|
|
8
|
+
|
|
9
|
+
const write = (file: string, body: string | object) => {
|
|
10
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
11
|
+
writeFileSync(file, typeof body === "string" ? body : JSON.stringify(body, null, 2) + "\n");
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** A product whose committed files are what its renders write: a workflow, two Dockerfiles by pattern, and a script that checks itself. */
|
|
15
|
+
function product(): { dir: string; config: GeneratedCheckConfig } {
|
|
16
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-4909-product-"));
|
|
17
|
+
write(join(dir, ".github/workflows/ci.yml"), "name: ci\non: push\n");
|
|
18
|
+
write(join(dir, "images/Dockerfile.tofu"), "FROM tofu\n");
|
|
19
|
+
write(join(dir, "images/Dockerfile.node"), "FROM node\n");
|
|
20
|
+
write(join(dir, "images/images.ts"), "// the source\n");
|
|
21
|
+
const config: GeneratedCheckConfig = {
|
|
22
|
+
regenerate: "just ci",
|
|
23
|
+
renders: [
|
|
24
|
+
{ name: "ci", run: "mkdir -p {out}/.github/workflows && printf 'name: ci\\non: push\\n' > {out}/.github/workflows/ci.yml", files: [".github/workflows/ci.yml"] },
|
|
25
|
+
{ name: "images", run: 'mkdir -p "$CHANT_GENERATED_OUT/images" && printf "FROM tofu\\n" > "$CHANT_GENERATED_OUT/images/Dockerfile.tofu" && printf "FROM node\\n" > "$CHANT_GENERATED_OUT/images/Dockerfile.node"', files: ["images/Dockerfile.*"] },
|
|
26
|
+
{ name: "dashboards", run: "true" },
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
write(join(dir, "package.json"), { name: "product", private: true, chantGenerated: config });
|
|
30
|
+
return { dir, config };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe("checkGenerated (#4909)", () => {
|
|
34
|
+
it("passes when every committed file is its render, and leaves the render tree", async () => {
|
|
35
|
+
const { dir, config } = product();
|
|
36
|
+
const r = await checkGenerated(dir, config);
|
|
37
|
+
expect(r.problems).toEqual([]);
|
|
38
|
+
expect(r.ok).toBe(true);
|
|
39
|
+
expect(r.matched).toEqual([".github/workflows/ci.yml", "images/Dockerfile.node", "images/Dockerfile.tofu"]);
|
|
40
|
+
expect(r.out).toContain("chant-generated-");
|
|
41
|
+
expect(readFileSync(join(r.out, "images/Dockerfile.tofu"), "utf8")).toBe("FROM tofu\n");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("fails a hand edit with a diff and the regenerate command, and a file on one side only", async () => {
|
|
45
|
+
const { dir, config } = product();
|
|
46
|
+
write(join(dir, ".github/workflows/ci.yml"), "name: ci\non: pull_request\n");
|
|
47
|
+
write(join(dir, "images/Dockerfile.old"), "FROM old\n");
|
|
48
|
+
const r = await checkGenerated(dir, config);
|
|
49
|
+
expect(r.ok).toBe(false);
|
|
50
|
+
expect(r.problems[0]).toContain(".github/workflows/ci.yml is not what 'ci' renders. Run 'just ci' and commit the result.");
|
|
51
|
+
expect(r.problems[0]).toContain("- on: pull_request");
|
|
52
|
+
expect(r.problems[0]).toContain("+ on: push");
|
|
53
|
+
expect(r.problems[1]).toBe("images/Dockerfile.old is committed, but 'images' no longer renders it. Run 'just ci' and commit the result.");
|
|
54
|
+
expect(existsSync(r.out)).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("fails a render that exits non-zero or writes nothing, and a name it does not have", async () => {
|
|
58
|
+
const { dir } = product();
|
|
59
|
+
const r = await checkGenerated(dir, {
|
|
60
|
+
renders: [
|
|
61
|
+
{ name: "broken", run: "echo nope >&2; exit 3", files: ["a.yml"] },
|
|
62
|
+
{ name: "silent", run: "true", files: [".github/workflows/ci.yml"] },
|
|
63
|
+
],
|
|
64
|
+
}, { only: ["broken", "silent", "absent"] });
|
|
65
|
+
expect(r.problems).toEqual([
|
|
66
|
+
"chantGenerated has no render named 'absent'",
|
|
67
|
+
"render 'broken' exited 3: echo nope >&2; exit 3\n nope",
|
|
68
|
+
"render 'silent' wrote no .github/workflows/ci.yml under the render tree",
|
|
69
|
+
]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("reads chantGenerated and refuses a malformed one", () => {
|
|
73
|
+
const { dir, config } = product();
|
|
74
|
+
expect(readGeneratedCheckConfig(dir)).toEqual(config);
|
|
75
|
+
write(join(dir, "package.json"), { chantGenerated: { renders: [{ name: "x", run: "true", files: ["../outside"] }] } });
|
|
76
|
+
expect(() => readGeneratedCheckConfig(dir)).toThrow("must be paths inside the product");
|
|
77
|
+
write(join(dir, "package.json"), { name: "none" });
|
|
78
|
+
expect(readGeneratedCheckConfig(dir)).toBeUndefined();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("diffs from the first line that differs", () => {
|
|
82
|
+
expect(diffLines("a\nb\nc\nd\n", "a\nb\nX\nd\n")).toEqual(["@@ line 3 @@", " a", " b", "- c", "+ X"]);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("chant's writers under a check (#4909)", () => {
|
|
87
|
+
afterEach(() => {
|
|
88
|
+
delete process.env[GENERATED_OUT_ENV];
|
|
89
|
+
delete process.env[GENERATED_ROOT_ENV];
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("move a product path into the render tree and name a render path as the committed one", () => {
|
|
93
|
+
expect(renderPathOf("/p/.github/workflows/a.yml")).toBe("/p/.github/workflows/a.yml");
|
|
94
|
+
process.env[GENERATED_OUT_ENV] = "/t/out";
|
|
95
|
+
process.env[GENERATED_ROOT_ENV] = "/p";
|
|
96
|
+
expect(renderPathOf("/p/.github/workflows/a.yml")).toBe("/t/out/.github/workflows/a.yml");
|
|
97
|
+
expect(renderPathOf("/elsewhere/a.yml")).toBe("/elsewhere/a.yml");
|
|
98
|
+
expect(renderPathOf("/t/out/a.yml")).toBe("/t/out/a.yml");
|
|
99
|
+
expect(committedPathOf("/t/out/.github/workflows/a.yml")).toBe("/p/.github/workflows/a.yml");
|
|
100
|
+
expect(committedPathOf("/p/a.yml")).toBe("/p/a.yml");
|
|
101
|
+
expect(isRenderPath("/t/out/x")).toBe(true);
|
|
102
|
+
expect(isRenderPath("/t/outside/x")).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
});
|