@intentius/chant 0.124.71 → 0.124.73
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-commit.d.ts +41 -1
- package/dist/ci-commit.d.ts.map +1 -1
- package/dist/ci-commit.js +54 -8
- package/dist/ci-estate/delivery.d.ts +75 -2
- package/dist/ci-estate/delivery.d.ts.map +1 -1
- package/dist/ci-estate/delivery.js +129 -0
- package/dist/ci-estate.d.ts +3 -1
- package/dist/ci-estate.d.ts.map +1 -1
- package/dist/ci-estate.js +3 -1
- package/dist/ci-product.d.ts +1 -1
- package/dist/ci-product.d.ts.map +1 -1
- package/dist/ci-product.js +1 -1
- package/dist/cli/handlers/commit.d.ts.map +1 -1
- package/dist/cli/handlers/commit.js +5 -2
- package/dist/cli/handlers/notify-relay.d.ts.map +1 -1
- package/dist/cli/handlers/notify-relay.js +22 -2
- package/dist/config.d.ts +14 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -0
- package/dist/lexicon.d.ts +17 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/publish-forge.d.ts.map +1 -1
- package/dist/lifecycle/publish-forge.js +1 -2
- package/dist/lifecycle/release-images.d.ts.map +1 -1
- package/dist/lifecycle/release-images.js +1 -2
- package/dist/notify-relay.d.ts +41 -1
- package/dist/notify-relay.d.ts.map +1 -1
- package/dist/notify-relay.js +39 -0
- package/dist/notify.d.ts +16 -3
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +16 -10
- package/dist/op/activities/activity-contracts.d.ts +4 -4
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +237 -237
- package/dist/workspace/release-workflow.d.ts +24 -0
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +61 -8
- package/package.json +1 -1
- package/src/ci-commit.test.ts +22 -1
- package/src/ci-commit.ts +79 -8
- package/src/ci-estate/__fixtures__/terragucci-dora.json +1305 -0
- package/src/ci-estate/delivery.ts +186 -2
- package/src/ci-estate/records-delivery.test.ts +55 -0
- package/src/ci-estate.ts +9 -0
- package/src/ci-product.ts +1 -0
- package/src/cli/handlers/commit.ts +4 -1
- package/src/cli/handlers/notify-relay.ts +21 -2
- package/src/config.ts +7 -0
- package/src/lexicon.ts +16 -0
- package/src/lifecycle/publish-forge.ts +1 -2
- package/src/lifecycle/release-images.ts +1 -2
- package/src/notify-relay.test.ts +55 -1
- package/src/notify-relay.ts +48 -1
- package/src/notify.ts +25 -12
- package/src/release-floors.ts +1 -1
- package/src/workspace/release-workflow.test.ts +49 -1
- package/src/workspace/release-workflow.ts +91 -7
package/src/notify.ts
CHANGED
|
@@ -301,19 +301,27 @@ export function slackMessage(e: NotifyEvent, relay?: RelayButtons): { text: stri
|
|
|
301
301
|
}
|
|
302
302
|
const text = lines.join("\n");
|
|
303
303
|
if (!relay) return { text };
|
|
304
|
+
return { text, blocks: [{ type: "section", text: { type: "mrkdwn", text } }, slackRelayActions(relay)] };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* The Slack actions block with the relay's Approve and Decline buttons
|
|
309
|
+
* (#4611), for a product that renders its own Slack message: its clicks reach
|
|
310
|
+
* `chant notify relay` like those on chant's own message.
|
|
311
|
+
*/
|
|
312
|
+
export function slackRelayActions(relay: RelayButtons): Record<string, unknown> {
|
|
304
313
|
const button = (label: string, action: string, style?: string) => ({ type: "button", text: { type: "plain_text", text: label }, action_id: action, value: relay.token, ...(style ? { style } : {}) });
|
|
305
|
-
return {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
};
|
|
314
|
+
return { type: "actions", elements: [button("Approve", RELAY_APPROVE_ACTION, "primary"), button("Decline", RELAY_DECLINE_ACTION)] };
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** The Teams reply that approves through the relay's outgoing webhook (#4611): `approve <token>`, after a mention of the relay. */
|
|
318
|
+
export function teamsRelayReply(relay: RelayButtons, action: "approve" | "decline" = "approve"): string {
|
|
319
|
+
return `${action} ${relay.token}`;
|
|
312
320
|
}
|
|
313
321
|
|
|
314
322
|
/** A Teams incoming webhook's body (a Workflows webhook): one Adaptive Card, with buttons that open the review page and the run. With `relay`, the reply that approves through the relay (#4611). */
|
|
315
323
|
export function teamsMessage(e: NotifyEvent, relay?: RelayButtons): Record<string, unknown> {
|
|
316
|
-
const all = [...facts(e), ...(relay ? [{ title: "Approve in chat", value: `mention the relay and reply:
|
|
324
|
+
const all = [...facts(e), ...(relay ? [{ title: "Approve in chat", value: `mention the relay and reply: ${teamsRelayReply(relay)}` }] : [])];
|
|
317
325
|
const actions = [
|
|
318
326
|
...(e.approve?.review ? [{ type: "Action.OpenUrl", title: "Review and approve", url: e.approve.review.url }] : []),
|
|
319
327
|
...(e.run?.url ? [{ type: "Action.OpenUrl", title: "Open the run", url: e.run.url }] : []),
|
|
@@ -434,8 +442,13 @@ export interface SendNotifyOptions {
|
|
|
434
442
|
/** The webhook headers' prefix. Default `x-chant`. */
|
|
435
443
|
prefix?: string;
|
|
436
444
|
userAgent?: string;
|
|
437
|
-
/**
|
|
438
|
-
|
|
445
|
+
/**
|
|
446
|
+
* A product's own Slack or Teams body, in place of {@link slackMessage} and
|
|
447
|
+
* {@link teamsMessage}. `relay` is the relay's signed button value for a
|
|
448
|
+
* waiting event when `notify.relay` names a key that is set (#4611), for
|
|
449
|
+
* {@link slackRelayActions} and {@link teamsRelayReply}.
|
|
450
|
+
*/
|
|
451
|
+
render?: { slack?: (e: NotifyEvent, relay?: RelayButtons) => unknown; teams?: (e: NotifyEvent, relay?: RelayButtons) => unknown };
|
|
439
452
|
/** Seconds since the epoch, for the signature's timestamp. Default: the clock. */
|
|
440
453
|
now?: number;
|
|
441
454
|
}
|
|
@@ -518,7 +531,7 @@ export async function sendNotify(config: NotifyConfig | undefined, event: Notify
|
|
|
518
531
|
const relayKey = config.relay ? env[config.relay] : undefined;
|
|
519
532
|
if (config.relay && ref && !relayKey) log(`notify: ${config.relay} is not set, so the message carries no relay buttons`);
|
|
520
533
|
const buttons = ref && relayKey ? { token: relayToken(relayKey, ref) } : undefined;
|
|
521
|
-
if (config.slack) await deliver("slack", config.slack, () => json(options.render?.slack ? options.render.slack(event) : slackMessage(event, buttons)));
|
|
522
|
-
if (config.teams) await deliver("teams", config.teams, () => json(options.render?.teams ? options.render.teams(event) : teamsMessage(event, buttons)));
|
|
534
|
+
if (config.slack) await deliver("slack", config.slack, () => json(options.render?.slack ? options.render.slack(event, buttons) : slackMessage(event, buttons)));
|
|
535
|
+
if (config.teams) await deliver("teams", config.teams, () => json(options.render?.teams ? options.render.teams(event, buttons) : teamsMessage(event, buttons)));
|
|
523
536
|
return out;
|
|
524
537
|
}
|
package/src/release-floors.ts
CHANGED
|
@@ -26,7 +26,7 @@ describe("a config with only publish (#4656)", () => {
|
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
type GhJob = { needs?: string | string[]; outputs?: Record<string, string>; env?: Record<string, string>; steps: Array<{ id?: string; uses?: string; run?: string; with?: Record<string, unknown> }> };
|
|
29
|
-
type GhDoc = { on: Record<string, unknown>; env?: Record<string, string>; permissions
|
|
29
|
+
type GhDoc = { on: Record<string, unknown>; env?: Record<string, string>; permissions?: Record<string, string>; jobs: Record<string, GhJob> };
|
|
30
30
|
const runs = (job: GhJob): string[] => job.steps.filter((s) => s.run).map((s) => s.run!.trim());
|
|
31
31
|
|
|
32
32
|
const dispatch = (forge: (typeof FORGES)[number], over: Partial<ReleaseWorkflowInput> = {}): string =>
|
|
@@ -149,3 +149,51 @@ describe("the tag trigger with images or after (#4656)", () => {
|
|
|
149
149
|
expect(doc["chant-release-after"]!.script.at(-1)).toBe("./notify.sh");
|
|
150
150
|
});
|
|
151
151
|
});
|
|
152
|
+
|
|
153
|
+
describe("the release workflow's permissions, env and setup (#4751)", () => {
|
|
154
|
+
const pipeline = {
|
|
155
|
+
trigger: "dispatch" as const,
|
|
156
|
+
permissions: { packages: "write" as const },
|
|
157
|
+
env: { OCI_USERNAME: "${{ github.actor }}", OCI_PASSWORD: "${{ github.token }}" },
|
|
158
|
+
setup: [{ uses: "docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392", with: { platforms: "arm64" } }, { run: "npm install -g npm@11.19.0" }],
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
test("github: the scope joins the workflow's, and the cut and publish jobs get the variables and the steps after the install", () => {
|
|
162
|
+
const doc = parseYAML(renderReleaseWorkflow({ forge: "github", groups: new Set(), images: true, pipeline })) as GhDoc;
|
|
163
|
+
expect(doc.permissions).toEqual({ contents: "write", "id-token": "write", packages: "write" });
|
|
164
|
+
expect(doc.jobs.cut!.env).toEqual({ CHANT_RELEASE_COMMIT: "${{ needs.gate.outputs.commit }}", OCI_USERNAME: "${{ github.actor }}", OCI_PASSWORD: "${{ github.token }}" });
|
|
165
|
+
expect(doc.jobs.publish!.env).toEqual({ OCI_USERNAME: "${{ github.actor }}", OCI_PASSWORD: "${{ github.token }}" });
|
|
166
|
+
expect(doc.jobs.gate!.env).toBeUndefined();
|
|
167
|
+
for (const job of [doc.jobs.cut!, doc.jobs.publish!]) {
|
|
168
|
+
const i = job.steps.findIndex((s) => s.run === "npm ci");
|
|
169
|
+
expect(job.steps[i + 1]).toEqual({ uses: "docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392", with: { platforms: "arm64" } });
|
|
170
|
+
expect(job.steps[i + 2]).toEqual({ run: "npm install -g npm@11.19.0" });
|
|
171
|
+
}
|
|
172
|
+
// An expression stays in env:, off every run: line.
|
|
173
|
+
expect(runs(doc.jobs.publish!).join("\n")).not.toContain("github.token");
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("the tag trigger's publish job takes them too", () => {
|
|
177
|
+
const doc = parseYAML(renderReleaseWorkflow({ forge: "github", groups: new Set(), pipeline: { ...pipeline, trigger: "tag" } })) as GhDoc;
|
|
178
|
+
expect(doc.permissions!.packages).toBe("write");
|
|
179
|
+
expect(doc.jobs.publish!.env).toEqual(pipeline.env);
|
|
180
|
+
expect(doc.jobs.publish!.steps.some((s) => s.uses?.startsWith("docker/setup-qemu-action@"))).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("gitlab: variables and run steps; permissions and an action are refused by name", () => {
|
|
184
|
+
const gl = { trigger: "dispatch" as const, env: { OCI_USERNAME: "$CI_REGISTRY_USER" }, setup: [{ run: "docker run --privileged --rm tonistiigi/binfmt --install arm64" }] };
|
|
185
|
+
const doc = parseYAML(renderReleaseWorkflow({ forge: "gitlab", groups: new Set(), pipeline: gl })) as Record<string, { variables: Record<string, string>; script: string[] }>;
|
|
186
|
+
for (const name of ["chant-release-cut", "chant-release-publish"]) {
|
|
187
|
+
expect(doc[name]!.variables).toEqual({ GIT_DEPTH: "0", OCI_USERNAME: "$CI_REGISTRY_USER" });
|
|
188
|
+
expect(doc[name]!.script).toContain("docker run --privileged --rm tonistiigi/binfmt --install arm64");
|
|
189
|
+
}
|
|
190
|
+
expect(doc["chant-release-gate"]!.variables).toEqual({ GIT_DEPTH: "0" });
|
|
191
|
+
expect(() => renderReleaseWorkflow({ forge: "gitlab", groups: new Set(), pipeline: { ...gl, permissions: { packages: "write" } } })).toThrow(/GitLab has no permissions/);
|
|
192
|
+
expect(() => renderReleaseWorkflow({ forge: "gitlab", groups: new Set(), pipeline: { ...pipeline, permissions: undefined } })).toThrow(/give it as \{ run \}/);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("a scope already granted and a bad variable name are refused", () => {
|
|
196
|
+
expect(() => renderReleaseWorkflow({ forge: "github", groups: new Set(), pipeline: { permissions: { contents: "read" } } })).toThrow(/already granted/);
|
|
197
|
+
expect(() => renderReleaseWorkflow({ forge: "github", groups: new Set(), pipeline: { env: { "BAD-NAME": "x" } } })).toThrow(/not a variable name/);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
import { ACTION_PINS, tagComments, usesRef } from "../action-pins";
|
|
31
31
|
import { GENERATED_MARKER } from "../discovery/files";
|
|
32
32
|
import type { SecurityGroup } from "./security";
|
|
33
|
+
import type { OpSetupStep } from "../lexicon";
|
|
33
34
|
|
|
34
35
|
export const RELEASE_WORKFLOW_FORGES = ["github", "forgejo", "gitlab"] as const;
|
|
35
36
|
export type ReleaseWorkflowForge = (typeof RELEASE_WORKFLOW_FORGES)[number];
|
|
@@ -56,6 +57,29 @@ export interface ReleasePipelineConfig {
|
|
|
56
57
|
chant?: string;
|
|
57
58
|
/** Shell lines run after the publish, with `CHANT_RELEASE_LABEL` set: steps that need a published release. */
|
|
58
59
|
after?: string[];
|
|
60
|
+
/**
|
|
61
|
+
* Scopes added to the workflow's `contents: write` and `id-token: write`
|
|
62
|
+
* (#4751), such as `{ packages: "write" }` for an `oci` target that pushes to
|
|
63
|
+
* GHCR with the run's token. A scope already granted is refused. GitHub and
|
|
64
|
+
* Forgejo only; GitLab has no `permissions:` and refuses it by name.
|
|
65
|
+
*/
|
|
66
|
+
permissions?: Record<string, "read" | "write">;
|
|
67
|
+
/**
|
|
68
|
+
* Variables for the cut and publish jobs (#4751), such as an `oci` target's
|
|
69
|
+
* `OCI_USERNAME: "${{ github.actor }}"` and `OCI_PASSWORD: "${{ github.token }}"`.
|
|
70
|
+
* A value may be a forge expression: it goes in the job's `env:` (GitLab:
|
|
71
|
+
* `variables:`), never on a `run:` line.
|
|
72
|
+
*/
|
|
73
|
+
env?: Record<string, string>;
|
|
74
|
+
/**
|
|
75
|
+
* Steps the cut and publish jobs run after the install (#4751): `{ run }`,
|
|
76
|
+
* or `{ uses, with }` on GitHub and Forgejo, such as QEMU's binfmt handlers
|
|
77
|
+
* for a two-platform image build, or a newer npm. GitLab takes `run` steps
|
|
78
|
+
* as script lines and refuses `uses` by name.
|
|
79
|
+
*/
|
|
80
|
+
setup?: OpSetupStep[];
|
|
81
|
+
/** Where the workflow is written, from the repository root, such as `.github/workflows/publish.yml` for an npm trusted publisher that names that file. Default {@link RELEASE_WORKFLOW_FILES}. */
|
|
82
|
+
file?: string;
|
|
59
83
|
}
|
|
60
84
|
|
|
61
85
|
export interface ReleaseWorkflowInput {
|
|
@@ -102,8 +126,9 @@ export function renderReleaseWorkflow(input: ReleaseWorkflowInput): string {
|
|
|
102
126
|
const flags = publishFlags(input.groups).join(" ");
|
|
103
127
|
const after = p.after ?? [];
|
|
104
128
|
const images = input.images === true;
|
|
129
|
+
const extra = jobExtras(p, input.forge);
|
|
105
130
|
if (p.trigger === "dispatch") {
|
|
106
|
-
const o = { chant, install, build, root, verify, flags, after, images, gate: p.gate ?? "last-green", ...(input.lane ? { lane: input.lane } : {}) };
|
|
131
|
+
const o = { chant, install, build, root, verify, flags, after, images, extra, gate: p.gate ?? "last-green", ...(input.lane ? { lane: input.lane } : {}) };
|
|
107
132
|
return input.forge === "gitlab" ? renderGitlabDispatch(o) : renderGithubDispatch(o);
|
|
108
133
|
}
|
|
109
134
|
// #4657: the images are built from the release, so chant/lifecycle is fetched before them and the build after.
|
|
@@ -118,9 +143,11 @@ export function renderReleaseWorkflow(input: ReleaseWorkflowInput): string {
|
|
|
118
143
|
" id_tokens:",
|
|
119
144
|
" SIGSTORE_ID_TOKEN:",
|
|
120
145
|
" aud: sigstore",
|
|
146
|
+
...(extra.gitlabVariables.length > 0 ? [" variables:", ...extra.gitlabVariables] : []),
|
|
121
147
|
" script:",
|
|
122
148
|
...(root ? [` - cd ${root}`] : []),
|
|
123
149
|
` - ${install}`,
|
|
150
|
+
...extra.gitlabScript.map((l) => ` - ${l}`),
|
|
124
151
|
...(images ? [...fetches, ...imageLines(label, `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`).map((l) => ` - ${l}`)] : []),
|
|
125
152
|
...(build ? [` - ${build}`] : []),
|
|
126
153
|
...(images ? [] : fetches),
|
|
@@ -153,13 +180,16 @@ export function renderReleaseWorkflow(input: ReleaseWorkflowInput): string {
|
|
|
153
180
|
"permissions:",
|
|
154
181
|
" contents: write",
|
|
155
182
|
" id-token: write",
|
|
183
|
+
...extra.permissions,
|
|
156
184
|
"jobs:",
|
|
157
185
|
" publish:",
|
|
158
186
|
" runs-on: ubuntu-latest",
|
|
159
187
|
...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []),
|
|
188
|
+
...extra.githubEnv([]),
|
|
160
189
|
" steps:",
|
|
161
190
|
...githubSetup(),
|
|
162
191
|
` - run: ${install}`,
|
|
192
|
+
...extra.githubSteps,
|
|
163
193
|
...(images ? [...fetches, ...imageLines(label, `echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`).map((l) => ` - run: ${l}`)] : []),
|
|
164
194
|
...(build ? [` - run: ${build}`] : []),
|
|
165
195
|
...(images ? [] : fetches),
|
|
@@ -182,6 +212,53 @@ export function renderReleaseWorkflow(input: ReleaseWorkflowInput): string {
|
|
|
182
212
|
return tagComments(`${lines.join("\n")}\n`);
|
|
183
213
|
}
|
|
184
214
|
|
|
215
|
+
interface JobExtras {
|
|
216
|
+
/** Lines added under the workflow's `permissions:`. */
|
|
217
|
+
permissions: string[];
|
|
218
|
+
/** The job's `env:` block with `base` entries first, or nothing when there is neither. */
|
|
219
|
+
githubEnv: (base: string[]) => string[];
|
|
220
|
+
/** Steps after the install. */
|
|
221
|
+
githubSteps: string[];
|
|
222
|
+
/** GitLab: the job's `variables:` entries, under a `variables:` key of their own. */
|
|
223
|
+
gitlabVariables: string[];
|
|
224
|
+
/** GitLab: script lines after the install. */
|
|
225
|
+
gitlabScript: string[];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** `release.workflow`'s `permissions`, `env` and `setup` (#4751) as lines of the forge's file. Empty for a config without them, so its file is what it was. */
|
|
229
|
+
function jobExtras(p: ReleasePipelineConfig, forge: ReleaseWorkflowForge): JobExtras {
|
|
230
|
+
const permissions = Object.entries(p.permissions ?? {});
|
|
231
|
+
const env = Object.entries(p.env ?? {});
|
|
232
|
+
const setup = p.setup ?? [];
|
|
233
|
+
const where = "release.workflow";
|
|
234
|
+
for (const [k, v] of env) if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k) || typeof v !== "string") throw new Error(`${where}.env: ${JSON.stringify(k)} is not a variable name with a string value`);
|
|
235
|
+
if (forge === "gitlab") {
|
|
236
|
+
if (permissions.length > 0) throw new Error(`${where}.permissions: GitLab has no permissions: block; a GitLab job's token scopes are the project's`);
|
|
237
|
+
const uses = setup.find((s) => "uses" in s);
|
|
238
|
+
if (uses) throw new Error(`${where}.setup: "${(uses as { uses: string }).uses}" is an action, and a GitLab job runs script lines; give it as { run }`);
|
|
239
|
+
} else {
|
|
240
|
+
for (const [k, v] of permissions) {
|
|
241
|
+
if (k === "contents" || k === "id-token") throw new Error(`${where}.permissions: ${k} is already granted (contents: write, id-token: write)`);
|
|
242
|
+
if (!/^[a-z][a-z-]*$/.test(k) || (v !== "read" && v !== "write")) throw new Error(`${where}.permissions: ${k}: ${String(v)} is not a scope and read or write`);
|
|
243
|
+
}
|
|
244
|
+
for (const s of setup) if (!("uses" in s) && s.run.trim() === "") throw new Error(`${where}.setup: a run step is empty`);
|
|
245
|
+
}
|
|
246
|
+
const q = (v: string | number | boolean): string => JSON.stringify(v);
|
|
247
|
+
const map = (indent: string, entries: Array<[string, string | number | boolean]>): string[] => entries.map(([k, v]) => `${indent}${k}: ${q(v)}`);
|
|
248
|
+
const githubSteps = setup.flatMap((s) => [
|
|
249
|
+
"uses" in s ? ` - uses: ${s.uses}` : ` - run: ${q(s.run)}`,
|
|
250
|
+
...("uses" in s && s.with && Object.keys(s.with).length > 0 ? [" with:", ...map(" ", Object.entries(s.with))] : []),
|
|
251
|
+
...(s.env && Object.keys(s.env).length > 0 ? [" env:", ...map(" ", Object.entries(s.env))] : []),
|
|
252
|
+
]);
|
|
253
|
+
return {
|
|
254
|
+
permissions: permissions.map(([k, v]) => ` ${k}: ${v}`),
|
|
255
|
+
githubEnv: (base) => (base.length + env.length > 0 ? [" env:", ...base, ...map(" ", env)] : []),
|
|
256
|
+
githubSteps,
|
|
257
|
+
gitlabVariables: map(" ", env),
|
|
258
|
+
gitlabScript: setup.flatMap((s) => ("uses" in s ? [] : [...Object.entries(s.env ?? {}).map(([k, v]) => `export ${k}=${q(v)}`), s.run])),
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
185
262
|
/** The checkout and node setup a GitHub or Forgejo job starts with; `ref` checks out that commit. */
|
|
186
263
|
function githubSetup(ref?: string): string[] {
|
|
187
264
|
return [
|
|
@@ -207,6 +284,7 @@ interface DispatchInput {
|
|
|
207
284
|
images: boolean;
|
|
208
285
|
gate: "last-green" | "head";
|
|
209
286
|
lane?: string;
|
|
287
|
+
extra: JobExtras;
|
|
210
288
|
}
|
|
211
289
|
|
|
212
290
|
/** The node one-liner that prints a JSON document's field from stdin, or from the file its argument names. */
|
|
@@ -251,6 +329,7 @@ function renderGithubDispatch(o: DispatchInput): string {
|
|
|
251
329
|
"permissions:",
|
|
252
330
|
" contents: write",
|
|
253
331
|
" id-token: write",
|
|
332
|
+
...o.extra.permissions,
|
|
254
333
|
"concurrency:",
|
|
255
334
|
" group: chant-release",
|
|
256
335
|
" cancel-in-progress: false",
|
|
@@ -273,20 +352,22 @@ function renderGithubDispatch(o: DispatchInput): string {
|
|
|
273
352
|
" needs: gate",
|
|
274
353
|
" runs-on: ubuntu-latest",
|
|
275
354
|
...defaults,
|
|
276
|
-
|
|
277
|
-
` CHANT_RELEASE_COMMIT: ${commit}`,
|
|
355
|
+
...o.extra.githubEnv([` CHANT_RELEASE_COMMIT: ${commit}`]),
|
|
278
356
|
" steps:",
|
|
279
357
|
...githubSetup(commit),
|
|
280
358
|
` - run: ${o.install}`,
|
|
359
|
+
...o.extra.githubSteps,
|
|
281
360
|
...fetches,
|
|
282
361
|
...block(cutScript(o, '"$RUNNER_TEMP/chant-cut.json"')),
|
|
283
362
|
" publish:",
|
|
284
363
|
" needs: [gate, cut]",
|
|
285
364
|
" runs-on: ubuntu-latest",
|
|
286
365
|
...defaults,
|
|
366
|
+
...o.extra.githubEnv([]),
|
|
287
367
|
" steps:",
|
|
288
368
|
...githubSetup(commit),
|
|
289
369
|
` - run: ${o.install}`,
|
|
370
|
+
...o.extra.githubSteps,
|
|
290
371
|
...fetches,
|
|
291
372
|
...(o.images ? [` - run: ${o.chant} release images "$CHANT_RELEASE_LABEL" -o ${RELEASE_DIGESTS_FILE}`, ` - run: echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`] : []),
|
|
292
373
|
...(o.build ? [` - run: ${o.build}`] : []),
|
|
@@ -314,12 +395,13 @@ function renderGitlabDispatch(o: DispatchInput): string {
|
|
|
314
395
|
'export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.extraheader GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $chant_auth"',
|
|
315
396
|
"unset chant_auth",
|
|
316
397
|
];
|
|
317
|
-
const job = (name: string, needs: string[], script: string[], extra: string[] = []): string[] => [
|
|
398
|
+
const job = (name: string, needs: string[], script: string[], extra: string[] = [], vars: string[] = []): string[] => [
|
|
318
399
|
`${name}:`,
|
|
319
400
|
" rules:",
|
|
320
401
|
' - if: $CHANT_RELEASE_LABEL && $CI_PIPELINE_SOURCE =~ /^(web|api|trigger)$/',
|
|
321
402
|
" variables:",
|
|
322
403
|
' GIT_DEPTH: "0"',
|
|
404
|
+
...vars,
|
|
323
405
|
...(needs.length > 0 ? [` needs: [${needs.join(", ")}]`] : []),
|
|
324
406
|
...extra,
|
|
325
407
|
" script:",
|
|
@@ -329,7 +411,7 @@ function renderGitlabDispatch(o: DispatchInput): string {
|
|
|
329
411
|
const lines = [
|
|
330
412
|
...job("chant-release-gate", [], [...cd, o.install, fetches[0]!, ...gateScript(o, "$CI_COMMIT_SHA"), 'echo "CHANT_RELEASE_COMMIT=$commit" > "$CI_PROJECT_DIR/chant-release-gate.env"'], [" artifacts:", " reports:", " dotenv: chant-release-gate.env"]),
|
|
331
413
|
"",
|
|
332
|
-
...job("chant-release-cut", ["chant-release-gate"], [...checkout, ...cd, o.install, ...fetches, ...auth, ...cutScript(o, "/tmp/chant-cut.json")]),
|
|
414
|
+
...job("chant-release-cut", ["chant-release-gate"], [...checkout, ...cd, o.install, ...o.extra.gitlabScript, ...fetches, ...auth, ...cutScript(o, "/tmp/chant-cut.json")], [], o.extra.gitlabVariables),
|
|
333
415
|
"",
|
|
334
416
|
...job(
|
|
335
417
|
"chant-release-publish",
|
|
@@ -338,6 +420,7 @@ function renderGitlabDispatch(o: DispatchInput): string {
|
|
|
338
420
|
...checkout,
|
|
339
421
|
...cd,
|
|
340
422
|
o.install,
|
|
423
|
+
...o.extra.gitlabScript,
|
|
341
424
|
...fetches,
|
|
342
425
|
...auth,
|
|
343
426
|
...(o.images ? [`${o.chant} release images "$CHANT_RELEASE_LABEL" -o ${RELEASE_DIGESTS_FILE}`, `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`] : []),
|
|
@@ -346,6 +429,7 @@ function renderGitlabDispatch(o: DispatchInput): string {
|
|
|
346
429
|
`${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
|
|
347
430
|
],
|
|
348
431
|
[" id_tokens:", " SIGSTORE_ID_TOKEN:", " aud: sigstore"],
|
|
432
|
+
o.extra.gitlabVariables,
|
|
349
433
|
),
|
|
350
434
|
];
|
|
351
435
|
if (o.after.length > 0) lines.push("", ...job("chant-release-after", ["chant-release-gate", "chant-release-publish"], [...checkout, ...cd, o.install, ...o.after]));
|
|
@@ -408,7 +492,7 @@ export async function runReleaseWorkflow(ctx: import("../cli/registry").CommandC
|
|
|
408
492
|
...(args.buildCommand ? { build: args.buildCommand } : {}),
|
|
409
493
|
...(args.ciChant ? { chant: args.ciChant } : {}),
|
|
410
494
|
});
|
|
411
|
-
const target = args.output ? resolve(process.cwd(), args.output) : join(repoRoot, RELEASE_WORKFLOW_FILES[forge]);
|
|
495
|
+
const target = args.output ? resolve(process.cwd(), args.output) : join(repoRoot, release?.workflow?.file ?? RELEASE_WORKFLOW_FILES[forge]);
|
|
412
496
|
const parts = ["chant", "release", "workflow", "--forge", forge];
|
|
413
497
|
if (args.ciInstall) parts.push("--install", args.ciInstall);
|
|
414
498
|
if (args.buildCommand) parts.push("--build", args.buildCommand);
|
|
@@ -420,7 +504,7 @@ export async function runReleaseWorkflow(ctx: import("../cli/registry").CommandC
|
|
|
420
504
|
const extras = [groups.has("supply-chain") ? "requires OIDC provenance (supply-chain)" : null, groups.has("verified-releases") ? "verifies the release first (verified-releases)" : null].filter(Boolean);
|
|
421
505
|
const what = release?.workflow?.trigger === "dispatch" ? "cuts and publishes a release started by hand with its label, from a green commit" : "publishes the release a release/** tag names";
|
|
422
506
|
console.log(formatSuccess(`Wrote ${shown}: ${what}${extras.length > 0 ? `, and ${extras.join(" and ")}` : ""}.`));
|
|
423
|
-
if (forge === "gitlab") console.log(`Include it from .gitlab-ci.yml: include: [{ local: ${RELEASE_WORKFLOW_FILES.gitlab} }]`);
|
|
507
|
+
if (forge === "gitlab") console.log(`Include it from .gitlab-ci.yml: include: [{ local: ${release?.workflow?.file ?? RELEASE_WORKFLOW_FILES.gitlab} }]`);
|
|
424
508
|
if (forge === "gitlab" && release?.workflow?.trigger === "dispatch") console.log("The cut and publish jobs push with CHANT_RELEASE_TOKEN: a project access token with write_repository, as a masked CI/CD variable.");
|
|
425
509
|
return 0;
|
|
426
510
|
}
|