@intentius/sql-yodeler 0.12.1 → 0.13.2
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/README.md +2 -0
- package/dist/bin.js +3 -0
- package/dist/bin.js.map +1 -1
- package/dist/chant/apply.js +3 -1
- package/dist/chant/apply.js.map +1 -1
- package/dist/chant/build.d.ts +4 -2
- package/dist/chant/build.js +8 -4
- package/dist/chant/build.js.map +1 -1
- package/dist/chant/confirm.d.ts +20 -20
- package/dist/chant/confirm.js +14 -27
- package/dist/chant/confirm.js.map +1 -1
- package/dist/chant/drift.d.ts +0 -17
- package/dist/chant/drift.js +6 -63
- package/dist/chant/drift.js.map +1 -1
- package/dist/chant/gated-request.d.ts +4 -8
- package/dist/chant/gated-request.js +5 -20
- package/dist/chant/gated-request.js.map +1 -1
- package/dist/chant/ledger-fetch.d.ts +46 -0
- package/dist/chant/ledger-fetch.js +42 -0
- package/dist/chant/ledger-fetch.js.map +1 -0
- package/dist/chant/sql-types.d.ts +4 -5
- package/dist/chant/sql-types.js +9 -9
- package/dist/chant/sql-types.js.map +1 -1
- package/dist/chant-floor-version.d.ts +4 -11
- package/dist/chant-floor-version.js +4 -11
- package/dist/chant-floor-version.js.map +1 -1
- package/dist/chant-floor.d.ts +5 -36
- package/dist/chant-floor.js +5 -65
- package/dist/chant-floor.js.map +1 -1
- package/dist/check/run.js +1 -1
- package/dist/check/run.js.map +1 -1
- package/dist/ci/check-hooks.d.ts +2 -2
- package/dist/ci/check-hooks.js +4 -17
- package/dist/ci/check-hooks.js.map +1 -1
- package/dist/ci/commit.d.ts +106 -0
- package/dist/ci/commit.js +115 -0
- package/dist/ci/commit.js.map +1 -0
- package/dist/ci/login.d.ts +17 -12
- package/dist/ci/login.js +32 -41
- package/dist/ci/login.js.map +1 -1
- package/dist/ci/render.d.ts +81 -47
- package/dist/ci/render.js +215 -285
- package/dist/ci/render.js.map +1 -1
- package/dist/ci-words.d.ts +18 -19
- package/dist/ci-words.js +16 -30
- package/dist/ci-words.js.map +1 -1
- package/dist/cli.js +1 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/approve.d.ts +1 -1
- package/dist/commands/approve.js +6 -7
- package/dist/commands/approve.js.map +1 -1
- package/dist/commands/chant.d.ts +7 -1
- package/dist/commands/chant.js +16 -3
- package/dist/commands/chant.js.map +1 -1
- package/dist/commands/ci.js +55 -9
- package/dist/commands/ci.js.map +1 -1
- package/dist/commands/create.d.ts +2 -2
- package/dist/commands/create.js +2 -2
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/drift.js +8 -18
- package/dist/commands/drift.js.map +1 -1
- package/dist/commands/emulator.d.ts +2 -2
- package/dist/commands/emulator.js +2 -2
- package/dist/commands/emulator.js.map +1 -1
- package/dist/commands/init.js +3 -2
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/lint.js +29 -3
- package/dist/commands/lint.js.map +1 -1
- package/dist/commands/new.d.ts +7 -0
- package/dist/commands/new.js +156 -22
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/override.js +2 -2
- package/dist/commands/override.js.map +1 -1
- package/dist/commands/plan.js +7 -4
- package/dist/commands/plan.js.map +1 -1
- package/dist/commands/upgrade.d.ts +2 -2
- package/dist/commands/upgrade.js +12 -36
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/config/define.d.ts +37 -0
- package/dist/config/define.js +4 -0
- package/dist/config/define.js.map +1 -1
- package/dist/config/load.js +22 -4
- package/dist/config/load.js.map +1 -1
- package/dist/declarative/plan.d.ts +1 -0
- package/dist/declarative/plan.js +5 -3
- package/dist/declarative/plan.js.map +1 -1
- package/dist/exit.d.ts +15 -37
- package/dist/exit.js +23 -79
- package/dist/exit.js.map +1 -1
- package/dist/init/adopt.d.ts +1 -1
- package/dist/init/adopt.js +3 -2
- package/dist/init/adopt.js.map +1 -1
- package/dist/lint/rules.d.ts +3 -1
- package/dist/lint/rules.js +3 -1
- package/dist/lint/rules.js.map +1 -1
- package/dist/lint/unmigrated.d.ts +18 -0
- package/dist/lint/unmigrated.js +62 -0
- package/dist/lint/unmigrated.js.map +1 -0
- package/dist/mcp/chant-hook.d.ts +1 -2
- package/dist/mcp/chant-hook.js +4 -12
- package/dist/mcp/chant-hook.js.map +1 -1
- package/dist/notify/index.d.ts +11 -4
- package/dist/notify/index.js +18 -16
- package/dist/notify/index.js.map +1 -1
- package/dist/pr/forge.d.ts +7 -6
- package/dist/pr/forge.js +19 -56
- package/dist/pr/forge.js.map +1 -1
- package/dist/pr/issue.d.ts +30 -19
- package/dist/pr/issue.js +66 -11
- package/dist/pr/issue.js.map +1 -1
- package/dist/pr/note.d.ts +4 -2
- package/dist/pr/note.js +21 -16
- package/dist/pr/note.js.map +1 -1
- package/dist/pr/overdue.d.ts +5 -12
- package/dist/pr/overdue.js +7 -49
- package/dist/pr/overdue.js.map +1 -1
- package/dist/pr/render.d.ts +0 -2
- package/dist/pr/render.js +0 -2
- package/dist/pr/render.js.map +1 -1
- package/dist/pr/tenants.d.ts +1 -0
- package/dist/pr/tenants.js +6 -4
- package/dist/pr/tenants.js.map +1 -1
- package/dist/project.d.ts +1 -1
- package/dist/project.js +3 -2
- package/dist/project.js.map +1 -1
- package/dist/schemas.d.ts +1 -1
- package/dist/sources/index.js +2 -1
- package/dist/sources/index.js.map +1 -1
- package/dist/versioned/op.js +8 -3
- package/dist/versioned/op.js.map +1 -1
- package/package.json +9 -8
- package/schemas/event.schema.json +17 -2
- package/dist/chant/process.d.ts +0 -46
- package/dist/chant/process.js +0 -92
- package/dist/chant/process.js.map +0 -1
package/dist/ci/render.js
CHANGED
|
@@ -79,6 +79,7 @@ import { existsSync } from "node:fs";
|
|
|
79
79
|
import { join, resolve } from "node:path";
|
|
80
80
|
import { pathToFileURL } from "node:url";
|
|
81
81
|
import { APPROVAL_MODES, WAVE_GATES, waveGateHint } from "../config/define.js";
|
|
82
|
+
import { commitFiles, COMMIT_TOKEN_ENV, GITLAB_COMMIT_FILES } from "./commit.js";
|
|
82
83
|
import { stepHooks } from "../apply-steps/index.js";
|
|
83
84
|
import { CLOUD_OF, jobLogins, loginSteps, tradeIdTokens } from "./login.js";
|
|
84
85
|
import { RECORD_PLANS_ENV } from "../approval-mode/index.js";
|
|
@@ -87,14 +88,14 @@ import { loadYodelConfig } from "../config/load.js";
|
|
|
87
88
|
import { testFiles } from "../testing/files.js";
|
|
88
89
|
import { CODE_QUALITY_FILE } from "../lint/annotations.js";
|
|
89
90
|
import { chantCheckHooks, checkPresets, declarationFile, declarationWithHooks } from "./check-hooks.js";
|
|
90
|
-
import {
|
|
91
|
+
import { ACTION_PINS, tagComments, usesRef } from "@intentius/chant/action-pins";
|
|
91
92
|
import { Concurrency, Job as ActionsJob, Permissions, Service as ActionsService, Step, Workflow as ActionsWorkflow, } from "@intentius/chant-lexicon-github";
|
|
92
93
|
import { githubSerializer } from "@intentius/chant-lexicon-github/serializer";
|
|
93
94
|
import { forgejoSerializer } from "@intentius/chant-lexicon-forgejo/serializer";
|
|
94
95
|
import { Artifacts as GitLabArtifacts, Image, Job as GitLabJob, Pipeline as GitLabPipeline, Rule, Service as GitLabService, Workflow as GitLabWorkflow, WorkflowRule, } from "@intentius/chant-lexicon-gitlab";
|
|
95
96
|
import { gitlabSerializer } from "@intentius/chant-lexicon-gitlab/serializer";
|
|
96
|
-
import {
|
|
97
|
-
import {
|
|
97
|
+
import { sqlTypesPath } from "@intentius/chant-lexicon-sql/sql-types";
|
|
98
|
+
import { chantProduct, WAVE_WORDS, YODEL_WORDS } from "../ci-words.js";
|
|
98
99
|
export const FORGES = ["github", "gitlab", "forgejo"];
|
|
99
100
|
/** The image every job runs in, where the forge runs jobs in a container. It needs git, so not -slim. */
|
|
100
101
|
export const IMAGE = "node:22-bookworm";
|
|
@@ -104,9 +105,14 @@ export const toolchainOf = (envs) => (envs.image ? { image: envs.image, yodelIma
|
|
|
104
105
|
/** The steps that install the project's packages and put their bins on PATH, as each forge writes them. */
|
|
105
106
|
const installLines = (tc, forge) => tc.yodelImage ? [] : ["npm ci", forge === "gitlab" ? 'export PATH="$PWD/node_modules/.bin:$PATH"' : 'echo "$PWD/node_modules/.bin" >> "$GITHUB_PATH"'];
|
|
106
107
|
export const MAIN = "main";
|
|
107
|
-
/**
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
/**
|
|
109
|
+
* The actions yodel's own jobs use, pinned by commit SHA from chant's
|
|
110
|
+
* ACTION_PINS (#319), with the release beside each `uses:` line
|
|
111
|
+
* ({@link renderActions}). The forgejo lexicon takes them to
|
|
112
|
+
* code.forgejo.org on Forgejo, and upload-artifact to its v3 row there.
|
|
113
|
+
*/
|
|
114
|
+
const CHECKOUT = usesRef(ACTION_PINS.checkout7);
|
|
115
|
+
const SETUP_NODE = usesRef(ACTION_PINS.setupNode7);
|
|
110
116
|
/** DEV for dev: the prefix of an environment's variables. */
|
|
111
117
|
export const prefixOf = (env) => env.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
112
118
|
/** The line the lint job runs chant's check moment with (#294): the hooks are read at the pull request's base. */
|
|
@@ -167,32 +173,11 @@ const idTokens = (clouds, logins = []) => ({
|
|
|
167
173
|
const loginsOf = (envs, held) => jobLogins(envs.login, held, (env, role) => envs.credentials?.[env]?.[role].cloud);
|
|
168
174
|
/** A job's login steps as the github lexicon's Steps. */
|
|
169
175
|
const actionsLogin = (forge, logins) => loginSteps(forge, logins).steps.map((st) => new Step({ name: st.name, run: st.lines.join("\n") }));
|
|
170
|
-
/** A job's login steps as plain step objects, for YAML chant rendered and yodel edits. */
|
|
171
|
-
const rawLogin = (forge, logins) => loginSteps(forge, logins).steps.map((st) => ({ name: st.name, run: st.lines.join("\n") }));
|
|
172
176
|
/** A GitLab job's login: its script lines and its variables. */
|
|
173
177
|
const gitlabLogin = (logins) => {
|
|
174
178
|
const out = loginSteps("gitlab", logins);
|
|
175
179
|
return { lines: out.steps.flatMap((st) => st.lines), variables: out.variables };
|
|
176
180
|
};
|
|
177
|
-
/** Puts `steps` before the first step `at` picks (refusing a job without one). */
|
|
178
|
-
function insertSteps(steps, add, at, what) {
|
|
179
|
-
if (add.length === 0)
|
|
180
|
-
return;
|
|
181
|
-
const i = steps.findIndex(at);
|
|
182
|
-
if (i < 0)
|
|
183
|
-
throw new Error(`${what}: no step to log in before`);
|
|
184
|
-
steps.splice(i, 0, ...add);
|
|
185
|
-
}
|
|
186
|
-
/** Puts `lines` before the first script line `at` picks (refusing a job without one). */
|
|
187
|
-
function insertLines(script, add, at, what) {
|
|
188
|
-
if (add.length === 0)
|
|
189
|
-
return;
|
|
190
|
-
const i = script?.findIndex(at) ?? -1;
|
|
191
|
-
if (!script || i < 0)
|
|
192
|
-
throw new Error(`${what}: no script line to log in before`);
|
|
193
|
-
script.splice(i, 0, ...add);
|
|
194
|
-
}
|
|
195
|
-
const runsChant = (st) => typeof st.run === "string" && st.run.startsWith("chant run ");
|
|
196
181
|
/** The roles a pull request's plan job for `env` holds: the environment's reader and the reader of the one it requires. */
|
|
197
182
|
const planRoles = (waves, env) => [env, ...requiredOf(waves, env)].map((e) => [e, "reader"]);
|
|
198
183
|
/** The roles a wave job for `env` holds: the writer, and the reader of the environment it requires. */
|
|
@@ -204,7 +189,7 @@ function identityHeader(forge, clouds) {
|
|
|
204
189
|
return [];
|
|
205
190
|
const names = clouds.join(", ");
|
|
206
191
|
if (forge === "github")
|
|
207
|
-
return [`# Cloud identity: a password here is a ${names} token, minted from the job's`, "# identity, so the
|
|
192
|
+
return [`# Cloud identity: a password here is a ${names} token, minted from the job's`, "# identity, so the jobs that hold one get id-token: write (an OIDC token)."];
|
|
208
193
|
if (forge === "gitlab")
|
|
209
194
|
return [`# Cloud identity: a password here is a ${names} token, minted from the job's`, `# identity: the jobs that hold one declare id_tokens (${clouds.map((c) => ID_TOKENS[c].variable).join(", ")}).`];
|
|
210
195
|
return [`# Cloud identity: a password here is a ${names} token. Forgejo gives a job no`, "# OIDC token, so the runner's own cloud identity mints it."];
|
|
@@ -215,10 +200,14 @@ const secret = (name) => `\${{ secrets.${name} }}`;
|
|
|
215
200
|
const secrets = (names) => Object.fromEntries(names.map((n) => [n, secret(n)]));
|
|
216
201
|
/**
|
|
217
202
|
* The approvals: `chant approve` records them on the chant/lifecycle branch,
|
|
218
|
-
* and approvers push it. A CI checkout fetches one ref, so
|
|
219
|
-
*
|
|
203
|
+
* and approvers push it. A CI checkout fetches one ref, so each job fetches
|
|
204
|
+
* this one too, through chant's reader (`yodel ci --fetch-ledger`, #326):
|
|
205
|
+
* yodel writes neither the branch nor the remote-tracking ref chant's push
|
|
206
|
+
* leases against. `yodel` is the project's, named by path, as the line may
|
|
207
|
+
* run before the install's PATH reaches the step; in the yodel image, the
|
|
208
|
+
* image's.
|
|
220
209
|
*/
|
|
221
|
-
export const
|
|
210
|
+
export const fetchApprovals = (tc = { yodelImage: false }) => `${tc.yodelImage ? "yodel" : "./node_modules/.bin/yodel"} ci --fetch-ledger`;
|
|
222
211
|
/** The watch reads; it never pushes. See the comment at the top. */
|
|
223
212
|
export const NO_PUSH = "git remote set-url --push origin no-push://the-drift-watch-only-reads";
|
|
224
213
|
/** After the watch's `chant run`: drift against the history, the environment's tracking issue, and exit 2 on drift. */
|
|
@@ -301,13 +290,9 @@ export const reportCommand = (env, tc = { image: IMAGE, yodelImage: false }) =>
|
|
|
301
290
|
};
|
|
302
291
|
/** The artifact a job keeps its report in. */
|
|
303
292
|
export const reportArtifact = (job) => `yodel-report-${job}`;
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
* forgejo lexicon resolves it, from code.forgejo.org/actions) refuses any
|
|
308
|
-
* server but github.com's and fails the step, so the job, on Forgejo.
|
|
309
|
-
*/
|
|
310
|
-
export const FORGEJO_UPLOAD_ARTIFACT = "https://code.forgejo.org/forgejo/upload-artifact@v4";
|
|
293
|
+
/** upload-artifact v4 on GitHub, and v3 from code.forgejo.org on Forgejo, where v4 refuses any server but github.com's (chant#4008), as chant's own Forgejo jobs have it. */
|
|
294
|
+
export const UPLOAD_ARTIFACT = usesRef(ACTION_PINS.uploadArtifact4);
|
|
295
|
+
export const FORGEJO_UPLOAD_ARTIFACT = `https://code.forgejo.org/${usesRef(ACTION_PINS.uploadArtifact3)}`;
|
|
311
296
|
const uploadArtifact = (forge) => (forge === "forgejo" ? FORGEJO_UPLOAD_ARTIFACT : UPLOAD_ARTIFACT);
|
|
312
297
|
/**
|
|
313
298
|
* The comment at the top of every file, as `#` lines. The files declared here
|
|
@@ -320,6 +305,10 @@ const HEADER = [
|
|
|
320
305
|
"# Rendered by yodel ci from chant.config.ts, yodel.config.ts and ops/.",
|
|
321
306
|
"# Edit those and render again; yodel ci --check says when this file is stale.",
|
|
322
307
|
];
|
|
308
|
+
/** The pipeline directories yodel ci writes into, besides the root `.gitlab-ci.yml`. */
|
|
309
|
+
export const PIPELINE_DIRS = [".github/workflows", ".forgejo/workflows", ".gitlab"];
|
|
310
|
+
/** Whether a file's text is one yodel ci wrote: it opens with the header (#348). */
|
|
311
|
+
export const renderedByYodel = (text) => text.startsWith(`${HEADER[0] ?? ""}\n`);
|
|
323
312
|
const withHeader = (header, yaml) => `${[...header, ""].join("\n")}${yaml}`;
|
|
324
313
|
/** `#` lines as a declaration's `comment`: the text without its `# `, which the serializer writes back. */
|
|
325
314
|
const asComment = (header) => header.map((l) => l.replace(/^# ?/, "")).join("\n");
|
|
@@ -350,7 +339,7 @@ function setupSteps(inContainer, tc, approvals = true) {
|
|
|
350
339
|
steps.push(new Step({ uses: SETUP_NODE, with: { "node-version": 22, cache: "npm" } }));
|
|
351
340
|
steps.push(...installLines(tc, "github").map((run) => new Step({ run })));
|
|
352
341
|
if (approvals)
|
|
353
|
-
steps.push(new Step({ name: "Fetch the approvals (chant/lifecycle)", run:
|
|
342
|
+
steps.push(new Step({ name: "Fetch the approvals (chant/lifecycle)", run: fetchApprovals(tc) }));
|
|
354
343
|
return steps;
|
|
355
344
|
}
|
|
356
345
|
/** Forgejo runs every job in the image; GitHub on the runner's VM, unless the job asks for the container or the image is yodel's. */
|
|
@@ -537,7 +526,7 @@ export function gitlabPipeline(envs_) {
|
|
|
537
526
|
const jobs = new Map();
|
|
538
527
|
jobs.set(".yodel", new GitLabJob({
|
|
539
528
|
image: new Image({ name: tc.image }),
|
|
540
|
-
before_script: [...installLines(tc, "gitlab"),
|
|
529
|
+
before_script: [...installLines(tc, "gitlab"), fetchApprovals(tc)],
|
|
541
530
|
}));
|
|
542
531
|
const svc = REPLAY_SERVICE[dialect];
|
|
543
532
|
const types = envs_.typedColumns === true ? [TYPES_CHECK] : [];
|
|
@@ -623,6 +612,8 @@ export function gitlabPipeline(envs_) {
|
|
|
623
612
|
"# pipeline (yodel.config.ts ci.apply: false): migrations are applied outside CI.",
|
|
624
613
|
]),
|
|
625
614
|
`# The drift watches are in ${GITLAB_WATCH_FILE} (stage ops).`,
|
|
615
|
+
...(respondsNew(envs_) ? [`# /yodel new, chant's commit job, is in ${GITLAB_COMMIT_FILES.new} (stage ops).`] : []),
|
|
616
|
+
...(rebaseRespond(envs_) !== "off" ? [`# /yodel rebase, after the merge request's check, is in ${GITLAB_COMMIT_FILES.rebase} (stage ops).`] : []),
|
|
626
617
|
"#",
|
|
627
618
|
"# GitLab gives every job the project's CI/CD variables unless a variable is",
|
|
628
619
|
"# protected or scoped to an environment, so the split between reader and",
|
|
@@ -657,7 +648,7 @@ export function gitlabPipeline(envs_) {
|
|
|
657
648
|
const applyStages = apply ? [...plans, ...waveStages(waves), ...(envs_.resume ? [RESUME_STAGE] : [])] : [];
|
|
658
649
|
const pipeline = new GitLabPipeline({
|
|
659
650
|
comment: asComment(header),
|
|
660
|
-
include: [...(apply ? [{ local: GITLAB_APPLY_FILE }] : []), { local: GITLAB_WATCH_FILE }],
|
|
651
|
+
include: [...(apply ? [{ local: GITLAB_APPLY_FILE }] : []), { local: GITLAB_WATCH_FILE }, ...(respondsNew(envs_) ? [{ local: GITLAB_COMMIT_FILES.new }] : []), ...(rebaseRespond(envs_) !== "off" ? [{ local: GITLAB_COMMIT_FILES.rebase }] : [])],
|
|
661
652
|
stages: [...new Set([...jobStages, ...applyStages, "ops"])],
|
|
662
653
|
variables: { GIT_DEPTH: "0" },
|
|
663
654
|
});
|
|
@@ -674,7 +665,7 @@ export const WAVES_SPEC = "yodel-waves.json";
|
|
|
674
665
|
export const APPLY_PIPELINE = "yodel-apply";
|
|
675
666
|
/**
|
|
676
667
|
* The waves spec. What the file holds is the same for every forge; each
|
|
677
|
-
* forge's jobs get their own variables on top (`
|
|
668
|
+
* forge's jobs get their own variables and OIDC tokens on top (`job`).
|
|
678
669
|
*
|
|
679
670
|
* The spec names the sql lexicon's `sql-migrate` capability (#291,
|
|
680
671
|
* chant#4569), and chant plans and applies each run through it, which calls
|
|
@@ -693,7 +684,7 @@ export const APPLY_PIPELINE = "yodel-apply";
|
|
|
693
684
|
* the base commit, as it does run by hand. A step runs once, under the
|
|
694
685
|
* lock, as #107 asks.
|
|
695
686
|
*/
|
|
696
|
-
export function wavesSpec(waves,
|
|
687
|
+
export function wavesSpec(waves, job, resume) {
|
|
697
688
|
const first = waves[0];
|
|
698
689
|
if (!first)
|
|
699
690
|
throw new Error("no waves to render");
|
|
@@ -710,7 +701,7 @@ export function wavesSpec(waves, variables, resume) {
|
|
|
710
701
|
gate: w.gate,
|
|
711
702
|
...(w.shares !== undefined && w.shares > 1 ? { shares: w.shares } : {}),
|
|
712
703
|
...(w.approval !== undefined && w.approval !== "ledger" ? { approval: w.approval } : {}),
|
|
713
|
-
...(
|
|
704
|
+
...(job ? { environment: { name: w.env }, ...job(w.env) } : {}),
|
|
714
705
|
// The steps around apply (#64) as chant's stage hooks, which the apply runs under its lock (#206).
|
|
715
706
|
...hooksOf(w.steps),
|
|
716
707
|
})),
|
|
@@ -724,10 +715,32 @@ function hooksOf(steps) {
|
|
|
724
715
|
const plan = stepHooks(steps)?.before?.plan;
|
|
725
716
|
return plan && plan.length > 0 ? { hooks: { before: { plan } } } : {};
|
|
726
717
|
}
|
|
718
|
+
/**
|
|
719
|
+
* What a job holding the roles `held` adds on `forge` for its cloud login
|
|
720
|
+
* (#132), in the shape chant's generators take (#4791): the login's steps,
|
|
721
|
+
* its variables (GitLab's trade spec; on GitHub and Forgejo the steps write
|
|
722
|
+
* $GITHUB_ENV) and the OIDC tokens the job requests. Forgejo gives a job no
|
|
723
|
+
* OIDC token, so it requests none there.
|
|
724
|
+
*/
|
|
725
|
+
function jobLogin(forge, envs, held) {
|
|
726
|
+
const logins = loginsOf(envs, held);
|
|
727
|
+
const out = loginSteps(forge, logins);
|
|
728
|
+
const clouds = cloudsOf(envs, held);
|
|
729
|
+
const before = out.steps.map((st) => ({ name: st.name, run: st.lines }));
|
|
730
|
+
if (forge === "forgejo" || clouds.length === 0)
|
|
731
|
+
return { before, variables: out.variables };
|
|
732
|
+
const tokens = Object.fromEntries(Object.entries(idTokens(clouds, logins)).map(([name, t]) => [name, t.aud]));
|
|
733
|
+
return { before, variables: out.variables, idTokens: tokens };
|
|
734
|
+
}
|
|
727
735
|
/**
|
|
728
736
|
* The waves spec file and the apply pipeline on each forge. The spec comes
|
|
729
737
|
* from chant's productPipelineJobs under yodel's words (#289), and each job
|
|
730
|
-
* runs `yodel chant` where chant's own runs `chant` (
|
|
738
|
+
* runs `yodel chant` where chant's own runs `chant` (chant's `bin`,
|
|
739
|
+
* {@link productWaves}). What yodel adds to chant's jobs goes in as
|
|
740
|
+
* generateOpWavesPipeline's inputs (#4791): each wave job's cloud login,
|
|
741
|
+
* its `yodel report` and the report's artifact (`waveJobs`), the plans
|
|
742
|
+
* job's login, write probe and readers (`recordPlans`), and each wave's
|
|
743
|
+
* variables and OIDC tokens in the spec.
|
|
731
744
|
*/
|
|
732
745
|
export async function applyPipelines(dir, envs, product) {
|
|
733
746
|
const { dialect, waves } = envs;
|
|
@@ -736,22 +749,51 @@ export async function applyPipelines(dir, envs, product) {
|
|
|
736
749
|
const named = (forge, spec) => productWaves(product, forge, spec);
|
|
737
750
|
const out = [{ path: WAVES_SPEC, content: `${JSON.stringify(named("github", wavesSpec(waves)).spec, null, 2)}\n` }];
|
|
738
751
|
// A GitLab job already has the project's variables, a writer's only under its environment.
|
|
739
|
-
const
|
|
752
|
+
const jobOf = (forge) => (env) => {
|
|
740
753
|
const wave = waves.find((w) => w.env === env);
|
|
741
754
|
const required = wave?.requires;
|
|
755
|
+
const login = jobLogin(forge, envs, waveRoles(waves, env));
|
|
756
|
+
return {
|
|
757
|
+
variables: {
|
|
758
|
+
YODEL_CREDENTIALS: `writer:${env}`,
|
|
759
|
+
...(forge === "gitlab"
|
|
760
|
+
? {}
|
|
761
|
+
: {
|
|
762
|
+
...secrets([...writerVariables(env, dialect, envs.credentials?.[env]), ...WEBHOOK_VARIABLES]),
|
|
763
|
+
// chant's sql-migrate runs the wave's yodel plan --part and --wave-plan with the writer taken out
|
|
764
|
+
// (readerEnv in the sql lexicon), so they connect as the environment's reader.
|
|
765
|
+
...secrets(readerVariables(env, dialect, envs.credentials?.[env])),
|
|
766
|
+
...(required ? secrets(readerVariables(required, dialect, envs.credentials?.[required])) : {}),
|
|
767
|
+
// A pr-review wave (#48) reads the merged pull request's reviews with the job's token.
|
|
768
|
+
...(wave?.approval === "pr-review" ? { GITHUB_TOKEN: "${{ github.token }}" } : {}),
|
|
769
|
+
}),
|
|
770
|
+
...login.variables,
|
|
771
|
+
},
|
|
772
|
+
...(login.idTokens ? { idTokens: login.idTokens } : {}),
|
|
773
|
+
};
|
|
774
|
+
};
|
|
775
|
+
// Each wave's jobs: the cloud login (#132) before the wave's command, and the report, kept as an artifact whatever the exit (a wave that waits exits 3).
|
|
776
|
+
const waveJobs = (forge) => Object.fromEntries(waves.map((w) => {
|
|
777
|
+
const login = jobLogin(forge, envs, waveRoles(waves, w.env));
|
|
778
|
+
const inputs = {
|
|
779
|
+
...(login.before.length > 0 ? { before: login.before } : {}),
|
|
780
|
+
report: { name: `yodel report ${w.env}`, run: [reportCommand(w.env, tc)] },
|
|
781
|
+
artifact: { step: "Keep the report", name: reportArtifact("{job}"), path: forge === "gitlab" ? `${REPORT_DIR}/` : REPORT_DIR },
|
|
782
|
+
};
|
|
783
|
+
return [w.env, inputs];
|
|
784
|
+
}));
|
|
785
|
+
// The plans job of a pr-review wave (#48): each environment's reader, which it plans the waves with, and the write probe first, as every pull request job has (#50, #130).
|
|
786
|
+
const recordPlans = (forge) => {
|
|
787
|
+
const waveEnvs = [...new Set(waves.map((w) => w.env))];
|
|
788
|
+
const login = jobLogin(forge, envs, waveEnvs.map((e) => [e, "reader"]));
|
|
742
789
|
return {
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
:
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
...secrets(readerVariables(env, dialect, envs.credentials?.[env])),
|
|
751
|
-
...(required ? secrets(readerVariables(required, dialect, envs.credentials?.[required])) : {}),
|
|
752
|
-
// A pr-review wave (#48) reads the merged pull request's reviews with the job's token.
|
|
753
|
-
...(wave?.approval === "pr-review" ? { GITHUB_TOKEN: "${{ github.token }}" } : {}),
|
|
754
|
-
}),
|
|
790
|
+
before: [...login.before, { name: "This job cannot write", run: [writeProbe(waveEnvs)] }],
|
|
791
|
+
variables: {
|
|
792
|
+
[RECORD_PLANS_ENV]: "1",
|
|
793
|
+
...(forge === "gitlab" ? {} : secrets(waveEnvs.flatMap((e) => readerVariables(e, dialect, envs.credentials?.[e])))),
|
|
794
|
+
...login.variables,
|
|
795
|
+
},
|
|
796
|
+
...(login.idTokens ? { idTokens: login.idTokens } : {}),
|
|
755
797
|
};
|
|
756
798
|
};
|
|
757
799
|
const header = [
|
|
@@ -791,11 +833,14 @@ export async function applyPipelines(dir, envs, product) {
|
|
|
791
833
|
"# holds no writer's credentials: it plans with each environment's reader.",
|
|
792
834
|
];
|
|
793
835
|
for (const forge of FORGES) {
|
|
794
|
-
const { spec, jobs } = named(forge, wavesSpec(waves,
|
|
836
|
+
const { spec, jobs } = named(forge, wavesSpec(waves, jobOf(forge), envs.resume));
|
|
795
837
|
const result = await generateOpWavesPipeline(spec, forge, {
|
|
796
838
|
specFile: WAVES_SPEC,
|
|
839
|
+
bin: YODEL_WORDS.bin,
|
|
797
840
|
image: tc.image,
|
|
798
|
-
beforeScript: [...installLines(tc, forge),
|
|
841
|
+
beforeScript: [...installLines(tc, forge), fetchApprovals(tc)],
|
|
842
|
+
waveJobs: waveJobs(forge),
|
|
843
|
+
recordPlans: recordPlans(forge),
|
|
799
844
|
...(forge === "gitlab" ? { opsFileName: GITLAB_APPLY_FILE } : {}),
|
|
800
845
|
}, dir);
|
|
801
846
|
if (!result.success || !result.files)
|
|
@@ -803,140 +848,17 @@ export async function applyPipelines(dir, envs, product) {
|
|
|
803
848
|
for (const file of result.files) {
|
|
804
849
|
const at = forge === "gitlab" ? GITLAB_APPLY_FILE : `${forge === "github" ? ".github" : ".forgejo"}/workflows/${file.name}`;
|
|
805
850
|
const yaml = file.yaml.endsWith("\n") ? file.yaml : `${file.yaml}\n`;
|
|
806
|
-
// The resume workflow (GitHub, Forgejo) has no wave job to report on.
|
|
807
851
|
if (forge !== "gitlab" && file.name === `${APPLY_PIPELINE}-resume.yml`)
|
|
808
|
-
out.push({ path: at, content: withHeader(resumeHeader(forge),
|
|
852
|
+
out.push({ path: at, content: withHeader(resumeHeader(forge), yaml) });
|
|
809
853
|
// The pull request workflow that records the plans a review approves (#48).
|
|
810
854
|
else if (forge !== "gitlab" && file.name === `${APPLY_PIPELINE}-plans.yml`)
|
|
811
|
-
out.push({ path: at, content: withHeader(plansHeader,
|
|
855
|
+
out.push({ path: at, content: withHeader(plansHeader, yaml) });
|
|
812
856
|
else
|
|
813
|
-
out.push({ path: at, content: withHeader([...header, ...identityHeader(forge, waveClouds)], withWaveLines(forge,
|
|
857
|
+
out.push({ path: at, content: withHeader([...header, ...identityHeader(forge, waveClouds)], withWaveLines(forge, yaml, jobs)) });
|
|
814
858
|
}
|
|
815
859
|
}
|
|
816
860
|
return out;
|
|
817
861
|
}
|
|
818
|
-
/**
|
|
819
|
-
* The wave jobs' report: chant's generateOpWavesPipeline takes run lines
|
|
820
|
-
* after the wave's command but no step that runs when it fails (a wave that
|
|
821
|
-
* waits exits 3), and no artifact, so they are added to its output here.
|
|
822
|
-
* The output is parsed and emitted again; the emitter is checked to give
|
|
823
|
-
* back chant's text unchanged before anything is added, so a change in
|
|
824
|
-
* chant's emitter fails here instead of rendering something else.
|
|
825
|
-
*/
|
|
826
|
-
/**
|
|
827
|
-
* chant writes a SHA-pinned action as `uses: owner/action@<sha> # vX.Y.Z`
|
|
828
|
-
* (chant#4403, #4410); the `# vX.Y.Z` is a YAML comment, which parsing drops.
|
|
829
|
-
* Each re-emit below puts every one back on the line that names the same
|
|
830
|
-
* pinned ref, so the re-emitted text still matches chant's and the files keep
|
|
831
|
-
* the release each SHA stands for.
|
|
832
|
-
*/
|
|
833
|
-
export function withPinComments(original, emitted) {
|
|
834
|
-
const comments = new Map();
|
|
835
|
-
for (const [, ref, comment] of original.matchAll(/uses: (\S+@[0-9a-f]{40}) (# [^\n]*)$/gm)) {
|
|
836
|
-
if (ref !== undefined && comment !== undefined)
|
|
837
|
-
comments.set(ref, comment);
|
|
838
|
-
}
|
|
839
|
-
if (comments.size === 0)
|
|
840
|
-
return emitted;
|
|
841
|
-
return emitted.replace(/uses: (\S+@[0-9a-f]{40})$/gm, (line, ref) => {
|
|
842
|
-
const comment = comments.get(ref);
|
|
843
|
-
return comment ? `${line} ${comment}` : line;
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
function withWaveReports(forge, yaml, waves, tc, envs = {}) {
|
|
847
|
-
// A wide wave's jobs are wave-<k>-<env>-decide and -share-<i>.
|
|
848
|
-
const envOf = (job) => waves.find((w, i) => new RegExp(`^wave-${String(i + 1)}-${w.env.replace(/[^A-Za-z0-9]/g, "\\$&")}(-decide|-share-\\d+)?$`).test(job))?.env;
|
|
849
|
-
const body = yaml.search(/^[^#\n]/m);
|
|
850
|
-
const header = yaml.slice(0, body);
|
|
851
|
-
const doc = parseYAMLDocument(yaml);
|
|
852
|
-
if (forge === "gitlab") {
|
|
853
|
-
const emit = (d) => withPinComments(yaml, `${header}${Object.entries(d).map(([k, v]) => emitYAMLEntry(k, v)).join("\n\n")}\n`);
|
|
854
|
-
if (emit(doc) !== yaml)
|
|
855
|
-
throw new Error("gitlab: the apply waves do not emit back to chant's text");
|
|
856
|
-
// The merge request job that records the plans a review approves (#48): the waves as after the merge.
|
|
857
|
-
const record = doc[`${APPLY_PIPELINE}-record-plans`];
|
|
858
|
-
if (record) {
|
|
859
|
-
record.variables = { ...(record.variables ?? {}), [RECORD_PLANS_ENV]: "1" };
|
|
860
|
-
// It holds readers only, and shows it first, as every merge request job does (#50, #130).
|
|
861
|
-
const waveEnvs = [...new Set(waves.map((w) => w.env))];
|
|
862
|
-
const at = record.script?.findIndex((l) => l.includes("--record-plans")) ?? -1;
|
|
863
|
-
if (!record.script || at < 0)
|
|
864
|
-
throw new Error("gitlab: the record-plans job has no chant run wave --record-plans line");
|
|
865
|
-
record.script.splice(at, 0, writeProbe(waveEnvs));
|
|
866
|
-
const readerRoles = waveEnvs.map((e) => [e, "reader"]);
|
|
867
|
-
const readers = cloudsOf(envs, readerRoles);
|
|
868
|
-
const logins = loginsOf(envs, readerRoles);
|
|
869
|
-
if (readers.length > 0)
|
|
870
|
-
record.id_tokens = idTokens(readers, logins);
|
|
871
|
-
const login = gitlabLogin(logins);
|
|
872
|
-
insertLines(record.script, login.lines, (l) => l === writeProbe(waveEnvs), "gitlab: the record-plans job");
|
|
873
|
-
if (Object.keys(login.variables).length > 0)
|
|
874
|
-
record.variables = { ...record.variables, ...login.variables };
|
|
875
|
-
}
|
|
876
|
-
for (const [name, job] of Object.entries(doc)) {
|
|
877
|
-
const env = envOf(name);
|
|
878
|
-
if (!env || typeof job !== "object" || job === null)
|
|
879
|
-
continue;
|
|
880
|
-
const clouds = cloudsOf(envs, waveRoles(waves, env));
|
|
881
|
-
const logins = loginsOf(envs, waveRoles(waves, env));
|
|
882
|
-
const login = gitlabLogin(logins);
|
|
883
|
-
const w = job;
|
|
884
|
-
insertLines(w.script, login.lines, (l) => l.startsWith("chant run "), `gitlab: ${name}`);
|
|
885
|
-
if (Object.keys(login.variables).length > 0)
|
|
886
|
-
w.variables = { ...w.variables, ...login.variables };
|
|
887
|
-
Object.assign(job, { after_script: [reportCommand(env, tc)], artifacts: { name: reportArtifact(name), when: "always", paths: [`${REPORT_DIR}/`] }, ...(clouds.length > 0 ? { id_tokens: idTokens(clouds, logins) } : {}) });
|
|
888
|
-
}
|
|
889
|
-
return emit(doc);
|
|
890
|
-
}
|
|
891
|
-
const at = yaml.indexOf("\njobs:\n");
|
|
892
|
-
if (at < 0)
|
|
893
|
-
throw new Error(`${forge}: the apply waves have no jobs`);
|
|
894
|
-
const jobs = doc.jobs;
|
|
895
|
-
const top = yaml.slice(0, at + 1);
|
|
896
|
-
const emitJobs = () => withPinComments(yaml, `${emitYAMLEntry("jobs", jobs)}\n`);
|
|
897
|
-
if (`${top}${emitJobs()}` !== yaml)
|
|
898
|
-
throw new Error(`${forge}: the apply waves do not emit back to chant's text`);
|
|
899
|
-
for (const [name, job] of Object.entries(jobs)) {
|
|
900
|
-
const env = envOf(name);
|
|
901
|
-
if (!env)
|
|
902
|
-
continue;
|
|
903
|
-
// The cloud login (#132) before the wave's chant run, when a role it holds is cloud-minted.
|
|
904
|
-
insertSteps(job.steps, rawLogin(forge, loginsOf(envs, waveRoles(waves, env))), runsChant, `${forge}: ${name}`);
|
|
905
|
-
job.steps.push({ name: `yodel report ${env}`, if: "always()", run: reportCommand(env, tc) }, { name: "Keep the report", if: "always()", uses: uploadArtifact(forge), with: { name: reportArtifact(name), path: REPORT_DIR, "if-no-files-found": "ignore" } });
|
|
906
|
-
}
|
|
907
|
-
return `${withIdToken(forge, top, cloudsOf(envs, waves.flatMap((w) => waveRoles(waves, w.env))))}${emitJobs()}`;
|
|
908
|
-
}
|
|
909
|
-
/**
|
|
910
|
-
* The plans workflow (GitHub, Forgejo) for a pr-review wave (#48): chant's,
|
|
911
|
-
* with each environment's reader (the waves are planned on every one, and a
|
|
912
|
-
* wave reads the history of the one it requires) and {@link RECORD_PLANS_ENV}
|
|
913
|
-
* on its job. The output is parsed and emitted again, checked first to give
|
|
914
|
-
* back chant's text unchanged.
|
|
915
|
-
*/
|
|
916
|
-
function withPlansReaders(forge, yaml, waves, dialect, creds = {}) {
|
|
917
|
-
const at = yaml.indexOf("\njobs:\n");
|
|
918
|
-
if (at < 0)
|
|
919
|
-
throw new Error(`${forge}: the plans workflow has no jobs`);
|
|
920
|
-
const doc = parseYAMLDocument(yaml);
|
|
921
|
-
const top = yaml.slice(0, at + 1);
|
|
922
|
-
const emitJobs = () => withPinComments(yaml, `${emitYAMLEntry("jobs", doc.jobs)}\n`);
|
|
923
|
-
if (`${top}${emitJobs()}` !== yaml)
|
|
924
|
-
throw new Error(`${forge}: the plans workflow does not emit back to chant's text`);
|
|
925
|
-
const job = doc.jobs["record-plans"];
|
|
926
|
-
if (!job)
|
|
927
|
-
throw new Error(`${forge}: the plans workflow has no record-plans job`);
|
|
928
|
-
const envs = [...new Set(waves.map((w) => w.env))];
|
|
929
|
-
const steps = job.steps;
|
|
930
|
-
// It holds readers only, and shows it before it plans, as every pull request job does (#50, #130).
|
|
931
|
-
const recordAt = steps.findIndex((st) => typeof st.run === "string" && st.run.includes("--record-plans"));
|
|
932
|
-
if (recordAt < 0)
|
|
933
|
-
throw new Error(`${forge}: the record-plans job has no chant run wave --record-plans step`);
|
|
934
|
-
steps.splice(recordAt, 0, ...(forge === "gitlab" ? [] : rawLogin(forge, loginsOf(creds, envs.map((e) => [e, "reader"])))), { name: "This job cannot write", run: writeProbe(envs) });
|
|
935
|
-
delete job.steps;
|
|
936
|
-
Object.assign(job, { env: { [RECORD_PLANS_ENV]: "1", ...secrets(envs.flatMap((e) => readerVariables(e, dialect, creds.credentials?.[e]))) }, steps });
|
|
937
|
-
// A reader whose password is a cloud token (#50) is minted from the job's identity.
|
|
938
|
-
return `${withIdToken(forge, top, cloudsOf(creds, envs.map((e) => [e, "reader"])))}${emitJobs()}`;
|
|
939
|
-
}
|
|
940
862
|
/** yodel.config.ts `waves`, checked against the environments; one wave per environment, gate `always`, without it. */
|
|
941
863
|
export async function readWaves(dir, envs) {
|
|
942
864
|
const declared = (await readConfig(dir))?.waves;
|
|
@@ -989,8 +911,8 @@ export async function withTenants(dir, waves) {
|
|
|
989
911
|
// the names on the ledger since the waves began, so approvals already
|
|
990
912
|
// recorded keep counting), and each job running `yodel chant` where chant's
|
|
991
913
|
// own runs `chant`, so the job writes yodel's statuses and approve lines.
|
|
992
|
-
// The forge lexicons serialize the jobs
|
|
993
|
-
//
|
|
914
|
+
// The forge lexicons serialize the jobs, and yodel's reports, logins and
|
|
915
|
+
// readers go in as generateOpWavesPipeline's inputs (#4791).
|
|
994
916
|
//
|
|
995
917
|
// Still yodel's own: the plan jobs (`yodel plan <env> --comment` with the
|
|
996
918
|
// write probe), which post chant's note (../pr/note.ts, #290); the lint
|
|
@@ -999,7 +921,7 @@ export async function withTenants(dir, waves) {
|
|
|
999
921
|
// ({@link watchPipelines}).
|
|
1000
922
|
/** The spec under yodel's words, and the wave jobs chant's product pipeline names for `forge`. */
|
|
1001
923
|
export function productWaves(product, forge, spec) {
|
|
1002
|
-
const out = product.productPipelineJobs(forge, spec.waves[0]?.name ?? MAIN, { words:
|
|
924
|
+
const out = product.productPipelineJobs(forge, spec.waves[0]?.name ?? MAIN, { words: WAVE_WORDS, waves: spec, wavesSpecFile: WAVES_SPEC });
|
|
1003
925
|
if (!out.waves)
|
|
1004
926
|
throw new Error(`${forge}: chant's product pipeline gave no apply waves`);
|
|
1005
927
|
if (out.waves.specFile !== WAVES_SPEC)
|
|
@@ -1009,13 +931,6 @@ export function productWaves(product, forge, spec) {
|
|
|
1009
931
|
throw new Error(`${forge}: chant's product pipeline names the waves ${named.name}, and the ledger has them as ${APPLY_PIPELINE}`);
|
|
1010
932
|
return { spec: named, jobs: out.waves.jobs };
|
|
1011
933
|
}
|
|
1012
|
-
/** A `chant` command line in a rendered file: a step's `run:` or a GitLab script line, never a comment. */
|
|
1013
|
-
const CHANT_LINE = /^(\s*(?:- )?(?:run: )?)(chant [a-z].*)$/gm;
|
|
1014
|
-
/** `yaml` with yodel's bin in each chant command line (#289), through chant's own productCommand. */
|
|
1015
|
-
export function withBin(product, yaml) {
|
|
1016
|
-
const words = product.assertProductWords(YODEL_WORDS);
|
|
1017
|
-
return yaml.replace(CHANT_LINE, (_m, lead, line) => `${lead}${product.productCommand(words, line)}`);
|
|
1018
|
-
}
|
|
1019
934
|
/** Refuses an apply file whose wave jobs do not run the line chant's product pipeline gives each of them. */
|
|
1020
935
|
function withWaveLines(forge, yaml, jobs) {
|
|
1021
936
|
for (const job of jobs) {
|
|
@@ -1027,81 +942,43 @@ function withWaveLines(forge, yaml, jobs) {
|
|
|
1027
942
|
return yaml;
|
|
1028
943
|
}
|
|
1029
944
|
/**
|
|
1030
|
-
* The watch's spec for one environment: the Op,
|
|
1031
|
-
* reader
|
|
1032
|
-
*
|
|
1033
|
-
*
|
|
945
|
+
* The watch's spec for one environment: the Op, the cloud login (#132) when
|
|
946
|
+
* its reader is cloud-minted, as setup steps before the job's other lines,
|
|
947
|
+
* and on GitHub and Forgejo the reader's secrets. A GitLab job already has
|
|
948
|
+
* the project's variables (a writer's only under its environment, which the
|
|
949
|
+
* watch does not declare), and `NAME: $NAME` there would refer to itself;
|
|
950
|
+
* there the login's variables and the job's ID tokens go on the job.
|
|
1034
951
|
*/
|
|
1035
|
-
export function watchSpec(env,
|
|
1036
|
-
|
|
1037
|
-
|
|
952
|
+
export function watchSpec(env, forge, envs) {
|
|
953
|
+
const held = [[env, "reader"]];
|
|
954
|
+
const logins = loginsOf(envs, held);
|
|
955
|
+
const login = loginSteps(forge, logins);
|
|
956
|
+
// GitLab: a script line each, as the job's own lines are; GitHub and Forgejo: a named step each.
|
|
957
|
+
const steps = forge === "gitlab" ? login.steps.flatMap((st) => st.lines.map((run) => ({ run }))) : login.steps.map((st) => ({ name: st.name, run: st.lines.join("\n") }));
|
|
958
|
+
const setup = steps.length > 0 ? { setup: steps } : {};
|
|
959
|
+
if (forge === "gitlab") {
|
|
960
|
+
const clouds = cloudsOf(envs, held);
|
|
961
|
+
return {
|
|
962
|
+
name: `watch-${env}`,
|
|
963
|
+
...setup,
|
|
964
|
+
...(Object.keys(login.variables).length > 0 ? { variables: login.variables } : {}),
|
|
965
|
+
...(clouds.length > 0 ? { gitlab: { idTokens: idTokens(clouds, logins) } } : {}),
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
const creds = envs.credentials?.[env];
|
|
1038
969
|
// The job's token, for the tracking issue: GitHub grants it issues: write here, Forgejo's can write already.
|
|
1039
970
|
return {
|
|
1040
971
|
name: `watch-${env}`,
|
|
1041
|
-
variables: { ...secrets([...readerVariables(env, dialect, creds), ...WEBHOOK_VARIABLES]), GITHUB_TOKEN: "${{ github.token }}" },
|
|
972
|
+
variables: { ...secrets([...readerVariables(env, envs.dialect, creds), ...WEBHOOK_VARIABLES]), GITHUB_TOKEN: "${{ github.token }}" },
|
|
1042
973
|
...(forge === "github" ? { permissions: { issues: "write", ...(creds?.reader.cloud ? { "id-token": "write" } : {}) } } : {}),
|
|
974
|
+
...setup,
|
|
1043
975
|
};
|
|
1044
976
|
}
|
|
1045
|
-
/** A GitHub workflow's top-level `permissions:` with `id-token: write` added, when a job holds a cloud-minted role. */
|
|
1046
|
-
function withIdToken(forge, top, clouds) {
|
|
1047
|
-
if (forge !== "github" || clouds.length === 0)
|
|
1048
|
-
return top;
|
|
1049
|
-
const added = top.replace(/^permissions:\n((?: {2}\S.*\n)*)/m, (_m, scopes) => `permissions:\n${scopes} id-token: write\n`);
|
|
1050
|
-
if (added === top)
|
|
1051
|
-
throw new Error("github: the apply waves have no top-level permissions to add id-token: write to");
|
|
1052
|
-
return added;
|
|
1053
|
-
}
|
|
1054
|
-
/**
|
|
1055
|
-
* A GitHub or Forgejo watch file with the cloud login (#132) before the
|
|
1056
|
-
* job's chant run, when its reader is cloud-minted and logs in. Parsed and
|
|
1057
|
-
* emitted again, checked against chant's text first.
|
|
1058
|
-
*/
|
|
1059
|
-
function withWatchLogin(forge, yaml, env, envs) {
|
|
1060
|
-
const login = rawLogin(forge, loginsOf(envs, [[env, "reader"]]));
|
|
1061
|
-
if (login.length === 0)
|
|
1062
|
-
return yaml;
|
|
1063
|
-
const at = yaml.indexOf("\njobs:\n");
|
|
1064
|
-
if (at < 0)
|
|
1065
|
-
throw new Error(`${forge}: the watch for ${env} has no jobs`);
|
|
1066
|
-
const doc = parseYAMLDocument(yaml);
|
|
1067
|
-
const top = yaml.slice(0, at + 1);
|
|
1068
|
-
const emitJobs = () => withPinComments(yaml, `${emitYAMLEntry("jobs", doc.jobs)}\n`);
|
|
1069
|
-
if (`${top}${emitJobs()}` !== yaml)
|
|
1070
|
-
throw new Error(`${forge}: the watch for ${env} does not emit back to chant's text`);
|
|
1071
|
-
const job = doc.jobs[`watch-${env}`];
|
|
1072
|
-
if (!job)
|
|
1073
|
-
throw new Error(`${forge}: the watch for ${env} has no watch-${env} job`);
|
|
1074
|
-
insertSteps(job.steps, login, runsChant, `${forge}: watch-${env}`);
|
|
1075
|
-
return `${top}${emitJobs()}`;
|
|
1076
|
-
}
|
|
1077
|
-
/** The GitLab watch file with `id_tokens` (and the cloud login, #132) on each watch job whose reader is cloud-minted. Parsed and emitted again, checked against chant's text first. */
|
|
1078
|
-
function withWatchIdTokens(yaml, envs) {
|
|
1079
|
-
const clouds = (env) => cloudsOf(envs, [[env, "reader"]]);
|
|
1080
|
-
if (!envs.names.some((env) => clouds(env).length > 0))
|
|
1081
|
-
return yaml;
|
|
1082
|
-
const body = yaml.search(/^[^#\n]/m);
|
|
1083
|
-
const header = yaml.slice(0, body);
|
|
1084
|
-
const doc = parseYAMLDocument(yaml);
|
|
1085
|
-
const emit = (d) => withPinComments(yaml, `${header}${Object.entries(d).map(([k, v]) => emitYAMLEntry(k, v)).join("\n\n")}\n`);
|
|
1086
|
-
if (emit(doc) !== yaml)
|
|
1087
|
-
throw new Error("gitlab: the watch file does not emit back to chant's text");
|
|
1088
|
-
for (const env of envs.names) {
|
|
1089
|
-
const job = doc[`watch-${env}`];
|
|
1090
|
-
if (clouds(env).length === 0 || job === undefined)
|
|
1091
|
-
continue;
|
|
1092
|
-
const logins = loginsOf(envs, [[env, "reader"]]);
|
|
1093
|
-
const login = gitlabLogin(logins);
|
|
1094
|
-
insertLines(job.script, login.lines, (l) => l.startsWith("chant run "), `gitlab: watch-${env}`);
|
|
1095
|
-
if (Object.keys(login.variables).length > 0)
|
|
1096
|
-
job.variables = { ...job.variables, ...login.variables };
|
|
1097
|
-
Object.assign(job, { id_tokens: idTokens(clouds(env), logins) });
|
|
1098
|
-
}
|
|
1099
|
-
return emit(doc);
|
|
1100
|
-
}
|
|
1101
977
|
/**
|
|
1102
|
-
* The drift watches, through chant's
|
|
1103
|
-
* `yodel chant run watch-<env>` where chant's runs `chant run watch-<env
|
|
1104
|
-
* so the Op's statuses and notices say
|
|
978
|
+
* The drift watches, through chant's generateOpsPipeline: each job runs
|
|
979
|
+
* `yodel chant run watch-<env>` where chant's runs `chant run watch-<env>`
|
|
980
|
+
* (the generator's `runCommand`), so the Op's statuses and notices say
|
|
981
|
+
* yodel (#289).
|
|
1105
982
|
*
|
|
1106
983
|
* The job stays chant's generateOpsPipeline and its last line stays `yodel
|
|
1107
984
|
* drift <env> --issue`, which plans the build for ClickHouse grant drift
|
|
@@ -1110,16 +987,17 @@ function withWatchIdTokens(yaml, envs) {
|
|
|
1110
987
|
* sql lexicon's live diff, the watch moves onto chant's drift job with
|
|
1111
988
|
* `stages.drift` and the workaround goes.
|
|
1112
989
|
*/
|
|
1113
|
-
export async function watchPipelines(dir, envs_
|
|
1114
|
-
const {
|
|
990
|
+
export async function watchPipelines(dir, envs_) {
|
|
991
|
+
const { names: envs } = envs_;
|
|
1115
992
|
const tc = toolchainOf(envs_);
|
|
1116
993
|
const { generateOpsPipeline } = (await import("@intentius/chant/op"));
|
|
1117
994
|
const out = [];
|
|
1118
995
|
const emit = async (forge, specs, extraScript) => {
|
|
1119
996
|
const result = await generateOpsPipeline(specs, forge, {
|
|
1120
997
|
image: tc.image,
|
|
1121
|
-
beforeScript: [...installLines(tc, forge),
|
|
998
|
+
beforeScript: [...installLines(tc, forge), fetchApprovals(tc), NO_PUSH],
|
|
1122
999
|
extraScript,
|
|
1000
|
+
runCommand: [...YODEL_WORDS.bin.split(" "), "run", "{name}"],
|
|
1123
1001
|
...(forge === "gitlab" ? { opsStage: "ops", opsFileName: GITLAB_WATCH_FILE } : {}),
|
|
1124
1002
|
}, dir);
|
|
1125
1003
|
if (!result.success || !result.files)
|
|
@@ -1127,18 +1005,62 @@ export async function watchPipelines(dir, envs_, product) {
|
|
|
1127
1005
|
for (const file of result.files) {
|
|
1128
1006
|
const at = forge === "gitlab" ? GITLAB_WATCH_FILE : `${forge === "github" ? ".github" : ".forgejo"}/workflows/${file.name}`;
|
|
1129
1007
|
const yaml = file.yaml.endsWith("\n") ? file.yaml : `${file.yaml}\n`;
|
|
1130
|
-
|
|
1131
|
-
const env = file.name.replace(/^watch-|\.yml$/g, "");
|
|
1132
|
-
out.push({ path: at, content: `${HEADER.join("\n")}\n${withBin(product, forge === "gitlab" ? withWatchIdTokens(yaml, envs_) : withWatchLogin(forge, yaml, env, envs_))}` });
|
|
1008
|
+
out.push({ path: at, content: `${HEADER.join("\n")}\n${yaml}` });
|
|
1133
1009
|
}
|
|
1134
1010
|
};
|
|
1135
1011
|
// `chant run` exits 0 when a watch finds drift; the last line, yodel drift, fails the job then.
|
|
1136
1012
|
for (const forge of ["github", "forgejo"]) {
|
|
1137
1013
|
for (const env of envs)
|
|
1138
|
-
await emit(forge, [watchSpec(env,
|
|
1014
|
+
await emit(forge, [watchSpec(env, forge, envs_)], [watchDrift(env)]);
|
|
1139
1015
|
}
|
|
1140
1016
|
// GitLab: one file for every watch, so the last line takes the environment from the job's own name.
|
|
1141
|
-
await emit("gitlab", envs.map((env) => watchSpec(env,
|
|
1017
|
+
await emit("gitlab", envs.map((env) => watchSpec(env, "gitlab", envs_)), [watchDrift('"${CI_JOB_NAME#watch-}"')]);
|
|
1018
|
+
return out;
|
|
1019
|
+
}
|
|
1020
|
+
/** Whether `/yodel new` gets chant's commit job (#312): `ci.respond.new` is not `off`. */
|
|
1021
|
+
export const respondsNew = (envs) => envs.checkOnly !== true && (envs.respondNew ?? "comment") !== "off";
|
|
1022
|
+
/** The environments whose reader's password a cloud token source mints, which chant's commit job gets no identity for yet. */
|
|
1023
|
+
const cloudReaders = (envs) => envs.names.filter((env) => envs.credentials?.[env]?.reader.cloud !== undefined);
|
|
1024
|
+
/**
|
|
1025
|
+
* What answers `/yodel rebase` (#313): `ci.respond.rebase`, by default
|
|
1026
|
+
* `comment`. The rebase reads every environment's history with its reader,
|
|
1027
|
+
* and chant's commit job takes no cloud identity yet, so with a
|
|
1028
|
+
* cloud-minted reader the default is `off`, and asking for it is refused.
|
|
1029
|
+
*/
|
|
1030
|
+
export function rebaseRespond(envs) {
|
|
1031
|
+
if (envs.checkOnly === true)
|
|
1032
|
+
return "off";
|
|
1033
|
+
const cloud = cloudReaders(envs);
|
|
1034
|
+
if (cloud.length === 0)
|
|
1035
|
+
return envs.respondRebase ?? "comment";
|
|
1036
|
+
if (envs.respondRebase === undefined || envs.respondRebase === "off")
|
|
1037
|
+
return "off";
|
|
1038
|
+
throw new Error(`yodel.config.ts ci.respond.rebase: ${envs.respondRebase} reads each environment's history in chant's commit job, and ${cloud.join(", ")}'s reader mints its password from a cloud identity, which that job does not get; set ci.respond.rebase: "off"`);
|
|
1039
|
+
}
|
|
1040
|
+
/**
|
|
1041
|
+
* `/yodel new` and `/yodel rebase`, chant's commit job (#312, #313,
|
|
1042
|
+
* ./commit.ts): a workflow per job on GitHub and Forgejo, and a file per
|
|
1043
|
+
* word GitLab's pipeline includes.
|
|
1044
|
+
*/
|
|
1045
|
+
export async function commitPipelines(dir, envs_) {
|
|
1046
|
+
const respondRebase = rebaseRespond(envs_);
|
|
1047
|
+
if (!respondsNew(envs_) && respondRebase === "off")
|
|
1048
|
+
return [];
|
|
1049
|
+
const tc = toolchainOf(envs_);
|
|
1050
|
+
// Both words read every applied environment's history with its reader. A cloud-minted reader gets no identity there, so then /yodel new reads none and /yodel rebase is off.
|
|
1051
|
+
const readers = cloudReaders(envs_).length > 0 ? undefined : { envs: envs_.names, variables: envs_.names.flatMap((env) => readerVariables(env, envs_.dialect, envs_.credentials?.[env])) };
|
|
1052
|
+
const r = { dir: resolve(dir), respond: respondsNew(envs_) ? (envs_.respondNew ?? "comment") : "off", respondRebase, ...(readers ? { readers } : {}), image: tc.image, yodelImage: tc.yodelImage };
|
|
1053
|
+
const out = [];
|
|
1054
|
+
for (const [forge, word] of FORGES.flatMap((f) => ["new", "rebase"].map((w) => [f, w]))) {
|
|
1055
|
+
for (const file of await commitFiles(r, forge, word)) {
|
|
1056
|
+
const at = forge === "gitlab" ? GITLAB_COMMIT_FILES[word] : `${forge === "github" ? ".github" : ".forgejo"}/workflows/${file.name}`;
|
|
1057
|
+
const yaml = file.yaml.endsWith("\n") ? file.yaml : `${file.yaml}\n`;
|
|
1058
|
+
const token = forge === "gitlab"
|
|
1059
|
+
? [`# The push job reads ${COMMIT_TOKEN_ENV}: a project access token with write_repository and api,`, `# as a protected, masked CI/CD variable (docs/workflows.md, /yodel ${word}).`]
|
|
1060
|
+
: [`# The push job reads the ${COMMIT_TOKEN_ENV} secret: a token of a person or an app that can push`, `# to the repository; a push with the job's own token would start no pipeline (docs/workflows.md, /yodel ${word}).`];
|
|
1061
|
+
out.push({ path: at, content: `${HEADER.join("\n")}\n${token.join("\n")}\n${yaml}` });
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1142
1064
|
return out;
|
|
1143
1065
|
}
|
|
1144
1066
|
// ── The project ─────────────────────────────────────────────────────────────
|
|
@@ -1194,7 +1116,7 @@ export async function environments(dir) {
|
|
|
1194
1116
|
...(Object.keys(credentials).length > 0 ? { credentials } : {}),
|
|
1195
1117
|
replay,
|
|
1196
1118
|
...(hasTests(dir) ? { tests: true } : {}),
|
|
1197
|
-
...(existsSync(
|
|
1119
|
+
...(existsSync(sqlTypesPath(dir, config)) ? { typedColumns: true } : {}),
|
|
1198
1120
|
waves: await withTenants(dir, await readWaves(dir, envs)),
|
|
1199
1121
|
forges: ci?.forges ?? FORGES,
|
|
1200
1122
|
...(ci?.jobs ? { jobs: await loadProjectJobs(dir, ci.jobs) } : {}),
|
|
@@ -1204,6 +1126,8 @@ export async function environments(dir) {
|
|
|
1204
1126
|
...(ci?.apply === false ? { apply: false } : {}),
|
|
1205
1127
|
...(check ? { check: true } : {}),
|
|
1206
1128
|
...(ci?.tools && ci.tools.length > 0 ? { tools: ci.tools } : {}),
|
|
1129
|
+
...(ci?.respond?.new ? { respondNew: ci.respond.new } : {}),
|
|
1130
|
+
...(ci?.respond?.rebase ? { respondRebase: ci.respond.rebase } : {}),
|
|
1207
1131
|
};
|
|
1208
1132
|
}
|
|
1209
1133
|
/** The roles of each environment whose profile is made with credentials(). */
|
|
@@ -1262,8 +1186,7 @@ export function review(envs) {
|
|
|
1262
1186
|
}
|
|
1263
1187
|
/**
|
|
1264
1188
|
* The workspace declaration with yodel's check presets in `ci.hooks.check`
|
|
1265
|
-
* (#294), or undefined when the
|
|
1266
|
-
* project has no declaration. The hooks are one list for every forge: the
|
|
1189
|
+
* (#294), or undefined when the project has no declaration. The hooks are one list for every forge: the
|
|
1267
1190
|
* lint and check presets print with `--format forge`, so a GitHub or
|
|
1268
1191
|
* Forgejo job annotates the files and a GitLab job writes the code quality
|
|
1269
1192
|
* report its artifact keeps.
|
|
@@ -1271,8 +1194,6 @@ export function review(envs) {
|
|
|
1271
1194
|
export async function checkHooksDeclaration(dir, envs_, declaration) {
|
|
1272
1195
|
const chant = await chantCheckHooks();
|
|
1273
1196
|
const file = declarationFile(dir);
|
|
1274
|
-
if (!chant)
|
|
1275
|
-
return undefined;
|
|
1276
1197
|
if (file)
|
|
1277
1198
|
return { path: file, content: declarationWithHooks(chant, dir, file, checkHooksOf(envs_)) };
|
|
1278
1199
|
// A declaration `yodel upgrade` adds, rendered before it is written (#298).
|
|
@@ -1290,12 +1211,9 @@ export function forgeOf(path) {
|
|
|
1290
1211
|
return "gitlab";
|
|
1291
1212
|
return undefined;
|
|
1292
1213
|
}
|
|
1293
|
-
/** chant's product pipeline (#289), which every pipeline renders through
|
|
1214
|
+
/** chant's product pipeline (#289), which every pipeline renders through. */
|
|
1294
1215
|
export async function requireProduct() {
|
|
1295
|
-
|
|
1296
|
-
if (!product)
|
|
1297
|
-
throw new Error(`the installed chant has no product pipeline (@intentius/chant/ci-product), and yodel ci renders every pipeline on it from chant ${CHANT_CI_FLOOR}. Install it, then run yodel upgrade:\n ${installLine()}`);
|
|
1298
|
-
return product;
|
|
1216
|
+
return chantProduct();
|
|
1299
1217
|
}
|
|
1300
1218
|
/**
|
|
1301
1219
|
* Every file `yodel ci` writes, through chant's product pipeline (#289).
|
|
@@ -1304,9 +1222,12 @@ export async function requireProduct() {
|
|
|
1304
1222
|
* check hooks into when the project has none on disk: the one `yodel
|
|
1305
1223
|
* upgrade` adds (#298). A project with no declaration, in its directory or
|
|
1306
1224
|
* given here, keeps the lint job's own steps ({@link checkHooksDeclaration}).
|
|
1225
|
+
* `options.respondNew` and `options.respondRebase` stand in for yodel.config.ts `ci.respond`.
|
|
1307
1226
|
*/
|
|
1308
1227
|
export async function render(dir, options = {}) {
|
|
1309
|
-
const
|
|
1228
|
+
const read = await environments(dir);
|
|
1229
|
+
// The starter templates render as the release before #312 did until the release that ships /yodel new renders them (test/template.test.ts).
|
|
1230
|
+
const envs = { ...read, ...(options.respondNew ? { respondNew: options.respondNew } : {}), ...(options.respondRebase ? { respondRebase: options.respondRebase } : {}) };
|
|
1310
1231
|
const forges = envs.forges ?? FORGES;
|
|
1311
1232
|
if (envs.checkOnly)
|
|
1312
1233
|
return review(envs).filter((f) => forges.includes(forgeOf(f.path)));
|
|
@@ -1315,10 +1236,19 @@ export async function render(dir, options = {}) {
|
|
|
1315
1236
|
const hooks = await checkHooksDeclaration(dir, envs, options.declaration);
|
|
1316
1237
|
const reviewed = hooks ? { ...envs, checkHooks: true } : envs;
|
|
1317
1238
|
// ci.apply: false (#175): no waves spec and no apply pipeline on any forge.
|
|
1318
|
-
const files = [
|
|
1319
|
-
|
|
1239
|
+
const files = [
|
|
1240
|
+
...review(reviewed),
|
|
1241
|
+
...(hooks ? [hooks] : []),
|
|
1242
|
+
...(rendersApply(envs) ? await applyPipelines(dir, envs, product) : []),
|
|
1243
|
+
...(await watchPipelines(dir, envs)),
|
|
1244
|
+
...(await commitPipelines(dir, envs)),
|
|
1245
|
+
];
|
|
1246
|
+
// Each pinned `uses:` line with its release beside it, as chant writes them (#319).
|
|
1247
|
+
return files
|
|
1248
|
+
.filter((f) => {
|
|
1320
1249
|
const forge = forgeOf(f.path);
|
|
1321
1250
|
return forge === undefined || forges.includes(forge);
|
|
1322
|
-
})
|
|
1251
|
+
})
|
|
1252
|
+
.map((f) => (f.path.endsWith(".yml") ? { ...f, content: tagComments(f.content) } : f));
|
|
1323
1253
|
}
|
|
1324
1254
|
//# sourceMappingURL=render.js.map
|