@intentius/sql-yodeler 0.13.5 → 0.14.0

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 (52) hide show
  1. package/dist/ci/login.d.ts +6 -0
  2. package/dist/ci/login.js +11 -0
  3. package/dist/ci/login.js.map +1 -1
  4. package/dist/ci/pipeline.d.ts +126 -0
  5. package/dist/ci/pipeline.js +292 -0
  6. package/dist/ci/pipeline.js.map +1 -0
  7. package/dist/ci/render.d.ts +49 -3
  8. package/dist/ci/render.js +220 -12
  9. package/dist/ci/render.js.map +1 -1
  10. package/dist/ci-words.d.ts +11 -1
  11. package/dist/ci-words.js +9 -0
  12. package/dist/ci-words.js.map +1 -1
  13. package/dist/commands/chant.js +4 -2
  14. package/dist/commands/chant.js.map +1 -1
  15. package/dist/commands/ci.js +36 -1
  16. package/dist/commands/ci.js.map +1 -1
  17. package/dist/commands/config.js +2 -0
  18. package/dist/commands/config.js.map +1 -1
  19. package/dist/commands/index.js +5 -0
  20. package/dist/commands/index.js.map +1 -1
  21. package/dist/commands/plan.js +28 -4
  22. package/dist/commands/plan.js.map +1 -1
  23. package/dist/commands/report.d.ts +2 -2
  24. package/dist/commands/report.js +3 -2
  25. package/dist/commands/report.js.map +1 -1
  26. package/dist/commands/stages.d.ts +9 -0
  27. package/dist/commands/stages.js +122 -0
  28. package/dist/commands/stages.js.map +1 -0
  29. package/dist/config/define.d.ts +205 -1
  30. package/dist/config/define.js +2 -0
  31. package/dist/config/define.js.map +1 -1
  32. package/dist/config/load.d.ts +6 -0
  33. package/dist/config/load.js +64 -7
  34. package/dist/config/load.js.map +1 -1
  35. package/dist/config/vocabulary.d.ts +28 -0
  36. package/dist/config/vocabulary.js +73 -0
  37. package/dist/config/vocabulary.js.map +1 -0
  38. package/dist/pr/note.d.ts +14 -1
  39. package/dist/pr/note.js +19 -3
  40. package/dist/pr/note.js.map +1 -1
  41. package/dist/project.d.ts +2 -1
  42. package/dist/report/chant-audit.d.ts +22 -0
  43. package/dist/report/chant-audit.js +30 -0
  44. package/dist/report/chant-audit.js.map +1 -0
  45. package/dist/report/jsonl.d.ts +16 -13
  46. package/dist/report/jsonl.js +26 -19
  47. package/dist/report/jsonl.js.map +1 -1
  48. package/dist/schemas.d.ts +1 -1
  49. package/dist/waves/index.js +21 -4
  50. package/dist/waves/index.js.map +1 -1
  51. package/package.json +7 -7
  52. package/schemas/report.schema.json +27 -1
package/dist/ci/render.js CHANGED
@@ -80,9 +80,10 @@ import { existsSync, realpathSync } from "node:fs";
80
80
  import { join, relative, resolve, sep } from "node:path";
81
81
  import { pathToFileURL } from "node:url";
82
82
  import { APPROVAL_MODES, WAVE_GATES, waveGateHint } from "../config/define.js";
83
+ import { environmentSetsOf, firstStageSpec, laterStages, pipelineDeclaration, pipelineOn, pipelineText, PIPELINE_TS } from "./pipeline.js";
83
84
  import { commitFiles, COMMIT_TOKEN_ENV, GITLAB_COMMIT_FILES } from "./commit.js";
84
85
  import { stepHooks } from "../apply-steps/index.js";
85
- import { CLOUD_OF, forgejoLoginSpec, jobLogins, loginSteps, tradeIdTokens, tradeSpec } from "./login.js";
86
+ import { CLOUD_OF, forgejoLoginLines, forgejoLoginSpec, jobLogins, loginSteps, tradeIdTokens, tradeSpec } from "./login.js";
86
87
  import { RECORD_PLANS_ENV } from "../approval-mode/index.js";
87
88
  import { cloudToken, credentialsOf, roleVariables } from "../credentials.js";
88
89
  import { loadYodelConfig } from "../config/load.js";
