@intentius/sql-yodeler 0.9.0 → 0.10.1

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.
Files changed (139) hide show
  1. package/README.md +5 -5
  2. package/dist/chant/apply.d.ts +6 -0
  3. package/dist/chant/apply.js +6 -2
  4. package/dist/chant/apply.js.map +1 -1
  5. package/dist/chant/build.d.ts +1 -0
  6. package/dist/chant/build.js +5 -0
  7. package/dist/chant/build.js.map +1 -1
  8. package/dist/chant/drift.d.ts +12 -1
  9. package/dist/chant/drift.js +41 -1
  10. package/dist/chant/drift.js.map +1 -1
  11. package/dist/chant/export-name.d.ts +9 -0
  12. package/dist/chant/export-name.js +16 -0
  13. package/dist/chant/export-name.js.map +1 -0
  14. package/dist/chant/runnable.d.ts +1 -1
  15. package/dist/chant/runnable.js +1 -1
  16. package/dist/chant/sql-types.d.ts +19 -0
  17. package/dist/chant/sql-types.js +29 -0
  18. package/dist/chant/sql-types.js.map +1 -0
  19. package/dist/check/flyway.d.ts +67 -0
  20. package/dist/check/flyway.js +106 -0
  21. package/dist/check/flyway.js.map +1 -0
  22. package/dist/check/readers.d.ts +77 -0
  23. package/dist/check/readers.js +270 -0
  24. package/dist/check/readers.js.map +1 -0
  25. package/dist/check/run.d.ts +72 -0
  26. package/dist/check/run.js +243 -0
  27. package/dist/check/run.js.map +1 -0
  28. package/dist/ci/render.d.ts +30 -0
  29. package/dist/ci/render.js +150 -21
  30. package/dist/ci/render.js.map +1 -1
  31. package/dist/commands/apply.d.ts +27 -3
  32. package/dist/commands/apply.js +98 -30
  33. package/dist/commands/apply.js.map +1 -1
  34. package/dist/commands/check.d.ts +5 -0
  35. package/dist/commands/check.js +211 -0
  36. package/dist/commands/check.js.map +1 -0
  37. package/dist/commands/config.js +5 -5
  38. package/dist/commands/config.js.map +1 -1
  39. package/dist/commands/drift.js +5 -0
  40. package/dist/commands/drift.js.map +1 -1
  41. package/dist/commands/index.js +2 -0
  42. package/dist/commands/index.js.map +1 -1
  43. package/dist/commands/init.js +15 -6
  44. package/dist/commands/init.js.map +1 -1
  45. package/dist/commands/lint.js +94 -16
  46. package/dist/commands/lint.js.map +1 -1
  47. package/dist/commands/new.js +56 -4
  48. package/dist/commands/new.js.map +1 -1
  49. package/dist/commands/override.js +80 -33
  50. package/dist/commands/override.js.map +1 -1
  51. package/dist/commands/plan.js +62 -30
  52. package/dist/commands/plan.js.map +1 -1
  53. package/dist/commands/revert.js +1 -1
  54. package/dist/config/define.d.ts +21 -0
  55. package/dist/config/define.js.map +1 -1
  56. package/dist/config/load.js +18 -2
  57. package/dist/config/load.js.map +1 -1
  58. package/dist/credentials.d.ts +18 -5
  59. package/dist/credentials.js +29 -11
  60. package/dist/credentials.js.map +1 -1
  61. package/dist/declarative/plan.d.ts +84 -0
  62. package/dist/declarative/plan.js +187 -0
  63. package/dist/declarative/plan.js.map +1 -0
  64. package/dist/declarative/review.d.ts +78 -0
  65. package/dist/declarative/review.js +162 -0
  66. package/dist/declarative/review.js.map +1 -0
  67. package/dist/init/adopt.d.ts +16 -7
  68. package/dist/init/adopt.js +37 -8
  69. package/dist/init/adopt.js.map +1 -1
  70. package/dist/init/baseline.d.ts +2 -1
  71. package/dist/init/baseline.js +3 -3
  72. package/dist/init/baseline.js.map +1 -1
  73. package/dist/init/clickhouse-access.d.ts +29 -10
  74. package/dist/init/clickhouse-access.js +84 -13
  75. package/dist/init/clickhouse-access.js.map +1 -1
  76. package/dist/init/live.d.ts +4 -2
  77. package/dist/init/live.js +8 -3
  78. package/dist/init/live.js.map +1 -1
  79. package/dist/init/unsupported.d.ts +15 -0
  80. package/dist/init/unsupported.js +34 -0
  81. package/dist/init/unsupported.js.map +1 -0
  82. package/dist/lint/annotations.d.ts +1 -1
  83. package/dist/lint/annotations.js +2 -0
  84. package/dist/lint/annotations.js.map +1 -1
  85. package/dist/lint/check.d.ts +5 -1
  86. package/dist/lint/check.js +58 -1
  87. package/dist/lint/check.js.map +1 -1
  88. package/dist/lint/report.js +6 -0
  89. package/dist/lint/report.js.map +1 -1
  90. package/dist/migrations/document.d.ts +6 -0
  91. package/dist/migrations/document.js +1 -0
  92. package/dist/migrations/document.js.map +1 -1
  93. package/dist/migrations/handwritten.d.ts +75 -0
  94. package/dist/migrations/handwritten.js +157 -0
  95. package/dist/migrations/handwritten.js.map +1 -0
  96. package/dist/migrations/index.d.ts +2 -0
  97. package/dist/migrations/index.js +2 -0
  98. package/dist/migrations/index.js.map +1 -1
  99. package/dist/pr/overdue.d.ts +48 -0
  100. package/dist/pr/overdue.js +88 -0
  101. package/dist/pr/overdue.js.map +1 -0
  102. package/dist/pr/part.d.ts +15 -0
  103. package/dist/pr/part.js +30 -0
  104. package/dist/pr/part.js.map +1 -0
  105. package/dist/rebase/index.js +28 -1
  106. package/dist/rebase/index.js.map +1 -1
  107. package/dist/release/index.d.ts +32 -7
  108. package/dist/release/index.js +42 -0
  109. package/dist/release/index.js.map +1 -1
  110. package/dist/replay/replay.d.ts +2 -0
  111. package/dist/replay/replay.js +2 -2
  112. package/dist/replay/replay.js.map +1 -1
  113. package/dist/replay/report.js +3 -1
  114. package/dist/replay/report.js.map +1 -1
  115. package/dist/schemas.d.ts +2 -1
  116. package/dist/schemas.js +1 -0
  117. package/dist/schemas.js.map +1 -1
  118. package/dist/steps/backfill.d.ts +8 -3
  119. package/dist/steps/backfill.js +20 -9
  120. package/dist/steps/backfill.js.map +1 -1
  121. package/dist/versioned/approval.d.ts +27 -7
  122. package/dist/versioned/approval.js +69 -18
  123. package/dist/versioned/approval.js.map +1 -1
  124. package/dist/versioned/engine.js +1 -1
  125. package/dist/versioned/engine.js.map +1 -1
  126. package/dist/versioned/op.d.ts +20 -3
  127. package/dist/versioned/op.js +12 -6
  128. package/dist/versioned/op.js.map +1 -1
  129. package/dist/versioned/policy.d.ts +2 -0
  130. package/dist/versioned/policy.js +2 -2
  131. package/dist/versioned/policy.js.map +1 -1
  132. package/package.json +9 -8
  133. package/schemas/apply.schema.json +36 -2
  134. package/schemas/check.schema.json +78 -0
  135. package/schemas/drift.schema.json +1 -0
  136. package/schemas/init.schema.json +1 -0
  137. package/schemas/lint.schema.json +9 -1
  138. package/schemas/new.schema.json +1 -0
  139. package/schemas/plan.schema.json +33 -0
