@intentius/sql-yodeler 0.13.2 → 0.13.3
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/drift.d.ts +13 -41
- package/dist/chant/drift.js +21 -117
- package/dist/chant/drift.js.map +1 -1
- package/dist/ci/render.d.ts +57 -20
- package/dist/ci/render.js +206 -131
- 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/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,14 @@ 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
|
-
/**
|
|
119
|
-
|
|
126
|
+
/**
|
|
127
|
+
* GitLab's lint job on chant's check moment (#294): the hooks the
|
|
128
|
+
* declaration at the merge request's base names. GitHub and Forgejo run
|
|
129
|
+
* them in chant's check job (chant issue 4964), which signs them; GitLab's
|
|
130
|
+
* stays yodel's until chant's GitLab check job keeps the code quality report
|
|
131
|
+
* as `artifacts:reports:codequality`.
|
|
132
|
+
*/
|
|
133
|
+
const GITLAB_CHECK_HOOKS = "yodel chant ci check --base $CI_MERGE_REQUEST_DIFF_BASE_SHA";
|
|
120
134
|
/** yodel's checks and the project's tools as check-hook presets for `forge` (#294). */
|
|
121
135
|
export function checkHooksOf(envs_) {
|
|
122
136
|
const forge = "github";
|
|
@@ -171,13 +185,6 @@ const idTokens = (clouds, logins = []) => ({
|
|
|
171
185
|
});
|
|
172
186
|
/** The cloud logins (#132) of a job holding the roles `held`, from yodel.config.ts `ci.login`. */
|
|
173
187
|
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
188
|
/** The roles a pull request's plan job for `env` holds: the environment's reader and the reader of the one it requires. */
|
|
182
189
|
const planRoles = (waves, env) => [env, ...requiredOf(waves, env)].map((e) => [e, "reader"]);
|
|
183
190
|
/** The roles a wave job for `env` holds: the writer, and the reader of the environment it requires. */
|
|
@@ -293,7 +300,6 @@ export const reportArtifact = (job) => `yodel-report-${job}`;
|
|
|
293
300
|
/** 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
301
|
export const UPLOAD_ARTIFACT = usesRef(ACTION_PINS.uploadArtifact4);
|
|
295
302
|
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
303
|
/**
|
|
298
304
|
* The comment at the top of every file, as `#` lines. The files declared here
|
|
299
305
|
* (the review workflows and .gitlab-ci.yml) take theirs as the Workflow's or
|
|
@@ -301,14 +307,11 @@ const uploadArtifact = (forge) => (forge === "forgejo" ? FORGEJO_UPLOAD_ARTIFACT
|
|
|
301
307
|
* generateOpWavesPipeline and generateOpsPipeline write take no comment, so
|
|
302
308
|
* withHeader puts it above their YAML.
|
|
303
309
|
*/
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
];
|
|
310
|
+
/** The first line of every file yodel ci writes, by which it knows the ones it wrote (#348). */
|
|
311
|
+
export const PIPELINE_HEADER = "# Rendered by yodel ci from chant.config.ts, yodel.config.ts and ops/.";
|
|
312
|
+
const HEADER = [PIPELINE_HEADER, "# Edit those and render again; yodel ci --check says when this file is stale."];
|
|
308
313
|
/** The pipeline directories yodel ci writes into, besides the root `.gitlab-ci.yml`. */
|
|
309
314
|
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
315
|
const withHeader = (header, yaml) => `${[...header, ""].join("\n")}${yaml}`;
|
|
313
316
|
/** `#` lines as a declaration's `comment`: the text without its `# `, which the serializer writes back. */
|
|
314
317
|
const asComment = (header) => header.map((l) => l.replace(/^# ?/, "")).join("\n");
|
|
@@ -325,13 +328,6 @@ function renderActions(forge, workflow) {
|
|
|
325
328
|
const serializer = forge === "github" ? githubSerializer : forgejoSerializer;
|
|
326
329
|
return oneFile(forge, serializer.serialize(new Map([["workflow", workflow]])));
|
|
327
330
|
}
|
|
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
331
|
/** `inContainer`: the job runs in the toolchain's image, which has node, so it needs no setup-node. */
|
|
336
332
|
function setupSteps(inContainer, tc, approvals = true) {
|
|
337
333
|
const steps = [new Step({ uses: CHECKOUT, with: { "fetch-depth": 0 } })];
|
|
@@ -345,9 +341,77 @@ function setupSteps(inContainer, tc, approvals = true) {
|
|
|
345
341
|
/** 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
342
|
const inContainer = (forge, tc) => forge === "forgejo" || tc.yodelImage;
|
|
347
343
|
const runner = (container, tc) => ({ "runs-on": "ubuntu-latest", ...(container ? { container: tc.image } : {}) });
|
|
348
|
-
/**
|
|
349
|
-
|
|
350
|
-
|
|
344
|
+
/**
|
|
345
|
+
* The pull request plan on chant's product plan (chant issues 4799, 4963,
|
|
346
|
+
* 4972; sql-yodeler issue 345): one plan job and one note job per
|
|
347
|
+
* environment, each environment a target. The plan job holds the
|
|
348
|
+
* environment's reader (and the reader of the environment it requires) and
|
|
349
|
+
* no forge token, logs in to its cloud through chant's trade (Forgejo:
|
|
350
|
+
* chant's login from the runner's token file), runs the write probe, then
|
|
351
|
+
* `yodel plan <env> --pr-note`, which writes chant's plan note hand-off, and
|
|
352
|
+
* `yodel report` whatever the plan's exit. chant's note job posts the note,
|
|
353
|
+
* says what moved since the previous one from the plan's subject, warns of
|
|
354
|
+
* an overdue drift watch, and sets `yodel/plan/<env>`.
|
|
355
|
+
*/
|
|
356
|
+
export function productPlanOptions(forge, envs_, watches = []) {
|
|
357
|
+
const { dialect, names: envs, waves } = envs_;
|
|
358
|
+
const tc = toolchainOf(envs_);
|
|
359
|
+
const targets = envs.map((env) => {
|
|
360
|
+
const read = [env, ...requiredOf(waves, env)];
|
|
361
|
+
const roles = planRoles(waves, env);
|
|
362
|
+
const logins = loginsOf(envs_, roles);
|
|
363
|
+
// A cloud token source with no login reads the forge's OIDC token itself; Forgejo issues none.
|
|
364
|
+
const own = forge === "forgejo" ? [] : cloudsOf(envs_, roles).filter((c) => !logins.some((l) => l.cloud === CLOUD_OF[c]));
|
|
365
|
+
const forgejoLogin = forge === "forgejo" ? forgejoLoginSpec(logins) : {};
|
|
366
|
+
const names = [...read.flatMap((e) => readerVariables(e, dialect, envs_.credentials?.[e])), ...WEBHOOK_VARIABLES];
|
|
367
|
+
return {
|
|
368
|
+
name: env,
|
|
369
|
+
secrets: Object.fromEntries(names.map((n) => [n, n])),
|
|
370
|
+
writeProbe: writeProbe(read),
|
|
371
|
+
...(logins.length > 0 && forge !== "forgejo" ? { trade: tradeSpec(logins) } : {}),
|
|
372
|
+
...(Object.keys(forgejoLogin).length > 0 ? { login: forgejoLogin } : {}),
|
|
373
|
+
...(own.length > 0 ? { idTokens: Object.fromEntries(own.map((c) => [ID_TOKENS[c].variable, ID_TOKENS[c].aud])) } : {}),
|
|
374
|
+
};
|
|
375
|
+
});
|
|
376
|
+
// The check moment (#294) on chant's check job (chant issue 4964): the hooks the declaration at base names, beside the replay server.
|
|
377
|
+
// Not on GitLab yet: chant's GitLab check job keeps no artifacts:reports:codequality, which yodel's lint job keeps (#129).
|
|
378
|
+
const svc = REPLAY_SERVICE[dialect];
|
|
379
|
+
const checkJob = envs_.checkHooks && forge !== "gitlab"
|
|
380
|
+
? envs_.replay
|
|
381
|
+
? {
|
|
382
|
+
services: [{ name: svc.name, image: svc.image, ...(Object.keys(svc.env).length > 0 ? { env: svc.env } : {}), health: svc.health }],
|
|
383
|
+
env: { [`${variablePrefix(REPLAY_PROFILE, dialect)}_URL`]: svc.url(svc.name), ...svc.jobEnv },
|
|
384
|
+
before: [waitFor(svc.name, svc.port)],
|
|
385
|
+
}
|
|
386
|
+
: true
|
|
387
|
+
: undefined;
|
|
388
|
+
return {
|
|
389
|
+
words: WAVE_WORDS,
|
|
390
|
+
branch: MAIN,
|
|
391
|
+
image: tc.image,
|
|
392
|
+
...(checkJob ? { checkJob } : {}),
|
|
393
|
+
// Signed checks (sql-yodeler issue 346): each target's plan as plan:<env> and policy:<env>, each hook by its name.
|
|
394
|
+
...(envs_.evidence ? { evidence: envs_.evidence } : {}),
|
|
395
|
+
...(envs_.refGate ? { refGateStatus: true } : {}),
|
|
396
|
+
// GitLab's runner clones one ref, so the plan job fetches the approvals itself; chant's checkout on GitHub and Forgejo fetches chant/lifecycle.
|
|
397
|
+
beforeScript: [...installLines(tc, forge), ...(forge === "gitlab" ? [fetchApprovals(tc)] : [])],
|
|
398
|
+
productPlan: {
|
|
399
|
+
command: "yodel plan {target} --pr-note {output}",
|
|
400
|
+
targets,
|
|
401
|
+
report: `mkdir -p {output}/report; yodel report {target} --json > {output}/report/{target}.json || true; yodel report {target} --html {output}/report/{target}.html || true`,
|
|
402
|
+
noteWords: { productMarker: YODEL_NOTE_MARKER, subjectParts: SUBJECT_PART_WORDS },
|
|
403
|
+
workflow: "yodel-pr",
|
|
404
|
+
concurrency: { group: "yodel-pr", cancelInProgress: true },
|
|
405
|
+
...(watches.length > 0 ? { watches: [...watches] } : {}),
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
/** The jobs of a workflow yodel declares with the github lexicon, as the plain mapping chant's workflow document holds. */
|
|
410
|
+
function jobsOf(forge, jobs) {
|
|
411
|
+
if (Object.keys(jobs).length === 0)
|
|
412
|
+
return {};
|
|
413
|
+
const yaml = renderActions(forge, new ActionsWorkflow({ name: "jobs", on: { pull_request: {} }, jobs }));
|
|
414
|
+
return (parseYAML(yaml).jobs ?? {});
|
|
351
415
|
}
|
|
352
416
|
/** The replay server's service and variables, for a job that replays into it. */
|
|
353
417
|
function replayService(dialect) {
|
|
@@ -380,9 +444,7 @@ function checkJob(forge, dialect, tc) {
|
|
|
380
444
|
],
|
|
381
445
|
});
|
|
382
446
|
}
|
|
383
|
-
function lintJob(forge, dialect, replay, tc, tests = false, typedColumns = false, check = false
|
|
384
|
-
if (hooks)
|
|
385
|
-
return checkHooksJob(forge, dialect, replay, tc);
|
|
447
|
+
function lintJob(forge, dialect, replay, tc, tests = false, typedColumns = false, check = false) {
|
|
386
448
|
// With the replay check, the job runs in IMAGE on every forge and reaches
|
|
387
449
|
// its replay server by the service's name on the job's own network. On
|
|
388
450
|
// GitHub's VM the service would be on localhost through a published port,
|
|
@@ -411,25 +473,6 @@ function lintJob(forge, dialect, replay, tc, tests = false, typedColumns = false
|
|
|
411
473
|
],
|
|
412
474
|
});
|
|
413
475
|
}
|
|
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
476
|
/** The pull request workflow of a project that only runs yodel check (#1). */
|
|
434
477
|
function checkOnlyActions(forge, envs_) {
|
|
435
478
|
const jobs = { check: checkJob(forge, envs_.dialect, toolchainOf(envs_)) };
|
|
@@ -451,56 +494,38 @@ function checkOnlyActions(forge, envs_) {
|
|
|
451
494
|
});
|
|
452
495
|
return { path: `${forge === "github" ? ".github" : ".forgejo"}/workflows/yodel-pr.yml`, content: renderActions(forge, workflow) };
|
|
453
496
|
}
|
|
454
|
-
export function actionsReview(forge, envs_) {
|
|
497
|
+
export function actionsReview(forge, envs_, watches = []) {
|
|
455
498
|
const { dialect, names: envs, replay, waves, jobs: own } = envs_;
|
|
456
499
|
const tc = toolchainOf(envs_);
|
|
457
500
|
if (envs_.checkOnly)
|
|
458
501
|
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
502
|
const clouds = cloudsOf(envs_, envs.flatMap((env) => planRoles(waves, env)));
|
|
479
503
|
const header = [
|
|
480
504
|
...HEADER,
|
|
481
505
|
"#",
|
|
482
506
|
"# 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
|
-
: []),
|
|
507
|
+
"# lint job starts), and the plan per environment on chant's product plan: a",
|
|
508
|
+
"# plan job with the environment's reader credentials and no forge token,",
|
|
509
|
+
"# then a note job that posts the note and the status yodel/plan/<env>. No job",
|
|
510
|
+
"# here holds a writer, and each plan job shows it first: yodel config check",
|
|
511
|
+
"# --write-probe tries a write and fails the job when the server lets it through.",
|
|
490
512
|
...identityHeader(forge, clouds),
|
|
491
513
|
];
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
514
|
+
const options = { ...productPlanOptions(forge, envs_, watches), header };
|
|
515
|
+
const { doc } = forge === "github" ? generateProductPlanPipeline(YODEL_PR_ENV, options) : generateForgejoProductPlanPipeline(YODEL_PR_ENV, options);
|
|
516
|
+
// yodel's lint job and the project's own jobs, declared with the github lexicon, beside chant's plan and note jobs.
|
|
517
|
+
// With the check moment (#294) the lint job is chant's check job (chant issue 4964), in chant's document.
|
|
518
|
+
const lint = envs_.checkHooks ? {} : jobsOf(forge, { lint: lintJob(forge, dialect, replay, tc, envs_.tests === true, envs_.typedColumns === true, envs_.check === true) });
|
|
519
|
+
const yodels = { ...lint, ...doc.jobsDoc };
|
|
520
|
+
const merged = {
|
|
521
|
+
...doc,
|
|
522
|
+
// 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.
|
|
523
|
+
...(forge === "github" ? { permissions: { contents: "read" } } : {}),
|
|
524
|
+
jobsDoc: { ...yodels, ...jobsOf(forge, ownJobs(own?.actions, yodels, "actions")) },
|
|
525
|
+
};
|
|
501
526
|
return {
|
|
502
527
|
path: `${forge === "github" ? ".github" : ".forgejo"}/workflows/yodel-pr.yml`,
|
|
503
|
-
content:
|
|
528
|
+
content: emitWorkflowYAML(merged),
|
|
504
529
|
};
|
|
505
530
|
}
|
|
506
531
|
// ── GitLab CI ───────────────────────────────────────────────────────────────
|
|
@@ -561,30 +586,17 @@ export function gitlabPipeline(envs_) {
|
|
|
561
586
|
rules: mr(),
|
|
562
587
|
...(replay
|
|
563
588
|
? {
|
|
564
|
-
script: envs_.checkHooks === true ? [waitFor(svc.name, svc.port),
|
|
589
|
+
script: envs_.checkHooks === true ? [waitFor(svc.name, svc.port), GITLAB_CHECK_HOOKS] : [CI_CHECK, ...types, lintCommand("gitlab"), waitFor(svc.name, svc.port), REPLAY, ...(envs_.tests === true ? [TEST] : []), ...check],
|
|
565
590
|
services: [new GitLabService({ name: svc.image, alias: svc.name, variables: svc.env })],
|
|
566
591
|
variables: { [`${variablePrefix(REPLAY_PROFILE, dialect)}_URL`]: svc.url(svc.name), ...svc.jobEnv },
|
|
567
592
|
}
|
|
568
|
-
: { script: envs_.checkHooks === true ? [
|
|
593
|
+
: { script: envs_.checkHooks === true ? [GITLAB_CHECK_HOOKS] : [CI_CHECK, ...types, lintCommand("gitlab")] }),
|
|
569
594
|
// The code quality report, kept when lint fails too: that is when it has something to show.
|
|
570
595
|
artifacts: new GitLabArtifacts({ when: "always", reports: { codequality: CODE_QUALITY_FILE } }),
|
|
571
596
|
}));
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
const login = gitlabLogin(logins);
|
|
576
|
-
jobs.set(`plan-${env}`, new GitLabJob({
|
|
577
|
-
extends: ".yodel",
|
|
578
|
-
stage: "review",
|
|
579
|
-
rules: mr(),
|
|
580
|
-
...(Object.keys(login.variables).length > 0 ? { variables: login.variables } : {}),
|
|
581
|
-
script: [...login.lines, writeProbe([env, ...requiredOf(waves, env)]), `yodel plan ${env} --comment`],
|
|
582
|
-
...(clouds.length > 0 ? { id_tokens: idTokens(clouds, logins) } : {}),
|
|
583
|
-
after_script: [reportCommand(env, tc)],
|
|
584
|
-
artifacts: new GitLabArtifacts({ name: reportArtifact(`plan-${env}`), when: "always", paths: [`${REPORT_DIR}/`] }),
|
|
585
|
-
}));
|
|
586
|
-
}
|
|
587
|
-
for (const [name, job] of Object.entries(ownJobs(own?.gitlab, Object.fromEntries(jobs), "gitlab")))
|
|
597
|
+
// The plan jobs and their note jobs are chant's, in GITLAB_PLAN_FILE (sql-yodeler issue 345).
|
|
598
|
+
const plan = gitlabPlan(envs_);
|
|
599
|
+
for (const [name, job] of Object.entries(ownJobs(own?.gitlab, { ...Object.fromEntries(jobs), ...Object.fromEntries(plan.jobs.map((j) => [j, true])) }, "gitlab")))
|
|
588
600
|
jobs.set(name, job);
|
|
589
601
|
const apply = rendersApply(envs_);
|
|
590
602
|
const variables = envs.flatMap((env) => {
|
|
@@ -602,15 +614,14 @@ export function gitlabPipeline(envs_) {
|
|
|
602
614
|
const header = [
|
|
603
615
|
...HEADER,
|
|
604
616
|
"#",
|
|
617
|
+
"# Merge requests: lint (stage review), and each environment's plan on chant's",
|
|
618
|
+
`# product plan (stage plan), in ${GITLAB_PLAN_FILE}. A merge request's own`,
|
|
619
|
+
"# pipeline holds no token for its notes: a pipeline schedule of the default",
|
|
620
|
+
`# branch with ${GITLAB_PLAN_NOTES_VAR}=1, which you create, posts every open merge`,
|
|
621
|
+
"# request's notes and sets yodel/plan/<env> (stage plan-note).",
|
|
605
622
|
...(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
|
-
]),
|
|
623
|
+
? [`# A push to the default branch: the apply waves, one stage each, in ${GITLAB_APPLY_FILE}.`]
|
|
624
|
+
: ["# No apply pipeline (yodel.config.ts ci.apply: false): migrations are applied outside CI."]),
|
|
614
625
|
`# The drift watches are in ${GITLAB_WATCH_FILE} (stage ops).`,
|
|
615
626
|
...(respondsNew(envs_) ? [`# /yodel new, chant's commit job, is in ${GITLAB_COMMIT_FILES.new} (stage ops).`] : []),
|
|
616
627
|
...(rebaseRespond(envs_) !== "off" ? [`# /yodel rebase, after the merge request's check, is in ${GITLAB_COMMIT_FILES.rebase} (stage ops).`] : []),
|
|
@@ -648,13 +659,32 @@ export function gitlabPipeline(envs_) {
|
|
|
648
659
|
const applyStages = apply ? [...plans, ...waveStages(waves), ...(envs_.resume ? [RESUME_STAGE] : [])] : [];
|
|
649
660
|
const pipeline = new GitLabPipeline({
|
|
650
661
|
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
|
|
662
|
+
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 }] : [])],
|
|
663
|
+
// The plan file's stages (chant's plan and plan-note) right after review.
|
|
664
|
+
stages: [...new Set(["review", ...plan.stages, ...jobStages, ...applyStages, "ops"])],
|
|
653
665
|
variables: { GIT_DEPTH: "0" },
|
|
654
666
|
});
|
|
655
667
|
const entities = new Map([["pipeline", pipeline], ["workflow", workflow], ...jobs]);
|
|
656
668
|
return { path: ".gitlab-ci.yml", content: oneFile("gitlab", gitlabSerializer.serialize(entities)) };
|
|
657
669
|
}
|
|
670
|
+
/** The file .gitlab-ci.yml includes for the plan jobs and their note jobs, chant's product plan (sql-yodeler issue 345). */
|
|
671
|
+
export const GITLAB_PLAN_FILE = ".gitlab/yodel-plan.gitlab-ci.yml";
|
|
672
|
+
/** chant's name for the variable a plan notes pipeline sets. */
|
|
673
|
+
const GITLAB_PLAN_NOTES_VAR = "CHANT_PLAN_NOTES";
|
|
674
|
+
/**
|
|
675
|
+
* The plan on GitLab through chant's product plan: its jobs as
|
|
676
|
+
* {@link GITLAB_PLAN_FILE}, their names and their stages. chant's
|
|
677
|
+
* `workflow` and `stages` stay out of the file: .gitlab-ci.yml has the
|
|
678
|
+
* pipeline's own, with chant's stages after review, and its rules let the
|
|
679
|
+
* plan notes pipeline (a schedule of the default branch) run.
|
|
680
|
+
*/
|
|
681
|
+
export function gitlabPlan(envs_, watches = []) {
|
|
682
|
+
const { entries } = generateGitlabProductPlanPipeline(YODEL_PR_ENV, productPlanOptions("gitlab", envs_, watches));
|
|
683
|
+
const stages = (entries.find(([k]) => k === "stages")?.[1] ?? []);
|
|
684
|
+
const kept = entries.filter(([k]) => k !== "workflow" && k !== "stages");
|
|
685
|
+
const jobs = kept.map(([k]) => k).filter((k) => k !== "variables");
|
|
686
|
+
return { file: { path: GITLAB_PLAN_FILE, content: emitGitlabFile(kept, HEADER) }, jobs, stages };
|
|
687
|
+
}
|
|
658
688
|
/** The environment `env`'s wave requires, as a list. */
|
|
659
689
|
const requiredOf = (waves, env) => {
|
|
660
690
|
const r = waves.find((w) => w.env === env)?.requires;
|
|
@@ -841,6 +871,8 @@ export async function applyPipelines(dir, envs, product) {
|
|
|
841
871
|
beforeScript: [...installLines(tc, forge), fetchApprovals(tc)],
|
|
842
872
|
waveJobs: waveJobs(forge),
|
|
843
873
|
recordPlans: recordPlans(forge),
|
|
874
|
+
// 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.
|
|
875
|
+
...(envs.evidence ? { evidence: envs.evidence } : {}),
|
|
844
876
|
...(forge === "gitlab" ? { opsFileName: GITLAB_APPLY_FILE } : {}),
|
|
845
877
|
}, dir);
|
|
846
878
|
if (!result.success || !result.files)
|
|
@@ -914,8 +946,8 @@ export async function withTenants(dir, waves) {
|
|
|
914
946
|
// The forge lexicons serialize the jobs, and yodel's reports, logins and
|
|
915
947
|
// readers go in as generateOpWavesPipeline's inputs (#4791).
|
|
916
948
|
//
|
|
917
|
-
//
|
|
918
|
-
//
|
|
949
|
+
// The plan jobs are chant's product plan (sql-yodeler issue 345,
|
|
950
|
+
// {@link productPlanOptions}). Still yodel's own: the lint
|
|
919
951
|
// job's own steps for a project with no workspace declaration, which has
|
|
920
952
|
// no check hooks to run (#294); the watch until chant#4582
|
|
921
953
|
// ({@link watchPipelines}).
|
|
@@ -981,11 +1013,8 @@ export function watchSpec(env, forge, envs) {
|
|
|
981
1013
|
* yodel (#289).
|
|
982
1014
|
*
|
|
983
1015
|
* 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.
|
|
1016
|
+
* drift <env> --issue`, which compares with the history's recorded schema
|
|
1017
|
+
* and keeps the tracking issue.
|
|
989
1018
|
*/
|
|
990
1019
|
export async function watchPipelines(dir, envs_) {
|
|
991
1020
|
const { names: envs } = envs_;
|
|
@@ -1128,6 +1157,8 @@ export async function environments(dir) {
|
|
|
1128
1157
|
...(ci?.tools && ci.tools.length > 0 ? { tools: ci.tools } : {}),
|
|
1129
1158
|
...(ci?.respond?.new ? { respondNew: ci.respond.new } : {}),
|
|
1130
1159
|
...(ci?.respond?.rebase ? { respondRebase: ci.respond.rebase } : {}),
|
|
1160
|
+
...(ci?.evidence ? { evidence: ci.evidence } : {}),
|
|
1161
|
+
...(ci?.refGate === true ? { refGate: true } : {}),
|
|
1131
1162
|
};
|
|
1132
1163
|
}
|
|
1133
1164
|
/** The roles of each environment whose profile is made with credentials(). */
|
|
@@ -1180,9 +1211,52 @@ function ownJobs(own, yodels, what) {
|
|
|
1180
1211
|
}
|
|
1181
1212
|
return own;
|
|
1182
1213
|
}
|
|
1183
|
-
/**
|
|
1184
|
-
|
|
1185
|
-
|
|
1214
|
+
/**
|
|
1215
|
+
* The ref gate's rule (yodel.config.ts `ci.refGate`, chant issues 4913 and
|
|
1216
|
+
* 4978): chant's `refGateInitPlan` for main, needing current evidence of
|
|
1217
|
+
* each environment's plan and policy, `plan:<env>` and `policy:<env>`,
|
|
1218
|
+
* which each environment's note job signs. `.chant/trust.json` gets the rule
|
|
1219
|
+
* when it has none for main and is left as it is when it has one. The
|
|
1220
|
+
* pre-push hook is the person's to install (`chant workspace ref-gate
|
|
1221
|
+
* install`), so yodel ci writes no file in the git directory.
|
|
1222
|
+
*/
|
|
1223
|
+
async function refGateFiles(dir, envs) {
|
|
1224
|
+
const { refGateInitPlan } = await import("@intentius/chant/ref-gate-init");
|
|
1225
|
+
const sign = "open a pull request: its yodel-pr pipeline's note job signs it";
|
|
1226
|
+
const plan = refGateInitPlan(dir, {
|
|
1227
|
+
branch: MAIN,
|
|
1228
|
+
checks: [
|
|
1229
|
+
{ check: "plan", command: sign },
|
|
1230
|
+
{ check: "policy", command: sign },
|
|
1231
|
+
],
|
|
1232
|
+
targets: envs.names,
|
|
1233
|
+
prePush: false,
|
|
1234
|
+
chant: YODEL_WORDS.bin,
|
|
1235
|
+
...(envs.evidence?.runnerKeySecret ? { runnerKeySecret: envs.evidence.runnerKeySecret } : {}),
|
|
1236
|
+
});
|
|
1237
|
+
// chant names the files from git's top level, the real path, so the project's own is read the same way.
|
|
1238
|
+
const root = realpathSync(dir);
|
|
1239
|
+
return plan.files.filter((f) => !f.local).map((f) => ({ path: relative(root, f.path).split(sep).join("/"), content: f.content }));
|
|
1240
|
+
}
|
|
1241
|
+
/** The pull request pipelines, and GitLab's main file. `watches` are the drift watches the plan note checks for having stopped. */
|
|
1242
|
+
export function review(envs, watches = []) {
|
|
1243
|
+
return [
|
|
1244
|
+
actionsReview("github", envs, watches),
|
|
1245
|
+
actionsReview("forgejo", envs, watches),
|
|
1246
|
+
gitlabPipeline(envs),
|
|
1247
|
+
...(envs.checkOnly ? [] : [gitlabPlan(envs, watches).file]),
|
|
1248
|
+
];
|
|
1249
|
+
}
|
|
1250
|
+
/**
|
|
1251
|
+
* The scheduled drift watches of the project's environments (chant#4289),
|
|
1252
|
+
* which chant's note job checks for having stopped (chant issue 4888): each
|
|
1253
|
+
* environment's WatchOp, found by its `Watch` and `Env` labels.
|
|
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
|
+
return scheduledWatches([...found.ops.values()].map((o) => o.config).filter((o) => o.labels?.Watch === "true" && envs.includes(o.labels.Env ?? "")));
|
|
1186
1260
|
}
|
|
1187
1261
|
/**
|
|
1188
1262
|
* The workspace declaration with yodel's check presets in `ci.hooks.check`
|
|
@@ -1237,11 +1311,12 @@ export async function render(dir, options = {}) {
|
|
|
1237
1311
|
const reviewed = hooks ? { ...envs, checkHooks: true } : envs;
|
|
1238
1312
|
// ci.apply: false (#175): no waves spec and no apply pipeline on any forge.
|
|
1239
1313
|
const files = [
|
|
1240
|
-
...review(reviewed),
|
|
1314
|
+
...review(reviewed, await envWatches(dir, envs.names)),
|
|
1241
1315
|
...(hooks ? [hooks] : []),
|
|
1242
1316
|
...(rendersApply(envs) ? await applyPipelines(dir, envs, product) : []),
|
|
1243
1317
|
...(await watchPipelines(dir, envs)),
|
|
1244
1318
|
...(await commitPipelines(dir, envs)),
|
|
1319
|
+
...(envs.refGate ? await refGateFiles(dir, envs) : []),
|
|
1245
1320
|
];
|
|
1246
1321
|
// Each pinned `uses:` line with its release beside it, as chant writes them (#319).
|
|
1247
1322
|
return files
|