@intentius/sql-yodeler 0.13.5 → 0.15.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.
- package/dist/ci/image-set.d.ts +75 -0
- package/dist/ci/image-set.js +124 -0
- package/dist/ci/image-set.js.map +1 -0
- package/dist/ci/login.d.ts +6 -0
- package/dist/ci/login.js +11 -0
- package/dist/ci/login.js.map +1 -1
- package/dist/ci/pipeline.d.ts +116 -0
- package/dist/ci/pipeline.js +271 -0
- package/dist/ci/pipeline.js.map +1 -0
- package/dist/ci/render.d.ts +52 -4
- package/dist/ci/render.js +245 -15
- package/dist/ci/render.js.map +1 -1
- package/dist/ci-words.d.ts +11 -1
- package/dist/ci-words.js +9 -0
- package/dist/ci-words.js.map +1 -1
- package/dist/commands/chant.js +4 -2
- package/dist/commands/chant.js.map +1 -1
- package/dist/commands/ci.js +30 -1
- package/dist/commands/ci.js.map +1 -1
- package/dist/commands/config.js +2 -0
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/index.js +5 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/plan.js +28 -4
- package/dist/commands/plan.js.map +1 -1
- package/dist/commands/report.d.ts +2 -2
- package/dist/commands/report.js +3 -2
- package/dist/commands/report.js.map +1 -1
- package/dist/commands/stages.d.ts +9 -0
- package/dist/commands/stages.js +122 -0
- package/dist/commands/stages.js.map +1 -0
- package/dist/config/define.d.ts +223 -1
- package/dist/config/define.js +3 -0
- package/dist/config/define.js.map +1 -1
- package/dist/config/load.d.ts +6 -0
- package/dist/config/load.js +74 -7
- package/dist/config/load.js.map +1 -1
- package/dist/config/vocabulary.d.ts +28 -0
- package/dist/config/vocabulary.js +73 -0
- package/dist/config/vocabulary.js.map +1 -0
- package/dist/image-digests.json +4 -0
- package/dist/pr/note.d.ts +14 -1
- package/dist/pr/note.js +19 -3
- package/dist/pr/note.js.map +1 -1
- package/dist/project.d.ts +10 -3
- package/dist/project.js +8 -2
- package/dist/project.js.map +1 -1
- package/dist/report/chant-audit.d.ts +22 -0
- package/dist/report/chant-audit.js +30 -0
- package/dist/report/chant-audit.js.map +1 -0
- package/dist/report/jsonl.d.ts +16 -13
- package/dist/report/jsonl.js +26 -19
- package/dist/report/jsonl.js.map +1 -1
- package/dist/schemas.d.ts +1 -1
- package/dist/waves/index.js +21 -4
- package/dist/waves/index.js.map +1 -1
- package/package.json +8 -8
- package/schemas/report.schema.json +27 -1
package/dist/ci/render.js
CHANGED
|
@@ -71,7 +71,9 @@
|
|
|
71
71
|
* needs no token, in IMAGE. With yodel.config.ts `ci.image` (#66), the CI
|
|
72
72
|
* image ghcr.io/intentius/sql-yodeler pinned by its digest, every job runs
|
|
73
73
|
* in that image instead, which carries node, yodel, chant and the lexicons
|
|
74
|
-
* on PATH, and no job runs `npm ci` ({@link Toolchain}).
|
|
74
|
+
* on PATH, and no job runs `npm ci` ({@link Toolchain}). `ci.imageBase`
|
|
75
|
+
* (sql-yodeler issue 405) names that image from the release's digests, in
|
|
76
|
+
* its Debian or Chainguard set ({@link imageOf}, ./image-set.ts).
|
|
75
77
|
*
|
|
76
78
|
* yodel ci renders through chant's product pipeline (chant#4550) with
|
|
77
79
|
* yodel's words (#289, ../ci-words.ts): {@link productWaves}.
|
|
@@ -80,12 +82,14 @@ import { existsSync, realpathSync } from "node:fs";
|
|
|
80
82
|
import { join, relative, resolve, sep } from "node:path";
|
|
81
83
|
import { pathToFileURL } from "node:url";
|
|
82
84
|
import { APPROVAL_MODES, WAVE_GATES, waveGateHint } from "../config/define.js";
|
|
85
|
+
import { environmentSetsOf, firstStageSpec, laterStages, pipelineDeclaration, pipelineOn, pipelineText, PIPELINE_TS } from "./pipeline.js";
|
|
83
86
|
import { commitFiles, COMMIT_TOKEN_ENV, GITLAB_COMMIT_FILES } from "./commit.js";
|
|
84
87
|
import { stepHooks } from "../apply-steps/index.js";
|
|
85
|
-
import { CLOUD_OF, forgejoLoginSpec, jobLogins, loginSteps, tradeIdTokens, tradeSpec } from "./login.js";
|
|
88
|
+
import { CLOUD_OF, forgejoLoginLines, forgejoLoginSpec, jobLogins, loginSteps, tradeIdTokens, tradeSpec } from "./login.js";
|
|
86
89
|
import { RECORD_PLANS_ENV } from "../approval-mode/index.js";
|
|
87
90
|
import { cloudToken, credentialsOf, roleVariables } from "../credentials.js";
|
|
88
91
|
import { loadYodelConfig } from "../config/load.js";
|
|
92
|
+
import { committedImage, imageForBase } from "./image-set.js";
|
|
89
93
|
import { testFiles } from "../testing/files.js";
|
|
90
94
|
import { CODE_QUALITY_FILE } from "../lint/annotations.js";
|
|
91
95
|
import { chantCheckHooks, checkPresets, declarationFile, declarationWithHooks } from "./check-hooks.js";
|
|
@@ -102,7 +106,7 @@ import { generateForgejoProductPlanPipeline } from "@intentius/chant-lexicon-for
|
|
|
102
106
|
import { generateGitlabProductPlanPipeline } from "@intentius/chant-lexicon-gitlab/components/product-plan-pipeline";
|
|
103
107
|
import { emitGitlabFile } from "@intentius/chant-lexicon-gitlab/components/ci-jobs";
|
|
104
108
|
import { parseYAML } from "@intentius/chant/yaml";
|
|
105
|
-
import { chantProduct, WAVE_WORDS, YODEL_NOTE_MARKER, YODEL_PR_ENV, YODEL_WORDS } from "../ci-words.js";
|
|
109
|
+
import { chantProduct, PIPELINE_WORDS, WAVE_WORDS, YODEL_NOTE_MARKER, YODEL_PR_ENV, YODEL_WORDS } from "../ci-words.js";
|
|
106
110
|
import { SUBJECT_PART_WORDS } from "../pr/note.js";
|
|
107
111
|
export const FORGES = ["github", "gitlab", "forgejo"];
|
|
108
112
|
/** The image every job runs in, where the forge runs jobs in a container. It needs git, so not -slim. */
|
|
@@ -595,6 +599,8 @@ export function gitlabPipeline(envs_) {
|
|
|
595
599
|
for (const [name, job] of Object.entries(ownJobs(own?.gitlab, { ...Object.fromEntries(jobs), ...Object.fromEntries(plan.jobs.map((j) => [j, true])) }, "gitlab")))
|
|
596
600
|
jobs.set(name, job);
|
|
597
601
|
const apply = rendersApply(envs_);
|
|
602
|
+
// In chant's pipeline (#384) a later stage's writer is held by its promote job.
|
|
603
|
+
const promotedHere = (env) => (envs_.pipeline?.promotion ?? []).slice(1).includes(env);
|
|
598
604
|
const variables = envs.flatMap((env) => {
|
|
599
605
|
const creds = envs_.credentials?.[env];
|
|
600
606
|
// With ci.apply: false no job holds a writer, so no writer variable is set.
|
|
@@ -603,7 +609,7 @@ export function gitlabPipeline(envs_) {
|
|
|
603
609
|
`# ${readerVariables(env, dialect, creds).join(", ")}: not protected (merge request`,
|
|
604
610
|
"# pipelines run on unprotected branches), masked; no environment scope.",
|
|
605
611
|
...(writer.length > 0
|
|
606
|
-
? [`# ${writer.join(", ")}: protected, masked,`, `# environment scope "${env}": only ${env}'s wave job declares that environment.`]
|
|
612
|
+
? [`# ${writer.join(", ")}: protected, masked,`, `# environment scope "${env}": only ${env}'s ${promotedHere(env) ? "promote" : "wave"} job declares that environment.`]
|
|
607
613
|
: []),
|
|
608
614
|
];
|
|
609
615
|
});
|
|
@@ -620,6 +626,9 @@ export function gitlabPipeline(envs_) {
|
|
|
620
626
|
...(apply
|
|
621
627
|
? [`# A push to the default branch: the apply waves, one stage each, in ${GITLAB_APPLY_FILE}.`]
|
|
622
628
|
: ["# No apply pipeline (yodel.config.ts ci.apply: false): migrations are applied outside CI."]),
|
|
629
|
+
...(apply && envs_.pipeline?.promotion && envs_.pipeline.promotion.length > 1
|
|
630
|
+
? [`# The stages after ${envs_.pipeline.promotion[0] ?? ""} take the release the merge cut, in ${GITLAB_PROMOTE_FILE}.`]
|
|
631
|
+
: []),
|
|
623
632
|
`# The drift watches are in ${GITLAB_WATCH_FILE} (stage ops).`,
|
|
624
633
|
...(respondsNew(envs_) ? [`# /yodel new, chant's commit job, is in ${GITLAB_COMMIT_FILES.new} (stage ops).`] : []),
|
|
625
634
|
...(rebaseRespond(envs_) !== "off" ? [`# /yodel rebase, after the merge request's check, is in ${GITLAB_COMMIT_FILES.rebase} (stage ops).`] : []),
|
|
@@ -653,11 +662,15 @@ export function gitlabPipeline(envs_) {
|
|
|
653
662
|
// A pr-review wave (#48) adds the merge request job that records the plans, in chant's stage "plans".
|
|
654
663
|
const jobStages = [...jobs.values()].map((job) => job.props?.stage).filter((stage) => typeof stage === "string");
|
|
655
664
|
// ci.apply: false (#175): no apply file, so neither its include nor its stages.
|
|
656
|
-
|
|
657
|
-
const
|
|
665
|
+
// chant's pipeline (#384): the merge applies the first stage's wave, and the promote file takes the rest.
|
|
666
|
+
const staged = envs_.pipeline?.promotion;
|
|
667
|
+
const merged = staged ? waves.filter((w) => w.env === staged[0]) : waves;
|
|
668
|
+
const promotes = apply && staged !== undefined && staged.length > 1;
|
|
669
|
+
const plans = apply && merged.some((w) => w.approval === "pr-review") ? [PLANS_STAGE] : [];
|
|
670
|
+
const applyStages = apply ? [...plans, ...waveStages(merged), ...(envs_.resume ? [RESUME_STAGE] : []), ...(promotes ? [PROMOTE_STAGE] : [])] : [];
|
|
658
671
|
const pipeline = new GitLabPipeline({
|
|
659
672
|
comment: asComment(header),
|
|
660
|
-
include: [{ local: GITLAB_PLAN_FILE }, ...(apply ? [{ local: GITLAB_APPLY_FILE }] : []), { local: GITLAB_WATCH_FILE }, ...(respondsNew(envs_) ? [{ local: GITLAB_COMMIT_FILES.new }] : []), ...(rebaseRespond(envs_) !== "off" ? [{ local: GITLAB_COMMIT_FILES.rebase }] : [])],
|
|
673
|
+
include: [{ local: GITLAB_PLAN_FILE }, ...(apply ? [{ local: GITLAB_APPLY_FILE }] : []), ...(promotes ? [{ local: GITLAB_PROMOTE_FILE }] : []), { local: GITLAB_WATCH_FILE }, ...(respondsNew(envs_) ? [{ local: GITLAB_COMMIT_FILES.new }] : []), ...(rebaseRespond(envs_) !== "off" ? [{ local: GITLAB_COMMIT_FILES.rebase }] : [])],
|
|
661
674
|
// The plan file's stages (chant's plan and plan-note) right after review.
|
|
662
675
|
stages: [...new Set(["review", ...plan.stages, ...jobStages, ...applyStages, "ops"])],
|
|
663
676
|
variables: { GIT_DEPTH: "0" },
|
|
@@ -691,6 +704,16 @@ const requiredOf = (waves, env) => {
|
|
|
691
704
|
/** The waves spec: committed, and read by every wave job (its gate policy at the commit before the push). */
|
|
692
705
|
export const WAVES_SPEC = "yodel-waves.json";
|
|
693
706
|
export const APPLY_PIPELINE = "yodel-apply";
|
|
707
|
+
/** `ci.agent["wave-refused"]` as chant's `WaveSummarySpec`: chant's mechanism, so the keys are only renamed. */
|
|
708
|
+
function waveSummaryOf(s) {
|
|
709
|
+
return {
|
|
710
|
+
...(s.command !== undefined ? { command: s.command } : {}),
|
|
711
|
+
...(s.key_secret !== undefined ? { keyEnv: s.key_secret } : {}),
|
|
712
|
+
...(s.timeout !== undefined ? { timeout: s.timeout } : {}),
|
|
713
|
+
...(s.max_runs !== undefined ? { maxRuns: s.max_runs } : {}),
|
|
714
|
+
...(s.max_cost_usd !== undefined ? { maxCostUsd: s.max_cost_usd } : {}),
|
|
715
|
+
};
|
|
716
|
+
}
|
|
694
717
|
/**
|
|
695
718
|
* The waves spec. What the file holds is the same for every forge; each
|
|
696
719
|
* forge's jobs get their own variables and OIDC tokens on top (`job`).
|
|
@@ -712,7 +735,7 @@ export const APPLY_PIPELINE = "yodel-apply";
|
|
|
712
735
|
* the base commit, as it does run by hand. A step runs once, under the
|
|
713
736
|
* lock, as #107 asks.
|
|
714
737
|
*/
|
|
715
|
-
export function wavesSpec(waves, job, resume) {
|
|
738
|
+
export function wavesSpec(waves, job, resume, waveRefused, summary) {
|
|
716
739
|
const first = waves[0];
|
|
717
740
|
if (!first)
|
|
718
741
|
throw new Error("no waves to render");
|
|
@@ -733,6 +756,8 @@ export function wavesSpec(waves, job, resume) {
|
|
|
733
756
|
// The steps around apply (#64) as chant's stage hooks, which the apply runs under its lock (#206).
|
|
734
757
|
...hooksOf(w.steps),
|
|
735
758
|
})),
|
|
759
|
+
...(waveRefused ? { respond: { "wave-refused": waveRefused } } : {}),
|
|
760
|
+
...(waveRefused === "summary" && summary ? { waveSummary: waveSummaryOf(summary) } : {}),
|
|
736
761
|
...(resume ? { resume } : {}),
|
|
737
762
|
};
|
|
738
763
|
}
|
|
@@ -771,11 +796,17 @@ function jobLogin(forge, envs, held) {
|
|
|
771
796
|
* variables and OIDC tokens in the spec.
|
|
772
797
|
*/
|
|
773
798
|
export async function applyPipelines(dir, envs, product) {
|
|
774
|
-
const { dialect
|
|
799
|
+
const { dialect } = envs;
|
|
775
800
|
const tc = toolchainOf(envs);
|
|
776
801
|
const { generateOpWavesPipeline } = (await import("@intentius/chant/op"));
|
|
777
802
|
const named = (forge, spec) => productWaves(product, forge, spec);
|
|
778
|
-
const
|
|
803
|
+
const plain = named("github", wavesSpec(envs.waves, undefined, undefined, envs.respondWaveRefused, envs.agentWaveRefused)).spec;
|
|
804
|
+
// chant's pipeline (#384): the spec the merge applies is the first stage's, from the folded .chant/pipeline.ts.
|
|
805
|
+
const staged = envs.pipeline ? await stagedWaves(envs.pipeline, plain) : undefined;
|
|
806
|
+
const first = staged?.spec.waves[0]?.name;
|
|
807
|
+
// The waves the merge applies: every one, or in a pipeline the first stage's.
|
|
808
|
+
const waves = first === undefined ? envs.waves : envs.waves.filter((w) => w.env === first);
|
|
809
|
+
const out = [{ path: WAVES_SPEC, content: `${JSON.stringify(staged?.spec ?? plain, null, 2)}\n` }, ...(staged ? [{ path: PIPELINE_TS, content: staged.text }] : [])];
|
|
779
810
|
// A GitLab job already has the project's variables, a writer's only under its environment.
|
|
780
811
|
const jobOf = (forge) => (env) => {
|
|
781
812
|
const wave = waves.find((w) => w.env === env);
|
|
@@ -861,14 +892,18 @@ export async function applyPipelines(dir, envs, product) {
|
|
|
861
892
|
"# holds no writer's credentials: it plans with each environment's reader.",
|
|
862
893
|
];
|
|
863
894
|
for (const forge of FORGES) {
|
|
864
|
-
const { spec, jobs } = named(forge, wavesSpec(waves, jobOf(forge), envs.resume));
|
|
895
|
+
const { spec, jobs } = named(forge, staged ? withJobs(staged.spec, jobOf(forge), envs.resume) : wavesSpec(waves, jobOf(forge), envs.resume, envs.respondWaveRefused, envs.agentWaveRefused));
|
|
865
896
|
const result = await generateOpWavesPipeline(spec, forge, {
|
|
897
|
+
// Each wave job gets its environment's set of config and secrets (#384, chant's environment sets).
|
|
898
|
+
...(envs.environmentSets ? { environmentSets: envs.environmentSets } : {}),
|
|
866
899
|
specFile: WAVES_SPEC,
|
|
867
900
|
bin: YODEL_WORDS.bin,
|
|
868
901
|
image: tc.image,
|
|
869
902
|
beforeScript: [...installLines(tc, forge), fetchApprovals(tc)],
|
|
870
903
|
waveJobs: waveJobs(forge),
|
|
871
904
|
recordPlans: recordPlans(forge),
|
|
905
|
+
// The wave jobs' token on GitHub and Forgejo (a GitLab job reads its CI/CD variables or CI_JOB_TOKEN): see commandToken.
|
|
906
|
+
...(commandToken(forge, envs.respondWaveRefused, envs.pipeline) ?? {}),
|
|
872
907
|
// Signed checks (sql-yodeler issue 346): each deciding wave signs plan:<wave> and policy:<wave>; on GitLab its <wave job>-evidence job, in chant-evidence.
|
|
873
908
|
...(envs.evidence ? { evidence: envs.evidence } : {}),
|
|
874
909
|
...(forge === "gitlab" ? { opsFileName: GITLAB_APPLY_FILE } : {}),
|
|
@@ -886,9 +921,179 @@ export async function applyPipelines(dir, envs, product) {
|
|
|
886
921
|
else
|
|
887
922
|
out.push({ path: at, content: withHeader([...header, ...identityHeader(forge, waveClouds)], withWaveLines(forge, yaml, jobs)) });
|
|
888
923
|
}
|
|
924
|
+
if (envs.pipeline)
|
|
925
|
+
out.push(...(await promoteFiles(forge, envs)));
|
|
889
926
|
}
|
|
890
927
|
return out;
|
|
891
928
|
}
|
|
929
|
+
/**
|
|
930
|
+
* The job's token a GitHub or Forgejo wave job's command gets, with the
|
|
931
|
+
* scopes it needs beside chant's own, or undefined for none. A refused
|
|
932
|
+
* wave's diff is posted with it: pull request comments, and the tracking
|
|
933
|
+
* issue a wave with no pull request uses. With `ci.promotion` the first
|
|
934
|
+
* stage's last wave cuts the release, and under `release.green:
|
|
935
|
+
* "forge-checks"` (chant's default without `ci.green`) the cut reads the
|
|
936
|
+
* merge commit's checks and statuses with it (#395).
|
|
937
|
+
*/
|
|
938
|
+
export function commandToken(forge, respondWaveRefused, pipeline) {
|
|
939
|
+
if (forge === "gitlab")
|
|
940
|
+
return undefined;
|
|
941
|
+
const permissions = {
|
|
942
|
+
...(respondWaveRefused === "diff" || respondWaveRefused === "summary" ? { "pull-requests": "write", issues: "write" } : {}),
|
|
943
|
+
...(pipeline && pipeline.release?.cut !== false ? { checks: "read", statuses: "read" } : {}),
|
|
944
|
+
};
|
|
945
|
+
return Object.keys(permissions).length > 0 ? { commandToken: { permissions } } : undefined;
|
|
946
|
+
}
|
|
947
|
+
/** `.chant/pipeline.ts` from yodel.config.ts, and the first stage's spec from the folded file: what the merge applies (#384). */
|
|
948
|
+
async function stagedWaves(ci, plain) {
|
|
949
|
+
const spec = Object.fromEntries(Object.entries(plain).filter(([k]) => k !== "resume"));
|
|
950
|
+
const declaration = await pipelineDeclaration({ name: APPLY_PIPELINE, ci, spec, bin: YODEL_WORDS.bin.split(" ") });
|
|
951
|
+
const text = await pipelineText(declaration);
|
|
952
|
+
return { text, spec: (await firstStageSpec(text, APPLY_PIPELINE)) };
|
|
953
|
+
}
|
|
954
|
+
/** The first stage's spec with each wave's forge settings, as {@link wavesSpec} adds them with a `job`. */
|
|
955
|
+
function withJobs(spec, job, resume) {
|
|
956
|
+
return { ...spec, waves: spec.waves.map((w) => ({ ...w, environment: { name: w.name }, ...job(w.name) })), ...(resume ? { resume } : {}) };
|
|
957
|
+
}
|
|
958
|
+
/** The reject comment workflow's job (#384). */
|
|
959
|
+
export const REJECT_JOB = "reject";
|
|
960
|
+
/**
|
|
961
|
+
* `/yodel reject [--stage <env>] <reason>` on a pull request (#384), on
|
|
962
|
+
* GitHub and Forgejo: chant's comment job (`components pr-comment`) under the
|
|
963
|
+
* words that map `reject` onto chant's reject, which records a rejection of
|
|
964
|
+
* the release a stage's gate waits on when the stage's approval mode takes
|
|
965
|
+
* the author's forge identity, and otherwise replies with the `yodel reject`
|
|
966
|
+
* line to run with `--sign`. It reads `.chant/pipeline.ts` at the default
|
|
967
|
+
* branch. On GitLab a person runs `yodel reject` at a terminal.
|
|
968
|
+
*/
|
|
969
|
+
async function rejectCommentFiles(envs) {
|
|
970
|
+
if (!envs.pipeline || laterStages(envs.pipeline).length === 0 || !rendersApply(envs))
|
|
971
|
+
return [];
|
|
972
|
+
const product = await chantProduct();
|
|
973
|
+
const { productCommentJob } = (await import("@intentius/chant/ci-product"));
|
|
974
|
+
const words = product.assertProductWords(PIPELINE_WORDS);
|
|
975
|
+
const tc = toolchainOf(envs);
|
|
976
|
+
const header = [
|
|
977
|
+
...HEADER,
|
|
978
|
+
"#",
|
|
979
|
+
"# A comment /yodel reject [--stage <env>] <reason> on a pull request: chant's",
|
|
980
|
+
"# comment job records a rejection of the release the stage's gate waits on,",
|
|
981
|
+
"# under the author's forge identity, where the stage's approval mode takes it;",
|
|
982
|
+
"# otherwise it replies with the yodel reject line to run with --sign. It reads",
|
|
983
|
+
"# .chant/pipeline.ts at the default branch and pushes chant/lifecycle.",
|
|
984
|
+
];
|
|
985
|
+
return ["github", "forgejo"].map((forge) => {
|
|
986
|
+
const job = productCommentJob(forge, words, { commits: true }, REJECT_JOB);
|
|
987
|
+
const container = inContainer(forge, tc);
|
|
988
|
+
const workflow = new ActionsWorkflow({
|
|
989
|
+
comment: asComment(header),
|
|
990
|
+
name: "yodel-reject",
|
|
991
|
+
on: { issue_comment: { types: ["created"] } },
|
|
992
|
+
permissions: new Permissions({ contents: "write", "pull-requests": "write", issues: "write" }),
|
|
993
|
+
jobs: {
|
|
994
|
+
[REJECT_JOB]: new ActionsJob({
|
|
995
|
+
...runner(container, tc),
|
|
996
|
+
if: "${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/yodel reject') }}",
|
|
997
|
+
steps: [...setupSteps(container, tc), new Step({ name: "/yodel reject (chant components pr-comment)", env: job.env, run: job.command })],
|
|
998
|
+
}),
|
|
999
|
+
},
|
|
1000
|
+
});
|
|
1001
|
+
return { path: `${forge === "github" ? ".github" : ".forgejo"}/workflows/yodel-reject.yml`, content: renderActions(forge, workflow) };
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
/** Where the promote jobs go on GitLab: their own file, which `.gitlab-ci.yml` includes. */
|
|
1005
|
+
export const GITLAB_PROMOTE_FILE = `.gitlab/${APPLY_PIPELINE}-promote.gitlab-ci.yml`;
|
|
1006
|
+
/** The stage chant's GitLab promote jobs run in: they name none, so GitLab's default. */
|
|
1007
|
+
export const PROMOTE_STAGE = "test";
|
|
1008
|
+
/**
|
|
1009
|
+
* The promote jobs of the stages after the first (#384), from the forge
|
|
1010
|
+
* lexicon's `generatePipelinePromote`: one job per stage, started by hand
|
|
1011
|
+
* with the release, running `yodel chant components promote --to <env>
|
|
1012
|
+
* --release <release>`. Each holds its environment's writer, as that
|
|
1013
|
+
* environment's wave job did, the reader of the environment it requires,
|
|
1014
|
+
* and its stage's set of config and secrets. It runs in the image the wave
|
|
1015
|
+
* jobs run in, with their install lines (chant's `image` and
|
|
1016
|
+
* `beforeScript`), and logs in to its cloud as that environment's wave job
|
|
1017
|
+
* does (#132): chant's trade from `ci.login` on GitHub and GitLab, as the
|
|
1018
|
+
* stage's `cloud`, the forge's OIDC token for a cloud-minted role with no
|
|
1019
|
+
* `ci.login` entry, as the stage's `idTokens`, and on Forgejo chant's login
|
|
1020
|
+
* from the runner's token files, in the promote's own step. chant's
|
|
1021
|
+
* generator checks out the default branch with its full history, which
|
|
1022
|
+
* holds each release's commit.
|
|
1023
|
+
*/
|
|
1024
|
+
async function promoteFiles(forge, envs) {
|
|
1025
|
+
const ci = envs.pipeline;
|
|
1026
|
+
if (!ci)
|
|
1027
|
+
return [];
|
|
1028
|
+
const later = laterStages(ci);
|
|
1029
|
+
if (later.length === 0)
|
|
1030
|
+
return [];
|
|
1031
|
+
const generate = forge === "github"
|
|
1032
|
+
? (await import("@intentius/chant-lexicon-github/components/generate-pipeline-promote")).generateGithubPipelinePromote
|
|
1033
|
+
: forge === "gitlab"
|
|
1034
|
+
? (await import("@intentius/chant-lexicon-gitlab/components/generate-pipeline-promote")).generateGitlabPipelinePromote
|
|
1035
|
+
: (await import("@intentius/chant-lexicon-forgejo/components/generate-pipeline-promote")).generateForgejoPipelinePromote;
|
|
1036
|
+
const { resolveEnvironmentSet, environmentSetJobInputs } = await import("@intentius/chant/components");
|
|
1037
|
+
const { environmentSetForgeVariables } = await import("@intentius/chant/op/op-waves-environment-sets");
|
|
1038
|
+
const tc = toolchainOf(envs);
|
|
1039
|
+
const stages = later.map((env) => {
|
|
1040
|
+
const required = envs.waves.find((w) => w.env === env)?.requires;
|
|
1041
|
+
const set = envs.environmentSets ? resolveEnvironmentSet(envs.environmentSets, env) : undefined;
|
|
1042
|
+
// The roles the stage's wave job held, and its cloud login from ci.login (#132).
|
|
1043
|
+
const held = waveRoles(envs.waves, env);
|
|
1044
|
+
const logins = loginsOf(envs, held);
|
|
1045
|
+
// A cloud-minted role with no ci.login reads the forge's OIDC token itself, as in the wave job: the token goes on the promote job (chant's idTokens). Forgejo issues none.
|
|
1046
|
+
const bare = forge === "forgejo" ? [] : cloudsOf(envs, held).filter((c) => !logins.some((l) => l.cloud === CLOUD_OF[c]));
|
|
1047
|
+
const tokens = bare.length > 0 ? { idTokens: Object.fromEntries(bare.map((c) => [ID_TOKENS[c].variable, ID_TOKENS[c].aud])) } : {};
|
|
1048
|
+
const cloud = forge !== "forgejo" && logins.length > 0 ? { cloud: tradeSpec(logins) } : {};
|
|
1049
|
+
// Forgejo: the runner's token files, logged in within the promote's step, so the command has the variables.
|
|
1050
|
+
const login = forge === "forgejo" ? forgejoLoginLines(logins) : [];
|
|
1051
|
+
// The ledger fetched as every job that reads an approval does, then the set's store secrets.
|
|
1052
|
+
const setup = [...login, fetchApprovals(tc), ...(set ? environmentSetJobInputs(set, forge).setup : [])];
|
|
1053
|
+
return {
|
|
1054
|
+
name: env,
|
|
1055
|
+
environment: { name: env },
|
|
1056
|
+
...cloud,
|
|
1057
|
+
...tokens,
|
|
1058
|
+
variables: {
|
|
1059
|
+
YODEL_CREDENTIALS: `writer:${env}`,
|
|
1060
|
+
...(forge === "gitlab"
|
|
1061
|
+
? {}
|
|
1062
|
+
: {
|
|
1063
|
+
...secrets([...writerVariables(env, envs.dialect, envs.credentials?.[env]), ...WEBHOOK_VARIABLES]),
|
|
1064
|
+
...secrets(readerVariables(env, envs.dialect, envs.credentials?.[env])),
|
|
1065
|
+
...(required ? secrets(readerVariables(required, envs.dialect, envs.credentials?.[required])) : {}),
|
|
1066
|
+
}),
|
|
1067
|
+
...(set ? environmentSetForgeVariables(set, forge) : {}),
|
|
1068
|
+
},
|
|
1069
|
+
setup,
|
|
1070
|
+
};
|
|
1071
|
+
});
|
|
1072
|
+
// yodel's image and install lines, as the wave jobs take them (chant's image and beforeScript). The promote's
|
|
1073
|
+
// command runs in the same shell as its install, on every forge, so the bins go on PATH with an export.
|
|
1074
|
+
const install = installLines(tc, "gitlab");
|
|
1075
|
+
const files = generate({
|
|
1076
|
+
pipeline: APPLY_PIPELINE,
|
|
1077
|
+
stages,
|
|
1078
|
+
bin: YODEL_WORDS.bin,
|
|
1079
|
+
image: tc.image,
|
|
1080
|
+
...(install.length > 0 ? { beforeScript: install } : {}),
|
|
1081
|
+
...(ci.recheck ? { recheck: { schedule: ci.recheck.schedule } } : {}),
|
|
1082
|
+
});
|
|
1083
|
+
const header = [
|
|
1084
|
+
...HEADER,
|
|
1085
|
+
"#",
|
|
1086
|
+
`# The stages after ${String(ci.promotion?.[0])} (yodel.config.ts ci.promotion): each takes the release the merge`,
|
|
1087
|
+
"# cut through yodel promote --to <env> --release <release>, behind the stage's gate,",
|
|
1088
|
+
"# which chant reads from .chant/pipeline.ts on the default branch. Each job holds",
|
|
1089
|
+
"# its environment's writer, as that environment's wave job did.",
|
|
1090
|
+
];
|
|
1091
|
+
return files.map((file) => {
|
|
1092
|
+
const yaml = file.yaml.endsWith("\n") ? file.yaml : `${file.yaml}\n`;
|
|
1093
|
+
const at = forge === "gitlab" ? GITLAB_PROMOTE_FILE : `${forge === "github" ? ".github" : ".forgejo"}/workflows/${file.name}`;
|
|
1094
|
+
return { path: at, content: withHeader(header, yaml) };
|
|
1095
|
+
});
|
|
1096
|
+
}
|
|
892
1097
|
/** yodel.config.ts `waves`, checked against the environments; one wave per environment, gate `always`, without it. */
|
|
893
1098
|
export async function readWaves(dir, envs) {
|
|
894
1099
|
const declared = (await readConfig(dir))?.waves;
|
|
@@ -1093,6 +1298,25 @@ export async function commitPipelines(dir, envs_) {
|
|
|
1093
1298
|
// ── The project ─────────────────────────────────────────────────────────────
|
|
1094
1299
|
/** Whether the project has a test file for yodel test (tests/*.test.ts). */
|
|
1095
1300
|
const hasTests = (dir) => testFiles(dir).length > 0;
|
|
1301
|
+
/**
|
|
1302
|
+
* The CI image the jobs run in: `ci.image`, which wins, else the image
|
|
1303
|
+
* `ci.imageBase` picks, else none, and the jobs run in IMAGE. The pick is
|
|
1304
|
+
* the digest this yodel's release carries (./image-set.ts). A yodel with no
|
|
1305
|
+
* release digests, a clone or the one inside the CI image, takes the digest
|
|
1306
|
+
* the project's committed pipelines name, so `yodel ci --check` runs in the
|
|
1307
|
+
* image; with none committed there is nothing to write and it refuses.
|
|
1308
|
+
*/
|
|
1309
|
+
function imageOf(dir, ci) {
|
|
1310
|
+
if (ci?.image)
|
|
1311
|
+
return { image: ci.image };
|
|
1312
|
+
if (!ci?.imageBase)
|
|
1313
|
+
return {};
|
|
1314
|
+
const image = imageForBase(ci.imageBase) ?? committedImage(dir, ci.imageBase);
|
|
1315
|
+
if (!image) {
|
|
1316
|
+
throw new Error(`yodel.config.ts ci.imageBase: "${ci.imageBase}" names the release's ${ci.imageBase} image by its digest, and this yodel carries no release digests (it is a clone, or runs inside the CI image) and no committed pipeline names that image; run yodel ci with a yodel from the registry, or set ci.image`);
|
|
1317
|
+
}
|
|
1318
|
+
return { image };
|
|
1319
|
+
}
|
|
1096
1320
|
/** The dialect and the environments chant.config.ts declares, in order. */
|
|
1097
1321
|
export async function environments(dir) {
|
|
1098
1322
|
const { loadChantConfig } = await import("@intentius/chant/config");
|
|
@@ -1123,7 +1347,7 @@ export async function environments(dir) {
|
|
|
1123
1347
|
checkOnly: true,
|
|
1124
1348
|
forges: ci0?.forges ?? FORGES,
|
|
1125
1349
|
...(ci0?.jobs ? { jobs: await loadProjectJobs(dir, ci0.jobs) } : {}),
|
|
1126
|
-
...(
|
|
1350
|
+
...imageOf(dir, ci0),
|
|
1127
1351
|
apply: false,
|
|
1128
1352
|
};
|
|
1129
1353
|
}
|
|
@@ -1147,7 +1371,7 @@ export async function environments(dir) {
|
|
|
1147
1371
|
waves: await withTenants(dir, await readWaves(dir, envs)),
|
|
1148
1372
|
forges: ci?.forges ?? FORGES,
|
|
1149
1373
|
...(ci?.jobs ? { jobs: await loadProjectJobs(dir, ci.jobs) } : {}),
|
|
1150
|
-
...(
|
|
1374
|
+
...imageOf(dir, ci),
|
|
1151
1375
|
...(ci?.resume ? { resume: { schedule: ci.resume.schedule } } : {}),
|
|
1152
1376
|
...(ci?.login ? { login: ci.login } : {}),
|
|
1153
1377
|
...(ci?.apply === false ? { apply: false } : {}),
|
|
@@ -1155,10 +1379,15 @@ export async function environments(dir) {
|
|
|
1155
1379
|
...(ci?.tools && ci.tools.length > 0 ? { tools: ci.tools } : {}),
|
|
1156
1380
|
...(ci?.respond?.new ? { respondNew: ci.respond.new } : {}),
|
|
1157
1381
|
...(ci?.respond?.rebase ? { respondRebase: ci.respond.rebase } : {}),
|
|
1382
|
+
...(ci?.respond?.["wave-refused"] ? { respondWaveRefused: ci.respond["wave-refused"] } : {}),
|
|
1383
|
+
...(ci?.agent?.["wave-refused"] ? { agentWaveRefused: ci.agent["wave-refused"] } : {}),
|
|
1158
1384
|
...(ci?.evidence ? { evidence: ci.evidence } : {}),
|
|
1159
1385
|
...(ci?.refGate === true ? { refGate: true } : {}),
|
|
1386
|
+
...(ci && pipelineOn(ci) ? { pipeline: ci } : {}),
|
|
1387
|
+
...withSets(environmentSetsOf(ci, envs)),
|
|
1160
1388
|
};
|
|
1161
1389
|
}
|
|
1390
|
+
const withSets = (sets) => (sets ? { environmentSets: sets } : {});
|
|
1162
1391
|
/** The roles of each environment whose profile is made with credentials(). */
|
|
1163
1392
|
export function credentialsIn(profiles, envs) {
|
|
1164
1393
|
const out = {};
|
|
@@ -1298,12 +1527,12 @@ export async function requireProduct() {
|
|
|
1298
1527
|
* check hooks into when the project has none on disk: the one `yodel
|
|
1299
1528
|
* upgrade` adds (#298). A project with no declaration, in its directory or
|
|
1300
1529
|
* given here, keeps the lint job's own steps ({@link checkHooksDeclaration}).
|
|
1301
|
-
* `options.respondNew` and `options.
|
|
1530
|
+
* `options.respondNew`, `options.respondRebase` and `options.respondWaveRefused` stand in for yodel.config.ts `ci.respond`.
|
|
1302
1531
|
*/
|
|
1303
1532
|
export async function render(dir, options = {}) {
|
|
1304
1533
|
const read = await environments(dir);
|
|
1305
1534
|
// The starter templates render as the release before #312 did until the release that ships /yodel new renders them (test/template.test.ts).
|
|
1306
|
-
const envs = { ...read, ...(options.respondNew ? { respondNew: options.respondNew } : {}), ...(options.respondRebase ? { respondRebase: options.respondRebase } : {}) };
|
|
1535
|
+
const envs = { ...read, ...(options.respondNew ? { respondNew: options.respondNew } : {}), ...(options.respondRebase ? { respondRebase: options.respondRebase } : {}), ...(options.respondWaveRefused ? { respondWaveRefused: options.respondWaveRefused } : {}) };
|
|
1307
1536
|
const forges = envs.forges ?? FORGES;
|
|
1308
1537
|
if (envs.checkOnly)
|
|
1309
1538
|
return review(envs).filter((f) => forges.includes(forgeOf(f.path)));
|
|
@@ -1316,6 +1545,7 @@ export async function render(dir, options = {}) {
|
|
|
1316
1545
|
...review(reviewed, await envWatches(dir, envs.names)),
|
|
1317
1546
|
...(hooks ? [hooks] : []),
|
|
1318
1547
|
...(rendersApply(envs) ? await applyPipelines(dir, envs, product) : []),
|
|
1548
|
+
...(await rejectCommentFiles(envs)),
|
|
1319
1549
|
...(await watchPipelines(dir, envs)),
|
|
1320
1550
|
...(await commitPipelines(dir, envs)),
|
|
1321
1551
|
...(envs.refGate ? await refGateFiles(dir, envs) : []),
|