@@ -102,7 +103,7 @@ import { generateForgejoProductPlanPipeline } from "@intentius/chant-lexicon-for
102
103
  import { generateGitlabProductPlanPipeline } from "@intentius/chant-lexicon-gitlab/components/product-plan-pipeline";
103
104
  import { emitGitlabFile } from "@intentius/chant-lexicon-gitlab/components/ci-jobs";
104
105
  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 { chantProduct, PIPELINE_WORDS, WAVE_WORDS, YODEL_NOTE_MARKER, YODEL_PR_ENV, YODEL_WORDS } from "../ci-words.js";
106
107
  import { SUBJECT_PART_WORDS } from "../pr/note.js";
107
108
  export const FORGES = ["github", "gitlab", "forgejo"];
108
109
  /** The image every job runs in, where the forge runs jobs in a container. It needs git, so not -slim. */
@@ -595,6 +596,8 @@ export function gitlabPipeline(envs_) {
595
596
  for (const [name, job] of Object.entries(ownJobs(own?.gitlab, { ...Object.fromEntries(jobs), ...Object.fromEntries(plan.jobs.map((j) => [j, true])) }, "gitlab")))
596
597
  jobs.set(name, job);
597
598
  const apply = rendersApply(envs_);
599
+ // In chant's pipeline (#384) a later stage's writer is held by its promote job.
600
+ const promotedHere = (env) => (envs_.pipeline?.promotion ?? []).slice(1).includes(env);
598
601
  const variables = envs.flatMap((env) => {
599
602
  const creds = envs_.credentials?.[env];
600
603
  // With ci.apply: false no job holds a writer, so no writer variable is set.
@@ -603,7 +606,7 @@ export function gitlabPipeline(envs_) {
603
606
  `# ${readerVariables(env, dialect, creds).join(", ")}: not protected (merge request`,
604
607
  "# pipelines run on unprotected branches), masked; no environment scope.",
605
608
  ...(writer.length > 0
606
- ? [`# ${writer.join(", ")}: protected, masked,`, `# environment scope "${env}": only ${env}'s wave job declares that environment.`]
609
+ ? [`# ${writer.join(", ")}: protected, masked,`, `# environment scope "${env}": only ${env}'s ${promotedHere(env) ? "promote" : "wave"} job declares that environment.`]
607
610
  : []),
608
611
  ];
609
612
  });
@@ -620,6 +623,9 @@ export function gitlabPipeline(envs_) {
620
623
  ...(apply
621
624
  ? [`# A push to the default branch: the apply waves, one stage each, in ${GITLAB_APPLY_FILE}.`]
622
625
  : ["# No apply pipeline (yodel.config.ts ci.apply: false): migrations are applied outside CI."]),
626
+ ...(apply && envs_.pipeline?.promotion && envs_.pipeline.promotion.length > 1
627
+ ? [`# The stages after ${envs_.pipeline.promotion[0] ?? ""} take the release the merge cut, in ${GITLAB_PROMOTE_FILE}.`]
628
+ : []),
623
629
  `# The drift watches are in ${GITLAB_WATCH_FILE} (stage ops).`,
624
630
  ...(respondsNew(envs_) ? [`# /yodel new, chant's commit job, is in ${GITLAB_COMMIT_FILES.new} (stage ops).`] : []),
625
631
  ...(rebaseRespond(envs_) !== "off" ? [`# /yodel rebase, after the merge request's check, is in ${GITLAB_COMMIT_FILES.rebase} (stage ops).`] : []),
@@ -653,11 +659,15 @@ export function gitlabPipeline(envs_) {
653
659
  // A pr-review wave (#48) adds the merge request job that records the plans, in chant's stage "plans".
654
660
  const jobStages = [...jobs.values()].map((job) => job.props?.stage).filter((stage) => typeof stage === "string");
655
661
  // ci.apply: false (#175): no apply file, so neither its include nor its stages.
656
- const plans = apply && waves.some((w) => w.approval === "pr-review") ? [PLANS_STAGE] : [];
657
- const applyStages = apply ? [...plans, ...waveStages(waves), ...(envs_.resume ? [RESUME_STAGE] : [])] : [];
662
+ // chant's pipeline (#384): the merge applies the first stage's wave, and the promote file takes the rest.
663
+ const staged = envs_.pipeline?.promotion;
664
+ const merged = staged ? waves.filter((w) => w.env === staged[0]) : waves;
665
+ const promotes = apply && staged !== undefined && staged.length > 1;
666
+ const plans = apply && merged.some((w) => w.approval === "pr-review") ? [PLANS_STAGE] : [];
667
+ const applyStages = apply ? [...plans, ...waveStages(merged), ...(envs_.resume ? [RESUME_STAGE] : []), ...(promotes ? [PROMOTE_STAGE] : [])] : [];
658
668
  const pipeline = new GitLabPipeline({
659
669
  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 }] : [])],
670
+ 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
671
  // The plan file's stages (chant's plan and plan-note) right after review.
662
672
  stages: [...new Set(["review", ...plan.stages, ...jobStages, ...applyStages, "ops"])],
663
673
  variables: { GIT_DEPTH: "0" },
@@ -691,6 +701,16 @@ const requiredOf = (waves, env) => {
691
701
  /** The waves spec: committed, and read by every wave job (its gate policy at the commit before the push). */
692
702
  export const WAVES_SPEC = "yodel-waves.json";
693
703
  export const APPLY_PIPELINE = "yodel-apply";
704
+ /** `ci.agent["wave-refused"]` as chant's `WaveSummarySpec`: chant's mechanism, so the keys are only renamed. */
705
+ function waveSummaryOf(s) {
706
+ return {
707
+ ...(s.command !== undefined ? { command: s.command } : {}),
708
+ ...(s.key_secret !== undefined ? { keyEnv: s.key_secret } : {}),
709
+ ...(s.timeout !== undefined ? { timeout: s.timeout } : {}),
710
+ ...(s.max_runs !== undefined ? { maxRuns: s.max_runs } : {}),
711
+ ...(s.max_cost_usd !== undefined ? { maxCostUsd: s.max_cost_usd } : {}),
712
+ };
713
+ }
694
714
  /**
695
715
  * The waves spec. What the file holds is the same for every forge; each
696
716
  * forge's jobs get their own variables and OIDC tokens on top (`job`).
@@ -712,7 +732,7 @@ export const APPLY_PIPELINE = "yodel-apply";
712
732
  * the base commit, as it does run by hand. A step runs once, under the
713
733
  * lock, as #107 asks.
714
734
  */
715
- export function wavesSpec(waves, job, resume) {
735
+ export function wavesSpec(waves, job, resume, waveRefused, summary) {
716
736
  const first = waves[0];
717
737
  if (!first)
718
738
  throw new Error("no waves to render");
@@ -733,6 +753,8 @@ export function wavesSpec(waves, job, resume) {
733
753
  // The steps around apply (#64) as chant's stage hooks, which the apply runs under its lock (#206).
734
754
  ...hooksOf(w.steps),
735
755
  })),
756
+ ...(waveRefused ? { respond: { "wave-refused": waveRefused } } : {}),
757
+ ...(waveRefused === "summary" && summary ? { waveSummary: waveSummaryOf(summary) } : {}),
736
758
  ...(resume ? { resume } : {}),
737
759
  };
738
760
  }
