@intentius/chant 0.116.0 → 0.117.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.
package/src/op/gate.ts CHANGED
@@ -52,6 +52,7 @@ import { sortedJsonReplacer } from "../utils";
52
52
  import type { GateApprover, ResolvedGateApproval } from "./gate-approval";
53
53
  import { pushLifecycle, requireLifecycleLedger } from "../lifecycle/git";
54
54
  import { parseDuration } from "./duration";
55
+ import { resolveGateRunLocator } from "./gate-resume";
55
56
 
56
57
  /**
57
58
  * What appending a pending fact learned about reaching the remote.
@@ -505,6 +506,8 @@ export async function evaluateGate(port: GateLedgerPort, input: GateCheckInput):
505
506
  }
506
507
 
507
508
  const url = resolveApprovalUrl();
509
+ // #3683: in CI, where this job runs, so an approval can start it again.
510
+ const resume = resolveGateRunLocator();
508
511
  const { record, pushed, pushWarning } = await port.appendPending({
509
512
  op: input.op,
510
513
  gate: input.gate,
@@ -515,6 +518,7 @@ export async function evaluateGate(port: GateLedgerPort, input: GateCheckInput):
515
518
  ...(input.description ? { description: input.description } : {}),
516
519
  ...(input.runId ? { runId: input.runId } : {}),
517
520
  ...(url ? { url } : {}),
521
+ ...(resume ? { resume } : {}),
518
522
  ...(input.planDigest !== undefined ? { planDigest: input.planDigest } : {}),
519
523
  ...(env !== undefined ? { environment: env } : {}),
520
524
  ...(input.approval ? { approval: input.approval } : {}),
@@ -295,7 +295,7 @@ export async function runOpWave(options: RunOpWaveOptions): Promise<RunOpWaveRes
295
295
  `digest ${digest}: ${decision.status}${decision.approvedBy ? ` by ${decision.approvedBy}` : ""}`,
296
296
  );
297
297
  if (decision.status === "waiting") {
298
- log(`Nothing in wave ${k} or after it ran. Read the plans, then approve: ${decision.approve}`);
298
+ log(`Nothing in wave ${k} or after it ran. Read the plans, then approve: ${decision.approve} (with --resume, the approval also starts this job again)`);
299
299
  return { ...result, exitCode: 3 };
300
300
  }
301
301
  if (options.decide) return result;
@@ -103,6 +103,29 @@ export interface OpWavesSpec {
103
103
  /** Apply one run whose plan is at `{plan}`. Default `chant run {op} --env {target}`. */
104
104
  apply?: string[];
105
105
  waves: OpWave[];
106
+ /**
107
+ * A scheduled job that starts again a wave job whose approval has arrived
108
+ * (#3683): it runs `chant run resume --op <name>`, which re-runs the
109
+ * GitHub run, retries the GitLab job or dispatches the Forgejo workflow.
110
+ * It approves nothing. Absent, no such job is rendered and an approval is
111
+ * followed by `chant approve --resume` or a re-run by hand.
112
+ */
113
+ resume?: OpWavesResume;
114
+ }
115
+
116
+ /** The scheduled resume job of an Op waves pipeline (#3683). */
117
+ export interface OpWavesResume {
118
+ /**
119
+ * Five-field cron, such as `"*\/10 * * * *"`. GitHub and Forgejo put it
120
+ * in the workflow; GitLab runs the job in a pipeline schedule you create,
121
+ * which sets the cron.
122
+ */
123
+ schedule: string;
124
+ }
125
+
126
+ /** The command a resume job runs. */
127
+ export function opWavesResumeCommand(spec: Pick<OpWavesSpec, "name">): string[] {
128
+ return ["chant", "run", "resume", "--op", spec.name];
106
129
  }
107
130
 
108
131
  /** The default apply command. */
@@ -146,6 +169,9 @@ export function assertOpWavesSpec(spec: OpWavesSpec): void {
146
169
  throw new Error(`${where}: the \`plan\` command never names {plan}, the file it writes the plan digest to.`);
147
170
  }
148
171
  if (spec.waves.length === 0) throw new Error(`${where} has no waves.`);
172
+ if (spec.resume !== undefined && (typeof spec.resume.schedule !== "string" || spec.resume.schedule.trim().split(/\s+/).length !== 5)) {
173
+ throw new Error(`${where}: resume.schedule must be a five-field cron expression, such as "*/10 * * * *".`);
174
+ }
149
175
  const names = new Set<string>();
150
176
  for (const wave of spec.waves) {
151
177
  if (!NAME.test(wave.name)) {