@intentius/sql-yodeler 0.13.1 → 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/bin.js +2 -2
- 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.js +3 -1
- 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 +13 -49
- package/dist/chant/drift.js +25 -138
- package/dist/chant/drift.js.map +1 -1
- package/dist/chant/sql-types.d.ts +4 -5
- package/dist/chant/sql-types.js +9 -10
- package/dist/chant/sql-types.js.map +1 -1
- package/dist/ci/render.d.ts +61 -18
- package/dist/ci/render.js +212 -132
- 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/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 +1 -1
- package/dist/commands/chant.js +2 -2
- package/dist/commands/chant.js.map +1 -1
- package/dist/commands/ci.js +32 -19
- 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.d.ts +1 -1
- package/dist/commands/drift.js +6 -42
- 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/override.js +2 -2
- package/dist/commands/override.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 +10 -5
- package/dist/pr/issue.js +26 -13
- 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/dist/versioned/op.js +3 -1
- package/dist/versioned/op.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/chant/process.d.ts +0 -34
- package/dist/chant/process.js +0 -74
- package/dist/chant/process.js.map +0 -1
- package/dist/chant/resolve-fallback.d.ts +0 -35
- package/dist/chant/resolve-fallback.js +0 -89
- package/dist/chant/resolve-fallback.js.map +0 -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";
|
|
@@ -94,7 +95,15 @@ import { githubSerializer } from "@intentius/chant-lexicon-github/serializer";
|
|
|
94
95
|
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
|
-
import {
|
|
98
|
+
import { sqlTypesPath } from "@intentius/chant-lexicon-sql/sql-types";
|
|
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";
|
|
98
107
|
export const FORGES = ["github", "gitlab", "forgejo"];
|
|
99
108
|
/** The image every job runs in, where the forge runs jobs in a container. It needs git, so not -slim. */
|
|
100
109
|
export const IMAGE = "node:22-bookworm";
|
|
@@ -114,8 +123,14 @@ const CHECKOUT = usesRef(ACTION_PINS.checkout7);
|
|
|
114
123
|
const SETUP_NODE = usesRef(ACTION_PINS.setupNode7);
|
|
115
124
|
/** DEV for dev: the prefix of an environment's variables. */
|
|
116
125
|
export const prefixOf = (env) => env.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
117
|
-
/**
|
|
118
|
-
|
|
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";
|
|
119
134
|
/** yodel's checks and the project's tools as check-hook presets for `forge` (#294). */
|
|
120
135
|
export function checkHooksOf(envs_) {
|
|
121
136
|
const forge = "github";
|
|
@@ -170,13 +185,6 @@ const idTokens = (clouds, logins = []) => ({
|
|
|
170
185
|
});
|
|
171
186
|
/** The cloud logins (#132) of a job holding the roles `held`, from yodel.config.ts `ci.login`. */
|
|
172
187
|
const loginsOf = (envs, held) => jobLogins(envs.login, held, (env, role) => envs.credentials?.[env]?.[role].cloud);
|
|
173
|
-
/** A job's login steps as the github lexicon's Steps. */
|
|
174
|
-
const actionsLogin = (forge, logins) => loginSteps(forge, logins).steps.map((st) => new Step({ name: st.name, run: st.lines.join("\n") }));
|
|
175
|
-
/** A GitLab job's login: its script lines and its variables. */
|
|
176
|
-
const gitlabLogin = (logins) => {
|
|
177
|
-
const out = loginSteps("gitlab", logins);
|
|
178
|
-
return { lines: out.steps.flatMap((st) => st.lines), variables: out.variables };
|
|
179
|
-
};
|
|
180
188
|
/** The roles a pull request's plan job for `env` holds: the environment's reader and the reader of the one it requires. */
|
|
181
189
|
const planRoles = (waves, env) => [env, ...requiredOf(waves, env)].map((e) => [e, "reader"]);
|
|
182
190
|
/** The roles a wave job for `env` holds: the writer, and the reader of the environment it requires. */
|
|
@@ -292,7 +300,6 @@ export const reportArtifact = (job) => `yodel-report-${job}`;
|
|
|
292
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. */
|
|
293
301
|
export const UPLOAD_ARTIFACT = usesRef(ACTION_PINS.uploadArtifact4);
|
|
294
302
|
export const FORGEJO_UPLOAD_ARTIFACT = `https://code.forgejo.org/${usesRef(ACTION_PINS.uploadArtifact3)}`;
|
|
295
|
-
const uploadArtifact = (forge) => (forge === "forgejo" ? FORGEJO_UPLOAD_ARTIFACT : UPLOAD_ARTIFACT);
|
|
296
303
|
/**
|
|
297
304
|
* The comment at the top of every file, as `#` lines. The files declared here
|
|
298
305
|
* (the review workflows and .gitlab-ci.yml) take theirs as the Workflow's or
|
|
@@ -300,10 +307,11 @@ const uploadArtifact = (forge) => (forge === "forgejo" ? FORGEJO_UPLOAD_ARTIFACT
|
|
|
300
307
|
* generateOpWavesPipeline and generateOpsPipeline write take no comment, so
|
|
301
308
|
* withHeader puts it above their YAML.
|
|
302
309
|
*/
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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."];
|
|
313
|
+
/** The pipeline directories yodel ci writes into, besides the root `.gitlab-ci.yml`. */
|
|
314
|
+
export const PIPELINE_DIRS = [".github/workflows", ".forgejo/workflows", ".gitlab"];
|
|
307
315
|
const withHeader = (header, yaml) => `${[...header, ""].join("\n")}${yaml}`;
|
|
308
316
|
/** `#` lines as a declaration's `comment`: the text without its `# `, which the serializer writes back. */
|
|
309
317
|
const asComment = (header) => header.map((l) => l.replace(/^# ?/, "")).join("\n");
|
|
@@ -320,13 +328,6 @@ function renderActions(forge, workflow) {
|
|
|
320
328
|
const serializer = forge === "github" ? githubSerializer : forgejoSerializer;
|
|
321
329
|
return oneFile(forge, serializer.serialize(new Map([["workflow", workflow]])));
|
|
322
330
|
}
|
|
323
|
-
/** The report steps of a job: `yodel report` into REPORT_DIR and the artifact, whatever the job's outcome. */
|
|
324
|
-
function reportSteps(forge, env, job, tc) {
|
|
325
|
-
return [
|
|
326
|
-
new Step({ name: `yodel report ${env}`, if: "always()", run: reportCommand(env, tc) }),
|
|
327
|
-
new Step({ name: "Keep the report", if: "always()", uses: uploadArtifact(forge), with: { name: reportArtifact(job), path: REPORT_DIR, "if-no-files-found": "ignore" } }),
|
|
328
|
-
];
|
|
329
|
-
}
|
|
330
331
|
/** `inContainer`: the job runs in the toolchain's image, which has node, so it needs no setup-node. */
|
|
331
332
|
function setupSteps(inContainer, tc, approvals = true) {
|
|
332
333
|
const steps = [new Step({ uses: CHECKOUT, with: { "fetch-depth": 0 } })];
|
|
@@ -340,9 +341,77 @@ function setupSteps(inContainer, tc, approvals = true) {
|
|
|
340
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. */
|
|
341
342
|
const inContainer = (forge, tc) => forge === "forgejo" || tc.yodelImage;
|
|
342
343
|
const runner = (container, tc) => ({ "runs-on": "ubuntu-latest", ...(container ? { container: tc.image } : {}) });
|
|
343
|
-
/**
|
|
344
|
-
|
|
345
|
-
|
|
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 ?? {});
|
|
346
415
|
}
|
|
347
416
|
/** The replay server's service and variables, for a job that replays into it. */
|
|
348
417
|
function replayService(dialect) {
|
|
@@ -375,9 +444,7 @@ function checkJob(forge, dialect, tc) {
|
|
|
375
444
|
],
|
|
376
445
|
});
|
|
377
446
|
}
|
|
378
|
-
function lintJob(forge, dialect, replay, tc, tests = false, typedColumns = false, check = false
|
|
379
|
-
if (hooks)
|
|
380
|
-
return checkHooksJob(forge, dialect, replay, tc);
|
|
447
|
+
function lintJob(forge, dialect, replay, tc, tests = false, typedColumns = false, check = false) {
|
|
381
448
|
// With the replay check, the job runs in IMAGE on every forge and reaches
|
|
382
449
|
// its replay server by the service's name on the job's own network. On
|
|
383
450
|
// GitHub's VM the service would be on localhost through a published port,
|
|
@@ -406,25 +473,6 @@ function lintJob(forge, dialect, replay, tc, tests = false, typedColumns = false
|
|
|
406
473
|
],
|
|
407
474
|
});
|
|
408
475
|
}
|
|
409
|
-
/**
|
|
410
|
-
* The lint job on chant's check moment (#294): the replay server when the
|
|
411
|
-
* project has one, then `yodel chant ci check`, which runs the hooks the
|
|
412
|
-
* declaration at the pull request's base names. The job runs in IMAGE with
|
|
413
|
-
* the replay server, as {@link lintJob} does.
|
|
414
|
-
*/
|
|
415
|
-
function checkHooksJob(forge, dialect, replay, tc) {
|
|
416
|
-
const container = replay || inContainer(forge, tc);
|
|
417
|
-
const steps = [...setupSteps(container, tc), new Step({ name: "Check hooks at the base (chant ci check)", run: checkHooksLine(forge) })];
|
|
418
|
-
if (!replay)
|
|
419
|
-
return new ActionsJob({ ...runner(container, tc), steps });
|
|
420
|
-
const { svc, services, env } = replayService(dialect);
|
|
421
|
-
return new ActionsJob({
|
|
422
|
-
...runner(container, tc),
|
|
423
|
-
services,
|
|
424
|
-
env,
|
|
425
|
-
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) })],
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
476
|
/** The pull request workflow of a project that only runs yodel check (#1). */
|
|
429
477
|
function checkOnlyActions(forge, envs_) {
|
|
430
478
|
const jobs = { check: checkJob(forge, envs_.dialect, toolchainOf(envs_)) };
|
|
@@ -446,56 +494,38 @@ function checkOnlyActions(forge, envs_) {
|
|
|
446
494
|
});
|
|
447
495
|
return { path: `${forge === "github" ? ".github" : ".forgejo"}/workflows/yodel-pr.yml`, content: renderActions(forge, workflow) };
|
|
448
496
|
}
|
|
449
|
-
export function actionsReview(forge, envs_) {
|
|
497
|
+
export function actionsReview(forge, envs_, watches = []) {
|
|
450
498
|
const { dialect, names: envs, replay, waves, jobs: own } = envs_;
|
|
451
499
|
const tc = toolchainOf(envs_);
|
|
452
500
|
if (envs_.checkOnly)
|
|
453
501
|
return checkOnlyActions(forge, envs_);
|
|
454
|
-
const jobs = { lint: lintJob(forge, dialect, replay, tc, envs_.tests === true, envs_.typedColumns === true, envs_.check === true, envs_.checkHooks === true) };
|
|
455
|
-
for (const env of envs) {
|
|
456
|
-
const read = [env, ...requiredOf(waves, env)];
|
|
457
|
-
jobs[`plan-${env}`] = new ActionsJob({
|
|
458
|
-
...runner(inContainer(forge, tc), tc),
|
|
459
|
-
// The plan shows where each migration has run: the required environment's reader too.
|
|
460
|
-
env: secrets([...read.flatMap((e) => readerVariables(e, dialect, envs_.credentials?.[e])), ...WEBHOOK_VARIABLES]),
|
|
461
|
-
steps: [
|
|
462
|
-
// The plan explains what moved since an approval from git's history of migrations/.
|
|
463
|
-
...setupSteps(inContainer(forge, tc), tc),
|
|
464
|
-
// The cloud login (#132), when a reader here is cloud-minted.
|
|
465
|
-
...actionsLogin(forge, loginsOf(envs_, planRoles(waves, env))),
|
|
466
|
-
new Step({ name: "This job cannot write", run: writeProbe(read) }),
|
|
467
|
-
new Step({ name: `yodel plan ${env} --comment`, run: `yodel plan ${env} --comment`, env: commentToken(forge) }),
|
|
468
|
-
...reportSteps(forge, env, `plan-${env}`, tc),
|
|
469
|
-
],
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
Object.assign(jobs, ownJobs(own?.actions, jobs, "actions"));
|
|
473
502
|
const clouds = cloudsOf(envs_, envs.flatMap((env) => planRoles(waves, env)));
|
|
474
503
|
const header = [
|
|
475
504
|
...HEADER,
|
|
476
505
|
"#",
|
|
477
506
|
"# Pull requests: yodel lint and the replay check (into a throwaway server the",
|
|
478
|
-
"# lint job starts), and the plan
|
|
479
|
-
"# environment's reader credentials
|
|
480
|
-
"# job
|
|
481
|
-
"#
|
|
482
|
-
|
|
483
|
-
? ["# The comment is posted with the job's own token (Forgejo gives a same-repository", "# pull request one that can comment)."]
|
|
484
|
-
: []),
|
|
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.",
|
|
485
512
|
...identityHeader(forge, clouds),
|
|
486
513
|
];
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
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
|
+
};
|
|
496
526
|
return {
|
|
497
527
|
path: `${forge === "github" ? ".github" : ".forgejo"}/workflows/yodel-pr.yml`,
|
|
498
|
-
content:
|
|
528
|
+
content: emitWorkflowYAML(merged),
|
|
499
529
|
};
|
|
500
530
|
}
|
|
501
531
|
// ── GitLab CI ───────────────────────────────────────────────────────────────
|
|
@@ -556,30 +586,17 @@ export function gitlabPipeline(envs_) {
|
|
|
556
586
|
rules: mr(),
|
|
557
587
|
...(replay
|
|
558
588
|
? {
|
|
559
|
-
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],
|
|
560
590
|
services: [new GitLabService({ name: svc.image, alias: svc.name, variables: svc.env })],
|
|
561
591
|
variables: { [`${variablePrefix(REPLAY_PROFILE, dialect)}_URL`]: svc.url(svc.name), ...svc.jobEnv },
|
|
562
592
|
}
|
|
563
|
-
: { script: envs_.checkHooks === true ? [
|
|
593
|
+
: { script: envs_.checkHooks === true ? [GITLAB_CHECK_HOOKS] : [CI_CHECK, ...types, lintCommand("gitlab")] }),
|
|
564
594
|
// The code quality report, kept when lint fails too: that is when it has something to show.
|
|
565
595
|
artifacts: new GitLabArtifacts({ when: "always", reports: { codequality: CODE_QUALITY_FILE } }),
|
|
566
596
|
}));
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const login = gitlabLogin(logins);
|
|
571
|
-
jobs.set(`plan-${env}`, new GitLabJob({
|
|
572
|
-
extends: ".yodel",
|
|
573
|
-
stage: "review",
|
|
574
|
-
rules: mr(),
|
|
575
|
-
...(Object.keys(login.variables).length > 0 ? { variables: login.variables } : {}),
|
|
576
|
-
script: [...login.lines, writeProbe([env, ...requiredOf(waves, env)]), `yodel plan ${env} --comment`],
|
|
577
|
-
...(clouds.length > 0 ? { id_tokens: idTokens(clouds, logins) } : {}),
|
|
578
|
-
after_script: [reportCommand(env, tc)],
|
|
579
|
-
artifacts: new GitLabArtifacts({ name: reportArtifact(`plan-${env}`), when: "always", paths: [`${REPORT_DIR}/`] }),
|
|
580
|
-
}));
|
|
581
|
-
}
|
|
582
|
-
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")))
|
|
583
600
|
jobs.set(name, job);
|
|
584
601
|
const apply = rendersApply(envs_);
|
|
585
602
|
const variables = envs.flatMap((env) => {
|
|
@@ -597,15 +614,14 @@ export function gitlabPipeline(envs_) {
|
|
|
597
614
|
const header = [
|
|
598
615
|
...HEADER,
|
|
599
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).",
|
|
600
622
|
...(apply
|
|
601
|
-
? [
|
|
602
|
-
|
|
603
|
-
`# default branch: the apply waves, one stage each, in ${GITLAB_APPLY_FILE}.`,
|
|
604
|
-
]
|
|
605
|
-
: [
|
|
606
|
-
"# Merge requests: lint and the plan comment (stage review). No apply",
|
|
607
|
-
"# pipeline (yodel.config.ts ci.apply: false): migrations are applied outside CI.",
|
|
608
|
-
]),
|
|
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."]),
|
|
609
625
|
`# The drift watches are in ${GITLAB_WATCH_FILE} (stage ops).`,
|
|
610
626
|
...(respondsNew(envs_) ? [`# /yodel new, chant's commit job, is in ${GITLAB_COMMIT_FILES.new} (stage ops).`] : []),
|
|
611
627
|
...(rebaseRespond(envs_) !== "off" ? [`# /yodel rebase, after the merge request's check, is in ${GITLAB_COMMIT_FILES.rebase} (stage ops).`] : []),
|
|
@@ -643,13 +659,32 @@ export function gitlabPipeline(envs_) {
|
|
|
643
659
|
const applyStages = apply ? [...plans, ...waveStages(waves), ...(envs_.resume ? [RESUME_STAGE] : [])] : [];
|
|
644
660
|
const pipeline = new GitLabPipeline({
|
|
645
661
|
comment: asComment(header),
|
|
646
|
-
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 }] : [])],
|
|
647
|
-
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"])],
|
|
648
665
|
variables: { GIT_DEPTH: "0" },
|
|
649
666
|
});
|
|
650
667
|
const entities = new Map([["pipeline", pipeline], ["workflow", workflow], ...jobs]);
|
|
651
668
|
return { path: ".gitlab-ci.yml", content: oneFile("gitlab", gitlabSerializer.serialize(entities)) };
|
|
652
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
|
+
}
|
|
653
688
|
/** The environment `env`'s wave requires, as a list. */
|
|
654
689
|
const requiredOf = (waves, env) => {
|
|
655
690
|
const r = waves.find((w) => w.env === env)?.requires;
|
|
@@ -836,6 +871,8 @@ export async function applyPipelines(dir, envs, product) {
|
|
|
836
871
|
beforeScript: [...installLines(tc, forge), fetchApprovals(tc)],
|
|
837
872
|
waveJobs: waveJobs(forge),
|
|
838
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 } : {}),
|
|
839
876
|
...(forge === "gitlab" ? { opsFileName: GITLAB_APPLY_FILE } : {}),
|
|
840
877
|
}, dir);
|
|
841
878
|
if (!result.success || !result.files)
|
|
@@ -909,8 +946,8 @@ export async function withTenants(dir, waves) {
|
|
|
909
946
|
// The forge lexicons serialize the jobs, and yodel's reports, logins and
|
|
910
947
|
// readers go in as generateOpWavesPipeline's inputs (#4791).
|
|
911
948
|
//
|
|
912
|
-
//
|
|
913
|
-
//
|
|
949
|
+
// The plan jobs are chant's product plan (sql-yodeler issue 345,
|
|
950
|
+
// {@link productPlanOptions}). Still yodel's own: the lint
|
|
914
951
|
// job's own steps for a project with no workspace declaration, which has
|
|
915
952
|
// no check hooks to run (#294); the watch until chant#4582
|
|
916
953
|
// ({@link watchPipelines}).
|
|
@@ -948,8 +985,8 @@ export function watchSpec(env, forge, envs) {
|
|
|
948
985
|
const held = [[env, "reader"]];
|
|
949
986
|
const logins = loginsOf(envs, held);
|
|
950
987
|
const login = loginSteps(forge, logins);
|
|
951
|
-
// GitLab: a script line each, as the job's own lines are; GitHub and Forgejo: a step each.
|
|
952
|
-
const steps = forge === "gitlab" ? login.steps.flatMap((st) => st.lines.map((run) => ({ run }))) : login.steps.map((st) => ({ run: st.lines.join("\n") }));
|
|
988
|
+
// GitLab: a script line each, as the job's own lines are; GitHub and Forgejo: a named step each.
|
|
989
|
+
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") }));
|
|
953
990
|
const setup = steps.length > 0 ? { setup: steps } : {};
|
|
954
991
|
if (forge === "gitlab") {
|
|
955
992
|
const clouds = cloudsOf(envs, held);
|
|
@@ -976,11 +1013,8 @@ export function watchSpec(env, forge, envs) {
|
|
|
976
1013
|
* yodel (#289).
|
|
977
1014
|
*
|
|
978
1015
|
* The job stays chant's generateOpsPipeline and its last line stays `yodel
|
|
979
|
-
* drift <env> --issue`, which
|
|
980
|
-
*
|
|
981
|
-
* --live` leaves ClickHouse::Grant out. Once chant#4582 puts grants in the
|
|
982
|
-
* sql lexicon's live diff, the watch moves onto chant's drift job with
|
|
983
|
-
* `stages.drift` and the workaround goes.
|
|
1016
|
+
* drift <env> --issue`, which compares with the history's recorded schema
|
|
1017
|
+
* and keeps the tracking issue.
|
|
984
1018
|
*/
|
|
985
1019
|
export async function watchPipelines(dir, envs_) {
|
|
986
1020
|
const { names: envs } = envs_;
|
|
@@ -1111,7 +1145,7 @@ export async function environments(dir) {
|
|
|
1111
1145
|
...(Object.keys(credentials).length > 0 ? { credentials } : {}),
|
|
1112
1146
|
replay,
|
|
1113
1147
|
...(hasTests(dir) ? { tests: true } : {}),
|
|
1114
|
-
...(existsSync(
|
|
1148
|
+
...(existsSync(sqlTypesPath(dir, config)) ? { typedColumns: true } : {}),
|
|
1115
1149
|
waves: await withTenants(dir, await readWaves(dir, envs)),
|
|
1116
1150
|
forges: ci?.forges ?? FORGES,
|
|
1117
1151
|
...(ci?.jobs ? { jobs: await loadProjectJobs(dir, ci.jobs) } : {}),
|
|
@@ -1123,6 +1157,8 @@ export async function environments(dir) {
|
|
|
1123
1157
|
...(ci?.tools && ci.tools.length > 0 ? { tools: ci.tools } : {}),
|
|
1124
1158
|
...(ci?.respond?.new ? { respondNew: ci.respond.new } : {}),
|
|
1125
1159
|
...(ci?.respond?.rebase ? { respondRebase: ci.respond.rebase } : {}),
|
|
1160
|
+
...(ci?.evidence ? { evidence: ci.evidence } : {}),
|
|
1161
|
+
...(ci?.refGate === true ? { refGate: true } : {}),
|
|
1126
1162
|
};
|
|
1127
1163
|
}
|
|
1128
1164
|
/** The roles of each environment whose profile is made with credentials(). */
|
|
@@ -1175,9 +1211,52 @@ function ownJobs(own, yodels, what) {
|
|
|
1175
1211
|
}
|
|
1176
1212
|
return own;
|
|
1177
1213
|
}
|
|
1178
|
-
/**
|
|
1179
|
-
|
|
1180
|
-
|
|
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 ?? "")));
|
|
1181
1260
|
}
|
|
1182
1261
|
/**
|
|
1183
1262
|
* The workspace declaration with yodel's check presets in `ci.hooks.check`
|
|
@@ -1232,11 +1311,12 @@ export async function render(dir, options = {}) {
|
|
|
1232
1311
|
const reviewed = hooks ? { ...envs, checkHooks: true } : envs;
|
|
1233
1312
|
// ci.apply: false (#175): no waves spec and no apply pipeline on any forge.
|
|
1234
1313
|
const files = [
|
|
1235
|
-
...review(reviewed),
|
|
1314
|
+
...review(reviewed, await envWatches(dir, envs.names)),
|
|
1236
1315
|
...(hooks ? [hooks] : []),
|
|
1237
1316
|
...(rendersApply(envs) ? await applyPipelines(dir, envs, product) : []),
|
|
1238
1317
|
...(await watchPipelines(dir, envs)),
|
|
1239
1318
|
...(await commitPipelines(dir, envs)),
|
|
1319
|
+
...(envs.refGate ? await refGateFiles(dir, envs) : []),
|
|
1240
1320
|
];
|
|
1241
1321
|
// Each pinned `uses:` line with its release beside it, as chant writes them (#319).
|
|
1242
1322
|
return files
|