@intentius/sql-yodeler 0.13.2 → 0.13.4
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/chant/build.d.ts +1 -0
- package/dist/chant/build.js +2 -0
- package/dist/chant/build.js.map +1 -1
- package/dist/chant/drift.d.ts +13 -41
- package/dist/chant/drift.js +21 -117
- package/dist/chant/drift.js.map +1 -1
- package/dist/ci/check-hooks.js +4 -2
- package/dist/ci/check-hooks.js.map +1 -1
- package/dist/ci/render.d.ts +57 -20
- package/dist/ci/render.js +215 -138
- package/dist/ci/render.js.map +1 -1
- package/dist/ci-words.d.ts +10 -0
- package/dist/ci-words.js +10 -0
- package/dist/ci-words.js.map +1 -1
- package/dist/commands/ci.js +20 -42
- package/dist/commands/ci.js.map +1 -1
- package/dist/commands/drift.d.ts +1 -1
- package/dist/commands/drift.js +5 -41
- package/dist/commands/drift.js.map +1 -1
- package/dist/commands/new.js +6 -4
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/plan.js +79 -80
- package/dist/commands/plan.js.map +1 -1
- package/dist/config/define.d.ts +29 -0
- package/dist/config/define.js.map +1 -1
- package/dist/config/load.js +20 -3
- package/dist/config/load.js.map +1 -1
- package/dist/declarative/plan.d.ts +2 -2
- package/dist/declarative/plan.js +2 -2
- package/dist/mcp/tools.js +2 -2
- package/dist/mcp/tools.js.map +1 -1
- package/dist/notify/index.d.ts +4 -0
- package/dist/notify/index.js +3 -1
- package/dist/notify/index.js.map +1 -1
- package/dist/pr/forge.d.ts +1 -1
- package/dist/pr/forge.js +1 -1
- package/dist/pr/issue.d.ts +7 -5
- package/dist/pr/issue.js +16 -9
- package/dist/pr/issue.js.map +1 -1
- package/dist/pr/model.d.ts +1 -5
- package/dist/pr/model.js +2 -7
- package/dist/pr/model.js.map +1 -1
- package/dist/pr/note.d.ts +25 -9
- package/dist/pr/note.js +56 -21
- package/dist/pr/note.js.map +1 -1
- package/dist/pr/render.d.ts +4 -6
- package/dist/pr/render.js +4 -10
- package/dist/pr/render.js.map +1 -1
- package/dist/versioned/explain.d.ts +1 -9
- package/dist/versioned/explain.js +1 -20
- package/dist/versioned/explain.js.map +1 -1
- package/package.json +7 -7
- package/schemas/drift.schema.json +9 -5
- package/schemas/plan.schema.json +1 -1
- package/dist/pr/overdue.d.ts +0 -41
- package/dist/pr/overdue.js +0 -46
- package/dist/pr/overdue.js.map +0 -1
package/dist/ci/render.js
CHANGED
|
@@ -33,9 +33,10 @@
|
|
|
33
33
|
* - yodel-pr: on a pull (merge) request, `yodel ci --check` (these files are
|
|
34
34
|
* what yodel ci renders), `yodel lint`, and the replay check into a
|
|
35
35
|
* throwaway server the job starts (the `replay` profile), then for each
|
|
36
|
-
* environment
|
|
37
|
-
*
|
|
38
|
-
* that
|
|
36
|
+
* environment chant's product plan ({@link productPlanOptions}): a plan
|
|
37
|
+
* job, holding that environment's reader credentials and no forge token,
|
|
38
|
+
* that runs `yodel plan <env> --pr-note`, and a note job that posts the
|
|
39
|
+
* pending migrations and the digest to approve.
|
|
39
40
|
* - yodel-apply: on a push to main, one job per wave, each needing the one
|
|
40
41
|
* before, running `yodel chant run wave`: through the sql lexicon's
|
|
41
42
|
* `sql-migrate` capability it plans the environment (`yodel apply <env>
|
|
@@ -75,13 +76,13 @@
|
|
|
75
76
|
* yodel ci renders through chant's product pipeline (chant#4550) with
|
|
76
77
|
* yodel's words (#289, ../ci-words.ts): {@link productWaves}.
|
|
77
78
|
*/
|
|
78
|
-
import { existsSync } from "node:fs";
|
|
79
|
-
import { join, resolve } from "node:path";
|
|
79
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
80
|
+
import { join, relative, resolve, sep } from "node:path";
|
|
80
81
|
import { pathToFileURL } from "node:url";
|
|
81
82
|
import { APPROVAL_MODES, WAVE_GATES, waveGateHint } from "../config/define.js";
|
|
82
83
|
import { commitFiles, COMMIT_TOKEN_ENV, GITLAB_COMMIT_FILES } from "./commit.js";
|
|
83
84
|
import { stepHooks } from "../apply-steps/index.js";
|
|
84
|
-
import { CLOUD_OF, jobLogins, loginSteps, tradeIdTokens } from "./login.js";
|
|
85
|
+
import { CLOUD_OF, forgejoLoginSpec, jobLogins, loginSteps, tradeIdTokens, tradeSpec } from "./login.js";
|
|
85
86
|
import { RECORD_PLANS_ENV } from "../approval-mode/index.js";
|
|
86
87
|
import { cloudToken, credentialsOf, roleVariables } from "../credentials.js";
|
|
87
88
|
import { loadYodelConfig } from "../config/load.js";
|
|
@@ -95,7 +96,14 @@ import { forgejoSerializer } from "@intentius/chant-lexicon-forgejo/serializer";
|
|
|
95
96
|
import { Artifacts as GitLabArtifacts, Image, Job as GitLabJob, Pipeline as GitLabPipeline, Rule, Service as GitLabService, Workflow as GitLabWorkflow, WorkflowRule, } from "@intentius/chant-lexicon-gitlab";
|
|
96
97
|
import { gitlabSerializer } from "@intentius/chant-lexicon-gitlab/serializer";
|
|
97
98
|
import { sqlTypesPath } from "@intentius/chant-lexicon-sql/sql-types";
|
|
98
|
-
import {
|
|
99
|
+
import { generateProductPlanPipeline } from "@intentius/chant-lexicon-github/components/product-plan-pipeline";
|
|
100
|
+
import { emitWorkflowYAML } from "@intentius/chant-lexicon-github/components/ci-jobs";
|
|
101
|
+
import { generateForgejoProductPlanPipeline } from "@intentius/chant-lexicon-forgejo/components/product-plan-pipeline";
|
|
102
|
+
import { generateGitlabProductPlanPipeline } from "@intentius/chant-lexicon-gitlab/components/product-plan-pipeline";
|
|
103
|
+
import { emitGitlabFile } from "@intentius/chant-lexicon-gitlab/components/ci-jobs";
|
|
104
|
+
import { parseYAML } from "@intentius/chant/yaml";
|
|
105
|
+
import { chantProduct, WAVE_WORDS, YODEL_NOTE_MARKER, YODEL_PR_ENV, YODEL_WORDS } from "../ci-words.js";
|
|
106
|
+
import { SUBJECT_PART_WORDS } from "../pr/note.js";
|
|
99
107
|
export const FORGES = ["github", "gitlab", "forgejo"];
|
|
100
108
|
/** The image every job runs in, where the forge runs jobs in a container. It needs git, so not -slim. */
|
|
101
109
|
export const IMAGE = "node:22-bookworm";
|
|
@@ -115,8 +123,6 @@ const CHECKOUT = usesRef(ACTION_PINS.checkout7);
|
|
|
115
123
|
const SETUP_NODE = usesRef(ACTION_PINS.setupNode7);
|
|
116
124
|
/** DEV for dev: the prefix of an environment's variables. */
|
|
117
125
|
export const prefixOf = (env) => env.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
118
|
-
/** The line the lint job runs chant's check moment with (#294): the hooks are read at the pull request's base. */
|
|
119
|
-
export const checkHooksLine = (forge) => `yodel chant ci check --base ${forge === "gitlab" ? "$CI_MERGE_REQUEST_DIFF_BASE_SHA" : "${{ github.event.pull_request.base.sha }}"}`;
|
|
120
126
|
/** yodel's checks and the project's tools as check-hook presets for `forge` (#294). */
|
|
121
127
|
export function checkHooksOf(envs_) {
|
|
122
128
|
const forge = "github";
|
|
@@ -171,13 +177,6 @@ const idTokens = (clouds, logins = []) => ({
|
|
|
171
177
|
});
|
|
172
178
|
/** The cloud logins (#132) of a job holding the roles `held`, from yodel.config.ts `ci.login`. */
|
|
173
179
|
const loginsOf = (envs, held) => jobLogins(envs.login, held, (env, role) => envs.credentials?.[env]?.[role].cloud);
|
|
174
|
-
/** A job's login steps as the github lexicon's Steps. */
|
|
175
|
-
const actionsLogin = (forge, logins) => loginSteps(forge, logins).steps.map((st) => new Step({ name: st.name, run: st.lines.join("\n") }));
|
|
176
|
-
/** A GitLab job's login: its script lines and its variables. */
|
|
177
|
-
const gitlabLogin = (logins) => {
|
|
178
|
-
const out = loginSteps("gitlab", logins);
|
|
179
|
-
return { lines: out.steps.flatMap((st) => st.lines), variables: out.variables };
|
|
180
|
-
};
|
|
181
180
|
/** The roles a pull request's plan job for `env` holds: the environment's reader and the reader of the one it requires. */
|
|
182
181
|
const planRoles = (waves, env) => [env, ...requiredOf(waves, env)].map((e) => [e, "reader"]);
|
|
183
182
|
/** The roles a wave job for `env` holds: the writer, and the reader of the environment it requires. */
|
|
@@ -293,7 +292,6 @@ export const reportArtifact = (job) => `yodel-report-${job}`;
|
|
|
293
292
|
/** 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
293
|
export const UPLOAD_ARTIFACT = usesRef(ACTION_PINS.uploadArtifact4);
|
|
295
294
|
export const FORGEJO_UPLOAD_ARTIFACT = `https://code.forgejo.org/${usesRef(ACTION_PINS.uploadArtifact3)}`;
|
|
296
|
-
const uploadArtifact = (forge) => (forge === "forgejo" ? FORGEJO_UPLOAD_ARTIFACT : UPLOAD_ARTIFACT);
|
|
297
295
|
/**
|
|
298
296
|
* The comment at the top of every file, as `#` lines. The files declared here
|
|
299
297
|
* (the review workflows and .gitlab-ci.yml) take theirs as the Workflow's or
|
|
@@ -301,14 +299,11 @@ const uploadArtifact = (forge) => (forge === "forgejo" ? FORGEJO_UPLOAD_ARTIFACT
|
|
|
301
299
|
* generateOpWavesPipeline and generateOpsPipeline write take no comment, so
|
|
302
300
|
* withHeader puts it above their YAML.
|
|
303
301
|
*/
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
];
|
|
302
|
+
/** The first line of every file yodel ci writes, by which it knows the ones it wrote (#348). */
|
|
303
|
+
export const PIPELINE_HEADER = "# Rendered by yodel ci from chant.config.ts, yodel.config.ts and ops/.";
|
|
304
|
+
const HEADER = [PIPELINE_HEADER, "# Edit those and render again; yodel ci --check says when this file is stale."];
|
|
308
305
|
/** The pipeline directories yodel ci writes into, besides the root `.gitlab-ci.yml`. */
|
|
309
306
|
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`);
|
|
312
307
|
const withHeader = (header, yaml) => `${[...header, ""].join("\n")}${yaml}`;
|
|
313
308
|
/** `#` lines as a declaration's `comment`: the text without its `# `, which the serializer writes back. */
|
|
314
309
|
const asComment = (header) => header.map((l) => l.replace(/^# ?/, "")).join("\n");
|
|
@@ -325,13 +320,6 @@ function renderActions(forge, workflow) {
|
|
|
325
320
|
const serializer = forge === "github" ? githubSerializer : forgejoSerializer;
|
|
326
321
|
return oneFile(forge, serializer.serialize(new Map([["workflow", workflow]])));
|
|
327
322
|
}
|
|
328
|
-
/** The report steps of a job: `yodel report` into REPORT_DIR and the artifact, whatever the job's outcome. */
|
|
329
|
-
function reportSteps(forge, env, job, tc) {
|
|
330
|
-
return [
|
|
331
|
-
new Step({ name: `yodel report ${env}`, if: "always()", run: reportCommand(env, tc) }),
|
|
332
|
-
new Step({ name: "Keep the report", if: "always()", uses: uploadArtifact(forge), with: { name: reportArtifact(job), path: REPORT_DIR, "if-no-files-found": "ignore" } }),
|
|
333
|
-
];
|
|
334
|
-
}
|
|
335
323
|
/** `inContainer`: the job runs in the toolchain's image, which has node, so it needs no setup-node. */
|
|
336
324
|
function setupSteps(inContainer, tc, approvals = true) {
|
|
337
325
|
const steps = [new Step({ uses: CHECKOUT, with: { "fetch-depth": 0 } })];
|
|
@@ -345,9 +333,78 @@ function setupSteps(inContainer, tc, approvals = true) {
|
|
|
345
333
|
/** 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. */
|
|
346
334
|
const inContainer = (forge, tc) => forge === "forgejo" || tc.yodelImage;
|
|
347
335
|
const runner = (container, tc) => ({ "runs-on": "ubuntu-latest", ...(container ? { container: tc.image } : {}) });
|
|
348
|
-
/**
|
|
349
|
-
|
|
350
|
-
|
|
336
|
+
/**
|
|
337
|
+
* The pull request plan on chant's product plan (chant issues 4799, 4963,
|
|
338
|
+
* 4972; sql-yodeler issue 345): one plan job and one note job per
|
|
339
|
+
* environment, each environment a target. The plan job holds the
|
|
340
|
+
* environment's reader (and the reader of the environment it requires) and
|
|
341
|
+
* no forge token, logs in to its cloud through chant's trade (Forgejo:
|
|
342
|
+
* chant's login from the runner's token file), runs the write probe, then
|
|
343
|
+
* `yodel plan <env> --pr-note`, which writes chant's plan note hand-off, and
|
|
344
|
+
* `yodel report` whatever the plan's exit. chant's note job posts the note,
|
|
345
|
+
* says what moved since the previous one from the plan's subject, warns of
|
|
346
|
+
* an overdue drift watch, and sets `yodel/plan/<env>`.
|
|
347
|
+
*/
|
|
348
|
+
export function productPlanOptions(forge, envs_, watches = []) {
|
|
349
|
+
const { dialect, names: envs, waves } = envs_;
|
|
350
|
+
const tc = toolchainOf(envs_);
|
|
351
|
+
const targets = envs.map((env) => {
|
|
352
|
+
const read = [env, ...requiredOf(waves, env)];
|
|
353
|
+
const roles = planRoles(waves, env);
|
|
354
|
+
const logins = loginsOf(envs_, roles);
|
|
355
|
+
// A cloud token source with no login reads the forge's OIDC token itself; Forgejo issues none.
|
|
356
|
+
const own = forge === "forgejo" ? [] : cloudsOf(envs_, roles).filter((c) => !logins.some((l) => l.cloud === CLOUD_OF[c]));
|
|
357
|
+
const forgejoLogin = forge === "forgejo" ? forgejoLoginSpec(logins) : {};
|
|
358
|
+
const names = [...read.flatMap((e) => readerVariables(e, dialect, envs_.credentials?.[e])), ...WEBHOOK_VARIABLES];
|
|
359
|
+
return {
|
|
360
|
+
name: env,
|
|
361
|
+
secrets: Object.fromEntries(names.map((n) => [n, n])),
|
|
362
|
+
writeProbe: writeProbe(read),
|
|
363
|
+
...(logins.length > 0 && forge !== "forgejo" ? { trade: tradeSpec(logins) } : {}),
|
|
364
|
+
...(Object.keys(forgejoLogin).length > 0 ? { login: forgejoLogin } : {}),
|
|
365
|
+
...(own.length > 0 ? { idTokens: Object.fromEntries(own.map((c) => [ID_TOKENS[c].variable, ID_TOKENS[c].aud])) } : {}),
|
|
366
|
+
};
|
|
367
|
+
});
|
|
368
|
+
// The check moment (#294) on chant's check job (chant issue 4964): the hooks the declaration at base names, beside the replay server.
|
|
369
|
+
// On GitLab the job keeps the lint hook's code quality report as artifacts:reports:codequality (#129, chant issue 4988).
|
|
370
|
+
const svc = REPLAY_SERVICE[dialect];
|
|
371
|
+
const replayServer = envs_.replay
|
|
372
|
+
? {
|
|
373
|
+
services: [{ name: svc.name, image: svc.image, ...(Object.keys(svc.env).length > 0 ? { env: svc.env } : {}), health: svc.health }],
|
|
374
|
+
env: { [`${variablePrefix(REPLAY_PROFILE, dialect)}_URL`]: svc.url(svc.name), ...svc.jobEnv },
|
|
375
|
+
before: [waitFor(svc.name, svc.port)],
|
|
376
|
+
}
|
|
377
|
+
: {};
|
|
378
|
+
const artifacts = forge === "gitlab" ? { artifacts: { reports: { codequality: CODE_QUALITY_FILE } } } : {};
|
|
379
|
+
const checkOptions = { ...replayServer, ...artifacts };
|
|
380
|
+
const checkJob = envs_.checkHooks ? (Object.keys(checkOptions).length > 0 ? checkOptions : true) : undefined;
|
|
381
|
+
return {
|
|
382
|
+
words: WAVE_WORDS,
|
|
383
|
+
branch: MAIN,
|
|
384
|
+
image: tc.image,
|
|
385
|
+
...(checkJob ? { checkJob } : {}),
|
|
386
|
+
// Signed checks (sql-yodeler issue 346): each target's plan as plan:<env> and policy:<env>, each hook by its name.
|
|
387
|
+
...(envs_.evidence ? { evidence: envs_.evidence } : {}),
|
|
388
|
+
...(envs_.refGate ? { refGateStatus: true } : {}),
|
|
389
|
+
// GitLab's runner clones one ref, so the plan job fetches the approvals itself; chant's checkout on GitHub and Forgejo fetches chant/lifecycle.
|
|
390
|
+
beforeScript: [...installLines(tc, forge), ...(forge === "gitlab" ? [fetchApprovals(tc)] : [])],
|
|
391
|
+
productPlan: {
|
|
392
|
+
command: "yodel plan {target} --pr-note {output}",
|
|
393
|
+
targets,
|
|
394
|
+
report: `mkdir -p {output}/report; yodel report {target} --json > {output}/report/{target}.json || true; yodel report {target} --html {output}/report/{target}.html || true`,
|
|
395
|
+
noteWords: { productMarker: YODEL_NOTE_MARKER, subjectParts: SUBJECT_PART_WORDS },
|
|
396
|
+
workflow: "yodel-pr",
|
|
397
|
+
concurrency: { group: "yodel-pr", cancelInProgress: true },
|
|
398
|
+
...(watches.length > 0 ? { watches: [...watches] } : {}),
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
/** The jobs of a workflow yodel declares with the github lexicon, as the plain mapping chant's workflow document holds. */
|
|
403
|
+
function jobsOf(forge, jobs) {
|
|
404
|
+
if (Object.keys(jobs).length === 0)
|
|
405
|
+
return {};
|
|
406
|
+
const yaml = renderActions(forge, new ActionsWorkflow({ name: "jobs", on: { pull_request: {} }, jobs }));
|
|
407
|
+
return (parseYAML(yaml).jobs ?? {});
|
|
351
408
|
}
|
|
352
409
|
/** The replay server's service and variables, for a job that replays into it. */
|
|
353
410
|
function replayService(dialect) {
|
|
@@ -380,9 +437,7 @@ function checkJob(forge, dialect, tc) {
|
|
|
380
437
|
],
|
|
381
438
|
});
|
|
382
439
|
}
|
|
383
|
-
function lintJob(forge, dialect, replay, tc, tests = false, typedColumns = false, check = false
|
|
384
|
-
if (hooks)
|
|
385
|
-
return checkHooksJob(forge, dialect, replay, tc);
|
|
440
|
+
function lintJob(forge, dialect, replay, tc, tests = false, typedColumns = false, check = false) {
|
|
386
441
|
// With the replay check, the job runs in IMAGE on every forge and reaches
|
|
387
442
|
// its replay server by the service's name on the job's own network. On
|
|
388
443
|
// GitHub's VM the service would be on localhost through a published port,
|
|
@@ -411,25 +466,6 @@ function lintJob(forge, dialect, replay, tc, tests = false, typedColumns = false
|
|
|
411
466
|
],
|
|
412
467
|
});
|
|
413
468
|
}
|
|
414
|
-
/**
|
|
415
|
-
* The lint job on chant's check moment (#294): the replay server when the
|
|
416
|
-
* project has one, then `yodel chant ci check`, which runs the hooks the
|
|
417
|
-
* declaration at the pull request's base names. The job runs in IMAGE with
|
|
418
|
-
* the replay server, as {@link lintJob} does.
|
|
419
|
-
*/
|
|
420
|
-
function checkHooksJob(forge, dialect, replay, tc) {
|
|
421
|
-
const container = replay || inContainer(forge, tc);
|
|
422
|
-
const steps = [...setupSteps(container, tc), new Step({ name: "Check hooks at the base (chant ci check)", run: checkHooksLine(forge) })];
|
|
423
|
-
if (!replay)
|
|
424
|
-
return new ActionsJob({ ...runner(container, tc), steps });
|
|
425
|
-
const { svc, services, env } = replayService(dialect);
|
|
426
|
-
return new ActionsJob({
|
|
427
|
-
...runner(container, tc),
|
|
428
|
-
services,
|
|
429
|
-
env,
|
|
430
|
-
steps: [...setupSteps(container, tc), new Step({ name: `Wait for the replay server (${svc.name})`, run: waitFor(svc.name, svc.port) }), new Step({ name: "Check hooks at the base (chant ci check)", run: checkHooksLine(forge) })],
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
469
|
/** The pull request workflow of a project that only runs yodel check (#1). */
|
|
434
470
|
function checkOnlyActions(forge, envs_) {
|
|
435
471
|
const jobs = { check: checkJob(forge, envs_.dialect, toolchainOf(envs_)) };
|
|
@@ -451,56 +487,38 @@ function checkOnlyActions(forge, envs_) {
|
|
|
451
487
|
});
|
|
452
488
|
return { path: `${forge === "github" ? ".github" : ".forgejo"}/workflows/yodel-pr.yml`, content: renderActions(forge, workflow) };
|
|
453
489
|
}
|
|
454
|
-
export function actionsReview(forge, envs_) {
|
|
490
|
+
export function actionsReview(forge, envs_, watches = []) {
|
|
455
491
|
const { dialect, names: envs, replay, waves, jobs: own } = envs_;
|
|
456
492
|
const tc = toolchainOf(envs_);
|
|
457
493
|
if (envs_.checkOnly)
|
|
458
494
|
return checkOnlyActions(forge, envs_);
|
|
459
|
-
const jobs = { lint: lintJob(forge, dialect, replay, tc, envs_.tests === true, envs_.typedColumns === true, envs_.check === true, envs_.checkHooks === true) };
|
|
460
|
-
for (const env of envs) {
|
|
461
|
-
const read = [env, ...requiredOf(waves, env)];
|
|
462
|
-
jobs[`plan-${env}`] = new ActionsJob({
|
|
463
|
-
...runner(inContainer(forge, tc), tc),
|
|
464
|
-
// The plan shows where each migration has run: the required environment's reader too.
|
|
465
|
-
env: secrets([...read.flatMap((e) => readerVariables(e, dialect, envs_.credentials?.[e])), ...WEBHOOK_VARIABLES]),
|
|
466
|
-
steps: [
|
|
467
|
-
// The plan explains what moved since an approval from git's history of migrations/.
|
|
468
|
-
...setupSteps(inContainer(forge, tc), tc),
|
|
469
|
-
// The cloud login (#132), when a reader here is cloud-minted.
|
|
470
|
-
...actionsLogin(forge, loginsOf(envs_, planRoles(waves, env))),
|
|
471
|
-
new Step({ name: "This job cannot write", run: writeProbe(read) }),
|
|
472
|
-
new Step({ name: `yodel plan ${env} --comment`, run: `yodel plan ${env} --comment`, env: commentToken(forge) }),
|
|
473
|
-
...reportSteps(forge, env, `plan-${env}`, tc),
|
|
474
|
-
],
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
Object.assign(jobs, ownJobs(own?.actions, jobs, "actions"));
|
|
478
495
|
const clouds = cloudsOf(envs_, envs.flatMap((env) => planRoles(waves, env)));
|
|
479
496
|
const header = [
|
|
480
497
|
...HEADER,
|
|
481
498
|
"#",
|
|
482
499
|
"# Pull requests: yodel lint and the replay check (into a throwaway server the",
|
|
483
|
-
"# lint job starts), and the plan
|
|
484
|
-
"# environment's reader credentials
|
|
485
|
-
"# job
|
|
486
|
-
"#
|
|
487
|
-
|
|
488
|
-
? ["# The comment is posted with the job's own token (Forgejo gives a same-repository", "# pull request one that can comment)."]
|
|
489
|
-
: []),
|
|
500
|
+
"# lint job starts), and the plan per environment on chant's product plan: a",
|
|
501
|
+
"# plan job with the environment's reader credentials and no forge token,",
|
|
502
|
+
"# then a note job that posts the note and the status yodel/plan/<env>. No job",
|
|
503
|
+
"# here holds a writer, and each plan job shows it first: yodel config check",
|
|
504
|
+
"# --write-probe tries a write and fails the job when the server lets it through.",
|
|
490
505
|
...identityHeader(forge, clouds),
|
|
491
506
|
];
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
507
|
+
const options = { ...productPlanOptions(forge, envs_, watches), header };
|
|
508
|
+
const { doc } = forge === "github" ? generateProductPlanPipeline(YODEL_PR_ENV, options) : generateForgejoProductPlanPipeline(YODEL_PR_ENV, options);
|
|
509
|
+
// yodel's lint job and the project's own jobs, declared with the github lexicon, beside chant's plan and note jobs.
|
|
510
|
+
// With the check moment (#294) the lint job is chant's check job (chant issue 4964), in chant's document.
|
|
511
|
+
const lint = envs_.checkHooks ? {} : jobsOf(forge, { lint: lintJob(forge, dialect, replay, tc, envs_.tests === true, envs_.typedColumns === true, envs_.check === true) });
|
|
512
|
+
const yodels = { ...lint, ...doc.jobsDoc };
|
|
513
|
+
const merged = {
|
|
514
|
+
...doc,
|
|
515
|
+
// A job without permissions of its own (lint, the project's) reads the repository and nothing else; chant's jobs name their own. Forgejo reads no permissions.
|
|
516
|
+
...(forge === "github" ? { permissions: { contents: "read" } } : {}),
|
|
517
|
+
jobsDoc: { ...yodels, ...jobsOf(forge, ownJobs(own?.actions, yodels, "actions")) },
|
|
518
|
+
};
|
|
501
519
|
return {
|
|
502
520
|
path: `${forge === "github" ? ".github" : ".forgejo"}/workflows/yodel-pr.yml`,
|
|
503
|
-
content:
|
|
521
|
+
content: emitWorkflowYAML(merged),
|
|
504
522
|
};
|
|
505
523
|
}
|
|
506
524
|
// ── GitLab CI ───────────────────────────────────────────────────────────────
|
|
@@ -555,36 +573,26 @@ export function gitlabPipeline(envs_) {
|
|
|
555
573
|
return { path: ".gitlab-ci.yml", content: oneFile("gitlab", gitlabSerializer.serialize(entities)) };
|
|
556
574
|
}
|
|
557
575
|
const check = envs_.check === true ? [checkCommand("gitlab")] : [];
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
rules: mr(),
|
|
562
|
-
...(replay
|
|
563
|
-
? {
|
|
564
|
-
script: envs_.checkHooks === true ? [waitFor(svc.name, svc.port), checkHooksLine("gitlab")] : [CI_CHECK, ...types, lintCommand("gitlab"), waitFor(svc.name, svc.port), REPLAY, ...(envs_.tests === true ? [TEST] : []), ...check],
|
|
565
|
-
services: [new GitLabService({ name: svc.image, alias: svc.name, variables: svc.env })],
|
|
566
|
-
variables: { [`${variablePrefix(REPLAY_PROFILE, dialect)}_URL`]: svc.url(svc.name), ...svc.jobEnv },
|
|
567
|
-
}
|
|
568
|
-
: { script: envs_.checkHooks === true ? [checkHooksLine("gitlab")] : [CI_CHECK, ...types, lintCommand("gitlab")] }),
|
|
569
|
-
// The code quality report, kept when lint fails too: that is when it has something to show.
|
|
570
|
-
artifacts: new GitLabArtifacts({ when: "always", reports: { codequality: CODE_QUALITY_FILE } }),
|
|
571
|
-
}));
|
|
572
|
-
for (const env of envs) {
|
|
573
|
-
const clouds = cloudsOf(envs_, planRoles(waves, env));
|
|
574
|
-
const logins = loginsOf(envs_, planRoles(waves, env));
|
|
575
|
-
const login = gitlabLogin(logins);
|
|
576
|
-
jobs.set(`plan-${env}`, new GitLabJob({
|
|
576
|
+
// With the check moment (#294) the lint job is chant's check job, in GITLAB_PLAN_FILE (chant issues 4964 and 4988).
|
|
577
|
+
if (envs_.checkHooks !== true) {
|
|
578
|
+
jobs.set("lint", new GitLabJob({
|
|
577
579
|
extends: ".yodel",
|
|
578
580
|
stage: "review",
|
|
579
581
|
rules: mr(),
|
|
580
|
-
...(
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
582
|
+
...(replay
|
|
583
|
+
? {
|
|
584
|
+
script: [CI_CHECK, ...types, lintCommand("gitlab"), waitFor(svc.name, svc.port), REPLAY, ...(envs_.tests === true ? [TEST] : []), ...check],
|
|
585
|
+
services: [new GitLabService({ name: svc.image, alias: svc.name, variables: svc.env })],
|
|
586
|
+
variables: { [`${variablePrefix(REPLAY_PROFILE, dialect)}_URL`]: svc.url(svc.name), ...svc.jobEnv },
|
|
587
|
+
}
|
|
588
|
+
: { script: [CI_CHECK, ...types, lintCommand("gitlab")] }),
|
|
589
|
+
// The code quality report, kept when lint fails too: that is when it has something to show.
|
|
590
|
+
artifacts: new GitLabArtifacts({ when: "always", reports: { codequality: CODE_QUALITY_FILE } }),
|
|
585
591
|
}));
|
|
586
592
|
}
|
|
587
|
-
|
|
593
|
+
// The plan jobs and their note jobs are chant's, in GITLAB_PLAN_FILE (sql-yodeler issue 345).
|
|
594
|
+
const plan = gitlabPlan(envs_);
|
|
595
|
+
for (const [name, job] of Object.entries(ownJobs(own?.gitlab, { ...Object.fromEntries(jobs), ...Object.fromEntries(plan.jobs.map((j) => [j, true])) }, "gitlab")))
|
|
588
596
|
jobs.set(name, job);
|
|
589
597
|
const apply = rendersApply(envs_);
|
|
590
598
|
const variables = envs.flatMap((env) => {
|
|
@@ -602,15 +610,16 @@ export function gitlabPipeline(envs_) {
|
|
|
602
610
|
const header = [
|
|
603
611
|
...HEADER,
|
|
604
612
|
"#",
|
|
613
|
+
...(envs_.checkHooks === true
|
|
614
|
+
? ["# Merge requests: chant's check job and each environment's plan on chant's"]
|
|
615
|
+
: ["# Merge requests: lint (stage review), and each environment's plan on chant's"]),
|
|
616
|
+
`# product plan (stage plan), in ${GITLAB_PLAN_FILE}. A merge request's own`,
|
|
617
|
+
"# pipeline holds no token for its notes: a pipeline schedule of the default",
|
|
618
|
+
`# branch with ${GITLAB_PLAN_NOTES_VAR}=1, which you create, posts every open merge`,
|
|
619
|
+
"# request's notes and sets yodel/plan/<env> (stage plan-note).",
|
|
605
620
|
...(apply
|
|
606
|
-
? [
|
|
607
|
-
|
|
608
|
-
`# default branch: the apply waves, one stage each, in ${GITLAB_APPLY_FILE}.`,
|
|
609
|
-
]
|
|
610
|
-
: [
|
|
611
|
-
"# Merge requests: lint and the plan comment (stage review). No apply",
|
|
612
|
-
"# pipeline (yodel.config.ts ci.apply: false): migrations are applied outside CI.",
|
|
613
|
-
]),
|
|
621
|
+
? [`# A push to the default branch: the apply waves, one stage each, in ${GITLAB_APPLY_FILE}.`]
|
|
622
|
+
: ["# No apply pipeline (yodel.config.ts ci.apply: false): migrations are applied outside CI."]),
|
|
614
623
|
`# The drift watches are in ${GITLAB_WATCH_FILE} (stage ops).`,
|
|
615
624
|
...(respondsNew(envs_) ? [`# /yodel new, chant's commit job, is in ${GITLAB_COMMIT_FILES.new} (stage ops).`] : []),
|
|
616
625
|
...(rebaseRespond(envs_) !== "off" ? [`# /yodel rebase, after the merge request's check, is in ${GITLAB_COMMIT_FILES.rebase} (stage ops).`] : []),
|
|
@@ -648,13 +657,32 @@ export function gitlabPipeline(envs_) {
|
|
|
648
657
|
const applyStages = apply ? [...plans, ...waveStages(waves), ...(envs_.resume ? [RESUME_STAGE] : [])] : [];
|
|
649
658
|
const pipeline = new GitLabPipeline({
|
|
650
659
|
comment: asComment(header),
|
|
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 }] : [])],
|
|
652
|
-
stages
|
|
660
|
+
include: [{ local: GITLAB_PLAN_FILE }, ...(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
|
+
// The plan file's stages (chant's plan and plan-note) right after review.
|
|
662
|
+
stages: [...new Set(["review", ...plan.stages, ...jobStages, ...applyStages, "ops"])],
|
|
653
663
|
variables: { GIT_DEPTH: "0" },
|
|
654
664
|
});
|
|
655
665
|
const entities = new Map([["pipeline", pipeline], ["workflow", workflow], ...jobs]);
|
|
656
666
|
return { path: ".gitlab-ci.yml", content: oneFile("gitlab", gitlabSerializer.serialize(entities)) };
|
|
657
667
|
}
|
|
668
|
+
/** The file .gitlab-ci.yml includes for the plan jobs and their note jobs, chant's product plan (sql-yodeler issue 345). */
|
|
669
|
+
export const GITLAB_PLAN_FILE = ".gitlab/yodel-plan.gitlab-ci.yml";
|
|
670
|
+
/** chant's name for the variable a plan notes pipeline sets. */
|
|
671
|
+
const GITLAB_PLAN_NOTES_VAR = "CHANT_PLAN_NOTES";
|
|
672
|
+
/**
|
|
673
|
+
* The plan on GitLab through chant's product plan: its jobs as
|
|
674
|
+
* {@link GITLAB_PLAN_FILE}, their names and their stages. chant's
|
|
675
|
+
* `workflow` and `stages` stay out of the file: .gitlab-ci.yml has the
|
|
676
|
+
* pipeline's own, with chant's stages after review, and its rules let the
|
|
677
|
+
* plan notes pipeline (a schedule of the default branch) run.
|
|
678
|
+
*/
|
|
679
|
+
export function gitlabPlan(envs_, watches = []) {
|
|
680
|
+
const { entries } = generateGitlabProductPlanPipeline(YODEL_PR_ENV, productPlanOptions("gitlab", envs_, watches));
|
|
681
|
+
const stages = (entries.find(([k]) => k === "stages")?.[1] ?? []);
|
|
682
|
+
const kept = entries.filter(([k]) => k !== "workflow" && k !== "stages");
|
|
683
|
+
const jobs = kept.map(([k]) => k).filter((k) => k !== "variables");
|
|
684
|
+
return { file: { path: GITLAB_PLAN_FILE, content: emitGitlabFile(kept, HEADER) }, jobs, stages };
|
|
685
|
+
}
|
|
658
686
|
/** The environment `env`'s wave requires, as a list. */
|
|
659
687
|
const requiredOf = (waves, env) => {
|
|
660
688
|
const r = waves.find((w) => w.env === env)?.requires;
|
|
@@ -841,6 +869,8 @@ export async function applyPipelines(dir, envs, product) {
|
|
|
841
869
|
beforeScript: [...installLines(tc, forge), fetchApprovals(tc)],
|
|
842
870
|
waveJobs: waveJobs(forge),
|
|
843
871
|
recordPlans: recordPlans(forge),
|
|
872
|
+
// Signed checks (sql-yodeler issue 346): each deciding wave signs plan:<wave> and policy:<wave>; on GitLab its <wave job>-evidence job, in chant-evidence.
|
|
873
|
+
...(envs.evidence ? { evidence: envs.evidence } : {}),
|
|
844
874
|
...(forge === "gitlab" ? { opsFileName: GITLAB_APPLY_FILE } : {}),
|
|
845
875
|
}, dir);
|
|
846
876
|
if (!result.success || !result.files)
|
|
@@ -914,8 +944,8 @@ export async function withTenants(dir, waves) {
|
|
|
914
944
|
// The forge lexicons serialize the jobs, and yodel's reports, logins and
|
|
915
945
|
// readers go in as generateOpWavesPipeline's inputs (#4791).
|
|
916
946
|
//
|
|
917
|
-
//
|
|
918
|
-
//
|
|
947
|
+
// The plan jobs are chant's product plan (sql-yodeler issue 345,
|
|
948
|
+
// {@link productPlanOptions}). Still yodel's own: the lint
|
|
919
949
|
// job's own steps for a project with no workspace declaration, which has
|
|
920
950
|
// no check hooks to run (#294); the watch until chant#4582
|
|
921
951
|
// ({@link watchPipelines}).
|
|
@@ -981,11 +1011,8 @@ export function watchSpec(env, forge, envs) {
|
|
|
981
1011
|
* yodel (#289).
|
|
982
1012
|
*
|
|
983
1013
|
* The job stays chant's generateOpsPipeline and its last line stays `yodel
|
|
984
|
-
* drift <env> --issue`, which
|
|
985
|
-
*
|
|
986
|
-
* --live` leaves ClickHouse::Grant out. Once chant#4582 puts grants in the
|
|
987
|
-
* sql lexicon's live diff, the watch moves onto chant's drift job with
|
|
988
|
-
* `stages.drift` and the workaround goes.
|
|
1014
|
+
* drift <env> --issue`, which compares with the history's recorded schema
|
|
1015
|
+
* and keeps the tracking issue.
|
|
989
1016
|
*/
|
|
990
1017
|
export async function watchPipelines(dir, envs_) {
|
|
991
1018
|
const { names: envs } = envs_;
|
|
@@ -1128,6 +1155,8 @@ export async function environments(dir) {
|
|
|
1128
1155
|
...(ci?.tools && ci.tools.length > 0 ? { tools: ci.tools } : {}),
|
|
1129
1156
|
...(ci?.respond?.new ? { respondNew: ci.respond.new } : {}),
|
|
1130
1157
|
...(ci?.respond?.rebase ? { respondRebase: ci.respond.rebase } : {}),
|
|
1158
|
+
...(ci?.evidence ? { evidence: ci.evidence } : {}),
|
|
1159
|
+
...(ci?.refGate === true ? { refGate: true } : {}),
|
|
1131
1160
|
};
|
|
1132
1161
|
}
|
|
1133
1162
|
/** The roles of each environment whose profile is made with credentials(). */
|
|
@@ -1180,9 +1209,56 @@ function ownJobs(own, yodels, what) {
|
|
|
1180
1209
|
}
|
|
1181
1210
|
return own;
|
|
1182
1211
|
}
|
|
1183
|
-
/**
|
|
1184
|
-
|
|
1185
|
-
|
|
1212
|
+
/**
|
|
1213
|
+
* The ref gate's rule (yodel.config.ts `ci.refGate`, chant issues 4913 and
|
|
1214
|
+
* 4978): chant's `refGateInitPlan` for main, needing current evidence of
|
|
1215
|
+
* each environment's plan and policy, `plan:<env>` and `policy:<env>`,
|
|
1216
|
+
* which each environment's note job signs. `.chant/trust.json` gets the rule
|
|
1217
|
+
* when it has none for main and is left as it is when it has one. The
|
|
1218
|
+
* pre-push hook is the person's to install (`chant workspace ref-gate
|
|
1219
|
+
* install`), so yodel ci writes no file in the git directory.
|
|
1220
|
+
*/
|
|
1221
|
+
async function refGateFiles(dir, envs) {
|
|
1222
|
+
const { refGateInitPlan } = await import("@intentius/chant/ref-gate-init");
|
|
1223
|
+
const sign = "open a pull request: its yodel-pr pipeline's note job signs it";
|
|
1224
|
+
const plan = refGateInitPlan(dir, {
|
|
1225
|
+
branch: MAIN,
|
|
1226
|
+
checks: [
|
|
1227
|
+
{ check: "plan", command: sign },
|
|
1228
|
+
{ check: "policy", command: sign },
|
|
1229
|
+
],
|
|
1230
|
+
targets: envs.names,
|
|
1231
|
+
prePush: false,
|
|
1232
|
+
chant: YODEL_WORDS.bin,
|
|
1233
|
+
...(envs.evidence?.runnerKeySecret ? { runnerKeySecret: envs.evidence.runnerKeySecret } : {}),
|
|
1234
|
+
});
|
|
1235
|
+
// chant names the files from git's top level, the real path, so the project's own is read the same way.
|
|
1236
|
+
const root = realpathSync(dir);
|
|
1237
|
+
return plan.files.filter((f) => !f.local).map((f) => ({ path: relative(root, f.path).split(sep).join("/"), content: f.content }));
|
|
1238
|
+
}
|
|
1239
|
+
/** The pull request pipelines, and GitLab's main file. `watches` are the drift watches the plan note checks for having stopped. */
|
|
1240
|
+
export function review(envs, watches = []) {
|
|
1241
|
+
return [
|
|
1242
|
+
actionsReview("github", envs, watches),
|
|
1243
|
+
actionsReview("forgejo", envs, watches),
|
|
1244
|
+
gitlabPipeline(envs),
|
|
1245
|
+
...(envs.checkOnly ? [] : [gitlabPlan(envs, watches).file]),
|
|
1246
|
+
];
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* The scheduled drift watches of the project's environments (chant#4289),
|
|
1250
|
+
* which chant's note job checks for having stopped (chant issue 4888): each
|
|
1251
|
+
* environment's WatchOp, found by its `Watch` and `Env` labels. Each is
|
|
1252
|
+
* scoped to its environment (`targets`, chant issue 4988), so an
|
|
1253
|
+
* environment's note warns of its own watch only.
|
|
1254
|
+
*/
|
|
1255
|
+
async function envWatches(dir, envs) {
|
|
1256
|
+
const { discoverOps } = await import("@intentius/chant/op/discover");
|
|
1257
|
+
const { scheduledWatches } = await import("@intentius/chant/op/schedule-overdue");
|
|
1258
|
+
const found = await discoverOps({ cwd: dir });
|
|
1259
|
+
const ops = [...found.ops.values()].map((o) => o.config).filter((o) => o.labels?.Watch === "true" && envs.includes(o.labels.Env ?? ""));
|
|
1260
|
+
const envOf = new Map(ops.map((o) => [o.name, o.labels?.Env ?? ""]));
|
|
1261
|
+
return scheduledWatches(ops).map((w) => ({ ...w, targets: [envOf.get(w.op) ?? ""] }));
|
|
1186
1262
|
}
|
|
1187
1263
|
/**
|
|
1188
1264
|
* The workspace declaration with yodel's check presets in `ci.hooks.check`
|
|
@@ -1237,11 +1313,12 @@ export async function render(dir, options = {}) {
|
|
|
1237
1313
|
const reviewed = hooks ? { ...envs, checkHooks: true } : envs;
|
|
1238
1314
|
// ci.apply: false (#175): no waves spec and no apply pipeline on any forge.
|
|
1239
1315
|
const files = [
|
|
1240
|
-
...review(reviewed),
|
|
1316
|
+
...review(reviewed, await envWatches(dir, envs.names)),
|
|
1241
1317
|
...(hooks ? [hooks] : []),
|
|
1242
1318
|
...(rendersApply(envs) ? await applyPipelines(dir, envs, product) : []),
|
|
1243
1319
|
...(await watchPipelines(dir, envs)),
|
|
1244
1320
|
...(await commitPipelines(dir, envs)),
|
|
1321
|
+
...(envs.refGate ? await refGateFiles(dir, envs) : []),
|
|
1245
1322
|
];
|
|
1246
1323
|
// Each pinned `uses:` line with its release beside it, as chant writes them (#319).
|
|
1247
1324
|
return files
|