@@ -0,0 +1,243 @@
1
+ /**
2
+ * `yodel check` (#1): another tool's migrations, replayed and linted.
3
+ *
4
+ * The directory's migrations run, in the tool's order, against a
5
+ * throwaway server (a profile bound to the emulator, `replay` by default).
6
+ * After the ones already on the base branch, and again after each new one,
7
+ * the server's schema is read the way `yodel init --from` reads it and
8
+ * built. Each new migration then becomes the change between two builds:
9
+ * yodel's classifier names what it does (a drop, a rewrite, a lock, a
10
+ * statement that can fail on the rows there), and every `yodel lint` rule
11
+ * runs on it, the project's own policies included. Nothing is applied to
12
+ * an environment that matters: the scope is emptied before and after.
13
+ */
14
+ import { mkdtempSync, rmSync } from "node:fs";
15
+ import { join, relative } from "node:path";
16
+ import { YodelError } from "../project.js";
17
+ import { buildSchema } from "../chant/build.js";
18
+ import { importLive } from "../init/live.js";
19
+ import { createMigration, writeMigration } from "../migrations/index.js";
20
+ import { lintMigrations } from "../lint/index.js";
21
+ const ident = (s) => `"${s.replace(/"/g, '""')}"`;
22
+ const bq = (s) => `\`${s.replace(/`/g, "``")}\``;
23
+ /** The check server for `env`, the profile's scope on its server. */
24
+ export async function openCheckServer(project, env, processEnv = process.env) {
25
+ if (project.dialect === "postgres") {
26
+ const { resolvePostgresTarget, isUnresolvedTarget, redactUrl } = await import("@intentius/chant-lexicon-sql/postgres/live/bind");
27
+ const target = resolvePostgresTarget({ environment: env.name, config: project.config, env: processEnv });
28
+ if (isUnresolvedTarget(target))
29
+ throw new YodelError(target.detail);
30
+ const scope = target.schemas ?? [target.defaultSchema];
31
+ const { connectPostgres } = await import("@intentius/chant-lexicon-sql/postgres/live/client");
32
+ const client = await connectPostgres(target.endpoint, { applicationName: "yodel check" });
33
+ const path = scope.map(ident).join(", ");
34
+ return {
35
+ where: `${redactUrl(target.endpoint.url)} (${target.source})`,
36
+ scope,
37
+ defaults: { defaultSchema: target.defaultSchema },
38
+ async occupied() {
39
+ const rows = await client.query(`SELECT n.nspname,
40
+ (SELECT count(*) FROM pg_catalog.pg_class c WHERE c.relnamespace = n.oid)
41
+ + (SELECT count(*) FROM pg_catalog.pg_type t WHERE t.typnamespace = n.oid AND t.typtype IN ('e', 'd'))
42
+ + (SELECT count(*) FROM pg_catalog.pg_proc p WHERE p.pronamespace = n.oid) AS n
43
+ FROM pg_catalog.pg_namespace n WHERE n.nspname = ANY($1::text[]) ORDER BY n.nspname`, [scope]);
44
+ return rows.filter((r) => Number(r.n) > 0).map((r) => r.nspname);
45
+ },
46
+ async clear() {
47
+ for (const s of scope)
48
+ await client.query(`DROP SCHEMA IF EXISTS ${ident(s)} CASCADE; CREATE SCHEMA ${ident(s)}`);
49
+ },
50
+ async run(sql) {
51
+ await client.query(`SELECT pg_catalog.set_config('search_path', $1, false)`, [path]);
52
+ await client.query(sql);
53
+ },
54
+ close: () => client.end(),
55
+ };
56
+ }
57
+ const { resolveClickHouseTarget, isUnresolvedTarget } = await import("@intentius/chant-lexicon-sql/clickhouse/live/bind");
58
+ const target = resolveClickHouseTarget({ environment: env.name, config: project.config, env: processEnv });
59
+ if (isUnresolvedTarget(target))
60
+ throw new YodelError(target.detail);
61
+ const scope = target.databases ?? [target.defaultDatabase];
62
+ const { httpPort } = await import("../history/index.js");
63
+ const port = await httpPort(target.endpoint);
64
+ const quote = (s) => `'${s.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
65
+ return {
66
+ where: `${target.endpoint.url} (${target.source})`,
67
+ scope,
68
+ defaults: { defaultDatabase: target.defaultDatabase },
69
+ async occupied() {
70
+ const rows = await port.query(`SELECT DISTINCT database FROM system.tables WHERE database IN (${scope.map(quote).join(", ")}) ORDER BY database`);
71
+ return rows.map((r) => r.database);
72
+ },
73
+ async clear() {
74
+ for (const d of scope) {
75
+ await port.query(`DROP DATABASE IF EXISTS ${bq(d)} SYNC`);
76
+ await port.query(`CREATE DATABASE ${bq(d)}`);
77
+ }
78
+ },
79
+ async run(sql) {
80
+ await port.query(sql, { settings: { mutations_sync: "2" } });
81
+ },
82
+ close: () => Promise.resolve(),
83
+ };
84
+ }
85
+ /** The server's schema in scope, read as `yodel init --from` reads it and built; an empty build when it holds nothing. */
86
+ export async function snapshot(project, env, processEnv = process.env) {
87
+ const live = await importLive(project, env, processEnv);
88
+ if (live.files.length === 0)
89
+ return { dialect: project.dialect, objects: [] };
90
+ // Built from a source directory of its own inside the project, so the declarations resolve the project's packages.
91
+ const dir = mkdtempSync(join(project.dir, ".yodel-check-"));
92
+ try {
93
+ const { writeFileSync } = await import("node:fs");
94
+ for (const f of live.files)
95
+ writeFileSync(join(dir, f.path), f.content);
96
+ // The project's DDL sources (#67) are not this schema's: the build reads the server's alone.
97
+ const yodel = project.yodel ? { ...project.yodel, config: { ...project.yodel.config } } : undefined;
98
+ if (yodel)
99
+ delete yodel.config.sources;
100
+ const scratch = { ...project, sourceDir: relative(project.dir, dir), yodel };
101
+ const build = await buildSchema(scratch, { env: processEnv });
102
+ try {
103
+ return build.output;
104
+ }
105
+ finally {
106
+ build.dispose();
107
+ }
108
+ }
109
+ finally {
110
+ rmSync(dir, { recursive: true, force: true });
111
+ }
112
+ }
113
+ /** A migration name yodel accepts, from the other tool's. */
114
+ export function migrationName(name) {
115
+ const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
116
+ return slug === "" ? "migration" : /^[a-z]/.test(slug) ? slug : `m-${slug}`;
117
+ }
118
+ /** Runs `migrations` in order into `server` and lints each new one; see the module comment. */
119
+ export async function runCheck(project, env, server, migrations, options) {
120
+ const log = options.log ?? (() => undefined);
121
+ const processEnv = options.processEnv ?? process.env;
122
+ const occupied = await server.occupied();
123
+ if (occupied.length > 0 && !options.reset) {
124
+ throw new YodelError(`${server.where} already holds ${occupied.join(", ")}; yodel check replays into an empty scope (a throwaway server). Pass --reset to empty it first, never on a server whose data matters`, 4);
125
+ }
126
+ await server.clear();
127
+ const work = mkdtempSync(join(project.dir, ".yodel-check-migrations-"));
128
+ try {
129
+ const ours = [];
130
+ const byId = new Map();
131
+ const start = Date.UTC(2000, 0, 1);
132
+ let previous;
133
+ let before;
134
+ const record = (name, build, i) => {
135
+ const made = createMigration({ name, build, previous, now: new Date(start + i * 60_000), ...server.defaults });
136
+ if (made.id === undefined)
137
+ return undefined;
138
+ const path = writeMigration(work, made);
139
+ const m = { id: made.id, dir: path, parent: previous?.id ?? null, checksum: made.document.checksum, document: made.document, files: made.files };
140
+ ours.push(m);
141
+ previous = m;
142
+ return m;
143
+ };
144
+ let i = 0;
145
+ for (const m of migrations) {
146
+ const fresh = options.isNew(m);
147
+ if (fresh && before === undefined) {
148
+ // The schema the base branch's migrations leave: the starting point the new ones are classified against.
149
+ before = await snapshot(project, env, processEnv);
150
+ record("base", before, i++);
151
+ }
152
+ log(`${m.file}: ${String(m.statements.length)} statement${m.statements.length === 1 ? "" : "s"}`);
153
+ for (const s of m.statements) {
154
+ try {
155
+ await server.run(s.sql);
156
+ }
157
+ catch (e) {
158
+ throw new YodelError(`${m.file}:${String(s.line)}: the server refused it: ${e instanceof Error ? e.message.split("\n")[0] ?? "" : String(e)}`, 3);
159
+ }
160
+ }
161
+ if (!fresh)
162
+ continue;
163
+ const after = await snapshot(project, env, processEnv);
164
+ const made = record(migrationName(m.name), after, i++);
165
+ if (made)
166
+ byId.set(made.id, m);
167
+ else
168
+ log(`${m.file}: changes nothing the schema shows`);
169
+ }
170
+ const lint = await lintMigrations(work, options.lint);
171
+ return { report: onForeignFiles(lint, byId, options.dir), migrations: migrations.map((m) => m.file), checked: migrations.filter(options.isNew).map((m) => m.file), where: server.where };
172
+ }
173
+ finally {
174
+ rmSync(work, { recursive: true, force: true });
175
+ if (!options.keep)
176
+ await server.clear().catch(() => undefined);
177
+ }
178
+ }
179
+ /** The rules a `-- yodel:allow` line in the other tool's file can name: the statement rules a finding on it carries. */
180
+ const SILENCEABLE = new Set(["destructive", "pg-rewrite", "pg-lock", "pg-signature", "pg-access", "data-dependent", "naming", "ch-mutation", "ch-rebuild", "ch-access"]);
181
+ /**
182
+ * The lint report on the other tool's files: findings on the base
183
+ * migration dropped, the rest moved onto the file that made the change, a
184
+ * `-- yodel:allow <rule> <reason>` line in that file silencing that rule
185
+ * there, and a pg-lock finding left out when the file builds or drops the
186
+ * index CONCURRENTLY (the classifier reads the schema, which does not say).
187
+ */
188
+ export function onForeignFiles(report, byId, dir) {
189
+ const findings = [];
190
+ const used = new Set();
191
+ for (const f of report.findings) {
192
+ const m = f.migration === undefined ? undefined : byId.get(f.migration);
193
+ if (!m)
194
+ continue;
195
+ if (f.rule === "pg-lock" && concurrently(m, f.object))
196
+ continue;
197
+ if (f.rule === "silence" || f.rule === "checksum" || f.rule === "migration-sql")
198
+ continue;
199
+ const line = lineOf(m, f.object);
200
+ const moved = { ...f, message: f.message.replace(/^step \d+: /, ""), migration: m.file, file: m.file, ...(line !== undefined ? { line } : {}) };
201
+ delete moved.step;
202
+ delete moved.silenced;
203
+ const allow = SILENCEABLE.has(f.rule) || f.rule.startsWith("SQL") || /^[A-Z]/.test(f.rule) ? m.allows.find((a) => a.rule === f.rule && a.reason !== "") : undefined;
204
+ if (allow)
205
+ used.add(`${m.file}\0${allow.rule}`);
206
+ findings.push(allow ? { ...moved, silenced: allow.reason } : moved);
207
+ }
208
+ for (const m of byId.values()) {
209
+ for (const a of m.allows) {
210
+ if (a.reason === "")
211
+ findings.push({ rule: "silence", level: "error", migration: m.file, file: m.file, line: a.line, message: `yodel:allow ${a.rule} gives no reason; write one after the rule` });
212
+ else if (!used.has(`${m.file}\0${a.rule}`))
213
+ findings.push({ rule: "silence", level: "warning", migration: m.file, file: m.file, line: a.line, message: `yodel:allow ${a.rule} silences nothing in ${m.file}` });
214
+ }
215
+ }
216
+ const live = findings.filter((f) => f.silenced === undefined);
217
+ return {
218
+ ...report,
219
+ dir,
220
+ migrations: [...byId.values()].map((m) => m.file),
221
+ findings,
222
+ silences: {},
223
+ errors: live.filter((f) => f.level === "error").length,
224
+ warnings: live.filter((f) => f.level === "warning").length,
225
+ silenced: findings.length - live.length,
226
+ };
227
+ }
228
+ /** The bare name of a step's object, `schema.table` or `table`. */
229
+ const bare = (object) => object?.split(".").pop()?.replace(/\(.*$/, "").replace(/"/g, "");
230
+ /** The line of the statement in `m` that names `object`; the first statement's line otherwise. */
231
+ function lineOf(m, object) {
232
+ const name = bare(object);
233
+ const hit = name ? m.statements.find((s) => new RegExp(`\\b${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`, "i").test(s.sql)) : undefined;
234
+ return (hit ?? m.statements[0])?.line;
235
+ }
236
+ /** Whether `m` builds or drops the index named by `object` CONCURRENTLY. */
237
+ function concurrently(m, object) {
238
+ const name = bare(object);
239
+ if (!name)
240
+ return false;
241
+ return m.statements.some((s) => /\bCONCURRENTLY\b/i.test(s.sql) && new RegExp(`\\b${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`, "i").test(s.sql));
242
+ }
243
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/check/run.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAkC,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAkB,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,cAAc,EAAmD,MAAM,kBAAkB,CAAC;AAkBnG,MAAM,KAAK,GAAG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AM,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7I,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;AACxC,CAAC;AAED,4EAA4E;AAC5E,SAAS,YAAY,CAAC,CAAmB,EAAE,MAA0B;IACnE,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IACxB,OAAO,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAC1J,CAAC"}
@@ -136,6 +136,14 @@ export interface Environments {
136
136
  login?: CiLogin;
137
137
  /** yodel.config.ts `ci.apply: false` (#175): no apply pipeline, so no job holds a writer. */
138
138
  apply?: false;
139
+ /** yodel.config.ts `check` (#1): the lint job runs yodel check on another tool's migrations too. */
140
+ check?: true;
141
+ /**
142
+ * The project declares no environment, only the `replay` profile, and
143
+ * `check`: it keeps another tool for its migrations and tries yodel on
144
+ * pull requests. The pipeline is one job, yodel check, and nothing else.
145
+ */
146
+ checkOnly?: true;
139
147
  }
140
148
  /** What a job holding one role of an environment needs: the variables it reads, and the cloud identity its token source mints from. */
141
149
  export interface RoleNeeds {
@@ -208,6 +216,12 @@ export declare const LINT = "yodel lint";
208
216
  */
209
217
  export declare const lintCommand: (forge: Forge) => string;
210
218
  export declare const REPLAY = "yodel lint --replay replay --reset";
219
+ /**
220
+ * yodel check (#1): another tool's migrations, replayed into the `replay`
221
+ * profile's throwaway server and linted, the new ones since the pull
222
+ * request's base, with findings where the forge shows them.
223
+ */
224
+ export declare const checkCommand: (forge: Forge) => string;
211
225
  /** yodel test (#54), after the replay check on the same throwaway server, its outcome as JUnit XML. */
212
226
  export declare const TEST = "yodel test --env replay --reset --junit yodel-test.xml";
213
227
  /** Fails a pull request whose pipelines differ from what yodel ci renders. */
@@ -304,6 +318,22 @@ export declare function wavesSpec(waves: readonly Wave[], variables?: (env: stri
304
318
  }): WavesSpec;
305
319
  /** The waves spec file and the apply pipeline on each forge. */
306
320
  export declare function applyPipelines(dir: string, envs: Environments): Promise<RenderedFile[]>;
321
+ /**
322
+ * The wave jobs' report: chant's generateOpWavesPipeline takes run lines
323
+ * after the wave's command but no step that runs when it fails (a wave that
324
+ * waits exits 3), and no artifact, so they are added to its output here.
325
+ * The output is parsed and emitted again; the emitter is checked to give
326
+ * back chant's text unchanged before anything is added, so a change in
327
+ * chant's emitter fails here instead of rendering something else.
328
+ */
329
+ /**
330
+ * chant writes a SHA-pinned action as `uses: owner/action@<sha> # vX.Y.Z`
331
+ * (chant#4403, #4410); the `# vX.Y.Z` is a YAML comment, which parsing drops.
332
+ * Each re-emit below puts every one back on the line that names the same
333
+ * pinned ref, so the re-emitted text still matches chant's and the files keep
334
+ * the release each SHA stands for.
335
+ */
336
+ export declare function withPinComments(original: string, emitted: string): string;
307
337
  /** yodel.config.ts `waves`, checked against the environments; one wave per environment, gate `always`, without it. */
308
338
  export declare function readWaves(dir: string, envs: readonly string[]): Promise<Wave[]>;
309
339
  /**
package/dist/ci/render.js CHANGED
@@ -246,6 +246,12 @@ export const LINT = "yodel lint";
246
246
  */
247
247
  export const lintCommand = (forge) => (forge === "gitlab" ? `${LINT} --format gitlab --output ${CODE_QUALITY_FILE}` : `${LINT} --format github`);
248
248
  export const REPLAY = `yodel lint --replay ${REPLAY_PROFILE} --reset`;
249
+ /**
250
+ * yodel check (#1): another tool's migrations, replayed into the `replay`
251
+ * profile's throwaway server and linted, the new ones since the pull
252
+ * request's base, with findings where the forge shows them.
253
+ */
254
+ export const checkCommand = (forge) => `yodel check --env ${REPLAY_PROFILE} --reset --base origin/${MAIN} ${forge === "gitlab" ? `--format gitlab --output ${CODE_QUALITY_FILE}` : "--format github"}`;
249
255
  /** yodel test (#54), after the replay check on the same throwaway server, its outcome as JUnit XML. */
250
256
  export const TEST = `yodel test --env ${REPLAY_PROFILE} --reset --junit yodel-test.xml`;
251
257
  /** Fails a pull request whose pipelines differ from what yodel ci renders. */
@@ -317,11 +323,13 @@ function reportSteps(forge, env, job, tc) {
317
323
  ];
318
324
  }
319
325
  /** `inContainer`: the job runs in the toolchain's image, which has node, so it needs no setup-node. */
320
- function setupSteps(inContainer, tc) {
326
+ function setupSteps(inContainer, tc, approvals = true) {
321
327
  const steps = [new Step({ uses: CHECKOUT, with: { "fetch-depth": 0 } })];
322
328
  if (!inContainer)
323
329
  steps.push(new Step({ uses: SETUP_NODE, with: { "node-version": 22, cache: "npm" } }));
324
- steps.push(...installLines(tc, "github").map((run) => new Step({ run })), new Step({ name: "Fetch the approvals (chant/lifecycle)", run: FETCH_APPROVALS }));
330
+ steps.push(...installLines(tc, "github").map((run) => new Step({ run })));
331
+ if (approvals)
332
+ steps.push(new Step({ name: "Fetch the approvals (chant/lifecycle)", run: FETCH_APPROVALS }));
325
333
  return steps;
326
334
  }
327
335
  /** 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. */
@@ -331,7 +339,38 @@ const runner = (container, tc) => ({ "runs-on": "ubuntu-latest", ...(container ?
331
339
  function commentToken(forge) {
332
340
  return forge === "github" ? { GITHUB_TOKEN: "${{ github.token }}" } : { FORGEJO_TOKEN: "${{ github.token }}" };
333
341
  }
334
- function lintJob(forge, dialect, replay, tc, tests = false, typedColumns = false) {
342
+ /** The replay server's service and variables, for a job that replays into it. */
343
+ function replayService(dialect) {
344
+ const svc = REPLAY_SERVICE[dialect];
345
+ return {
346
+ svc,
347
+ services: {
348
+ [svc.name]: new ActionsService({
349
+ image: svc.image,
350
+ env: svc.env,
351
+ options: `--health-cmd "${svc.health}" --health-interval 2s --health-timeout 5s --health-retries 45`,
352
+ }),
353
+ },
354
+ env: { [`${variablePrefix(REPLAY_PROFILE, dialect)}_URL`]: svc.url(svc.name), ...svc.jobEnv },
355
+ };
356
+ }
357
+ /** A project that only tries yodel on another tool's migrations (#1): one job, yodel check. */
358
+ function checkJob(forge, dialect, tc) {
359
+ const { svc, services, env } = replayService(dialect);
360
+ return new ActionsJob({
361
+ ...runner(true, tc),
362
+ services,
363
+ env,
364
+ steps: [
365
+ // No approvals to read: nothing in this job runs behind a gate.
366
+ ...setupSteps(true, tc, false),
367
+ new Step({ name: "The pipelines are up to date", run: CI_CHECK }),
368
+ new Step({ name: `Wait for the replay server (${svc.name})`, run: waitFor(svc.name, svc.port) }),
369
+ new Step({ name: "yodel check", run: checkCommand(forge) }),
370
+ ],
371
+ });
372
+ }
373
+ function lintJob(forge, dialect, replay, tc, tests = false, typedColumns = false, check = false) {
335
374
  // With the replay check, the job runs in IMAGE on every forge and reaches
336
375
  // its replay server by the service's name on the job's own network. On
337
376
  // GitHub's VM the service would be on localhost through a published port,
@@ -346,29 +385,47 @@ function lintJob(forge, dialect, replay, tc, tests = false, typedColumns = false
346
385
  ];
347
386
  if (!replay)
348
387
  return new ActionsJob({ ...runner(container, tc), steps });
349
- const svc = REPLAY_SERVICE[dialect];
388
+ const { svc, services, env } = replayService(dialect);
350
389
  return new ActionsJob({
351
390
  ...runner(container, tc),
352
- services: {
353
- [svc.name]: new ActionsService({
354
- image: svc.image,
355
- env: svc.env,
356
- options: `--health-cmd "${svc.health}" --health-interval 2s --health-timeout 5s --health-retries 45`,
357
- }),
358
- },
359
- env: { [`${variablePrefix(REPLAY_PROFILE, dialect)}_URL`]: svc.url(svc.name), ...svc.jobEnv },
391
+ services,
392
+ env,
360
393
  steps: [
361
394
  ...steps,
362
395
  new Step({ name: `Wait for the replay server (${svc.name})`, run: waitFor(svc.name, svc.port) }),
363
396
  new Step({ name: "yodel lint --replay", run: REPLAY }),
364
397
  ...(tests ? [new Step({ name: "yodel test", run: TEST })] : []),
398
+ ...(check ? [new Step({ name: "yodel check", run: checkCommand(forge) })] : []),
365
399
  ],
366
400
  });
367
401
  }
402
+ /** The pull request workflow of a project that only runs yodel check (#1). */
403
+ function checkOnlyActions(forge, envs_) {
404
+ const jobs = { check: checkJob(forge, envs_.dialect, toolchainOf(envs_)) };
405
+ Object.assign(jobs, ownJobs(envs_.jobs?.actions, jobs, "actions"));
406
+ const header = [
407
+ ...HEADER,
408
+ "#",
409
+ "# Pull requests: yodel check replays the migrations another tool keeps into a",
410
+ "# throwaway server the job starts, and lints the new ones. No job here reads",
411
+ "# or writes an environment.",
412
+ ];
413
+ const workflow = new ActionsWorkflow({
414
+ comment: asComment(header),
415
+ name: "yodel-pr",
416
+ on: { pull_request: { branches: [MAIN] } },
417
+ permissions: new Permissions({ contents: "read" }),
418
+ concurrency: new Concurrency({ group: "yodel-pr-${{ github.event.pull_request.number }}", "cancel-in-progress": true }),
419
+ jobs,
420
+ });
421
+ return { path: `${forge === "github" ? ".github" : ".forgejo"}/workflows/yodel-pr.yml`, content: renderActions(forge, workflow) };
422
+ }
368
423
  export function actionsReview(forge, envs_) {
369
424
  const { dialect, names: envs, replay, waves, jobs: own } = envs_;
370
425
  const tc = toolchainOf(envs_);
371
- const jobs = { lint: lintJob(forge, dialect, replay, tc, envs_.tests === true, envs_.typedColumns === true) };
426
+ if (envs_.checkOnly)
427
+ return checkOnlyActions(forge, envs_);
428
+ const jobs = { lint: lintJob(forge, dialect, replay, tc, envs_.tests === true, envs_.typedColumns === true, envs_.check === true) };
372
429
  for (const env of envs) {
373
430
  const read = [env, ...requiredOf(waves, env)];
374
431
  jobs[`plan-${env}`] = new ActionsJob({
@@ -405,7 +462,8 @@ export function actionsReview(forge, envs_) {
405
462
  comment: asComment(header),
406
463
  name: "yodel-pr",
407
464
  on: { pull_request: { branches: [MAIN] } },
408
- permissions: new Permissions({ contents: "read", "pull-requests": "write", ...(clouds.length > 0 ? { "id-token": "write" } : {}) }),
465
+ // actions: read lets yodel plan --comment ask when the watch workflows last ran (chant#4289).
466
+ permissions: new Permissions({ contents: "read", "pull-requests": "write", ...(forge === "github" ? { actions: "read" } : {}), ...(clouds.length > 0 ? { "id-token": "write" } : {}) }),
409
467
  concurrency: new Concurrency({ group: "yodel-pr-${{ github.event.pull_request.number }}", "cancel-in-progress": true }),
410
468
  jobs,
411
469
  });
@@ -441,13 +499,38 @@ export function gitlabPipeline(envs_) {
441
499
  }));
442
500
  const svc = REPLAY_SERVICE[dialect];
443
501
  const types = envs_.typedColumns === true ? [TYPES_CHECK] : [];
502
+ if (envs_.checkOnly) {
503
+ jobs.set("check", new GitLabJob({
504
+ extends: ".yodel",
505
+ stage: "review",
506
+ rules: mr(),
507
+ script: [CI_CHECK, waitFor(svc.name, svc.port), checkCommand("gitlab")],
508
+ services: [new GitLabService({ name: svc.image, alias: svc.name, variables: svc.env })],
509
+ variables: { [`${variablePrefix(REPLAY_PROFILE, dialect)}_URL`]: svc.url(svc.name), ...svc.jobEnv },
510
+ artifacts: new GitLabArtifacts({ when: "always", reports: { codequality: CODE_QUALITY_FILE } }),
511
+ }));
512
+ for (const [name, job] of Object.entries(ownJobs(own?.gitlab, Object.fromEntries(jobs), "gitlab")))
513
+ jobs.set(name, job);
514
+ const header = [
515
+ ...HEADER,
516
+ "#",
517
+ "# Merge requests: yodel check replays the migrations another tool keeps into a",
518
+ "# throwaway server the job starts, and lints the new ones (stage review). No",
519
+ "# job here reads or writes an environment.",
520
+ ];
521
+ const jobStages = [...jobs.values()].map((job) => job.props?.stage).filter((stage) => typeof stage === "string");
522
+ const pipeline = new GitLabPipeline({ comment: asComment(header), stages: [...new Set(jobStages)], variables: { GIT_DEPTH: "0" } });
523
+ const entities = new Map([["pipeline", pipeline], ["workflow", workflow], ...jobs]);
524
+ return { path: ".gitlab-ci.yml", content: oneFile("gitlab", gitlabSerializer.serialize(entities)) };
525
+ }
526
+ const check = envs_.check === true ? [checkCommand("gitlab")] : [];
444
527
  jobs.set("lint", new GitLabJob({
445
528
  extends: ".yodel",
446
529
  stage: "review",
447
530
  rules: mr(),
448
531
  ...(replay
449
532
  ? {
450
- script: [CI_CHECK, ...types, lintCommand("gitlab"), waitFor(svc.name, svc.port), REPLAY, ...(envs_.tests === true ? [TEST] : [])],
533
+ script: [CI_CHECK, ...types, lintCommand("gitlab"), waitFor(svc.name, svc.port), REPLAY, ...(envs_.tests === true ? [TEST] : []), ...check],
451
534
  services: [new GitLabService({ name: svc.image, alias: svc.name, variables: svc.env })],
452
535
  variables: { [`${variablePrefix(REPLAY_PROFILE, dialect)}_URL`]: svc.url(svc.name), ...svc.jobEnv },
453
536
  }
@@ -669,6 +752,26 @@ export async function applyPipelines(dir, envs) {
669
752
  * back chant's text unchanged before anything is added, so a change in
670
753
  * chant's emitter fails here instead of rendering something else.
671
754
  */
755
+ /**
756
+ * chant writes a SHA-pinned action as `uses: owner/action@<sha> # vX.Y.Z`
757
+ * (chant#4403, #4410); the `# vX.Y.Z` is a YAML comment, which parsing drops.
758
+ * Each re-emit below puts every one back on the line that names the same
759
+ * pinned ref, so the re-emitted text still matches chant's and the files keep
760
+ * the release each SHA stands for.
761
+ */
762
+ export function withPinComments(original, emitted) {
763
+ const comments = new Map();
764
+ for (const [, ref, comment] of original.matchAll(/uses: (\S+@[0-9a-f]{40}) (# [^\n]*)$/gm)) {
765
+ if (ref !== undefined && comment !== undefined)
766
+ comments.set(ref, comment);
767
+ }
768
+ if (comments.size === 0)
769
+ return emitted;
770
+ return emitted.replace(/uses: (\S+@[0-9a-f]{40})$/gm, (line, ref) => {
771
+ const comment = comments.get(ref);
772
+ return comment ? `${line} ${comment}` : line;
773
+ });
774
+ }
672
775
  function withWaveReports(forge, yaml, waves, tc, envs = {}) {
673
776
  // A wide wave's jobs are wave-<k>-<env>-decide and -share-<i>.
674
777
  const envOf = (job) => waves.find((w, i) => new RegExp(`^wave-${String(i + 1)}-${w.env.replace(/[^A-Za-z0-9]/g, "\\$&")}(-decide|-share-\\d+)?$`).test(job))?.env;
@@ -676,7 +779,7 @@ function withWaveReports(forge, yaml, waves, tc, envs = {}) {
676
779
  const header = yaml.slice(0, body);
677
780
  const doc = parseYAMLDocument(yaml);
678
781
  if (forge === "gitlab") {
679
- const emit = (d) => `${header}${Object.entries(d).map(([k, v]) => emitYAMLEntry(k, v)).join("\n\n")}\n`;
782
+ const emit = (d) => withPinComments(yaml, `${header}${Object.entries(d).map(([k, v]) => emitYAMLEntry(k, v)).join("\n\n")}\n`);
680
783
  if (emit(doc) !== yaml)
681
784
  throw new Error("gitlab: the apply waves do not emit back to chant's text");
682
785
  // The merge request job that records the plans a review approves (#48): the waves as after the merge.
@@ -719,7 +822,7 @@ function withWaveReports(forge, yaml, waves, tc, envs = {}) {
719
822
  throw new Error(`${forge}: the apply waves have no jobs`);
720
823
  const jobs = doc.jobs;
721
824
  const top = yaml.slice(0, at + 1);
722
- const emitJobs = () => `${emitYAMLEntry("jobs", jobs)}\n`;
825
+ const emitJobs = () => withPinComments(yaml, `${emitYAMLEntry("jobs", jobs)}\n`);
723
826
  if (`${top}${emitJobs()}` !== yaml)
724
827
  throw new Error(`${forge}: the apply waves do not emit back to chant's text`);
725
828
  for (const [name, job] of Object.entries(jobs)) {
@@ -745,7 +848,7 @@ function withPlansReaders(forge, yaml, waves, dialect, creds = {}) {
745
848
  throw new Error(`${forge}: the plans workflow has no jobs`);
746
849
  const doc = parseYAMLDocument(yaml);
747
850
  const top = yaml.slice(0, at + 1);
748
- const emitJobs = () => `${emitYAMLEntry("jobs", doc.jobs)}\n`;
851
+ const emitJobs = () => withPinComments(yaml, `${emitYAMLEntry("jobs", doc.jobs)}\n`);
749
852
  if (`${top}${emitJobs()}` !== yaml)
750
853
  throw new Error(`${forge}: the plans workflow does not emit back to chant's text`);
751
854
  const job = doc.jobs["record-plans"];
@@ -846,7 +949,7 @@ function withWatchLogin(forge, yaml, env, envs) {
846
949
  throw new Error(`${forge}: the watch for ${env} has no jobs`);
847
950
  const doc = parseYAMLDocument(yaml);
848
951
  const top = yaml.slice(0, at + 1);
849
- const emitJobs = () => `${emitYAMLEntry("jobs", doc.jobs)}\n`;
952
+ const emitJobs = () => withPinComments(yaml, `${emitYAMLEntry("jobs", doc.jobs)}\n`);
850
953
  if (`${top}${emitJobs()}` !== yaml)
851
954
  throw new Error(`${forge}: the watch for ${env} does not emit back to chant's text`);
852
955
  const job = doc.jobs[`watch-${env}`];
@@ -863,7 +966,7 @@ function withWatchIdTokens(yaml, envs) {
863
966
  const body = yaml.search(/^[^#\n]/m);
864
967
  const header = yaml.slice(0, body);
865
968
  const doc = parseYAMLDocument(yaml);
866
- const emit = (d) => `${header}${Object.entries(d).map(([k, v]) => emitYAMLEntry(k, v)).join("\n\n")}\n`;
969
+ const emit = (d) => withPinComments(yaml, `${header}${Object.entries(d).map(([k, v]) => emitYAMLEntry(k, v)).join("\n\n")}\n`);
867
970
  if (emit(doc) !== yaml)
868
971
  throw new Error("gitlab: the watch file does not emit back to chant's text");
869
972
  for (const env of envs.names) {
@@ -924,6 +1027,29 @@ export async function environments(dir) {
924
1027
  const all = Object.keys(sql?.profiles ?? {});
925
1028
  const replay = all.includes(REPLAY_PROFILE);
926
1029
  const envs = all.filter((name) => name !== REPLAY_PROFILE);
1030
+ const yodelConfig = await readConfig(dir);
1031
+ const check = yodelConfig?.check;
1032
+ if (check) {
1033
+ if (!replay)
1034
+ throw new Error(`yodel.config.ts: check runs in CI against the ${REPLAY_PROFILE} profile's throwaway server, which chant.config.ts does not declare`);
1035
+ if (check.env !== undefined && check.env !== REPLAY_PROFILE)
1036
+ throw new Error(`yodel.config.ts: check.env is ${check.env}; in CI yodel check runs against the ${REPLAY_PROFILE} profile's throwaway server, so leave check.env out or set it to ${REPLAY_PROFILE}`);
1037
+ }
1038
+ if (envs.length === 0 && check) {
1039
+ const ci0 = yodelConfig.ci;
1040
+ return {
1041
+ dialect,
1042
+ names: [],
1043
+ replay,
1044
+ waves: [],
1045
+ check: true,
1046
+ checkOnly: true,
1047
+ forges: ci0?.forges ?? FORGES,
1048
+ ...(ci0?.jobs ? { jobs: await loadProjectJobs(dir, ci0.jobs) } : {}),
1049
+ ...(ci0?.image ? { image: ci0.image } : {}),
1050
+ apply: false,
1051
+ };
1052
+ }
927
1053
  if (envs.length === 0)
928
1054
  throw new Error("chant.config.ts declares no sql.profiles");
929
1055
  for (const env of envs) {
@@ -932,7 +1058,7 @@ export async function environments(dir) {
932
1058
  throw new Error(`sql.profiles.${env} has no ops/${op}.op.ts`);
933
1059
  }
934
1060
  }
935
- const ci = (await readConfig(dir))?.ci;
1061
+ const ci = yodelConfig?.ci;
936
1062
  const credentials = credentialsIn(sql?.profiles ?? {}, envs);
937
1063
  return {
938
1064
  dialect,
@@ -948,6 +1074,7 @@ export async function environments(dir) {
948
1074
  ...(ci?.resume ? { resume: { schedule: ci.resume.schedule } } : {}),
949
1075
  ...(ci?.login ? { login: ci.login } : {}),
950
1076
  ...(ci?.apply === false ? { apply: false } : {}),
1077
+ ...(check ? { check: true } : {}),
951
1078
  };
952
1079
  }
953
1080
  /** The roles of each environment whose profile is made with credentials(). */
@@ -1017,6 +1144,8 @@ export function forgeOf(path) {
1017
1144
  export async function render(dir) {
1018
1145
  const envs = await environments(dir);
1019
1146
  const forges = envs.forges ?? FORGES;
1147
+ if (envs.checkOnly)
1148
+ return review(envs).filter((f) => forges.includes(forgeOf(f.path)));
1020
1149
  // ci.apply: false (#175): no waves spec and no apply pipeline on any forge.
1021
1150
  const files = [...review(envs), ...(rendersApply(envs) ? await applyPipelines(dir, envs) : []), ...(await watchPipelines(dir, envs))];
1022
1151
  return files.filter((f) => {