@@ -771,11 +793,17 @@ function jobLogin(forge, envs, held) {
771
793
  * variables and OIDC tokens in the spec.
772
794
  */
773
795
  export async function applyPipelines(dir, envs, product) {
774
- const { dialect, waves } = envs;
796
+ const { dialect } = envs;
775
797
  const tc = toolchainOf(envs);
776
798
  const { generateOpWavesPipeline } = (await import("@intentius/chant/op"));
777
799
  const named = (forge, spec) => productWaves(product, forge, spec);
778
- const out = [{ path: WAVES_SPEC, content: `${JSON.stringify(named("github", wavesSpec(waves)).spec, null, 2)}\n` }];
800
+ const plain = named("github", wavesSpec(envs.waves, undefined, undefined, envs.respondWaveRefused, envs.agentWaveRefused)).spec;
801
+ // chant's pipeline (#384): the spec the merge applies is the first stage's, from the folded .chant/pipeline.ts.
802
+ const staged = envs.pipeline ? await stagedWaves(envs.pipeline, plain) : undefined;
803
+ const first = staged?.spec.waves[0]?.name;
804
+ // The waves the merge applies: every one, or in a pipeline the first stage's.
805
+ const waves = first === undefined ? envs.waves : envs.waves.filter((w) => w.env === first);
806
+ const out = [{ path: WAVES_SPEC, content: `${JSON.stringify(staged?.spec ?? plain, null, 2)}\n` }, ...(staged ? [{ path: PIPELINE_TS, content: staged.text }] : [])];
779
807
  // A GitLab job already has the project's variables, a writer's only under its environment.
780
808
  const jobOf = (forge) => (env) => {
781
809
  const wave = waves.find((w) => w.env === env);
@@ -861,14 +889,18 @@ export async function applyPipelines(dir, envs, product) {
861
889
  "# holds no writer's credentials: it plans with each environment's reader.",
862
890
  ];
863
891
  for (const forge of FORGES) {
864
- const { spec, jobs } = named(forge, wavesSpec(waves, jobOf(forge), envs.resume));
892
+ const { spec, jobs } = named(forge, staged ? withJobs(staged.spec, jobOf(forge), envs.resume) : wavesSpec(waves, jobOf(forge), envs.resume, envs.respondWaveRefused, envs.agentWaveRefused));
865
893
  const result = await generateOpWavesPipeline(spec, forge, {
894
+ // Each wave job gets its environment's set of config and secrets (#384, chant's environment sets).
895
+ ...(envs.environmentSets ? { environmentSets: envs.environmentSets } : {}),
866
896
  specFile: WAVES_SPEC,
867
897
  bin: YODEL_WORDS.bin,
868
898
  image: tc.image,
869
899
  beforeScript: [...installLines(tc, forge), fetchApprovals(tc)],
870
900
  waveJobs: waveJobs(forge),
871
901
  recordPlans: recordPlans(forge),
902
+ // The wave jobs' token on GitHub and Forgejo (a GitLab job reads its CI/CD variables or CI_JOB_TOKEN): see commandToken.
903
+ ...(commandToken(forge, envs.respondWaveRefused, envs.pipeline) ?? {}),
872
904
  // 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
905
  ...(envs.evidence ? { evidence: envs.evidence } : {}),
874
906
  ...(forge === "gitlab" ? { opsFileName: GITLAB_APPLY_FILE } : {}),
@@ -886,9 +918,179 @@ export async function applyPipelines(dir, envs, product) {
886
918
  else
887
919
  out.push({ path: at, content: withHeader([...header, ...identityHeader(forge, waveClouds)], withWaveLines(forge, yaml, jobs)) });
888
920
  }
921
+ if (envs.pipeline)
922
+ out.push(...(await promoteFiles(forge, envs)));
889
923
  }
890
924
  return out;
891
925
  }
926
+ /**
927
+ * The job's token a GitHub or Forgejo wave job's command gets, with the
928
+ * scopes it needs beside chant's own, or undefined for none. A refused
929
+ * wave's diff is posted with it: pull request comments, and the tracking
930
+ * issue a wave with no pull request uses. With `ci.promotion` the first
931
+ * stage's last wave cuts the release, and under `release.green:
932
+ * "forge-checks"` (chant's default without `ci.green`) the cut reads the
933
+ * merge commit's checks and statuses with it (#395).
934
+ */
935
+ export function commandToken(forge, respondWaveRefused, pipeline) {
936
+ if (forge === "gitlab")
937
+ return undefined;
938
+ const permissions = {
939
+ ...(respondWaveRefused === "diff" || respondWaveRefused === "summary" ? { "pull-requests": "write", issues: "write" } : {}),
940
+ ...(pipeline && pipeline.release?.cut !== false ? { checks: "read", statuses: "read" } : {}),
941
+ };
942
+ return Object.keys(permissions).length > 0 ? { commandToken: { permissions } } : undefined;
943
+ }
944
+ /** `.chant/pipeline.ts` from yodel.config.ts, and the first stage's spec from the folded file: what the merge applies (#384). */
945
+ async function stagedWaves(ci, plain) {
946
+ const spec = Object.fromEntries(Object.entries(plain).filter(([k]) => k !== "resume"));
947
+ const declaration = await pipelineDeclaration({ name: APPLY_PIPELINE, ci, spec, bin: YODEL_WORDS.bin.split(" ") });
948
+ const text = await pipelineText(declaration);
949
+ return { text, spec: (await firstStageSpec(text, APPLY_PIPELINE)) };
950
+ }
951
+ /** The first stage's spec with each wave's forge settings, as {@link wavesSpec} adds them with a `job`. */
952
+ function withJobs(spec, job, resume) {
953
+ return { ...spec, waves: spec.waves.map((w) => ({ ...w, environment: { name: w.name }, ...job(w.name) })), ...(resume ? { resume } : {}) };
954
+ }
955
+ /** The reject comment workflow's job (#384). */
956
+ export const REJECT_JOB = "reject";
957
+ /**
958
+ * `/yodel reject [--stage <env>] <reason>` on a pull request (#384), on
959
+ * GitHub and Forgejo: chant's comment job (`components pr-comment`) under the
960
+ * words that map `reject` onto chant's reject, which records a rejection of
961
+ * the release a stage's gate waits on when the stage's approval mode takes
962
+ * the author's forge identity, and otherwise replies with the `yodel reject`
963
+ * line to run with `--sign`. It reads `.chant/pipeline.ts` at the default
964
+ * branch. On GitLab a person runs `yodel reject` at a terminal.
965
+ */
966
+ async function rejectCommentFiles(envs) {
967
+ if (!envs.pipeline || laterStages(envs.pipeline).length === 0 || !rendersApply(envs))
968
+ return [];
969
+ const product = await chantProduct();
970
+ const { productCommentJob } = (await import("@intentius/chant/ci-product"));
971
+ const words = product.assertProductWords(PIPELINE_WORDS);
972
+ const tc = toolchainOf(envs);
973
+ const header = [
974
+ ...HEADER,
975
+ "#",
976
+ "# A comment /yodel reject [--stage <env>] <reason> on a pull request: chant's",
977
+ "# comment job records a rejection of the release the stage's gate waits on,",
978
+ "# under the author's forge identity, where the stage's approval mode takes it;",
979
+ "# otherwise it replies with the yodel reject line to run with --sign. It reads",
980
+ "# .chant/pipeline.ts at the default branch and pushes chant/lifecycle.",
981
+ ];
982
+ return ["github", "forgejo"].map((forge) => {
983
+ const job = productCommentJob(forge, words, { commits: true }, REJECT_JOB);
984
+ const container = inContainer(forge, tc);
985
+ const workflow = new ActionsWorkflow({
986
+ comment: asComment(header),
987
+ name: "yodel-reject",
988
+ on: { issue_comment: { types: ["created"] } },
989
+ permissions: new Permissions({ contents: "write", "pull-requests": "write", issues: "write" }),
990
+ jobs: {
991
+ [REJECT_JOB]: new ActionsJob({
992
+ ...runner(container, tc),
993
+ if: "${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/yodel reject') }}",
994
+ steps: [...setupSteps(container, tc), new Step({ name: "/yodel reject (chant components pr-comment)", env: job.env, run: job.command })],
995
+ }),
996
+ },
997
+ });
998
+ return { path: `${forge === "github" ? ".github" : ".forgejo"}/workflows/yodel-reject.yml`, content: renderActions(forge, workflow) };
999
+ });
1000
+ }
1001
+ /** Where the promote jobs go on GitLab: their own file, which `.gitlab-ci.yml` includes. */
1002
+ export const GITLAB_PROMOTE_FILE = `.gitlab/${APPLY_PIPELINE}-promote.gitlab-ci.yml`;
1003
+ /** The stage chant's GitLab promote jobs run in: they name none, so GitLab's default. */
1004
+ export const PROMOTE_STAGE = "test";
1005
+ /**
1006
+ * The promote jobs of the stages after the first (#384), from the forge
1007
+ * lexicon's `generatePipelinePromote`: one job per stage, started by hand
1008
+ * with the release, running `yodel chant components promote --to <env>
1009
+ * --release <release>`. Each holds its environment's writer, as that
1010
+ * environment's wave job did, the reader of the environment it requires,
1011
+ * and its stage's set of config and secrets. It runs in the image the wave
1012
+ * jobs run in, with their install lines (chant's `image` and
1013
+ * `beforeScript`), and logs in to its cloud as that environment's wave job
1014
+ * does (#132): chant's trade from `ci.login` on GitHub and GitLab, as the
1015
+ * stage's `cloud`, the forge's OIDC token for a cloud-minted role with no
1016
+ * `ci.login` entry, as the stage's `idTokens`, and on Forgejo chant's login
1017
+ * from the runner's token files, in the promote's own step. chant's
1018
+ * generator checks out the default branch with its full history, which
1019
+ * holds each release's commit.
1020
+ */
1021
+ async function promoteFiles(forge, envs) {
1022
+ const ci = envs.pipeline;
1023
+ if (!ci)
1024
+ return [];
1025
+ const later = laterStages(ci);
1026
+ if (later.length === 0)
1027
+ return [];
1028
+ const generate = forge === "github"
1029
+ ? (await import("@intentius/chant-lexicon-github/components/generate-pipeline-promote")).generateGithubPipelinePromote
1030
+ : forge === "gitlab"
1031
+ ? (await import("@intentius/chant-lexicon-gitlab/components/generate-pipeline-promote")).generateGitlabPipelinePromote
1032
+ : (await import("@intentius/chant-lexicon-forgejo/components/generate-pipeline-promote")).generateForgejoPipelinePromote;
1033
+ const { resolveEnvironmentSet, environmentSetJobInputs } = await import("@intentius/chant/components");
1034
+ const { environmentSetForgeVariables } = await import("@intentius/chant/op/op-waves-environment-sets");
1035
+ const tc = toolchainOf(envs);
1036
+ const stages = later.map((env) => {
1037
+ const required = envs.waves.find((w) => w.env === env)?.requires;
1038
+ const set = envs.environmentSets ? resolveEnvironmentSet(envs.environmentSets, env) : undefined;
1039
+ // The roles the stage's wave job held, and its cloud login from ci.login (#132).
1040
+ const held = waveRoles(envs.waves, env);
1041
+ const logins = loginsOf(envs, held);
1042
+ // 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.
1043
+ const bare = forge === "forgejo" ? [] : cloudsOf(envs, held).filter((c) => !logins.some((l) => l.cloud === CLOUD_OF[c]));
1044
+ const tokens = bare.length > 0 ? { idTokens: Object.fromEntries(bare.map((c) => [ID_TOKENS[c].variable, ID_TOKENS[c].aud])) } : {};
1045
+ const cloud = forge !== "forgejo" && logins.length > 0 ? { cloud: tradeSpec(logins) } : {};
1046
+ // Forgejo: the runner's token files, logged in within the promote's step, so the command has the variables.
1047
+ const login = forge === "forgejo" ? forgejoLoginLines(logins) : [];
1048
+ // The ledger fetched as every job that reads an approval does, then the set's store secrets.
1049
+ const setup = [...login, fetchApprovals(tc), ...(set ? environmentSetJobInputs(set, forge).setup : [])];
1050
+ return {
1051
+ name: env,
1052
+ environment: { name: env },
1053
+ ...cloud,
1054
+ ...tokens,
1055
+ variables: {
1056
+ YODEL_CREDENTIALS: `writer:${env}`,
1057
+ ...(forge === "gitlab"
1058
+ ? {}
1059
+ : {
1060
+ ...secrets([...writerVariables(env, envs.dialect, envs.credentials?.[env]), ...WEBHOOK_VARIABLES]),
1061
+ ...secrets(readerVariables(env, envs.dialect, envs.credentials?.[env])),
1062
+ ...(required ? secrets(readerVariables(required, envs.dialect, envs.credentials?.[required])) : {}),
1063
+ }),
1064
+ ...(set ? environmentSetForgeVariables(set, forge) : {}),
1065
+ },
1066
+ setup,
1067
+ };
1068
+ });
1069
+ // yodel's image and install lines, as the wave jobs take them (chant's image and beforeScript). The promote's
1070
+ // command runs in the same shell as its install, on every forge, so the bins go on PATH with an export.
1071
+ const install = installLines(tc, "gitlab");
1072
+ const files = generate({
1073
+ pipeline: APPLY_PIPELINE,
1074
+ stages,
1075
+ bin: YODEL_WORDS.bin,
1076
+ image: tc.image,
1077
+ ...(install.length > 0 ? { beforeScript: install } : {}),
1078
+ ...(ci.recheck ? { recheck: { schedule: ci.recheck.schedule } } : {}),
1079
+ });
1080
+ const header = [
1081
+ ...HEADER,
1082
+ "#",
1083
+ `# The stages after ${String(ci.promotion?.[0])} (yodel.config.ts ci.promotion): each takes the release the merge`,
1084
+ "# cut through yodel promote --to <env> --release <release>, behind the stage's gate,",
1085
+ "# which chant reads from .chant/pipeline.ts on the default branch. Each job holds",
1086
+ "# its environment's writer, as that environment's wave job did.",
1087
+ ];
1088
+ return files.map((file) => {
1089
+ const yaml = file.yaml.endsWith("\n") ? file.yaml : `${file.yaml}\n`;
1090
+ const at = forge === "gitlab" ? GITLAB_PROMOTE_FILE : `${forge === "github" ? ".github" : ".forgejo"}/workflows/${file.name}`;
1091
+ return { path: at, content: withHeader(header, yaml) };
1092
+ });
1093
+ }
892
1094
  /** yodel.config.ts `waves`, checked against the environments; one wave per environment, gate `always`, without it. */
893
1095
  export async function readWaves(dir, envs) {
894
1096
  const declared = (await readConfig(dir))?.waves;
@@ -1155,10 +1357,15 @@ export async function environments(dir) {
1155
1357
  ...(ci?.tools && ci.tools.length > 0 ? { tools: ci.tools } : {}),
1156
1358
  ...(ci?.respond?.new ? { respondNew: ci.respond.new } : {}),
1157
1359
  ...(ci?.respond?.rebase ? { respondRebase: ci.respond.rebase } : {}),
1360
+ ...(ci?.respond?.["wave-refused"] ? { respondWaveRefused: ci.respond["wave-refused"] } : {}),
1361
+ ...(ci?.agent?.["wave-refused"] ? { agentWaveRefused: ci.agent["wave-refused"] } : {}),
1158
1362
  ...(ci?.evidence ? { evidence: ci.evidence } : {}),
1159
1363
  ...(ci?.refGate === true ? { refGate: true } : {}),
1364
+ ...(ci && pipelineOn(ci) ? { pipeline: ci } : {}),
1365
+ ...withSets(environmentSetsOf(ci, envs)),
1160
1366
  };
1161
1367
  }
1368
+ const withSets = (sets) => (sets ? { environmentSets: sets } : {});
1162
1369
  /** The roles of each environment whose profile is made with credentials(). */
1163
1370
  export function credentialsIn(profiles, envs) {
1164
1371
  const out = {};
@@ -1298,12 +1505,12 @@ export async function requireProduct() {
1298
1505
  * check hooks into when the project has none on disk: the one `yodel
1299
1506
  * upgrade` adds (#298). A project with no declaration, in its directory or
1300
1507
  * given here, keeps the lint job's own steps ({@link checkHooksDeclaration}).
1301
- * `options.respondNew` and `options.respondRebase` stand in for yodel.config.ts `ci.respond`.
1508
+ * `options.respondNew`, `options.respondRebase` and `options.respondWaveRefused` stand in for yodel.config.ts `ci.respond`.
1302
1509
  */
1303
1510
  export async function render(dir, options = {}) {
1304
1511
  const read = await environments(dir);
1305
1512
  // 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 } : {}) };
1513
+ const envs = { ...read, ...(options.respondNew ? { respondNew: options.respondNew } : {}), ...(options.respondRebase ? { respondRebase: options.respondRebase } : {}), ...(options.respondWaveRefused ? { respondWaveRefused: options.respondWaveRefused } : {}) };
1307
1514
  const forges = envs.forges ?? FORGES;
1308
1515
  if (envs.checkOnly)
1309
1516
  return review(envs).filter((f) => forges.includes(forgeOf(f.path)));
@@ -1316,6 +1523,7 @@ export async function render(dir, options = {}) {
1316
1523
  ...review(reviewed, await envWatches(dir, envs.names)),
1317
1524
  ...(hooks ? [hooks] : []),
1318
1525
  ...(rendersApply(envs) ? await applyPipelines(dir, envs, product) : []),
1526
+ ...(await rejectCommentFiles(envs)),
1319
1527
  ...(await watchPipelines(dir, envs)),
1320
1528
  ...(await commitPipelines(dir, envs)),
1321
1529
  ...(envs.refGate ? await refGateFiles(dir, envs) : []),