@intentius/chant 0.124.109 → 0.124.110
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/__golden__/wave-loop/fan-out-applied.json +12 -6
- package/dist/__golden__/wave-loop/fan-out-apply-fails.json +8 -4
- package/dist/__golden__/wave-loop/fan-out-gated.json +4 -2
- package/dist/__golden__/wave-loop/fan-out-no-members.json +16 -8
- package/dist/__golden__/wave-loop/fan-out-plan-fails.json +8 -4
- package/dist/__golden__/wave-loop/fan-out-same-root.json +4 -2
- package/dist/agent-facts.d.ts +130 -0
- package/dist/agent-facts.js +196 -0
- package/dist/change-risk.d.ts +216 -0
- package/dist/change-risk.js +304 -0
- package/dist/change-set.d.ts +8 -0
- package/dist/ci-agent-alert.d.ts +139 -0
- package/dist/ci-agent-alert.js +342 -0
- package/dist/ci-agent-triggers.d.ts +152 -0
- package/dist/ci-agent-triggers.js +232 -0
- package/dist/ci-agent-verify-failed.d.ts +149 -0
- package/dist/ci-agent-verify-failed.js +191 -0
- package/dist/ci-agent.d.ts +136 -8
- package/dist/ci-agent.js +353 -26
- package/dist/ci-comment-commands.d.ts +8 -0
- package/dist/ci-comment-commands.js +17 -1
- package/dist/ci-comment-reject.d.ts +70 -0
- package/dist/ci-comment-reject.js +135 -0
- package/dist/ci-comment-replies.d.ts +3 -1
- package/dist/ci-comment-replies.js +6 -0
- package/dist/ci-estate/delivery.d.ts +25 -3
- package/dist/ci-estate/delivery.js +28 -9
- package/dist/ci-estate/page.d.ts +7 -3
- package/dist/ci-estate/page.js +19 -4
- package/dist/ci-estate/rows.d.ts +14 -2
- package/dist/ci-estate/rows.js +9 -1
- package/dist/ci-estate.d.ts +5 -2
- package/dist/ci-estate.js +3 -2
- package/dist/ci-handover.d.ts +2 -7
- package/dist/ci-handover.js +3 -20
- package/dist/ci-jobs.d.ts +6 -0
- package/dist/ci-jobs.js +17 -0
- package/dist/ci-note-commands.d.ts +2 -0
- package/dist/ci-note-commands.js +12 -1
- package/dist/ci-product-words.d.ts +151 -1
- package/dist/ci-product-words.js +1390 -3
- package/dist/ci-product.d.ts +100 -4
- package/dist/ci-product.js +99 -3
- package/dist/ci-respond-run.d.ts +9 -0
- package/dist/ci-respond-run.js +35 -4
- package/dist/ci-respond-summary-env.d.ts +56 -0
- package/dist/ci-respond-summary-env.js +81 -0
- package/dist/ci-respond-summary.d.ts +103 -0
- package/dist/ci-respond-summary.js +243 -0
- package/dist/ci-respond.d.ts +4 -2
- package/dist/ci-respond.js +4 -2
- package/dist/cli/command-group.js +1 -1
- package/dist/cli/commands/lint.js +21 -3
- package/dist/cli/handlers/agent.js +49 -4
- package/dist/cli/handlers/approve.js +3 -1
- package/dist/cli/handlers/build.d.ts +97 -1
- package/dist/cli/handlers/build.js +251 -3
- package/dist/cli/handlers/fan-out.js +55 -0
- package/dist/cli/handlers/graph.d.ts +14 -0
- package/dist/cli/handlers/graph.js +58 -3
- package/dist/cli/handlers/lifecycle-health.d.ts +7 -0
- package/dist/cli/handlers/lifecycle-health.js +47 -9
- package/dist/cli/handlers/lifecycle.js +4 -1
- package/dist/cli/handlers/notify-relay.d.ts +2 -2
- package/dist/cli/handlers/notify-relay.js +67 -7
- package/dist/cli/handlers/pipeline-agent.d.ts +30 -0
- package/dist/cli/handlers/pipeline-agent.js +255 -0
- package/dist/cli/handlers/pipeline-artifacts.d.ts +39 -0
- package/dist/cli/handlers/pipeline-artifacts.js +203 -0
- package/dist/cli/handlers/pipeline.d.ts +16 -0
- package/dist/cli/handlers/pipeline.js +112 -0
- package/dist/cli/handlers/pr-comment.js +4 -0
- package/dist/cli/handlers/pr-notes.js +4 -1
- package/dist/cli/handlers/pr.d.ts +20 -0
- package/dist/cli/handlers/pr.js +114 -11
- package/dist/cli/handlers/promote.js +792 -47
- package/dist/cli/handlers/reject.d.ts +84 -0
- package/dist/cli/handlers/reject.js +216 -0
- package/dist/cli/handlers/replan.d.ts +54 -0
- package/dist/cli/handlers/replan.js +177 -0
- package/dist/cli/handlers/run-generate.d.ts +5 -0
- package/dist/cli/handlers/run-generate.js +31 -4
- package/dist/cli/handlers/run-wave.js +15 -2
- package/dist/cli/handlers/run.js +4 -2
- package/dist/cli/handlers/stage.d.ts +35 -0
- package/dist/cli/handlers/stage.js +90 -0
- package/dist/cli/lsp/server.js +4 -0
- package/dist/cli/main.js +88 -8
- package/dist/cli/parse-args.js +35 -2
- package/dist/cli/registry.d.ts +12 -0
- package/dist/components/auto-release.d.ts +2 -0
- package/dist/components/auto-release.js +1 -0
- package/dist/components/capability.d.ts +40 -0
- package/dist/components/cli-support.d.ts +21 -1
- package/dist/components/cli-support.js +28 -6
- package/dist/components/component.d.ts +23 -4
- package/dist/components/component.schema.json +28 -0
- package/dist/components/declared-reads.d.ts +44 -4
- package/dist/components/declared-reads.js +80 -3
- package/dist/components/discover.d.ts +8 -0
- package/dist/components/discover.js +1 -1
- package/dist/components/driver.d.ts +13 -0
- package/dist/components/driver.js +23 -2
- package/dist/components/environment-sets.d.ts +229 -0
- package/dist/components/environment-sets.js +338 -0
- package/dist/components/fan-out-canary.d.ts +47 -0
- package/dist/components/fan-out-canary.js +58 -0
- package/dist/components/fan-out-run.d.ts +17 -0
- package/dist/components/fan-out-run.js +14 -1
- package/dist/components/fan-out-support.d.ts +7 -0
- package/dist/components/fan-out-support.js +1 -1
- package/dist/components/groups.d.ts +8 -1
- package/dist/components/groups.js +19 -1
- package/dist/components/index.d.ts +5 -2
- package/dist/components/index.js +4 -1
- package/dist/components/pr-cost.d.ts +28 -0
- package/dist/components/pr-cost.js +53 -0
- package/dist/components/pr-pipeline.d.ts +33 -0
- package/dist/components/pr-pipeline.js +32 -5
- package/dist/components/pr-policy.d.ts +33 -2
- package/dist/components/pr-policy.js +5 -2
- package/dist/components/pr-risk.d.ts +42 -0
- package/dist/components/pr-risk.js +74 -0
- package/dist/components/product-pipeline.d.ts +43 -0
- package/dist/components/product-pipeline.js +67 -1
- package/dist/components/promote.d.ts +6 -0
- package/dist/components/promote.js +13 -0
- package/dist/components/release-compile.js +3 -1
- package/dist/components/release-gate.d.ts +6 -1
- package/dist/components/release-gate.js +10 -2
- package/dist/components/step-environments.d.ts +236 -0
- package/dist/components/step-environments.js +392 -0
- package/dist/components/upstream-replan.d.ts +201 -0
- package/dist/components/upstream-replan.js +249 -0
- package/dist/components/verify-step.d.ts +30 -0
- package/dist/components/verify-step.js +27 -0
- package/dist/components/wave-plan.js +6 -2
- package/dist/config-environments.d.ts +4 -2
- package/dist/control/dispatch.d.ts +15 -0
- package/dist/control/dispatch.js +28 -4
- package/dist/cost-estimate.d.ts +188 -0
- package/dist/cost-estimate.js +363 -0
- package/dist/drift-record.d.ts +36 -0
- package/dist/drift-record.js +44 -0
- package/dist/engine-facts.d.ts +105 -0
- package/dist/engine-facts.js +111 -0
- package/dist/exit-codes.d.ts +4 -3
- package/dist/exit-codes.js +4 -3
- package/dist/flag-params.d.ts +2 -2
- package/dist/flag-params.js +9 -4
- package/dist/floor-table.data.js +53 -0
- package/dist/forge-token-vars.d.ts +12 -0
- package/dist/forge-token-vars.js +25 -0
- package/dist/gate-decision.d.ts +3 -1
- package/dist/gate-decision.js +3 -1
- package/dist/gated-waves.d.ts +2 -0
- package/dist/gated-waves.js +1 -0
- package/dist/graph-ir.d.ts +30 -0
- package/dist/graph-ir.js +33 -1
- package/dist/graph-refs.d.ts +26 -0
- package/dist/graph-refs.js +34 -3
- package/dist/graph-schema/graph.schema.json +136 -0
- package/dist/health.d.ts +65 -0
- package/dist/health.js +62 -0
- package/dist/lexicon.d.ts +188 -1
- package/dist/lifecycle/disruption.d.ts +14 -1
- package/dist/lifecycle/disruption.js +5 -1
- package/dist/lifecycle/gate-change-set.d.ts +8 -0
- package/dist/lifecycle/gate-change-set.js +2 -1
- package/dist/lifecycle/gate-ledger.d.ts +26 -0
- package/dist/lifecycle/gate-rejection.d.ts +82 -0
- package/dist/lifecycle/gate-rejection.js +93 -0
- package/dist/lifecycle/gate-seal.d.ts +3 -3
- package/dist/lifecycle/gate-seal.js +5 -5
- package/dist/lifecycle/observe.d.ts +17 -0
- package/dist/lifecycle/observe.js +10 -1
- package/dist/lifecycle/release-cut.js +4 -0
- package/dist/lifecycle/release-ledger.d.ts +8 -0
- package/dist/lifecycle/release-risk.d.ts +137 -0
- package/dist/lifecycle/release-risk.js +214 -0
- package/dist/lifecycle/release-store.d.ts +9 -0
- package/dist/lifecycle/release-store.js +4 -0
- package/dist/lifecycle/stage-log.d.ts +85 -0
- package/dist/lifecycle/stage-log.js +141 -0
- package/dist/lint/canary-checks.d.ts +31 -0
- package/dist/lint/canary-checks.js +45 -0
- package/dist/lint/rule.d.ts +1 -0
- package/dist/lint/rules/evl012-pipeline-fold.d.ts +14 -0
- package/dist/lint/rules/evl012-pipeline-fold.js +30 -0
- package/dist/lint/rules/index.d.ts +1 -0
- package/dist/lint/rules/index.js +3 -0
- package/dist/notify-relay-repo.d.ts +54 -0
- package/dist/notify-relay-repo.js +84 -0
- package/dist/notify-relay.d.ts +53 -3
- package/dist/notify-relay.js +96 -3
- package/dist/notify.d.ts +57 -1
- package/dist/notify.js +7 -1
- package/dist/notify.schema.json +61 -3
- package/dist/observation.d.ts +34 -0
- package/dist/observation.js +14 -1
- package/dist/op/activities/review-agent.d.ts +39 -2
- package/dist/op/activities/review-agent.js +88 -5
- package/dist/op/agent-permit.d.ts +88 -0
- package/dist/op/agent-permit.js +97 -0
- package/dist/op/gate-approval-base.d.ts +8 -0
- package/dist/op/gate-approval-base.js +9 -0
- package/dist/op/gate-approval.d.ts +30 -1
- package/dist/op/gate-approval.js +23 -2
- package/dist/op/gate-quorum.d.ts +114 -8
- package/dist/op/gate-quorum.js +198 -21
- package/dist/op/gate-reject.d.ts +79 -0
- package/dist/op/gate-reject.js +96 -0
- package/dist/op/gate-summary.js +1 -1
- package/dist/op/gate.d.ts +28 -3
- package/dist/op/gate.js +55 -13
- package/dist/op/generate-pipeline.d.ts +15 -1
- package/dist/op/generate-pipeline.js +32 -5
- package/dist/op/index.d.ts +11 -6
- package/dist/op/index.js +10 -5
- package/dist/op/local-executor.d.ts +2 -0
- package/dist/op/local-executor.js +23 -4
- package/dist/op/op-waves-after-plan.d.ts +23 -0
- package/dist/op/op-waves-after-plan.js +12 -1
- package/dist/op/op-waves-capability-spec.d.ts +14 -0
- package/dist/op/op-waves-capability-spec.js +46 -6
- package/dist/op/op-waves-capability.d.ts +21 -13
- package/dist/op/op-waves-capability.js +22 -59
- package/dist/op/op-waves-environment-sets.d.ts +41 -0
- package/dist/op/op-waves-environment-sets.js +82 -0
- package/dist/op/op-waves-quorum-warnings.d.ts +53 -0
- package/dist/op/op-waves-quorum-warnings.js +90 -0
- package/dist/op/op-waves-release-port.d.ts +7 -0
- package/dist/op/op-waves-release-port.js +15 -3
- package/dist/op/op-waves-release.d.ts +15 -0
- package/dist/op/op-waves-release.js +15 -0
- package/dist/op/op-waves-run.d.ts +37 -3
- package/dist/op/op-waves-run.js +141 -18
- package/dist/op/op-waves-soak.d.ts +57 -0
- package/dist/op/op-waves-soak.js +111 -0
- package/dist/op/op-waves-split.d.ts +4 -0
- package/dist/op/op-waves-split.js +4 -0
- package/dist/op/op-waves.d.ts +67 -4
- package/dist/op/op-waves.js +71 -3
- package/dist/pipeline/agent-ajv.d.ts +4 -0
- package/dist/pipeline/agent-ajv.js +14 -0
- package/dist/pipeline/agent-steps.d.ts +329 -0
- package/dist/pipeline/agent-steps.js +602 -0
- package/dist/pipeline/artifacts.d.ts +264 -0
- package/dist/pipeline/artifacts.js +425 -0
- package/dist/pipeline/diff.d.ts +45 -0
- package/dist/pipeline/diff.js +177 -0
- package/dist/pipeline/fold.d.ts +43 -0
- package/dist/pipeline/fold.js +140 -0
- package/dist/pipeline/generate.d.ts +52 -0
- package/dist/pipeline/generate.js +120 -0
- package/dist/pipeline/product.d.ts +225 -0
- package/dist/pipeline/product.js +257 -0
- package/dist/pipeline/promote.d.ts +404 -0
- package/dist/pipeline/promote.js +694 -0
- package/dist/pipeline/read.d.ts +37 -0
- package/dist/pipeline/read.js +58 -0
- package/dist/pipeline/rendered.d.ts +25 -0
- package/dist/pipeline/rendered.js +53 -0
- package/dist/pipeline/soak-checks.d.ts +80 -0
- package/dist/pipeline/soak-checks.js +254 -0
- package/dist/pipeline/soak-gate.d.ts +97 -0
- package/dist/pipeline/soak-gate.js +176 -0
- package/dist/pipeline/soak-sources.d.ts +17 -0
- package/dist/pipeline/soak-sources.js +42 -0
- package/dist/pipeline/soak.d.ts +260 -0
- package/dist/pipeline/soak.js +378 -0
- package/dist/pipeline/spec.d.ts +724 -0
- package/dist/pipeline/spec.js +567 -0
- package/dist/pipeline/stage-ledger.d.ts +187 -0
- package/dist/pipeline/stage-ledger.js +185 -0
- package/dist/pipeline/stage-waves.d.ts +114 -0
- package/dist/pipeline/stage-waves.js +161 -0
- package/dist/pipeline/stages.d.ts +64 -0
- package/dist/pipeline/stages.js +174 -0
- package/dist/pipeline/verify-rollback.d.ts +277 -0
- package/dist/pipeline/verify-rollback.js +393 -0
- package/dist/pipeline.d.ts +142 -0
- package/dist/pipeline.js +143 -0
- package/dist/pr-loop.d.ts +22 -0
- package/dist/pr-loop.js +8 -0
- package/dist/pr-plan-note.d.ts +15 -1
- package/dist/pr-plan-note.js +8 -0
- package/dist/pr-post.d.ts +31 -0
- package/dist/pr-post.js +89 -0
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/report-store/audit.schema.json +50 -0
- package/dist/report-store/dora.schema.json +331 -0
- package/dist/report-store/estate.schema.json +96 -0
- package/dist/report-store/run.schema.json +14 -0
- package/dist/report-store.d.ts +151 -0
- package/dist/report-store.js +344 -0
- package/dist/run-event.d.ts +7 -2
- package/dist/wave-runtime.mjs +458 -404
- package/dist/workspace/catalog-edges.js +3 -3
- package/dist/workspace/change-set.schema.json +4 -0
- package/dist/workspace/ci-cloud-identity.d.ts +4 -0
- package/dist/workspace/ci-cloud-identity.js +30 -0
- package/dist/workspace/ci-run.js +17 -2
- package/dist/workspace/ci-secrets.d.ts +3 -1
- package/dist/workspace/ci-secrets.js +7 -1
- package/dist/workspace/compose-graph.d.ts +1 -1
- package/dist/workspace/compose-graph.js +3 -1
- package/dist/workspace/declaration.d.ts +27 -0
- package/dist/workspace/declaration.js +35 -0
- package/dist/workspace/declaration.schema.json +56 -0
- package/dist/workspace/graph-cli.js +26 -0
- package/dist/workspace/graph.schema.json +5 -1
- package/dist/workspace/identity-gate-rule.d.ts +4 -0
- package/dist/workspace/identity-gate-rule.js +2 -2
- package/dist/workspace/identity-reject-rule.d.ts +14 -0
- package/dist/workspace/identity-reject-rule.js +24 -0
- package/dist/workspace/identity.d.ts +3 -0
- package/dist/workspace/identity.js +2 -1
- package/dist/workspace/nested-graph.js +2 -0
- package/dist/workspace/pr-report.schema.json +65 -0
- package/dist/workspace/promotion-order.d.ts +19 -4
- package/dist/workspace/promotion-order.js +26 -4
- package/dist/workspace/release-train.d.ts +14 -0
- package/dist/workspace/release-train.js +32 -0
- package/dist/workspace/run-event.schema.json +2 -2
- package/dist/workspace/stack-read-edges.d.ts +19 -0
- package/dist/workspace/stack-read-edges.js +54 -0
- package/dist/workspace/status-gates.d.ts +51 -1
- package/dist/workspace/status-gates.js +60 -0
- package/dist/workspace/status-stages.d.ts +223 -0
- package/dist/workspace/status-stages.js +279 -0
- package/dist/workspace/status.d.ts +45 -1
- package/dist/workspace/status.js +109 -5
- package/dist/workspace/status.schema.json +283 -2
- package/dist/workspace/trust/seal.d.ts +7 -0
- package/dist/workspace/trust/seal.js +9 -0
- package/package.json +5 -1
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config and secret sets per environment (#5348): one declared set per
|
|
3
|
+
* environment, which the jobs of that environment's stage receive.
|
|
4
|
+
*
|
|
5
|
+
* A stage applies the same code in each environment with that
|
|
6
|
+
* environment's config and secrets. The declaration keys a set by
|
|
7
|
+
* environment name, as a step's `environments` map is keyed (#5360,
|
|
8
|
+
* ./step-environments.ts), and shared sets sit beside them under
|
|
9
|
+
* `configSets`:
|
|
10
|
+
*
|
|
11
|
+
* {
|
|
12
|
+
* configSets: {
|
|
13
|
+
* common: { config: { LOG_LEVEL: "info" } },
|
|
14
|
+
* },
|
|
15
|
+
* environments: {
|
|
16
|
+
* staging: {
|
|
17
|
+
* imports: ["common"],
|
|
18
|
+
* config: { REGION: "us-east-2" },
|
|
19
|
+
* secrets: {
|
|
20
|
+
* DB_PASSWORD: "STAGING_DB_PASSWORD",
|
|
21
|
+
* API_KEY: { awsSecretsManager: "arn:aws:secretsmanager:us-east-2:111111111111:secret:staging/api", jsonKey: "key" },
|
|
22
|
+
* },
|
|
23
|
+
* },
|
|
24
|
+
* prod: { imports: ["common"], config: { REGION: "us-east-1" }, secrets: { DB_PASSWORD: "PROD_DB_PASSWORD" } },
|
|
25
|
+
* },
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* `config` holds plain values. `secrets` holds where each secret is kept,
|
|
29
|
+
* never the secret: a forge secret's name (a string, or `{ forgeSecret }`),
|
|
30
|
+
* an AWS Secrets Manager secret, a Google Secret Manager version or an
|
|
31
|
+
* Azure Key Vault secret. A job reads a store's secret with the cloud
|
|
32
|
+
* identity it logged in as, the one `ci.identity` gives that stage
|
|
33
|
+
* (../ci-identity.ts, ../ci-login.ts), so a staging job can read only what
|
|
34
|
+
* the staging identity may.
|
|
35
|
+
*
|
|
36
|
+
* {@link resolveEnvironmentSet} picks the environment's entry with
|
|
37
|
+
* `environmentEntryName`, the lookup a step's `environments` uses: the
|
|
38
|
+
* environment's own entry, or for a pull request environment `pr-<n>` its
|
|
39
|
+
* template's. An environment the sets do not name is refused, naming the
|
|
40
|
+
* ones they do. A set's `imports` name shared sets, applied in order, and
|
|
41
|
+
* the set's own values then replace theirs. An environment's set imports
|
|
42
|
+
* shared sets alone, never another environment's, so one stage's set never
|
|
43
|
+
* carries another stage's secrets. Each value keeps the set it came from
|
|
44
|
+
* and the imports that led there.
|
|
45
|
+
*
|
|
46
|
+
* {@link environmentSetJobInputs} is what a generator hands a stage's jobs:
|
|
47
|
+
* the config as variables, the forge secrets as passed secrets, the lines
|
|
48
|
+
* that read the store secrets after the login, and {@link ENV_SET_ENV}, the
|
|
49
|
+
* set's record of names and sources, which holds no secret. `chant ci run`
|
|
50
|
+
* reads the record and redacts each secret variable's value from the run's
|
|
51
|
+
* events, record and report, whatever its name (../workspace/ci-secrets.ts).
|
|
52
|
+
*
|
|
53
|
+
* This module imports only the step environments and the release floors at
|
|
54
|
+
* run time.
|
|
55
|
+
*/
|
|
56
|
+
import { type StepEnvironmentOptions } from "./step-environments.js";
|
|
57
|
+
/**
|
|
58
|
+
* The first chant with config and secret sets per environment (#5348):
|
|
59
|
+
* `resolveEnvironmentSet`, `environmentSetJobInputs`, `environmentSets` on
|
|
60
|
+
* the Op waves generators, the pipeline's generator and the pull request
|
|
61
|
+
* loop, which hand each stage's jobs the set of their environment,
|
|
62
|
+
* `ci.environmentSets` in the workspace declaration, each stage's own
|
|
63
|
+
* identity on a pipeline's promote jobs, and `chant ci run`'s redaction of
|
|
64
|
+
* each secret the set names.
|
|
65
|
+
*/
|
|
66
|
+
export declare const ENVIRONMENT_SETS_FLOOR = "0.124.110";
|
|
67
|
+
/** The job variable holding the set's record (#5348), as JSON: names and sources, never a secret. */
|
|
68
|
+
export declare const ENV_SET_ENV = "CHANT_ENV_SET";
|
|
69
|
+
/** The variable the store read takes its list from, as JSON: names and where each is kept. */
|
|
70
|
+
export declare const ENV_SET_FETCH_ENV = "CHANT_ENV_SET_FETCH";
|
|
71
|
+
/** The schema of {@link EnvironmentSetRecord}. */
|
|
72
|
+
export declare const ENV_SET_SCHEMA = "chant.environment-set/v1";
|
|
73
|
+
/**
|
|
74
|
+
* Where one secret is kept. A string is a forge secret's name (a GitLab
|
|
75
|
+
* CI/CD variable's on GitLab).
|
|
76
|
+
*/
|
|
77
|
+
export type EnvironmentSecretRef = string | {
|
|
78
|
+
forgeSecret: string;
|
|
79
|
+
}
|
|
80
|
+
/** A Secrets Manager secret's ARN or name; `jsonKey` picks one key of a JSON secret. Default region: the job's. */
|
|
81
|
+
| {
|
|
82
|
+
awsSecretsManager: string;
|
|
83
|
+
jsonKey?: string;
|
|
84
|
+
region?: string;
|
|
85
|
+
}
|
|
86
|
+
/** `projects/<project>/secrets/<secret>`, with `/versions/<version>` or the latest. */
|
|
87
|
+
| {
|
|
88
|
+
gcpSecretManager: string;
|
|
89
|
+
}
|
|
90
|
+
/** The secret's URL, `https://<vault>.vault.azure.net/secrets/<name>`, with `/<version>` or the latest. */
|
|
91
|
+
| {
|
|
92
|
+
azureKeyVault: string;
|
|
93
|
+
};
|
|
94
|
+
/** One set: the shared sets it imports, its plain values and its secrets. */
|
|
95
|
+
export interface EnvironmentSet {
|
|
96
|
+
/** Shared sets (`configSets` keys) applied first, in order; this set's own values replace theirs. */
|
|
97
|
+
imports?: string[];
|
|
98
|
+
/** Plain values, by variable name. */
|
|
99
|
+
config?: Record<string, string>;
|
|
100
|
+
/** Secrets, by variable name: where each is kept. */
|
|
101
|
+
secrets?: Record<string, EnvironmentSecretRef>;
|
|
102
|
+
}
|
|
103
|
+
/** Every set: one per environment, and the shared ones they import. */
|
|
104
|
+
export interface EnvironmentSets {
|
|
105
|
+
/** One set per environment, keyed by environment name (product key `environments.<name>`). */
|
|
106
|
+
environments: Record<string, EnvironmentSet>;
|
|
107
|
+
/** Shared sets, keyed by name (product key `config_sets.<set>`). */
|
|
108
|
+
configSets?: Record<string, EnvironmentSet>;
|
|
109
|
+
}
|
|
110
|
+
/** Where a resolved secret is kept. */
|
|
111
|
+
export type EnvironmentSecretSource = {
|
|
112
|
+
store: "forge";
|
|
113
|
+
secret: string;
|
|
114
|
+
} | {
|
|
115
|
+
store: "aws-secrets-manager";
|
|
116
|
+
id: string;
|
|
117
|
+
jsonKey?: string;
|
|
118
|
+
region?: string;
|
|
119
|
+
} | {
|
|
120
|
+
store: "gcp-secret-manager";
|
|
121
|
+
name: string;
|
|
122
|
+
} | {
|
|
123
|
+
store: "azure-key-vault";
|
|
124
|
+
id: string;
|
|
125
|
+
};
|
|
126
|
+
/** What every resolved value records of where it came from. */
|
|
127
|
+
export interface EnvironmentSetOrigin {
|
|
128
|
+
/** The variable. */
|
|
129
|
+
name: string;
|
|
130
|
+
/** The set that gives the value: the environment's entry, or a `configSets` key. */
|
|
131
|
+
from: string;
|
|
132
|
+
/** The sets from the environment's entry to `from`, first to last; `[from]` when the entry gives it. */
|
|
133
|
+
via: string[];
|
|
134
|
+
}
|
|
135
|
+
export interface EnvironmentConfigValue extends EnvironmentSetOrigin {
|
|
136
|
+
kind: "config";
|
|
137
|
+
value: string;
|
|
138
|
+
}
|
|
139
|
+
export interface EnvironmentSecretValue extends EnvironmentSetOrigin {
|
|
140
|
+
kind: "secret";
|
|
141
|
+
source: EnvironmentSecretSource;
|
|
142
|
+
}
|
|
143
|
+
/** One environment's set, resolved: every value once, in name order. */
|
|
144
|
+
export interface ResolvedEnvironmentSet {
|
|
145
|
+
/** The environment the set was resolved for. */
|
|
146
|
+
env: string;
|
|
147
|
+
/** The `environments` entry it took: `env`, or a pull request environment's template. */
|
|
148
|
+
entry: string;
|
|
149
|
+
config: EnvironmentConfigValue[];
|
|
150
|
+
secrets: EnvironmentSecretValue[];
|
|
151
|
+
}
|
|
152
|
+
/** The set's record (#5348): each variable, its kind and where it came from. A secret's value is never in it. */
|
|
153
|
+
export interface EnvironmentSetRecord {
|
|
154
|
+
schema: typeof ENV_SET_SCHEMA;
|
|
155
|
+
env: string;
|
|
156
|
+
entry: string;
|
|
157
|
+
values: Array<EnvironmentSetOrigin & ({
|
|
158
|
+
kind: "config";
|
|
159
|
+
value: string;
|
|
160
|
+
} | {
|
|
161
|
+
kind: "secret";
|
|
162
|
+
source: EnvironmentSecretSource;
|
|
163
|
+
})>;
|
|
164
|
+
}
|
|
165
|
+
export declare class EnvironmentSetError extends Error {
|
|
166
|
+
constructor(message: string);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Where `ref` is kept, or why it names no store: a sentence that follows
|
|
170
|
+
* the secret's name. A release artifact's secret (#5356) is checked here too.
|
|
171
|
+
*/
|
|
172
|
+
export declare function environmentSecretSource(ref: unknown): EnvironmentSecretSource | string;
|
|
173
|
+
/** Every problem of `sets`: shapes, names, references and imports, cycles included. Empty when the sets resolve. */
|
|
174
|
+
export declare function environmentSetsProblems(sets: EnvironmentSets): string[];
|
|
175
|
+
/**
|
|
176
|
+
* `env`'s set, resolved: its entry's imports in order, each with its own
|
|
177
|
+
* imports first, then the entry's own values, a later value replacing an
|
|
178
|
+
* earlier one of the same name. Each value records the set it came from and
|
|
179
|
+
* the imports that led there. Throws an {@link EnvironmentSetError} when
|
|
180
|
+
* the sets have a problem or do not name `env` (nor, for `pr-<n>`, its
|
|
181
|
+
* template), naming the environments they do.
|
|
182
|
+
*/
|
|
183
|
+
export declare function resolveEnvironmentSet(sets: EnvironmentSets, env: string, options?: StepEnvironmentOptions): ResolvedEnvironmentSet;
|
|
184
|
+
/** The set's record: every variable with its kind and origin, a config value with its value, a secret with where it is kept. */
|
|
185
|
+
export declare function environmentSetRecord(set: ResolvedEnvironmentSet): EnvironmentSetRecord;
|
|
186
|
+
/**
|
|
187
|
+
* The secret variables the set in `env` names, from its record in
|
|
188
|
+
* {@link ENV_SET_ENV}. Empty when the variable is absent or not a record.
|
|
189
|
+
* `chant ci run` redacts each one's value, whatever its name.
|
|
190
|
+
*/
|
|
191
|
+
export declare function environmentSetSecretNames(env: Record<string, string | undefined>): string[];
|
|
192
|
+
/** The forges a stage's jobs are rendered for. */
|
|
193
|
+
export type EnvironmentSetForge = "github" | "gitlab" | "forgejo";
|
|
194
|
+
/** What a generator hands one stage's jobs (#5348). */
|
|
195
|
+
export interface EnvironmentSetJobInputs {
|
|
196
|
+
/** The config values and {@link ENV_SET_ENV}, by variable name, as the pull request loop's `variables` take them. */
|
|
197
|
+
variables: Record<string, string>;
|
|
198
|
+
/** The forge secrets, as `{ <variable>: <secret> }`, as the pull request loop's `secrets` take them. Empty with `secrets: false`. */
|
|
199
|
+
secrets: Record<string, string>;
|
|
200
|
+
/**
|
|
201
|
+
* Shell lines that read the store secrets and export them, run in the
|
|
202
|
+
* step of the job's command after the job logged in. Empty when the set
|
|
203
|
+
* keeps no secret in a store, or with `secrets: false`.
|
|
204
|
+
*/
|
|
205
|
+
setup: string[];
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The store read, a script for `node -e` with no dependency. argv 1 is the
|
|
209
|
+
* forge: on `github` and `forgejo` it also prints a `::add-mask::` line
|
|
210
|
+
* per line of each value, which the runner takes and never shows. It
|
|
211
|
+
* prints `export` lines for the shell to evaluate, and never a value on its
|
|
212
|
+
* own. A failed read names the variable and where it is kept.
|
|
213
|
+
*/
|
|
214
|
+
export declare const ENV_SET_FETCH_JS: string;
|
|
215
|
+
/**
|
|
216
|
+
* The shell lines that read the store secrets of `set` and export them in
|
|
217
|
+
* the shell that runs them, then unset what held them. An assignment's
|
|
218
|
+
* status is its command substitution's, so a failed read stops the job.
|
|
219
|
+
*/
|
|
220
|
+
export declare function environmentSetFetchLines(set: ResolvedEnvironmentSet, forge: EnvironmentSetForge): string[];
|
|
221
|
+
/**
|
|
222
|
+
* What a generator hands the jobs of `set`'s stage: the config as
|
|
223
|
+
* variables, the forge secrets as passed secrets, the store read as setup
|
|
224
|
+
* lines, and the record as {@link ENV_SET_ENV}. With `secrets: false`, for
|
|
225
|
+
* a job that runs a pull request's code, the config and the record alone.
|
|
226
|
+
*/
|
|
227
|
+
export declare function environmentSetJobInputs(set: ResolvedEnvironmentSet, forge: EnvironmentSetForge, options?: {
|
|
228
|
+
secrets?: boolean;
|
|
229
|
+
}): EnvironmentSetJobInputs;
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config and secret sets per environment (#5348): one declared set per
|
|
3
|
+
* environment, which the jobs of that environment's stage receive.
|
|
4
|
+
*
|
|
5
|
+
* A stage applies the same code in each environment with that
|
|
6
|
+
* environment's config and secrets. The declaration keys a set by
|
|
7
|
+
* environment name, as a step's `environments` map is keyed (#5360,
|
|
8
|
+
* ./step-environments.ts), and shared sets sit beside them under
|
|
9
|
+
* `configSets`:
|
|
10
|
+
*
|
|
11
|
+
* {
|
|
12
|
+
* configSets: {
|
|
13
|
+
* common: { config: { LOG_LEVEL: "info" } },
|
|
14
|
+
* },
|
|
15
|
+
* environments: {
|
|
16
|
+
* staging: {
|
|
17
|
+
* imports: ["common"],
|
|
18
|
+
* config: { REGION: "us-east-2" },
|
|
19
|
+
* secrets: {
|
|
20
|
+
* DB_PASSWORD: "STAGING_DB_PASSWORD",
|
|
21
|
+
* API_KEY: { awsSecretsManager: "arn:aws:secretsmanager:us-east-2:111111111111:secret:staging/api", jsonKey: "key" },
|
|
22
|
+
* },
|
|
23
|
+
* },
|
|
24
|
+
* prod: { imports: ["common"], config: { REGION: "us-east-1" }, secrets: { DB_PASSWORD: "PROD_DB_PASSWORD" } },
|
|
25
|
+
* },
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* `config` holds plain values. `secrets` holds where each secret is kept,
|
|
29
|
+
* never the secret: a forge secret's name (a string, or `{ forgeSecret }`),
|
|
30
|
+
* an AWS Secrets Manager secret, a Google Secret Manager version or an
|
|
31
|
+
* Azure Key Vault secret. A job reads a store's secret with the cloud
|
|
32
|
+
* identity it logged in as, the one `ci.identity` gives that stage
|
|
33
|
+
* (../ci-identity.ts, ../ci-login.ts), so a staging job can read only what
|
|
34
|
+
* the staging identity may.
|
|
35
|
+
*
|
|
36
|
+
* {@link resolveEnvironmentSet} picks the environment's entry with
|
|
37
|
+
* `environmentEntryName`, the lookup a step's `environments` uses: the
|
|
38
|
+
* environment's own entry, or for a pull request environment `pr-<n>` its
|
|
39
|
+
* template's. An environment the sets do not name is refused, naming the
|
|
40
|
+
* ones they do. A set's `imports` name shared sets, applied in order, and
|
|
41
|
+
* the set's own values then replace theirs. An environment's set imports
|
|
42
|
+
* shared sets alone, never another environment's, so one stage's set never
|
|
43
|
+
* carries another stage's secrets. Each value keeps the set it came from
|
|
44
|
+
* and the imports that led there.
|
|
45
|
+
*
|
|
46
|
+
* {@link environmentSetJobInputs} is what a generator hands a stage's jobs:
|
|
47
|
+
* the config as variables, the forge secrets as passed secrets, the lines
|
|
48
|
+
* that read the store secrets after the login, and {@link ENV_SET_ENV}, the
|
|
49
|
+
* set's record of names and sources, which holds no secret. `chant ci run`
|
|
50
|
+
* reads the record and redacts each secret variable's value from the run's
|
|
51
|
+
* events, record and report, whatever its name (../workspace/ci-secrets.ts).
|
|
52
|
+
*
|
|
53
|
+
* This module imports only the step environments and the release floors at
|
|
54
|
+
* run time.
|
|
55
|
+
*/
|
|
56
|
+
import { environmentEntryName } from "./step-environments.js";
|
|
57
|
+
/**
|
|
58
|
+
* The first chant with config and secret sets per environment (#5348):
|
|
59
|
+
* `resolveEnvironmentSet`, `environmentSetJobInputs`, `environmentSets` on
|
|
60
|
+
* the Op waves generators, the pipeline's generator and the pull request
|
|
61
|
+
* loop, which hand each stage's jobs the set of their environment,
|
|
62
|
+
* `ci.environmentSets` in the workspace declaration, each stage's own
|
|
63
|
+
* identity on a pipeline's promote jobs, and `chant ci run`'s redaction of
|
|
64
|
+
* each secret the set names.
|
|
65
|
+
*/
|
|
66
|
+
export const ENVIRONMENT_SETS_FLOOR = "0.124.110";
|
|
67
|
+
/** The job variable holding the set's record (#5348), as JSON: names and sources, never a secret. */
|
|
68
|
+
export const ENV_SET_ENV = "CHANT_ENV_SET";
|
|
69
|
+
/** The variable the store read takes its list from, as JSON: names and where each is kept. */
|
|
70
|
+
export const ENV_SET_FETCH_ENV = "CHANT_ENV_SET_FETCH";
|
|
71
|
+
/** The shell variable the store read's `export` lines sit in until the shell evaluates them. Not exported. */
|
|
72
|
+
const ENV_SET_VARS = "CHANT_ENV_SET_VARS";
|
|
73
|
+
/** The schema of {@link EnvironmentSetRecord}. */
|
|
74
|
+
export const ENV_SET_SCHEMA = "chant.environment-set/v1";
|
|
75
|
+
export class EnvironmentSetError extends Error {
|
|
76
|
+
constructor(message) {
|
|
77
|
+
super(message);
|
|
78
|
+
this.name = "EnvironmentSetError";
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
82
|
+
const SET_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
83
|
+
const GCP_SECRET = /^projects\/[^/\s]+\/secrets\/[^/\s]+(\/versions\/[^/\s]+)?$/;
|
|
84
|
+
const AZURE_SECRET = /^https:\/\/[^/\s]+\/secrets\/[^/\s]+(\/[^/\s]+)?$/;
|
|
85
|
+
const isMap = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
86
|
+
/** The variable names a set refuses: chant's own, which the jobs set themselves. */
|
|
87
|
+
const isReserved = (name) => name.startsWith("CHANT_");
|
|
88
|
+
/**
|
|
89
|
+
* Where `ref` is kept, or why it names no store: a sentence that follows
|
|
90
|
+
* the secret's name. A release artifact's secret (#5356) is checked here too.
|
|
91
|
+
*/
|
|
92
|
+
export function environmentSecretSource(ref) {
|
|
93
|
+
return sourceOf(ref);
|
|
94
|
+
}
|
|
95
|
+
/** Where `ref` is kept, or why it names no store. */
|
|
96
|
+
function sourceOf(ref) {
|
|
97
|
+
if (typeof ref === "string")
|
|
98
|
+
return NAME.test(ref) ? { store: "forge", secret: ref } : `names the forge secret ${JSON.stringify(ref)}, which is not a secret name`;
|
|
99
|
+
if (!isMap(ref))
|
|
100
|
+
return "takes a forge secret's name, or a map naming where the secret is kept";
|
|
101
|
+
const stores = ["forgeSecret", "awsSecretsManager", "gcpSecretManager", "azureKeyVault"].filter((k) => k in ref);
|
|
102
|
+
if (stores.length !== 1)
|
|
103
|
+
return "names one of forgeSecret, awsSecretsManager, gcpSecretManager and azureKeyVault";
|
|
104
|
+
const extra = Object.keys(ref).filter((k) => k !== stores[0] && !(stores[0] === "awsSecretsManager" && (k === "jsonKey" || k === "region")));
|
|
105
|
+
if (extra.length > 0)
|
|
106
|
+
return `sets ${extra.join(", ")} beside ${stores[0]}`;
|
|
107
|
+
const at = ref[stores[0]];
|
|
108
|
+
if (typeof at !== "string" || at.trim() === "")
|
|
109
|
+
return `sets ${stores[0]} to something other than a name`;
|
|
110
|
+
switch (stores[0]) {
|
|
111
|
+
case "forgeSecret":
|
|
112
|
+
return NAME.test(at) ? { store: "forge", secret: at } : `names the forge secret ${JSON.stringify(at)}, which is not a secret name`;
|
|
113
|
+
case "awsSecretsManager": {
|
|
114
|
+
if (/\s/.test(at))
|
|
115
|
+
return `names the Secrets Manager secret ${JSON.stringify(at)}, with a space in it`;
|
|
116
|
+
if (ref.jsonKey !== undefined && (typeof ref.jsonKey !== "string" || ref.jsonKey === ""))
|
|
117
|
+
return "sets jsonKey to something other than a key";
|
|
118
|
+
if (ref.region !== undefined && (typeof ref.region !== "string" || !/^[a-z0-9-]+$/.test(ref.region)))
|
|
119
|
+
return "sets region to something other than a region";
|
|
120
|
+
return { store: "aws-secrets-manager", id: at, ...(ref.jsonKey !== undefined ? { jsonKey: ref.jsonKey } : {}), ...(ref.region !== undefined ? { region: ref.region } : {}) };
|
|
121
|
+
}
|
|
122
|
+
case "gcpSecretManager":
|
|
123
|
+
return GCP_SECRET.test(at) ? { store: "gcp-secret-manager", name: at } : `names ${JSON.stringify(at)}, where it takes projects/<project>/secrets/<secret>, with /versions/<version> or the latest`;
|
|
124
|
+
default:
|
|
125
|
+
return AZURE_SECRET.test(at) ? { store: "azure-key-vault", id: at } : `names ${JSON.stringify(at)}, where it takes the secret's URL, https://<vault>.vault.azure.net/secrets/<name>`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** Every problem of one set, each a sentence about `where`. */
|
|
129
|
+
function setProblems(where, set, sets) {
|
|
130
|
+
if (!isMap(set))
|
|
131
|
+
return [`${where} is a map of imports, config and secrets`];
|
|
132
|
+
const out = [];
|
|
133
|
+
for (const key of Object.keys(set))
|
|
134
|
+
if (!["imports", "config", "secrets"].includes(key))
|
|
135
|
+
out.push(`${where} sets ${key}, where a set takes imports, config and secrets`);
|
|
136
|
+
if (set.imports !== undefined) {
|
|
137
|
+
if (!Array.isArray(set.imports) || set.imports.some((i) => typeof i !== "string"))
|
|
138
|
+
out.push(`${where}'s imports is a list of shared set names`);
|
|
139
|
+
else
|
|
140
|
+
for (const name of set.imports) {
|
|
141
|
+
if (Object.prototype.hasOwnProperty.call(sets.configSets ?? {}, name))
|
|
142
|
+
continue;
|
|
143
|
+
out.push(Object.prototype.hasOwnProperty.call(sets.environments, name)
|
|
144
|
+
? `${where} imports ${name}, an environment's set; a set imports shared sets (configSets) alone, so one stage never holds another's values`
|
|
145
|
+
: `${where} imports ${name}, which configSets does not declare`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const names = new Set();
|
|
149
|
+
for (const part of ["config", "secrets"]) {
|
|
150
|
+
const map = set[part];
|
|
151
|
+
if (map === undefined)
|
|
152
|
+
continue;
|
|
153
|
+
if (!isMap(map)) {
|
|
154
|
+
out.push(`${where}'s ${part} is a map of variable name to ${part === "config" ? "value" : "where the secret is kept"}`);
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
for (const [name, value] of Object.entries(map)) {
|
|
158
|
+
if (!NAME.test(name))
|
|
159
|
+
out.push(`${where}'s ${part} names ${JSON.stringify(name)}, which is not a variable name`);
|
|
160
|
+
else if (isReserved(name))
|
|
161
|
+
out.push(`${where}'s ${part} names ${name}; a variable starting CHANT_ is one chant's jobs set themselves`);
|
|
162
|
+
if (names.has(name))
|
|
163
|
+
out.push(`${where} sets ${name} in both config and secrets; give it once`);
|
|
164
|
+
names.add(name);
|
|
165
|
+
if (part === "config" && typeof value !== "string")
|
|
166
|
+
out.push(`${where}'s config sets ${name} to something other than a string`);
|
|
167
|
+
if (part === "secrets") {
|
|
168
|
+
const source = sourceOf(value);
|
|
169
|
+
if (typeof source === "string")
|
|
170
|
+
out.push(`${where}'s secret ${name} ${source}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
/** Every problem of `sets`: shapes, names, references and imports, cycles included. Empty when the sets resolve. */
|
|
177
|
+
export function environmentSetsProblems(sets) {
|
|
178
|
+
if (!isMap(sets) || !isMap(sets.environments))
|
|
179
|
+
return ["the sets take environments, a map of environment name to its set"];
|
|
180
|
+
if (sets.configSets !== undefined && !isMap(sets.configSets))
|
|
181
|
+
return ["configSets is a map of shared set name to its set"];
|
|
182
|
+
const out = [];
|
|
183
|
+
for (const [name, set] of Object.entries(sets.configSets ?? {})) {
|
|
184
|
+
if (!SET_NAME.test(name))
|
|
185
|
+
out.push(`the shared set ${JSON.stringify(name)} needs a name of letters, digits, '.', '_' and '-'`);
|
|
186
|
+
out.push(...setProblems(`the shared set ${name}`, set, sets));
|
|
187
|
+
}
|
|
188
|
+
for (const [env, set] of Object.entries(sets.environments))
|
|
189
|
+
out.push(...setProblems(`the set of ${env}`, set, sets));
|
|
190
|
+
if (out.length > 0)
|
|
191
|
+
return out;
|
|
192
|
+
// A cycle of imports among the shared sets.
|
|
193
|
+
const state = new Map();
|
|
194
|
+
const visit = (name, path) => {
|
|
195
|
+
if (state.get(name) === "done")
|
|
196
|
+
return;
|
|
197
|
+
if (state.get(name) === "open") {
|
|
198
|
+
out.push(`the shared sets import each other: ${[...path.slice(path.indexOf(name)), name].join(" -> ")}`);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
state.set(name, "open");
|
|
202
|
+
for (const next of sets.configSets?.[name]?.imports ?? [])
|
|
203
|
+
visit(next, [...path, name]);
|
|
204
|
+
state.set(name, "done");
|
|
205
|
+
};
|
|
206
|
+
for (const name of Object.keys(sets.configSets ?? {}))
|
|
207
|
+
visit(name, []);
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* `env`'s set, resolved: its entry's imports in order, each with its own
|
|
212
|
+
* imports first, then the entry's own values, a later value replacing an
|
|
213
|
+
* earlier one of the same name. Each value records the set it came from and
|
|
214
|
+
* the imports that led there. Throws an {@link EnvironmentSetError} when
|
|
215
|
+
* the sets have a problem or do not name `env` (nor, for `pr-<n>`, its
|
|
216
|
+
* template), naming the environments they do.
|
|
217
|
+
*/
|
|
218
|
+
export function resolveEnvironmentSet(sets, env, options = {}) {
|
|
219
|
+
const problems = environmentSetsProblems(sets);
|
|
220
|
+
if (problems.length > 0)
|
|
221
|
+
throw new EnvironmentSetError(problems.join("\n"));
|
|
222
|
+
const entry = environmentEntryName(sets.environments, env, options);
|
|
223
|
+
if (entry === undefined) {
|
|
224
|
+
throw new EnvironmentSetError(`the config and secret sets name ${Object.keys(sets.environments).join(", ") || "no environment"}, and not ${env}`);
|
|
225
|
+
}
|
|
226
|
+
const values = new Map();
|
|
227
|
+
const apply = (set, from, via) => {
|
|
228
|
+
for (const name of set.imports ?? [])
|
|
229
|
+
apply(sets.configSets[name], name, [...via, name]);
|
|
230
|
+
for (const [name, value] of Object.entries(set.config ?? {}))
|
|
231
|
+
values.set(name, { kind: "config", name, value, from, via });
|
|
232
|
+
for (const [name, ref] of Object.entries(set.secrets ?? {}))
|
|
233
|
+
values.set(name, { kind: "secret", name, source: sourceOf(ref), from, via });
|
|
234
|
+
};
|
|
235
|
+
apply(sets.environments[entry], entry, [entry]);
|
|
236
|
+
const sorted = [...values.values()].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
237
|
+
return {
|
|
238
|
+
env,
|
|
239
|
+
entry,
|
|
240
|
+
config: sorted.filter((v) => v.kind === "config"),
|
|
241
|
+
secrets: sorted.filter((v) => v.kind === "secret"),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/** The set's record: every variable with its kind and origin, a config value with its value, a secret with where it is kept. */
|
|
245
|
+
export function environmentSetRecord(set) {
|
|
246
|
+
const values = [...set.config, ...set.secrets]
|
|
247
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
248
|
+
.map((v) => (v.kind === "config" ? { name: v.name, kind: v.kind, value: v.value, from: v.from, via: v.via } : { name: v.name, kind: v.kind, source: v.source, from: v.from, via: v.via }));
|
|
249
|
+
return { schema: ENV_SET_SCHEMA, env: set.env, entry: set.entry, values };
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* The secret variables the set in `env` names, from its record in
|
|
253
|
+
* {@link ENV_SET_ENV}. Empty when the variable is absent or not a record.
|
|
254
|
+
* `chant ci run` redacts each one's value, whatever its name.
|
|
255
|
+
*/
|
|
256
|
+
export function environmentSetSecretNames(env) {
|
|
257
|
+
const text = env[ENV_SET_ENV];
|
|
258
|
+
if (!text)
|
|
259
|
+
return [];
|
|
260
|
+
try {
|
|
261
|
+
const record = JSON.parse(text);
|
|
262
|
+
if (record.schema !== ENV_SET_SCHEMA || !Array.isArray(record.values))
|
|
263
|
+
return [];
|
|
264
|
+
return record.values.filter((v) => v && v.kind === "secret" && typeof v.name === "string" && NAME.test(v.name)).map((v) => v.name);
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* The store read, a script for `node -e` with no dependency. argv 1 is the
|
|
272
|
+
* forge: on `github` and `forgejo` it also prints a `::add-mask::` line
|
|
273
|
+
* per line of each value, which the runner takes and never shows. It
|
|
274
|
+
* prints `export` lines for the shell to evaluate, and never a value on its
|
|
275
|
+
* own. A failed read names the variable and where it is kept.
|
|
276
|
+
*/
|
|
277
|
+
export const ENV_SET_FETCH_JS = [
|
|
278
|
+
'const cp=require("child_process");',
|
|
279
|
+
"const forge=process.argv[1];",
|
|
280
|
+
"const Q=String.fromCharCode(39);",
|
|
281
|
+
'const q=(v)=>Q+String(v).split(Q).join(Q+"\\\\"+Q+Q)+Q;',
|
|
282
|
+
'const fail=(m)=>{console.error("chant: the environment set\\u0027s secrets could not be read: "+m);process.exit(1)};',
|
|
283
|
+
`let list;try{list=JSON.parse(process.env.${ENV_SET_FETCH_ENV}||"")}catch{fail("${ENV_SET_FETCH_ENV} is not JSON")}`,
|
|
284
|
+
'if(!Array.isArray(list))fail("' + ENV_SET_FETCH_ENV + ' is not a list");',
|
|
285
|
+
'const call=(at,cmd,args)=>{const r=cp.spawnSync(cmd,args,{encoding:"utf8",stdio:["ignore","pipe","pipe"],maxBuffer:1<<26});',
|
|
286
|
+
'if(r.error)fail(at+": "+cmd+" could not run: "+r.error.message);',
|
|
287
|
+
'if(r.status!==0)fail(at+": "+cmd+" exited "+r.status+(r.stderr&&r.stderr.trim()?": "+r.stderr.trim().split("\\n").pop():""));',
|
|
288
|
+
"return r.stdout};",
|
|
289
|
+
'const chomp=(v)=>v.endsWith("\\r\\n")?v.slice(0,-2):v.endsWith("\\n")?v.slice(0,-1):v;',
|
|
290
|
+
'const read=(e)=>{const s=e.source,at=e.name+" ("+s.store+" "+(s.id||s.name)+")";',
|
|
291
|
+
'if(s.store==="aws-secrets-manager"){let v=chomp(call(at,"aws",["secretsmanager","get-secret-value","--secret-id",s.id,"--query","SecretString","--output","text",...(s.region?["--region",s.region]:[])]));',
|
|
292
|
+
'if(s.jsonKey!==undefined){let d;try{d=JSON.parse(v)}catch{fail(at+": the secret is not JSON, and jsonKey reads a key of a JSON secret")}',
|
|
293
|
+
'if(!d||typeof d!=="object"||!(s.jsonKey in d))fail(at+": the secret has no key "+s.jsonKey);v=typeof d[s.jsonKey]==="string"?d[s.jsonKey]:JSON.stringify(d[s.jsonKey])}return v}',
|
|
294
|
+
'if(s.store==="gcp-secret-manager"){const m=/^projects\\/([^/]+)\\/secrets\\/([^/]+)(?:\\/versions\\/([^/]+))?$/.exec(s.name);if(!m)fail(at+": not a secret version");',
|
|
295
|
+
'return call(at,"gcloud",["secrets","versions","access",m[3]||"latest","--secret="+m[2],"--project="+m[1]])}',
|
|
296
|
+
'if(s.store==="azure-key-vault")return chomp(call(at,"az",["keyvault","secret","show","--id",s.id,"--query","value","--output","tsv"]));',
|
|
297
|
+
'fail(at+": not a store chant reads")};',
|
|
298
|
+
'let out="";',
|
|
299
|
+
"for(const e of list){",
|
|
300
|
+
'if(!e||typeof e.name!=="string"||!/^[A-Za-z_][A-Za-z0-9_]*$/.test(e.name)||!e.source)fail("an entry names no variable");',
|
|
301
|
+
"const v=read(e);",
|
|
302
|
+
'if(forge!=="gitlab")for(const l of v.split(/\\r?\\n/))if(l.trim())out+="printf "+q("%s\\\\n")+" "+q("::add-mask::"+l)+"\\n";',
|
|
303
|
+
'out+="export "+e.name+"="+q(v)+"\\n";',
|
|
304
|
+
'console.error("chant: read "+e.name+" from "+e.source.store)}',
|
|
305
|
+
"process.stdout.write(out);",
|
|
306
|
+
].join("");
|
|
307
|
+
const sh = (s) => `'${s.split("'").join(`'\\''`)}'`;
|
|
308
|
+
/**
|
|
309
|
+
* The shell lines that read the store secrets of `set` and export them in
|
|
310
|
+
* the shell that runs them, then unset what held them. An assignment's
|
|
311
|
+
* status is its command substitution's, so a failed read stops the job.
|
|
312
|
+
*/
|
|
313
|
+
export function environmentSetFetchLines(set, forge) {
|
|
314
|
+
const list = set.secrets.filter((s) => s.source.store !== "forge").map((s) => ({ name: s.name, source: s.source }));
|
|
315
|
+
if (list.length === 0)
|
|
316
|
+
return [];
|
|
317
|
+
return [
|
|
318
|
+
`export ${ENV_SET_FETCH_ENV}=${sh(JSON.stringify(list))}`,
|
|
319
|
+
`${ENV_SET_VARS}="$(cd / && node -e '${ENV_SET_FETCH_JS}' ${forge})" || exit 1`,
|
|
320
|
+
`eval "$${ENV_SET_VARS}"`,
|
|
321
|
+
`unset ${ENV_SET_VARS} ${ENV_SET_FETCH_ENV}`,
|
|
322
|
+
];
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* What a generator hands the jobs of `set`'s stage: the config as
|
|
326
|
+
* variables, the forge secrets as passed secrets, the store read as setup
|
|
327
|
+
* lines, and the record as {@link ENV_SET_ENV}. With `secrets: false`, for
|
|
328
|
+
* a job that runs a pull request's code, the config and the record alone.
|
|
329
|
+
*/
|
|
330
|
+
export function environmentSetJobInputs(set, forge, options = {}) {
|
|
331
|
+
const withSecrets = options.secrets !== false;
|
|
332
|
+
const variables = Object.fromEntries(set.config.map((c) => [c.name, c.value]));
|
|
333
|
+
variables[ENV_SET_ENV] = JSON.stringify(environmentSetRecord(set));
|
|
334
|
+
const secrets = withSecrets
|
|
335
|
+
? Object.fromEntries(set.secrets.flatMap((s) => (s.source.store === "forge" ? [[s.name, s.source.secret]] : [])))
|
|
336
|
+
: {};
|
|
337
|
+
return { variables, secrets, setup: withSecrets ? environmentSetFetchLines(set, forge) : [] };
|
|
338
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canary's soak in a gated-wave fan-out (#5327).
|
|
3
|
+
*
|
|
4
|
+
* `chant components fan-out --canary <component> --wave-gate <gate>` puts
|
|
5
|
+
* the canary components the change selects in wave 1. The soak that holds
|
|
6
|
+
* the waves after it is the soak of the pipeline stage the fan-out runs in
|
|
7
|
+
* (`--env`), read from `.chant/pipeline.ts` at the default branch's tip: the
|
|
8
|
+
* same soak, so no key of its own. Before each wave after the canary
|
|
9
|
+
* plans, the run reads it through gate `<gate>-wave-1-soak` under the
|
|
10
|
+
* `fan-out` op (`waveSoakGate`), with its clock at the end of the canary
|
|
11
|
+
* wave's applies (`WaveRecord.settledAt`). While it holds, the run stops
|
|
12
|
+
* with exit 3, as at a gate nobody approved; running the same command
|
|
13
|
+
* again reads it again, and approving that gate ends it early.
|
|
14
|
+
*
|
|
15
|
+
* A canary wave that applied nothing, or whose record is not at hand,
|
|
16
|
+
* gives the soak no clock, so it holds: a canary that did not land never
|
|
17
|
+
* lets the waves after it through on time alone.
|
|
18
|
+
*/
|
|
19
|
+
import { type WaveRecord } from "../gated-waves.js";
|
|
20
|
+
import type { GateLedgerPort } from "../op/gate.js";
|
|
21
|
+
import { type SoakGateInput } from "../pipeline/soak-gate.js";
|
|
22
|
+
import type { Soak, SoakCheckReader } from "../pipeline/soak.js";
|
|
23
|
+
import type { PipelineSpec } from "../pipeline/spec.js";
|
|
24
|
+
import type { FanOutSoakHold } from "./fan-out-run.js";
|
|
25
|
+
/** The soak of stage `env` in `pipeline`, the one a fan-out's canary takes; undefined when the stage or its soak is absent. */
|
|
26
|
+
export declare function fanOutCanarySoakOf(pipeline: Pick<PipelineSpec, "stages"> | undefined, env: string): Soak | undefined;
|
|
27
|
+
/** Whether the plan's first wave is the canary: it holds a component `--canary` named. */
|
|
28
|
+
export declare function fanOutHasCanaryWave(waves: readonly (readonly string[])[], canary: readonly string[]): boolean;
|
|
29
|
+
export interface FanOutCanarySoakInput {
|
|
30
|
+
/** The op the gates are recorded under, `fan-out`. */
|
|
31
|
+
op: string;
|
|
32
|
+
/** The base wave gate (`--wave-gate`). */
|
|
33
|
+
gate: string;
|
|
34
|
+
soak: Soak;
|
|
35
|
+
/** The environment the fan-out runs in, the stage whose soak this is. */
|
|
36
|
+
env: string;
|
|
37
|
+
/** The canary wave's record as the run knows it now: this attempt's, else the one `--resume` carried. */
|
|
38
|
+
canaryWave: () => WaveRecord | undefined;
|
|
39
|
+
port: GateLedgerPort;
|
|
40
|
+
read: SoakCheckReader;
|
|
41
|
+
now?: () => Date;
|
|
42
|
+
notify?: SoakGateInput["notify"];
|
|
43
|
+
/** Each line a passed soak says. */
|
|
44
|
+
log?: (line: string) => void;
|
|
45
|
+
}
|
|
46
|
+
/** The `waveGate.soak` hook: the canary's soak in front of wave `k`. */
|
|
47
|
+
export declare function fanOutCanarySoak(input: FanOutCanarySoakInput): (k: number) => Promise<FanOutSoakHold | undefined>;
|