@intentius/chant 0.124.88 → 0.124.90
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/actor.d.ts +36 -1
- package/dist/actor.d.ts.map +1 -1
- package/dist/actor.js +39 -1
- package/dist/chant-install.d.ts.map +1 -1
- package/dist/chant-install.js +1 -2
- package/dist/ci-base.d.ts +30 -0
- package/dist/ci-base.d.ts.map +1 -0
- package/dist/ci-base.js +33 -0
- package/dist/ci-comment-commands.d.ts +193 -0
- package/dist/ci-comment-commands.d.ts.map +1 -0
- package/dist/ci-comment-commands.js +353 -0
- package/dist/ci-comment-replies.d.ts +40 -0
- package/dist/ci-comment-replies.d.ts.map +1 -0
- package/dist/ci-comment-replies.js +59 -0
- package/dist/ci-evidence-from-job.d.ts +25 -0
- package/dist/ci-evidence-from-job.d.ts.map +1 -1
- package/dist/ci-evidence-from-job.js +43 -2
- package/dist/ci-evidence-jobs.d.ts +30 -1
- package/dist/ci-evidence-jobs.d.ts.map +1 -1
- package/dist/ci-evidence-jobs.js +46 -3
- package/dist/ci-image.d.ts +21 -4
- package/dist/ci-image.d.ts.map +1 -1
- package/dist/ci-image.js +62 -10
- package/dist/ci-job-guard.d.ts +42 -45
- package/dist/ci-job-guard.d.ts.map +1 -1
- package/dist/ci-job-guard.js +206 -3
- package/dist/ci-note-commands.d.ts +104 -4
- package/dist/ci-note-commands.d.ts.map +1 -1
- package/dist/ci-note-commands.js +131 -38
- package/dist/ci-product-words.d.ts +42 -0
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +25 -0
- package/dist/ci-product.d.ts +72 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +73 -6
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/build.js +29 -2
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +2 -1
- package/dist/cli/handlers/ci-check.d.ts +1 -1
- package/dist/cli/handlers/ci-check.d.ts.map +1 -1
- package/dist/cli/handlers/ci-check.js +17 -7
- package/dist/cli/handlers/ci-evidence.d.ts.map +1 -1
- package/dist/cli/handlers/ci-evidence.js +33 -7
- package/dist/cli/handlers/components.d.ts.map +1 -1
- package/dist/cli/handlers/components.js +3 -1
- package/dist/cli/handlers/generated-check.d.ts +8 -0
- package/dist/cli/handlers/generated-check.d.ts.map +1 -1
- package/dist/cli/handlers/generated-check.js +31 -1
- package/dist/cli/handlers/lock.d.ts.map +1 -1
- package/dist/cli/handlers/lock.js +121 -4
- package/dist/cli/handlers/pr-comment.d.ts +33 -0
- package/dist/cli/handlers/pr-comment.d.ts.map +1 -0
- package/dist/cli/handlers/pr-comment.js +201 -0
- package/dist/cli/handlers/pr-env.d.ts.map +1 -1
- package/dist/cli/handlers/pr-env.js +6 -3
- package/dist/cli/handlers/pr-notes.d.ts.map +1 -1
- package/dist/cli/handlers/pr-notes.js +23 -1
- package/dist/cli/handlers/pr.d.ts +23 -1
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +71 -23
- package/dist/cli/handlers/promote.d.ts.map +1 -1
- package/dist/cli/handlers/promote.js +2 -1
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +11 -2
- package/dist/cli/handlers/run-wave.d.ts.map +1 -1
- package/dist/cli/handlers/run-wave.js +180 -4
- package/dist/cli/handlers/run.d.ts.map +1 -1
- package/dist/cli/handlers/run.js +2 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +41 -2
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +31 -0
- package/dist/cli/registry.d.ts +19 -1
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/auto-release.d.ts.map +1 -1
- package/dist/components/auto-release.js +2 -1
- package/dist/components/pr-checks.d.ts +97 -6
- package/dist/components/pr-checks.d.ts.map +1 -1
- package/dist/components/pr-checks.js +107 -13
- package/dist/components/pr-pipeline.d.ts +19 -14
- package/dist/components/pr-pipeline.d.ts.map +1 -1
- package/dist/components/pr-pipeline.js +7 -13
- package/dist/components/product-pipeline.d.ts +96 -3
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +120 -14
- package/dist/components/product-plan.d.ts +203 -6
- package/dist/components/product-plan.d.ts.map +1 -1
- package/dist/components/product-plan.js +250 -43
- package/dist/drift-record.d.ts +7 -0
- package/dist/drift-record.d.ts.map +1 -1
- package/dist/drift-record.js +19 -0
- package/dist/floor-table.data.d.ts.map +1 -1
- package/dist/floor-table.data.js +63 -31
- package/dist/forge-check/contract.d.ts +11 -1
- 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/gate-resume-run.d.ts +9 -1
- package/dist/gate-resume-run.d.ts.map +1 -1
- package/dist/gate-resume-run.js +26 -3
- package/dist/generated-check.d.ts +18 -4
- package/dist/generated-check.d.ts.map +1 -1
- package/dist/generated-check.js +37 -5
- package/dist/image-pins.d.ts +26 -0
- package/dist/image-pins.d.ts.map +1 -0
- package/dist/image-pins.js +19 -0
- package/dist/lexicon.d.ts +93 -4
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/gate-applied.d.ts +9 -0
- package/dist/lifecycle/gate-applied.d.ts.map +1 -1
- package/dist/lifecycle/git.d.ts +11 -0
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +30 -3
- package/dist/lifecycle/publish-npm.d.ts +11 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +27 -1
- package/dist/lifecycle/reach-locks.d.ts +131 -0
- package/dist/lifecycle/reach-locks.d.ts.map +1 -0
- package/dist/lifecycle/reach-locks.js +118 -0
- package/dist/lifecycle/release-cut.d.ts +3 -1
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +15 -0
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +1 -2
- package/dist/notify-product.d.ts +12 -3
- package/dist/notify-product.d.ts.map +1 -1
- package/dist/notify-product.js +10 -6
- package/dist/op/activities/source-release.d.ts.map +1 -1
- package/dist/op/activities/source-release.js +2 -1
- package/dist/op/activities/source-rollback.d.ts.map +1 -1
- package/dist/op/activities/source-rollback.js +2 -1
- package/dist/op/apply-status.d.ts +84 -0
- package/dist/op/apply-status.d.ts.map +1 -0
- package/dist/op/apply-status.js +106 -0
- package/dist/op/before-merge-decide.d.ts +102 -0
- package/dist/op/before-merge-decide.d.ts.map +1 -0
- package/dist/op/before-merge-decide.js +142 -0
- package/dist/op/before-merge-done.d.ts +56 -0
- package/dist/op/before-merge-done.d.ts.map +1 -0
- package/dist/op/before-merge-done.js +69 -0
- package/dist/op/before-merge-store.d.ts +20 -0
- package/dist/op/before-merge-store.d.ts.map +1 -0
- package/dist/op/before-merge-store.js +48 -0
- package/dist/op/before-merge.d.ts +150 -0
- package/dist/op/before-merge.d.ts.map +1 -0
- package/dist/op/before-merge.js +207 -0
- package/dist/op/follow-on-run.d.ts +117 -0
- package/dist/op/follow-on-run.d.ts.map +1 -0
- package/dist/op/follow-on-run.js +154 -0
- package/dist/op/follow-on-store.d.ts +17 -0
- package/dist/op/follow-on-store.d.ts.map +1 -0
- package/dist/op/follow-on-store.js +54 -0
- package/dist/op/gate.d.ts +6 -0
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +10 -1
- package/dist/op/index.d.ts +5 -1
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/index.js +2 -0
- package/dist/op/op-waves-after-plan.d.ts +13 -0
- package/dist/op/op-waves-after-plan.d.ts.map +1 -1
- package/dist/op/op-waves-evidence-jobs.d.ts +10 -2
- package/dist/op/op-waves-evidence-jobs.d.ts.map +1 -1
- package/dist/op/op-waves-evidence-jobs.js +19 -5
- package/dist/op/op-waves-follow-on.d.ts +162 -0
- package/dist/op/op-waves-follow-on.d.ts.map +1 -0
- package/dist/op/op-waves-follow-on.js +355 -0
- package/dist/op/op-waves-render-spec.d.ts +100 -0
- package/dist/op/op-waves-render-spec.d.ts.map +1 -0
- package/dist/op/op-waves-render-spec.js +162 -0
- package/dist/op/op-waves-run.d.ts +148 -6
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +873 -100
- package/dist/op/op-waves-split.d.ts +122 -0
- package/dist/op/op-waves-split.d.ts.map +1 -0
- package/dist/op/op-waves-split.js +166 -0
- package/dist/op/op-waves.d.ts +24 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +18 -1
- package/dist/op/schedule-overdue.d.ts +15 -1
- package/dist/op/schedule-overdue.d.ts.map +1 -1
- package/dist/op/schedule-overdue.js +77 -5
- package/dist/op/stage-hooks.d.ts +36 -1
- package/dist/op/stage-hooks.d.ts.map +1 -1
- package/dist/op/stage-hooks.js +17 -3
- package/dist/op/wave-stop.d.ts +67 -0
- package/dist/op/wave-stop.d.ts.map +1 -0
- package/dist/op/wave-stop.js +129 -0
- package/dist/planned-files.d.ts +76 -0
- package/dist/planned-files.d.ts.map +1 -0
- package/dist/planned-files.js +108 -0
- package/dist/pr-forge-job.d.ts +22 -0
- package/dist/pr-forge-job.d.ts.map +1 -0
- package/dist/pr-forge-job.js +46 -0
- package/dist/pr-loop.d.ts +3 -6
- package/dist/pr-loop.d.ts.map +1 -1
- package/dist/pr-loop.js +4 -81
- package/dist/pr-plan-note.d.ts +97 -0
- package/dist/pr-plan-note.d.ts.map +1 -1
- package/dist/pr-plan-note.js +94 -1
- package/dist/pr-post.d.ts +28 -3
- package/dist/pr-post.d.ts.map +1 -1
- package/dist/pr-post.js +146 -13
- package/dist/pr-status.d.ts +16 -0
- package/dist/pr-status.d.ts.map +1 -0
- package/dist/pr-status.js +90 -0
- package/dist/ref-gate-init.d.ts +16 -2
- package/dist/ref-gate-init.d.ts.map +1 -1
- package/dist/ref-gate-init.js +24 -13
- package/dist/release-floors.d.ts +39 -1
- package/dist/release-floors.d.ts.map +1 -1
- package/dist/release-floors.js +63 -25
- package/dist/render-module.d.ts +15 -0
- package/dist/render-module.d.ts.map +1 -0
- package/dist/render-module.js +73 -0
- package/dist/state-migration.d.ts.map +1 -1
- package/dist/state-migration.js +1 -2
- package/dist/wave-blocked.d.ts +7 -1
- package/dist/wave-blocked.d.ts.map +1 -1
- package/dist/wave-blocked.js +7 -2
- package/dist/wave-runtime.mjs +366 -350
- package/dist/workspace/ci-green-cli.d.ts.map +1 -1
- package/dist/workspace/ci-green-cli.js +3 -2
- package/dist/workspace/release-train.d.ts.map +1 -1
- package/dist/workspace/release-train.js +2 -1
- package/dist/workspace/release-workflow.d.ts +4 -3
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +10 -7
- package/dist/workspace/trust/check-evidence-report.d.ts +7 -2
- package/dist/workspace/trust/check-evidence-report.d.ts.map +1 -1
- package/dist/workspace/trust/check-evidence-report.js +15 -8
- package/dist/workspace/trust/ref-gate-cli.d.ts +10 -1
- package/dist/workspace/trust/ref-gate-cli.d.ts.map +1 -1
- package/dist/workspace/trust/ref-gate-cli.js +30 -10
- package/dist/workspace/workspace-run.d.ts.map +1 -1
- package/dist/workspace/workspace-run.js +2 -1
- package/package.json +1 -1
- package/src/actor.test.ts +68 -2
- package/src/actor.ts +61 -1
- package/src/chant-install.test.ts +2 -3
- package/src/chant-install.ts +1 -2
- package/src/ci-base.test.ts +41 -0
- package/src/ci-base.ts +43 -0
- package/src/ci-comment-commands.test.ts +439 -0
- package/src/ci-comment-commands.ts +428 -0
- package/src/ci-comment-replies.ts +78 -0
- package/src/ci-commit.test.ts +2 -3
- package/src/ci-evidence-from-job.test.ts +18 -0
- package/src/ci-evidence-from-job.ts +58 -2
- package/src/ci-evidence-jobs.ts +50 -5
- package/src/ci-image.test.ts +130 -10
- package/src/ci-image.ts +85 -12
- package/src/ci-job-guard.before-merge.test.ts +148 -0
- package/src/ci-job-guard.follow-on-record.test.ts +137 -0
- package/src/ci-job-guard.follow-on.test.ts +144 -0
- package/src/ci-job-guard.ts +221 -3
- package/src/ci-note-commands.test.ts +76 -1
- package/src/ci-note-commands.ts +198 -46
- package/src/ci-product-words.ts +59 -0
- package/src/ci-product.ts +90 -6
- package/src/cli/commands/build.test.ts +41 -0
- package/src/cli/commands/build.ts +27 -2
- package/src/cli/handlers/approve.ts +2 -1
- package/src/cli/handlers/ci-check.ts +19 -7
- package/src/cli/handlers/ci-evidence.ts +29 -8
- package/src/cli/handlers/components.ts +3 -1
- package/src/cli/handlers/generated-check.ts +31 -1
- package/src/cli/handlers/lock-reach.test.ts +103 -0
- package/src/cli/handlers/lock.ts +100 -4
- package/src/cli/handlers/pr-comment.ts +187 -0
- package/src/cli/handlers/pr-env.ts +6 -3
- package/src/cli/handlers/pr-notes.ts +30 -6
- package/src/cli/handlers/pr-record.test.ts +1 -1
- package/src/cli/handlers/pr.ts +64 -21
- package/src/cli/handlers/promote.ts +2 -1
- package/src/cli/handlers/release.e2e.test.ts +35 -0
- package/src/cli/handlers/release.ts +14 -2
- package/src/cli/handlers/run-wave.ts +170 -4
- package/src/cli/handlers/run.ts +2 -1
- package/src/cli/main.ts +41 -2
- package/src/cli/parse-args.ts +23 -0
- package/src/cli/registry.ts +19 -1
- package/src/components/auto-release.ts +2 -1
- package/src/components/pr-checks.ts +165 -17
- package/src/components/pr-pipeline.ts +22 -18
- package/src/components/product-pipeline.apply-status.test.ts +50 -0
- package/src/components/product-pipeline.ts +204 -17
- package/src/components/product-plan.test.ts +60 -4
- package/src/components/product-plan.ts +367 -50
- package/src/drift-record.test.ts +20 -0
- package/src/drift-record.ts +16 -0
- package/src/floor-table.data.ts +63 -31
- package/src/forge-check/contract.ts +12 -1
- package/src/forge-check/forge-check.test.ts +17 -0
- package/src/forge-check/index.ts +2 -0
- package/src/gate-resume-run.ts +27 -3
- package/src/generated-check.e2e.test.ts +21 -1
- package/src/generated-check.test.ts +66 -0
- package/src/generated-check.ts +51 -10
- package/src/image-pins.ts +31 -0
- package/src/lexicon.ts +89 -1
- package/src/lifecycle/gate-applied.ts +7 -0
- package/src/lifecycle/git.test.ts +48 -0
- package/src/lifecycle/git.ts +27 -4
- package/src/lifecycle/publish-npm.ts +31 -1
- package/src/lifecycle/reach-locks.test.ts +87 -0
- package/src/lifecycle/reach-locks.ts +169 -0
- package/src/lifecycle/release-cut.ts +17 -1
- package/src/lifecycle/release-images.test.ts +56 -0
- package/src/lifecycle/release-images.ts +1 -2
- package/src/notify-product.ts +19 -8
- package/src/op/activities/source-release.ts +2 -1
- package/src/op/activities/source-rollback.ts +2 -1
- package/src/op/apply-status.test.ts +83 -0
- package/src/op/apply-status.ts +132 -0
- package/src/op/before-merge-decide.ts +190 -0
- package/src/op/before-merge-done.ts +99 -0
- package/src/op/before-merge-store.ts +44 -0
- package/src/op/before-merge.test.ts +201 -0
- package/src/op/before-merge.ts +266 -0
- package/src/op/follow-on-run.ts +206 -0
- package/src/op/follow-on-store.ts +54 -0
- package/src/op/gate-resume.test.ts +27 -0
- package/src/op/gate.ts +16 -1
- package/src/op/index.ts +15 -0
- package/src/op/op-waves-after-plan.ts +13 -0
- package/src/op/op-waves-evidence-jobs.ts +21 -7
- package/src/op/op-waves-follow-on-record.test.ts +152 -0
- package/src/op/op-waves-follow-on.test.ts +247 -0
- package/src/op/op-waves-follow-on.ts +385 -0
- package/src/op/op-waves-notify-words.test.ts +18 -0
- package/src/op/op-waves-render-spec.test.ts +159 -0
- package/src/op/op-waves-render-spec.ts +171 -0
- package/src/op/op-waves-run.ts +973 -94
- package/src/op/op-waves-split-product.test.ts +288 -0
- package/src/op/op-waves-split-step.test.ts +298 -0
- package/src/op/op-waves-split.test.ts +196 -0
- package/src/op/op-waves-split.ts +189 -0
- package/src/op/op-waves.ts +31 -3
- package/src/op/schedule-overdue.test.ts +72 -1
- package/src/op/schedule-overdue.ts +84 -6
- package/src/op/stage-hooks.ts +52 -4
- package/src/op/wave-stop.test.ts +72 -0
- package/src/op/wave-stop.ts +139 -0
- package/src/planned-files.test.ts +80 -0
- package/src/planned-files.ts +134 -0
- package/src/pr-forge-job.test.ts +53 -0
- package/src/pr-forge-job.ts +46 -0
- package/src/pr-loop-narrowed.test.ts +2 -1
- package/src/pr-loop-words.test.ts +2 -1
- package/src/pr-loop.test.ts +1 -2
- package/src/pr-loop.ts +4 -80
- package/src/pr-plan-note.ts +155 -3
- package/src/pr-post-replan.test.ts +144 -0
- package/src/pr-post-subject.test.ts +230 -0
- package/src/pr-post.test.ts +2 -1
- package/src/pr-post.ts +151 -15
- package/src/pr-status.ts +91 -0
- package/src/ref-gate-init.ts +30 -11
- package/src/release-floors.ts +81 -25
- package/src/render-module.ts +73 -0
- package/src/state-migration-record.test.ts +2 -3
- package/src/state-migration.ts +1 -2
- package/src/wave-blocked.ts +9 -4
- package/src/workspace/ci-green-cli.ts +3 -2
- package/src/workspace/ci-green-workflow.test.ts +32 -1
- package/src/workspace/release-train.ts +2 -1
- package/src/workspace/release-workflow.test.ts +36 -5
- package/src/workspace/release-workflow.ts +10 -7
- package/src/workspace/trust/check-evidence-report.ts +15 -8
- package/src/workspace/trust/check-evidence.test.ts +5 -0
- package/src/workspace/trust/ref-gate-cli.ts +30 -8
- package/src/workspace/trust/ref-gate-pieces.test.ts +46 -1
- package/src/workspace/trust/ref-gate.test.ts +10 -0
- package/src/workspace/workspace-run.ts +2 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4950: render a module's file-text export.
|
|
3
|
+
*
|
|
4
|
+
* A product keeps some generated files as the text a TypeScript function
|
|
5
|
+
* returns: plywood's `dockerfiles()` in `src/images.ts` gives each image's
|
|
6
|
+
* Dockerfile by its path from the repository root, and a schema or a set of
|
|
7
|
+
* dashboards can be the same. plywood bundled each such module with esbuild
|
|
8
|
+
* (`build-images.mjs`, `build-schema.mjs`) only to call that export and write
|
|
9
|
+
* the files. Here chant imports the module itself, with the TypeScript loader
|
|
10
|
+
* and chant's own modules served as the running CLI, calls the export, and
|
|
11
|
+
* writes each file below an output root:
|
|
12
|
+
*
|
|
13
|
+
* - `chant dev render <module> <export> [--output <root>]` writes them in
|
|
14
|
+
* place (the root is the working directory unless `--output` names one);
|
|
15
|
+
* under `chant dev generated-check` they go to the render tree.
|
|
16
|
+
* - a `chantGenerated` render of the module kind (`{ "module", "export" }`)
|
|
17
|
+
* renders them into the check's render tree and compares them.
|
|
18
|
+
*
|
|
19
|
+
* The export is a `{ path: text }` object, or a function, async or not, that
|
|
20
|
+
* returns one when called with no arguments. Each path is relative, with `/`
|
|
21
|
+
* between segments and no `..`.
|
|
22
|
+
*/
|
|
23
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
24
|
+
import { dirname, join, resolve } from "node:path";
|
|
25
|
+
import { importModule } from "./discovery/import";
|
|
26
|
+
|
|
27
|
+
/** Files by their path below the output root. */
|
|
28
|
+
export type RenderedFiles = Record<string, string>;
|
|
29
|
+
|
|
30
|
+
/** Whether `path` is one an export may name: relative, `/`-separated, with no `.` or `..` segment. */
|
|
31
|
+
function isRenderedPath(path: string): boolean {
|
|
32
|
+
if (!path || path.startsWith("/") || path.includes("\\") || /^[A-Za-z]:/.test(path)) return false;
|
|
33
|
+
return path.split("/").every((s) => s !== "" && s !== "." && s !== "..");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Import `modulePath` (resolved from `cwd`) and return the files its export
|
|
38
|
+
* `exportName` renders. Throws, naming the module and export, when the export
|
|
39
|
+
* is missing, is not files, or names a path outside the root.
|
|
40
|
+
*/
|
|
41
|
+
export async function renderModuleFiles(modulePath: string, exportName: string, cwd = process.cwd()): Promise<RenderedFiles> {
|
|
42
|
+
const at = resolve(cwd, modulePath);
|
|
43
|
+
const where = `${modulePath} export ${exportName}`;
|
|
44
|
+
const mod = await importModule(at);
|
|
45
|
+
if (!(exportName in mod)) throw new Error(`${modulePath} has no export named ${exportName}`);
|
|
46
|
+
const exported = mod[exportName];
|
|
47
|
+
const value = typeof exported === "function" ? await (exported as () => unknown)() : exported;
|
|
48
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${where} must be, or return, an object of file paths to their text`);
|
|
49
|
+
const files: RenderedFiles = {};
|
|
50
|
+
for (const [path, text] of Object.entries(value as Record<string, unknown>)) {
|
|
51
|
+
if (!isRenderedPath(path)) throw new Error(`${where} names ${JSON.stringify(path)}, which is not a relative path inside the output root`);
|
|
52
|
+
if (typeof text !== "string") throw new Error(`${where} gives ${path} a ${text === null ? "null" : typeof text}, not its text`);
|
|
53
|
+
files[path] = text;
|
|
54
|
+
}
|
|
55
|
+
if (Object.keys(files).length === 0) throw new Error(`${where} renders no files`);
|
|
56
|
+
return files;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Write each file below `root`, creating its directories. `place` maps the
|
|
61
|
+
* absolute path before the write (`renderPathOf`, under a check). Returns
|
|
62
|
+
* the paths written, in the export's order.
|
|
63
|
+
*/
|
|
64
|
+
export function writeRenderedFiles(root: string, files: RenderedFiles, place: (path: string) => string = (p) => p): string[] {
|
|
65
|
+
const written: string[] = [];
|
|
66
|
+
for (const [path, text] of Object.entries(files)) {
|
|
67
|
+
const target = place(join(root, path));
|
|
68
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
69
|
+
writeFileSync(target, text);
|
|
70
|
+
written.push(target);
|
|
71
|
+
}
|
|
72
|
+
return written;
|
|
73
|
+
}
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
import { describe, expect, test } from "vitest";
|
|
8
8
|
import { fakeLedger } from "./__fixtures__/gated-ledger";
|
|
9
9
|
import type { RequestGateInput } from "./lifecycle/gated-request";
|
|
10
|
-
import { NEXT_RELEASE } from "./release-floors";
|
|
11
10
|
import {
|
|
12
11
|
runStateMigration,
|
|
13
12
|
STATE_MIGRATION_RECORD_FLOOR,
|
|
@@ -84,7 +83,7 @@ describe("runStateMigration's record (#4928)", () => {
|
|
|
84
83
|
expect(l.attachments).toEqual([]);
|
|
85
84
|
});
|
|
86
85
|
|
|
87
|
-
test("the floor is the
|
|
88
|
-
expect(STATE_MIGRATION_RECORD_FLOOR).toBe(
|
|
86
|
+
test("the floor is the release that shipped it", () => {
|
|
87
|
+
expect(STATE_MIGRATION_RECORD_FLOOR).toBe("0.124.88");
|
|
89
88
|
});
|
|
90
89
|
});
|
package/src/state-migration.ts
CHANGED
|
@@ -48,7 +48,6 @@ import { chantGatedLedger, gatedOp, type GatedRequestLedger } from "./lifecycle/
|
|
|
48
48
|
import type { GatedRequestRules } from "./lifecycle/gated-request";
|
|
49
49
|
import { gatedRequestAttachmentPath } from "./lifecycle/gated-request-digest";
|
|
50
50
|
import { samePlanDigest } from "./lifecycle/plan-digest";
|
|
51
|
-
import { NEXT_RELEASE } from "./release-floors";
|
|
52
51
|
|
|
53
52
|
/** The first chant with the engine-neutral state migration (#4762). */
|
|
54
53
|
export const STATE_MIGRATION_FLOOR = "0.124.77";
|
|
@@ -57,7 +56,7 @@ export const STATE_MIGRATION_FLOOR = "0.124.77";
|
|
|
57
56
|
export const STATE_MIGRATION_SOURCE_FLOOR = "0.124.86";
|
|
58
57
|
|
|
59
58
|
/** The first chant whose `runStateMigration` takes a product's `record`, which the request's attachment binds beside the roots and `chant approve` shows (#4928). */
|
|
60
|
-
export const STATE_MIGRATION_RECORD_FLOOR =
|
|
59
|
+
export const STATE_MIGRATION_RECORD_FLOOR = "0.124.88";
|
|
61
60
|
|
|
62
61
|
/** The most a product's migration `record` may take, as canonical JSON in UTF-8 (#4928): a record names moves, retags and stamps, never a state's contents. */
|
|
63
62
|
export const STATE_MIGRATION_RECORD_MAX_BYTES = 64 * 1024;
|
package/src/wave-blocked.ts
CHANGED
|
@@ -180,18 +180,23 @@ export function runSummary(outcomes: Iterable<WaveMemberOutcome>): string | unde
|
|
|
180
180
|
return parts.join(", ");
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
/**
|
|
184
|
-
|
|
183
|
+
/**
|
|
184
|
+
* The outcome file of a wave's job, or of one group or share of it. With
|
|
185
|
+
* `apply` (#4987), a split wave's own applying job's: `-apply`, so it is
|
|
186
|
+
* never the gate job's file of the same wave, which that job reads.
|
|
187
|
+
*/
|
|
188
|
+
export function waveOutcomeFileName(wave: number, part: { group?: string; share?: number; apply?: boolean } = {}): string {
|
|
185
189
|
const group = part.group !== undefined ? `-group-${part.group.replace(/[^A-Za-z0-9._-]/g, "_")}` : "";
|
|
186
190
|
const share = part.share !== undefined ? `-share-${part.share}` : "";
|
|
187
|
-
|
|
191
|
+
const apply = part.apply === true && !group && !share ? "-apply" : "";
|
|
192
|
+
return `outcome-wave-${wave}${group}${share}${apply}.json`;
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
/** Write a wave job's outcome file in `dir`, members sorted by name. Returns its path. */
|
|
191
196
|
export function writeWaveOutcomeFile(
|
|
192
197
|
dir: string,
|
|
193
198
|
wave: number,
|
|
194
|
-
part: { group?: string; share?: number },
|
|
199
|
+
part: { group?: string; share?: number; apply?: boolean },
|
|
195
200
|
members: Record<string, WaveMemberOutcome>,
|
|
196
201
|
at = new Date().toISOString(),
|
|
197
202
|
holdsAll = false,
|
|
@@ -232,10 +232,11 @@ export async function runCiWorkflow(ctx: CommandContext): Promise<number> {
|
|
|
232
232
|
const root = realpathSync(found.dir);
|
|
233
233
|
const repoRoot = gitTop(root) ?? root;
|
|
234
234
|
const member = resolveMemberContext(cwd, found);
|
|
235
|
-
const target = ctx.args.output ? resolve(realpathSync(cwd), ctx.args.output) : join(repoRoot, CI_GREEN_WORKFLOW_FILE);
|
|
236
235
|
// #4909: under `chant dev generated-check` the file goes to the render
|
|
237
|
-
// tree; it is read and named as the committed file it stands for.
|
|
236
|
+
// tree; it is read and named as the committed file it stands for. #4950:
|
|
237
|
+
// with no --output too, so a render needs no `--output {out}/...`.
|
|
238
238
|
const { committedPathOf, isRenderPath, renderPathOf } = await import("../generated-check");
|
|
239
|
+
const target = ctx.args.output ? resolve(realpathSync(cwd), ctx.args.output) : renderPathOf(join(repoRoot, CI_GREEN_WORKFLOW_FILE));
|
|
239
240
|
const rendering = isRenderPath(target);
|
|
240
241
|
const asCommitted = committedPathOf(target);
|
|
241
242
|
const fromRepo = relative(repoRoot, asCommitted).split(sep).join("/");
|
|
@@ -4,10 +4,11 @@
|
|
|
4
4
|
* the generated-file rules (ws-042, #2524 D14).
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
8
8
|
import { join } from "node:path";
|
|
9
9
|
import { afterAll, describe, expect, test, vi } from "vitest";
|
|
10
10
|
import { GENERATED_MARKER } from "../discovery/files";
|
|
11
|
+
import { GENERATED_OUT_ENV, GENERATED_ROOT_ENV } from "../generated-check";
|
|
11
12
|
import type { CommandContext } from "../cli/registry";
|
|
12
13
|
import { parseYAMLDocument } from "../yaml";
|
|
13
14
|
import { runCiWorkflow } from "./ci-green-cli";
|
|
@@ -187,6 +188,36 @@ describe("chant ci workflow (#3573)", () => {
|
|
|
187
188
|
}
|
|
188
189
|
});
|
|
189
190
|
|
|
191
|
+
test("under chant dev generated-check, writes into the render tree with no --output and leaves the committed file (#4950)", async () => {
|
|
192
|
+
const root = realpathSync(scratchDir("chant-ci-workflow-"));
|
|
193
|
+
const out = realpathSync(scratchDir("chant-ci-workflow-out-"));
|
|
194
|
+
git(root, "init", "-q");
|
|
195
|
+
writeFiles(root, {
|
|
196
|
+
"chant.workspace.json": declaration([], { ci: { green: GREEN } }),
|
|
197
|
+
".github/workflows/ci.yml": CI,
|
|
198
|
+
".github/workflows/macos.yml": MACOS,
|
|
199
|
+
[CI_GREEN_WORKFLOW_FILE]: "committed\n",
|
|
200
|
+
});
|
|
201
|
+
const cwd = vi.spyOn(process, "cwd").mockReturnValue(root);
|
|
202
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
203
|
+
const error = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
204
|
+
process.env[GENERATED_OUT_ENV] = out;
|
|
205
|
+
process.env[GENERATED_ROOT_ENV] = root;
|
|
206
|
+
try {
|
|
207
|
+
expect(await runCiWorkflow({ args: {} } as unknown as CommandContext)).toBe(0);
|
|
208
|
+
expect(readFileSync(join(root, CI_GREEN_WORKFLOW_FILE), "utf-8")).toBe("committed\n");
|
|
209
|
+
const rendered = readFileSync(join(out, CI_GREEN_WORKFLOW_FILE), "utf-8");
|
|
210
|
+
expect(rendered.split("\n")[0]).toBe(`# ${GENERATED_MARKER}. Regenerate with: chant ci workflow (in the workspace root)`);
|
|
211
|
+
expect(existsSync(join(root, ".chant", "generated.json"))).toBe(false);
|
|
212
|
+
} finally {
|
|
213
|
+
delete process.env[GENERATED_OUT_ENV];
|
|
214
|
+
delete process.env[GENERATED_ROOT_ENV];
|
|
215
|
+
cwd.mockRestore();
|
|
216
|
+
log.mockRestore();
|
|
217
|
+
error.mockRestore();
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
|
|
190
221
|
test("--chant and --install go into the file and its header, and regenerate byte-identically", async () => {
|
|
191
222
|
const root = scratchDir("chant-ci-workflow-");
|
|
192
223
|
git(root, "init", "-q");
|
|
@@ -18,6 +18,7 @@ import { readAllReleases, readCuts } from "../lifecycle/release-store";
|
|
|
18
18
|
import { readDeclaration, WorkspaceReadError } from "./declaration";
|
|
19
19
|
import { locateWorkspace } from "./which-chant";
|
|
20
20
|
import { appendWorkspaceLine, readWorkspaceLines } from "./workspace-ledger";
|
|
21
|
+
import { actorFromEnv } from "../actor";
|
|
21
22
|
|
|
22
23
|
export interface TrainMember {
|
|
23
24
|
member: string;
|
|
@@ -140,7 +141,7 @@ export async function runWorkspaceTrain(ctx: CommandContext): Promise<number> {
|
|
|
140
141
|
for (const p of picked.problems) console.error(` ${p}`);
|
|
141
142
|
return 1;
|
|
142
143
|
}
|
|
143
|
-
const actor = ctx.args.actor ??
|
|
144
|
+
const actor = ctx.args.actor ?? actorFromEnv();
|
|
144
145
|
const record: ReleaseTrainRecord = { version: 1, id: `train-${randomUUID()}`, env, timestamp: new Date().toISOString(), actor, members: picked.members };
|
|
145
146
|
if (!ctx.args.dryRun) await appendReleaseTrain(root, record);
|
|
146
147
|
if (ctx.args.json) console.log(JSON.stringify({ ...record, written: !ctx.args.dryRun }, null, 2));
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/** #4656: `chant release workflow` renders the release pipeline from the `release` block. */
|
|
2
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { describe, expect, test, vi } from "vitest";
|
|
3
3
|
import { spawnSync } from "node:child_process";
|
|
4
|
-
import { mkdtempSync, readFileSync } from "node:fs";
|
|
4
|
+
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { parseYAML } from "../yaml";
|
|
8
8
|
import { ACTION_PINS } from "../action-pins";
|
|
9
|
-
import {
|
|
9
|
+
import { IMAGE_PINS } from "../image-pins";
|
|
10
|
+
import type { CommandContext } from "../cli/registry";
|
|
11
|
+
import { GENERATED_OUT_ENV, GENERATED_ROOT_ENV } from "../generated-check";
|
|
12
|
+
import { NPM_TRUSTED_PUBLISHING_SETUP, releaseWorkflowHeader, renderReleaseWorkflow, runReleaseWorkflow, RELEASE_DIGESTS_PATHS, RELEASE_WORKFLOW_FILES, type ReleaseWorkflowInput, type ReleaseWorkflowTarget } from "./release-workflow";
|
|
10
13
|
import type { SecurityGroup } from "./security";
|
|
11
14
|
|
|
12
15
|
const FIXTURES = join(__dirname, "__fixtures__", "release-workflow");
|
|
@@ -500,11 +503,12 @@ describe("QEMU for the platforms release.images builds (#4876)", () => {
|
|
|
500
503
|
}
|
|
501
504
|
});
|
|
502
505
|
|
|
503
|
-
test("on GitLab, a binfmt run line in the cut and the publish", () => {
|
|
506
|
+
test("on GitLab, a binfmt run line in the cut and the publish, the image pinned by digest (#4941)", () => {
|
|
504
507
|
const doc = parseYAML(render("gitlab", TWO)) as Record<string, { script: string[] }>;
|
|
505
508
|
for (const job of ["chant-release-cut", "chant-release-publish"]) {
|
|
506
509
|
const script = doc[job]!.script;
|
|
507
|
-
expect(script[script.indexOf("npm ci") + 1], job).toBe(
|
|
510
|
+
expect(script[script.indexOf("npm ci") + 1], job).toBe(`docker run --privileged --rm tonistiigi/binfmt:${IMAGE_PINS.binfmt.tag}@${IMAGE_PINS.binfmt.digest} --install arm64`);
|
|
511
|
+
expect(IMAGE_PINS.binfmt.digest).toMatch(/^sha256:[0-9a-f]{64}$/);
|
|
508
512
|
}
|
|
509
513
|
});
|
|
510
514
|
|
|
@@ -535,3 +539,30 @@ describe("QEMU for the platforms release.images builds (#4876)", () => {
|
|
|
535
539
|
expect(steps.find((s) => s.uses?.startsWith("docker/setup-qemu-action@"))!.with).toEqual({ platforms: "arm,arm64,riscv64" });
|
|
536
540
|
});
|
|
537
541
|
});
|
|
542
|
+
|
|
543
|
+
describe("chant release workflow under chant dev generated-check (#4950)", () => {
|
|
544
|
+
test("writes into the render tree with no --output, names no --output in the header, and leaves the committed file", async () => {
|
|
545
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), "chant-4950-release-")));
|
|
546
|
+
const out = realpathSync(mkdtempSync(join(tmpdir(), "chant-4950-release-out-")));
|
|
547
|
+
writeFileSync(join(root, "chant.workspace.json"), JSON.stringify({ name: "product", schema: 1, members: [] }));
|
|
548
|
+
writeFileSync(join(root, "chant.config.json"), JSON.stringify({ lexicons: [] }));
|
|
549
|
+
mkdirSync(join(root, ".github/workflows"), { recursive: true });
|
|
550
|
+
writeFileSync(join(root, RELEASE_WORKFLOW_FILES.github), "committed\n");
|
|
551
|
+
expect(spawnSync("git", ["init", "-q"], { cwd: root }).status).toBe(0);
|
|
552
|
+
const cwd = vi.spyOn(process, "cwd").mockReturnValue(root);
|
|
553
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
554
|
+
process.env[GENERATED_OUT_ENV] = out;
|
|
555
|
+
process.env[GENERATED_ROOT_ENV] = root;
|
|
556
|
+
try {
|
|
557
|
+
expect(await runReleaseWorkflow({ args: { forge: "github" } } as unknown as CommandContext)).toBe(0);
|
|
558
|
+
expect(readFileSync(join(root, RELEASE_WORKFLOW_FILES.github), "utf-8")).toBe("committed\n");
|
|
559
|
+
const rendered = readFileSync(join(out, RELEASE_WORKFLOW_FILES.github), "utf-8");
|
|
560
|
+
expect(rendered.split("\n")[0]).toBe(releaseWorkflowHeader("chant release workflow --forge github").trimEnd());
|
|
561
|
+
} finally {
|
|
562
|
+
delete process.env[GENERATED_OUT_ENV];
|
|
563
|
+
delete process.env[GENERATED_ROOT_ENV];
|
|
564
|
+
cwd.mockRestore();
|
|
565
|
+
log.mockRestore();
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
});
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
* renders the tag-triggered file it always did.
|
|
29
29
|
*/
|
|
30
30
|
import { ACTION_PINS, tagComments, usesRef } from "../action-pins";
|
|
31
|
+
import { IMAGE_PINS, imageRef } from "../image-pins";
|
|
31
32
|
import { releaseImagePlatforms, resolveReleaseImages } from "../lifecycle/release-images";
|
|
32
33
|
import { GENERATED_MARKER } from "../discovery/files";
|
|
33
34
|
import type { SecurityGroup } from "./security";
|
|
@@ -183,8 +184,8 @@ export function targetExtras(forge: ReleaseWorkflowForge, targets: ReadonlyArray
|
|
|
183
184
|
/** The platform the jobs `chant release workflow` writes run on: GitHub's and Forgejo's `ubuntu-latest`, and a GitLab runner's default (#4876). */
|
|
184
185
|
export const RELEASE_RUNNER_PLATFORM = "linux/amd64";
|
|
185
186
|
|
|
186
|
-
/** The binfmt image a GitLab job installs QEMU's handlers with (#4876). */
|
|
187
|
-
export const RELEASE_BINFMT_IMAGE =
|
|
187
|
+
/** The binfmt image a GitLab job installs QEMU's handlers with (#4876): the repository, which a config's own setup line is recognised by. */
|
|
188
|
+
export const RELEASE_BINFMT_IMAGE = IMAGE_PINS.binfmt.repository;
|
|
188
189
|
|
|
189
190
|
/** The architectures among `platforms` the runner can't run, as QEMU names them (`linux/arm/v7` is `arm`), each once. */
|
|
190
191
|
export function qemuArchitectures(platforms: readonly string[]): string[] {
|
|
@@ -196,7 +197,8 @@ export function qemuArchitectures(platforms: readonly string[]): string[] {
|
|
|
196
197
|
* runner can't, such as `linux/arm64` on an amd64 runner (#4876), so no
|
|
197
198
|
* product names it in `release.workflow.setup`. GitHub and Forgejo get
|
|
198
199
|
* `docker/setup-qemu-action` at its pin; GitLab a `docker run --privileged`
|
|
199
|
-
* of {@link RELEASE_BINFMT_IMAGE}
|
|
200
|
+
* of {@link RELEASE_BINFMT_IMAGE} by the digest `IMAGE_PINS.binfmt` records
|
|
201
|
+
* (#4941, ../image-pins.ts), which `chant release workflow` notes needs
|
|
200
202
|
* an executor that runs privileged containers. A config whose `setup` names
|
|
201
203
|
* the action or the binfmt image already gets nothing more, so its file
|
|
202
204
|
* renders as it did.
|
|
@@ -206,7 +208,7 @@ export function qemuSetup(forge: ReleaseWorkflowForge, platforms: readonly strin
|
|
|
206
208
|
if (archs.length === 0) return [];
|
|
207
209
|
const named = (p.setup ?? []).some((s) => ("uses" in s ? /^docker\/setup-qemu-action@/.test(s.uses) : s.run.includes(RELEASE_BINFMT_IMAGE)));
|
|
208
210
|
if (named) return [];
|
|
209
|
-
return forge === "gitlab" ? [{ run: `docker run --privileged --rm ${
|
|
211
|
+
return forge === "gitlab" ? [{ run: `docker run --privileged --rm ${imageRef(IMAGE_PINS.binfmt)} --install ${archs.join(",")}` }] : [{ uses: usesRef(ACTION_PINS.dockerSetupQemu4), with: { platforms: archs.join(",") } }];
|
|
210
212
|
}
|
|
211
213
|
|
|
212
214
|
/** The flags `chant release publish` gets under the groups. */
|
|
@@ -712,11 +714,12 @@ export async function runReleaseWorkflow(ctx: import("../cli/registry").CommandC
|
|
|
712
714
|
...(args.buildCommand ? { build: args.buildCommand } : {}),
|
|
713
715
|
...(args.ciChant ? { chant: args.ciChant } : {}),
|
|
714
716
|
});
|
|
715
|
-
const target = args.output ? resolve(process.cwd(), args.output) : join(repoRoot, release?.workflow?.file ?? RELEASE_WORKFLOW_FILES[forge]);
|
|
716
717
|
// #4909: under `chant dev generated-check` the header names the committed file the render stands for.
|
|
717
|
-
|
|
718
|
-
const
|
|
718
|
+
// #4950: with no --output the file goes to the render tree too, so a render needs no `--output {out}/...`.
|
|
719
|
+
const { committedPathOf, isRenderPath, renderPathOf } = await import("../generated-check");
|
|
719
720
|
const defaultTarget = join(repoRoot, release?.workflow?.file ?? RELEASE_WORKFLOW_FILES[forge]);
|
|
721
|
+
const target = args.output ? resolve(process.cwd(), args.output) : renderPathOf(defaultTarget);
|
|
722
|
+
const asCommitted = committedPathOf(target);
|
|
720
723
|
const parts = ["chant", "release", "workflow", "--forge", forge];
|
|
721
724
|
if (args.ciInstall) parts.push("--install", args.ciInstall);
|
|
722
725
|
if (args.buildCommand) parts.push("--build", args.buildCommand);
|
|
@@ -76,24 +76,31 @@ function policyOf(dir: string): { passed: boolean; reason: string } | null {
|
|
|
76
76
|
return standing === 0 ? { passed: true, reason: "the policy denied nothing that stands" } : { passed: false, reason: `the policy denied ${standing} unit${standing === 1 ? "" : "s"} with no override` };
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
/**
|
|
80
|
-
|
|
79
|
+
/**
|
|
80
|
+
* The checks to sign from the plan job's hand-off directory and result, and
|
|
81
|
+
* those left unsigned with why. #4964: a workspace member's plan job plans
|
|
82
|
+
* that member alone, so with `member` the two are `plan:<member>` and
|
|
83
|
+
* `policy:<member>`.
|
|
84
|
+
*/
|
|
85
|
+
export function planReportChecks(dir: string, result: string | undefined, member?: string): { sign: Array<{ check: string; claim?: Buffer }>; skipped: CheckEvidenceNote["skipped"] } {
|
|
86
|
+
const planCheck = member ? `plan:${member}` : "plan";
|
|
87
|
+
const policyCheck = member ? `policy:${member}` : "policy";
|
|
81
88
|
const file = [REPORT_FILE, HANDOFF_FILE].map((f) => join(dir, f)).find((f) => existsSync(f));
|
|
82
89
|
if (result !== "success") {
|
|
83
90
|
const why = `the plan job's result is ${result ?? "not given"}`;
|
|
84
|
-
return { sign: [], skipped: [{ check:
|
|
91
|
+
return { sign: [], skipped: [{ check: planCheck, reason: why }, { check: policyCheck, reason: why }] };
|
|
85
92
|
}
|
|
86
93
|
if (!file) {
|
|
87
94
|
const why = `the plan job left no ${REPORT_FILE} or ${HANDOFF_FILE}`;
|
|
88
|
-
return { sign: [], skipped: [{ check:
|
|
95
|
+
return { sign: [], skipped: [{ check: planCheck, reason: why }, { check: policyCheck, reason: why }] };
|
|
89
96
|
}
|
|
90
97
|
const claim = readFileSync(file);
|
|
91
|
-
const sign: Array<{ check: string; claim?: Buffer }> = [{ check:
|
|
98
|
+
const sign: Array<{ check: string; claim?: Buffer }> = [{ check: planCheck, claim }];
|
|
92
99
|
const skipped: CheckEvidenceNote["skipped"] = [];
|
|
93
100
|
const policy = policyOf(dir);
|
|
94
|
-
if (policy === null) skipped.push({ check:
|
|
95
|
-
else if (policy.passed) sign.push({ check:
|
|
96
|
-
else skipped.push({ check:
|
|
101
|
+
if (policy === null) skipped.push({ check: policyCheck, reason: "the plan ran no policy" });
|
|
102
|
+
else if (policy.passed) sign.push({ check: policyCheck, claim });
|
|
103
|
+
else skipped.push({ check: policyCheck, reason: policy.reason });
|
|
97
104
|
return { sign, skipped };
|
|
98
105
|
}
|
|
99
106
|
|
|
@@ -120,6 +120,11 @@ describe("the plan job's two checks (#4870)", () => {
|
|
|
120
120
|
expect(planReportChecks(dir(handoff([{ member: "a", rules: ["r"], overriders: [] }])), "success").sign.map((c) => c.check)).toEqual(["plan"]);
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
+
test("a workspace member's plan job signs its checks under the member's name (#4964)", () => {
|
|
124
|
+
expect(planReportChecks(dir({ "pr-plan.json": { policy: { result: "passed" } } }), "success", "app").sign.map((c) => c.check)).toEqual(["plan:app", "policy:app"]);
|
|
125
|
+
expect(planReportChecks(dir({ "pr-plan.json": {} }), "failure", "app").skipped.map((s) => s.check)).toEqual(["plan:app", "policy:app"]);
|
|
126
|
+
});
|
|
127
|
+
|
|
123
128
|
test("a failed plan job signs neither, and the note line says which were signed", () => {
|
|
124
129
|
const failed = planReportChecks(dir({ "pr-plan.json": { policy: { result: "passed" } } }), "failure");
|
|
125
130
|
expect(failed.sign).toEqual([]);
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
describeDecision,
|
|
28
28
|
readRefGateLedger,
|
|
29
29
|
refGateLedgerPath,
|
|
30
|
+
REF_GATE_STATUS,
|
|
30
31
|
RefUpdateInputError,
|
|
31
32
|
runPrePush,
|
|
32
33
|
runPreReceive,
|
|
@@ -192,17 +193,20 @@ export async function runWorkspaceRefGate(ctx: CommandContext): Promise<number>
|
|
|
192
193
|
if (!args.dryRun) appendRefGateLedger(ledger, [{ ...d, version: 1, kind: "ref-update", site, timestamp: now }]);
|
|
193
194
|
print(args.json, [d], args.dryRun ? undefined : ledger, "out");
|
|
194
195
|
if (site === "check" && d.decision === "refuse" && !args.dryRun && !here.bare) await recordRequests(here.repo, [d], now);
|
|
195
|
-
|
|
196
|
+
const context = refGateStatusContext(d);
|
|
197
|
+
if (site === "status" && context !== null) {
|
|
196
198
|
if (args.dryRun) {
|
|
197
|
-
console.error(`chant ref gate: would set ${
|
|
199
|
+
console.error(`chant ref gate: would set ${context} to ${d.decision === "admit" ? "success" : "failure"} on ${at.slice(0, 8)}`);
|
|
198
200
|
} else {
|
|
199
|
-
const { detectForge
|
|
201
|
+
const { detectForge } = await import("../../pr-forge");
|
|
200
202
|
const kind = detectForge();
|
|
201
203
|
if (!kind) {
|
|
202
|
-
console.error(formatError({ message: `no forge detected, so ${
|
|
204
|
+
console.error(formatError({ message: `no forge detected, so ${context} was not set`, hint: "run it in a GitHub, GitLab or Forgejo job, or pass --dry-run" }));
|
|
203
205
|
return 1;
|
|
204
206
|
}
|
|
205
|
-
|
|
207
|
+
// #4964: `--at` is a pull_request run's merge preview; the status goes on the pull request's head.
|
|
208
|
+
const { forgeFromJobEnv } = await import("../../pr-forge-job");
|
|
209
|
+
await postRefGateStatus(forgeFromJobEnv(kind), d);
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
return d.decision === "admit" ? 0 : 1;
|
|
@@ -244,7 +248,8 @@ async function statusOpen(repo: string, ref: string, baseRev: string | undefined
|
|
|
244
248
|
const d = decideRefUpdate({ repo, update: { ref, old: base, new: pr.headSha }, base, spent, now });
|
|
245
249
|
decisions.push(d);
|
|
246
250
|
if (dryRun) {
|
|
247
|
-
|
|
251
|
+
const context = refGateStatusContext(d);
|
|
252
|
+
if (context !== null) console.error(`chant ref gate: would set ${context} to ${d.decision === "admit" ? "success" : "failure"} on #${pr.number} at ${pr.headSha.slice(0, 8)}`);
|
|
248
253
|
continue;
|
|
249
254
|
}
|
|
250
255
|
appendRefGateLedger(ledger, [{ ...d, version: 1, kind: "ref-update", site: "status", timestamp: now }]);
|
|
@@ -259,9 +264,26 @@ async function statusOpen(repo: string, ref: string, baseRev: string | undefined
|
|
|
259
264
|
return 0;
|
|
260
265
|
}
|
|
261
266
|
|
|
262
|
-
/** The
|
|
267
|
+
/** The status `d` sets: its rule's, or `chant/ref-gate` when the gate could not decide (#4964); null when no rule matched. */
|
|
268
|
+
export function refGateStatusContext(d: Pick<RefDecision, "status" | "error">): string | null {
|
|
269
|
+
return d.status ?? (d.error ? REF_GATE_STATUS : null);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The commit status a forge requires for `d`'s ref: `success` when it is
|
|
274
|
+
* admitted, `failure` naming the missing checks when not. A gate that could
|
|
275
|
+
* not decide (#4964: the policy at base does not read, or the commit is not
|
|
276
|
+
* there) fails `chant/ref-gate` closed: the policy that would name another
|
|
277
|
+
* status is the one that did not read, and a forge that requires the status
|
|
278
|
+
* then refuses the merge rather than waiting for a status that never comes.
|
|
279
|
+
*/
|
|
263
280
|
export async function postRefGateStatus(forge: { setStatus(sha: string, status: { context: string; state: "success" | "failure"; description: string }): Promise<void> }, d: RefDecision): Promise<void> {
|
|
264
|
-
|
|
281
|
+
const context = refGateStatusContext(d);
|
|
282
|
+
if (context === null || d.new === null) return;
|
|
283
|
+
if (d.status === null) {
|
|
284
|
+
await forge.setStatus(d.new, { context, state: "failure", description: `refused: ${d.error!.code}` });
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
265
287
|
const missing = d.checks.filter((c) => c.action === "block" && (c.status === "missing" || c.status === "stale"));
|
|
266
288
|
const overridden = d.checks.filter((c) => c.status === "overridden").map((c) => c.check);
|
|
267
289
|
const description = d.error
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
import { existsSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
11
11
|
import { join } from "node:path";
|
|
12
12
|
import { describe, expect, test } from "vitest";
|
|
13
|
-
import {
|
|
13
|
+
import { beforeMergeBranch, beforeMergeRefGate } from "../../cli/handlers/pr";
|
|
14
|
+
import { refGateInitChecks, refGateInitPlan, RefGateInitError, writeRefGateInit } from "../../ref-gate-init";
|
|
15
|
+
import { productPlanEvidenceChecks, targetEvidenceCheck } from "../../ci-evidence-jobs";
|
|
14
16
|
import { REF_GATE_STATUS, refGateRulesAt, refGateStatusFor } from "../../ref-gate-rules";
|
|
15
17
|
import { decideRefUpdate, describeDecision, requestCommand } from "./ref-gate";
|
|
16
18
|
import { REF_GATE_HOOK_MARK } from "./ref-gate-cli";
|
|
@@ -77,6 +79,30 @@ describe("the ref gate's rules as a library (#4913)", () => {
|
|
|
77
79
|
});
|
|
78
80
|
});
|
|
79
81
|
|
|
82
|
+
describe("an apply before merge waits for the ref gate's status (#4966)", () => {
|
|
83
|
+
test("the target branch: --branch, the pull request's target, then the branch the job runs on", () => {
|
|
84
|
+
expect(beforeMergeBranch("release/2", { GITHUB_REF_NAME: "main" })).toBe("release/2");
|
|
85
|
+
expect(beforeMergeBranch(undefined, { GITHUB_BASE_REF: "trunk", GITHUB_REF_NAME: "7/merge" })).toBe("trunk");
|
|
86
|
+
expect(beforeMergeBranch(undefined, { CI_COMMIT_BRANCH: "main" })).toBe("main");
|
|
87
|
+
expect(beforeMergeBranch(undefined, { GITHUB_REF_NAME: "main" })).toBe("main");
|
|
88
|
+
expect(beforeMergeBranch(" ", {})).toBeUndefined();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("the status the policy at base sets for the target branch is required, and none without a rule", async () => {
|
|
92
|
+
const r = new GateRepos("4966-before-merge");
|
|
93
|
+
const ci = runnerKey();
|
|
94
|
+
r.write(".chant/trust.json", JSON.stringify({ schema: 1, runners: [{ principal: RUNNER, class: "runner", key: ci.pub }], refs: [{ ref: "refs/heads/main", checks: CHECKS, status: "acme/gate" }] }));
|
|
95
|
+
const base = r.commit("policy");
|
|
96
|
+
expect(await beforeMergeRefGate(r.work, base, undefined, { GITHUB_REF_NAME: "main" })).toMatchObject({ require: ["acme/gate"] });
|
|
97
|
+
expect(await beforeMergeRefGate(r.work, base, "feature", {})).toEqual({ require: [] });
|
|
98
|
+
expect(await beforeMergeRefGate(r.work, base, undefined, {})).toMatchObject({ require: [], note: expect.stringContaining("names no target branch") });
|
|
99
|
+
r.write(".chant/trust.json", "{ not json");
|
|
100
|
+
const broken = r.commit("broken policy");
|
|
101
|
+
const refused = await beforeMergeRefGate(r.work, broken, "main", {});
|
|
102
|
+
expect("problem" in refused && refused.problem).toContain("the trust policy at base can't be read");
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
80
106
|
describe("the ref gate's init pieces (#4913)", () => {
|
|
81
107
|
test("a checkout with no trust policy gets one with the rule, the pre-push hook and the runner key hint", () => {
|
|
82
108
|
const r = new GateRepos("4913-init-new");
|
|
@@ -139,6 +165,25 @@ describe("the ref gate's init pieces (#4913)", () => {
|
|
|
139
165
|
expect(bad.notes[0]).toContain("does not read as chant's trust policy");
|
|
140
166
|
});
|
|
141
167
|
|
|
168
|
+
test("#4978: with a product plan's targets, plan and policy are each target's, the checks the targets' note jobs sign", () => {
|
|
169
|
+
const r = new GateRepos("4978-init-targets");
|
|
170
|
+
r.commit("start");
|
|
171
|
+
const checks = [{ check: "lint", command: "npm run lint" }, { check: "plan", command: "/yodel plan" }, { check: "policy", action: "warn" as const, command: "/yodel plan" }];
|
|
172
|
+
const plan = refGateInitPlan(r.work, { checks, targets: ["staging", "prod"], prePush: false });
|
|
173
|
+
expect(JSON.parse(plan.files[0]!.content).refs[0].checks).toEqual([
|
|
174
|
+
{ check: "lint", command: "npm run lint" },
|
|
175
|
+
{ check: "plan:staging", command: "/yodel plan" },
|
|
176
|
+
{ check: "plan:prod", command: "/yodel plan" },
|
|
177
|
+
{ check: "policy:staging", action: "warn", command: "/yodel plan" },
|
|
178
|
+
{ check: "policy:prod", action: "warn", command: "/yodel plan" },
|
|
179
|
+
]);
|
|
180
|
+
expect(productPlanEvidenceChecks(["staging", "prod"])).toEqual(["plan:staging", "policy:staging", "plan:prod", "policy:prod"]);
|
|
181
|
+
expect(productPlanEvidenceChecks()).toEqual(["plan", "policy"]);
|
|
182
|
+
expect(targetEvidenceCheck("policy", "prod")).toBe("policy:prod");
|
|
183
|
+
expect(refGateInitChecks(checks, [])).toEqual(checks);
|
|
184
|
+
expect(() => refGateInitPlan(r.work, { checks, targets: ["no:colon"], prePush: false })).toThrow("is not a product plan target's name");
|
|
185
|
+
});
|
|
186
|
+
|
|
142
187
|
test("options no rule can hold, or a directory outside git, are refused", () => {
|
|
143
188
|
const r = new GateRepos("4913-init-refuse");
|
|
144
189
|
r.commit("start");
|
|
@@ -232,6 +232,16 @@ describe("the developer's side and the forge", () => {
|
|
|
232
232
|
]);
|
|
233
233
|
});
|
|
234
234
|
|
|
235
|
+
test("a policy at base that does not read fails the status closed (#4964)", async () => {
|
|
236
|
+
const { r, base } = setup("status-unreadable");
|
|
237
|
+
r.write(".chant/trust.json", "{ not json");
|
|
238
|
+
const broken = r.commit("broken policy");
|
|
239
|
+
const posted: Array<{ sha: string; context: string; state: string; description: string }> = [];
|
|
240
|
+
const forge = { setStatus: async (sha: string, s: { context: string; state: string; description: string }) => void posted.push({ sha, ...s }) };
|
|
241
|
+
await postRefGateStatus(forge, decideRefUpdate({ repo: r.work, update: { ref: "refs/heads/main", old: base, new: broken }, base: broken, now: NOW }));
|
|
242
|
+
expect(posted).toEqual([{ sha: broken, context: "chant/ref-gate", state: "failure", description: "refused: trust-policy-unreadable" }]);
|
|
243
|
+
});
|
|
244
|
+
|
|
235
245
|
test("the hooks run chant with git's arguments and input", () => {
|
|
236
246
|
expect(refGateHook("pre-receive")).toBe('#!/bin/sh\n# chant ref gate (#4867)\nexec chant workspace ref-gate pre-receive "$@"\n');
|
|
237
247
|
expect(refGateHook("pre-push", "npx chant")).toContain("exec npx chant workspace ref-gate pre-push");
|
|
@@ -47,6 +47,7 @@ import { executePlan, planMembers } from "./member-commands";
|
|
|
47
47
|
import { locateWorkspace } from "./which-chant";
|
|
48
48
|
import { appendWorkspaceRun, type WorkspaceRunRecord, type WorkspaceRunStep } from "./workspace-ledger";
|
|
49
49
|
import { appendWorkspaceGatePending, type WorkspaceGateCover, type WorkspaceGatePending } from "./workspace-gates";
|
|
50
|
+
import { actorFromEnv } from "../actor";
|
|
50
51
|
|
|
51
52
|
/** `chant run`'s exit code for a run that stopped at an unapproved gate (`GATED_EXIT_CODE`). */
|
|
52
53
|
const GATED_EXIT = CHANT_EXIT.waiting;
|
|
@@ -444,7 +445,7 @@ async function runWorkspaceRunApprove(ctx: CommandContext, words: string[]): Pro
|
|
|
444
445
|
return 1;
|
|
445
446
|
}
|
|
446
447
|
const { approveWorkspaceGate } = await import("./workspace-gates");
|
|
447
|
-
const approvedBy = ctx.args.approver ?? ctx.args.actor ??
|
|
448
|
+
const approvedBy = ctx.args.approver ?? ctx.args.actor ?? actorFromEnv();
|
|
448
449
|
try {
|
|
449
450
|
const record = await approveWorkspaceGate(resolve("."), {
|
|
450
451
|
gate,
|