@intentius/chant 0.124.69 → 0.124.71
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-agent.d.ts +12 -1
- package/dist/ci-agent.d.ts.map +1 -1
- package/dist/ci-agent.js +13 -8
- package/dist/ci-commit.d.ts +297 -0
- package/dist/ci-commit.d.ts.map +1 -0
- package/dist/ci-commit.js +696 -0
- package/dist/ci-product-words.d.ts +6 -1
- package/dist/ci-product-words.d.ts.map +1 -1
- package/dist/ci-product-words.js +3 -1
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +7 -2
- package/dist/cli/handlers/commit.d.ts +26 -0
- package/dist/cli/handlers/commit.d.ts.map +1 -0
- package/dist/cli/handlers/commit.js +142 -0
- package/dist/cli/handlers/pr.d.ts +6 -0
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +16 -7
- package/dist/cli/handlers/release.d.ts +9 -0
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +114 -5
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +23 -0
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +15 -0
- package/dist/cli/registry.d.ts +4 -0
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/product-pipeline.d.ts +33 -0
- package/dist/components/product-pipeline.d.ts.map +1 -1
- package/dist/components/product-pipeline.js +34 -1
- package/dist/components/release-compile.d.ts +2 -0
- package/dist/components/release-compile.d.ts.map +1 -1
- package/dist/components/release-compile.js +8 -4
- package/dist/config.d.ts +46 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +9 -0
- package/dist/lexicon.d.ts +37 -0
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lexicon.js +28 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +4 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
- package/dist/lifecycle/__fixtures__/publish-fakes.js +6 -2
- package/dist/lifecycle/gated-request.d.ts +3 -1
- package/dist/lifecycle/gated-request.d.ts.map +1 -1
- package/dist/lifecycle/gated-request.js +5 -2
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +57 -0
- package/dist/lifecycle/publish-declaration.d.ts +16 -0
- package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
- package/dist/lifecycle/publish-declaration.js +35 -3
- package/dist/lifecycle/publish-forge.d.ts +12 -0
- package/dist/lifecycle/publish-forge.d.ts.map +1 -1
- package/dist/lifecycle/publish-forge.js +103 -19
- package/dist/lifecycle/publish-npm.d.ts +15 -0
- package/dist/lifecycle/publish-npm.d.ts.map +1 -1
- package/dist/lifecycle/publish-npm.js +28 -1
- package/dist/lifecycle/publish-oci.d.ts +2 -0
- package/dist/lifecycle/publish-oci.d.ts.map +1 -1
- package/dist/lifecycle/publish-oci.js +10 -0
- package/dist/lifecycle/release-cut.d.ts +7 -1
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +8 -1
- package/dist/lifecycle/release-images.d.ts +87 -0
- package/dist/lifecycle/release-images.d.ts.map +1 -0
- package/dist/lifecycle/release-images.js +139 -0
- package/dist/lifecycle/release-publish.d.ts +2 -0
- package/dist/lifecycle/release-publish.d.ts.map +1 -1
- package/dist/op/activities/activity-contracts.d.ts +4 -4
- package/dist/op/activities/review-agent.d.ts.map +1 -1
- package/dist/op/activities/review-agent.js +4 -2
- package/dist/op/gate.d.ts +5 -1
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +7 -2
- package/dist/op/op-waves-notify.d.ts +1 -1
- package/dist/op/op-waves-notify.d.ts.map +1 -1
- package/dist/op/op-waves-notify.js +2 -1
- package/dist/op/op-waves-run.d.ts.map +1 -1
- package/dist/op/op-waves-run.js +12 -8
- package/dist/op/op-waves.d.ts +9 -0
- package/dist/op/op-waves.d.ts.map +1 -1
- package/dist/op/op-waves.js +11 -0
- package/dist/pr-forge-base.d.ts +18 -0
- package/dist/pr-forge-base.d.ts.map +1 -0
- package/dist/pr-forge-base.js +29 -0
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +305 -305
- package/dist/workspace/ci-green-cli.d.ts +7 -3
- package/dist/workspace/ci-green-cli.d.ts.map +1 -1
- package/dist/workspace/ci-green-cli.js +29 -8
- package/dist/workspace/ci-green-forge.d.ts +29 -0
- package/dist/workspace/ci-green-forge.d.ts.map +1 -1
- package/dist/workspace/ci-green-forge.js +50 -0
- package/dist/workspace/ci-green-workflow.d.ts +9 -1
- package/dist/workspace/ci-green-workflow.d.ts.map +1 -1
- package/dist/workspace/ci-green-workflow.js +15 -3
- package/dist/workspace/ci-green.d.ts +35 -1
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +122 -4
- package/dist/workspace/declaration.d.ts +14 -2
- package/dist/workspace/declaration.d.ts.map +1 -1
- package/dist/workspace/declaration.js +14 -1
- package/dist/workspace/declaration.schema.json +17 -2
- package/dist/workspace/release-workflow.d.ts +23 -0
- package/dist/workspace/release-workflow.d.ts.map +1 -1
- package/dist/workspace/release-workflow.js +203 -12
- package/package.json +1 -1
- package/src/ci-agent.ts +13 -8
- package/src/ci-commit.test.ts +415 -0
- package/src/ci-commit.ts +857 -0
- package/src/ci-product-words.ts +6 -2
- package/src/cli/handlers/approve.ts +6 -2
- package/src/cli/handlers/commit.ts +152 -0
- package/src/cli/handlers/operator.test.ts +2 -0
- package/src/cli/handlers/pr-wave-approve-lines.test.ts +32 -0
- package/src/cli/handlers/pr.ts +17 -7
- package/src/cli/handlers/release.ts +110 -5
- package/src/cli/main.ts +23 -0
- package/src/cli/parse-args.ts +11 -0
- package/src/cli/registry.ts +4 -0
- package/src/components/product-pipeline.test.ts +28 -1
- package/src/components/product-pipeline.ts +54 -1
- package/src/components/release-compile.ts +9 -3
- package/src/config.ts +24 -0
- package/src/lexicon.ts +56 -0
- package/src/lifecycle/__fixtures__/publish-fakes.ts +11 -5
- package/src/lifecycle/gated-request-spend.test.ts +115 -0
- package/src/lifecycle/gated-request.ts +5 -2
- package/src/lifecycle/git.ts +53 -0
- package/src/lifecycle/ledger-two-clones.test.ts +132 -0
- package/src/lifecycle/publish-declaration.ts +35 -3
- package/src/lifecycle/publish-forge-notes.test.ts +193 -0
- package/src/lifecycle/publish-forge.ts +101 -22
- package/src/lifecycle/publish-npm.ts +31 -2
- package/src/lifecycle/publish-oci.ts +10 -0
- package/src/lifecycle/publish-targets.test.ts +2 -1
- package/src/lifecycle/release-cut.ts +17 -1
- package/src/lifecycle/release-images.test.ts +242 -0
- package/src/lifecycle/release-images.ts +175 -0
- package/src/lifecycle/release-publish.ts +2 -0
- package/src/op/activities/review-agent.test.ts +20 -1
- package/src/op/activities/review-agent.ts +5 -2
- package/src/op/gate.ts +7 -2
- package/src/op/op-waves-approve-target.test.ts +108 -0
- package/src/op/op-waves-notify.ts +2 -2
- package/src/op/op-waves-run.ts +12 -7
- package/src/op/op-waves.ts +12 -0
- package/src/pr-forge-base.test.ts +37 -0
- package/src/pr-forge-base.ts +36 -0
- package/src/release-floors.ts +1 -1
- package/src/workspace/__fixtures__/release-workflow/forgejo-plain-member.yml +26 -0
- package/src/workspace/__fixtures__/release-workflow/forgejo-plain.yml +23 -0
- package/src/workspace/__fixtures__/release-workflow/forgejo-secure-member.yml +27 -0
- package/src/workspace/__fixtures__/release-workflow/forgejo-secure.yml +24 -0
- package/src/workspace/__fixtures__/release-workflow/github-plain-member.yml +26 -0
- package/src/workspace/__fixtures__/release-workflow/github-plain.yml +23 -0
- package/src/workspace/__fixtures__/release-workflow/github-secure-member.yml +27 -0
- package/src/workspace/__fixtures__/release-workflow/github-secure.yml +24 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-plain-member.yml +13 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-plain.yml +12 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-secure-member.yml +14 -0
- package/src/workspace/__fixtures__/release-workflow/gitlab-secure.yml +13 -0
- package/src/workspace/ci-green-cli.ts +27 -8
- package/src/workspace/ci-green-forge.ts +70 -0
- package/src/workspace/ci-green-workflow.ts +15 -3
- package/src/workspace/ci-green.ts +130 -5
- package/src/workspace/ci-verdict-retries.test.ts +376 -0
- package/src/workspace/declaration.schema.json +17 -2
- package/src/workspace/declaration.ts +28 -4
- package/src/workspace/release-workflow.test.ts +151 -0
- package/src/workspace/release-workflow.ts +270 -12
|
@@ -15,6 +15,17 @@
|
|
|
15
15
|
* The OIDC permission (`id-token: write`, or GitLab's `id_tokens`) is always
|
|
16
16
|
* there: it costs nothing, and with it what the job uploads carries
|
|
17
17
|
* provenance whether or not the group requires it.
|
|
18
|
+
*
|
|
19
|
+
* `release.workflow` in the root's `chant.config.ts` (#4656) renders the
|
|
20
|
+
* rest of the release from the same file. `trigger: "dispatch"` starts it by
|
|
21
|
+
* hand with a label, and four jobs follow: the gate names the commit to cut
|
|
22
|
+
* (`chant ci last-green`, or the dispatched commit itself under `gate:
|
|
23
|
+
* "head"`), the cut runs `chant release cut <label> --at <commit>` and pushes
|
|
24
|
+
* the release's tag, the publish job publishes it, and the post-release job
|
|
25
|
+
* runs `after`. No tag exists until the gate has passed. With
|
|
26
|
+
* `release.images` (#4657) the publish job builds the images again with
|
|
27
|
+
* `chant release images` before the build. A config with only `publish`
|
|
28
|
+
* renders the tag-triggered file it always did.
|
|
18
29
|
*/
|
|
19
30
|
import { ACTION_PINS, tagComments, usesRef } from "../action-pins";
|
|
20
31
|
import { GENERATED_MARKER } from "../discovery/files";
|
|
@@ -31,6 +42,22 @@ export const RELEASE_WORKFLOW_FILES: Record<ReleaseWorkflowForge, string> = {
|
|
|
31
42
|
gitlab: ".gitlab/chant-release.yml",
|
|
32
43
|
};
|
|
33
44
|
|
|
45
|
+
/** `release.workflow` in `chant.config.ts` (#4656): how the release pipeline starts and what it runs. */
|
|
46
|
+
export interface ReleasePipelineConfig {
|
|
47
|
+
/** `tag` (default): the publish job runs on a `release/**` tag. `dispatch`: the whole release starts by hand with a label. */
|
|
48
|
+
trigger?: "tag" | "dispatch";
|
|
49
|
+
/** For `dispatch`: the commit to cut. `last-green` (default) is the newest green commit at or below the dispatched one; `head` is the dispatched commit, which must be green. */
|
|
50
|
+
gate?: "last-green" | "head";
|
|
51
|
+
/** The command that installs what the build needs. Default `npm ci`. */
|
|
52
|
+
install?: string;
|
|
53
|
+
/** The command that builds what the targets upload, run by the cut (as its `--build`) and the publish job. `false` for none. Default `npm run build`. */
|
|
54
|
+
build?: string | false;
|
|
55
|
+
/** What runs chant. Default `npx chant`. */
|
|
56
|
+
chant?: string;
|
|
57
|
+
/** Shell lines run after the publish, with `CHANT_RELEASE_LABEL` set: steps that need a published release. */
|
|
58
|
+
after?: string[];
|
|
59
|
+
}
|
|
60
|
+
|
|
34
61
|
export interface ReleaseWorkflowInput {
|
|
35
62
|
forge: ReleaseWorkflowForge;
|
|
36
63
|
/** The security groups the workspace opts into at its root. */
|
|
@@ -43,6 +70,12 @@ export interface ReleaseWorkflowInput {
|
|
|
43
70
|
chant?: string;
|
|
44
71
|
/** The workspace root relative to the repository root, `.` at the top. */
|
|
45
72
|
workspaceRoot?: string;
|
|
73
|
+
/** `release.workflow` (#4656). A flag above wins over the field it names. */
|
|
74
|
+
pipeline?: ReleasePipelineConfig;
|
|
75
|
+
/** The config declares `release.images` (#4657): the publish job builds them again first. */
|
|
76
|
+
images?: boolean;
|
|
77
|
+
/** `release.lane` (#4692): the gate's green lane. */
|
|
78
|
+
lane?: string;
|
|
46
79
|
}
|
|
47
80
|
|
|
48
81
|
/** The flags `chant release publish` gets under the groups. */
|
|
@@ -50,16 +83,34 @@ export function publishFlags(groups: ReadonlySet<SecurityGroup>): string[] {
|
|
|
50
83
|
return [...(groups.has("supply-chain") ? ["--require-provenance"] : []), "--yes"];
|
|
51
84
|
}
|
|
52
85
|
|
|
86
|
+
/** Where `chant release images` writes the digests the publish job's build reads (#4657). */
|
|
87
|
+
export const RELEASE_DIGESTS_FILE = ".chant/release-digests.json";
|
|
88
|
+
|
|
89
|
+
/** A string as a single-quoted shell word. */
|
|
90
|
+
function sq(s: string): string {
|
|
91
|
+
return `'${s.replaceAll("'", "'\\''")}'`;
|
|
92
|
+
}
|
|
93
|
+
|
|
53
94
|
/** The workflow file's text, without the generated-by header. */
|
|
54
95
|
export function renderReleaseWorkflow(input: ReleaseWorkflowInput): string {
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
96
|
+
const p = input.pipeline ?? {};
|
|
97
|
+
const chant = input.chant ?? p.chant ?? "npx chant";
|
|
98
|
+
const install = input.install ?? p.install ?? "npm ci";
|
|
99
|
+
const build = input.build !== undefined ? input.build : p.build === false ? null : (p.build ?? "npm run build");
|
|
58
100
|
const root = input.workspaceRoot && input.workspaceRoot !== "." ? input.workspaceRoot : null;
|
|
59
101
|
const verify = input.groups.has("verified-releases");
|
|
60
102
|
const flags = publishFlags(input.groups).join(" ");
|
|
103
|
+
const after = p.after ?? [];
|
|
104
|
+
const images = input.images === true;
|
|
105
|
+
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 } : {}) };
|
|
107
|
+
return input.forge === "gitlab" ? renderGitlabDispatch(o) : renderGithubDispatch(o);
|
|
108
|
+
}
|
|
109
|
+
// #4657: the images are built from the release, so chant/lifecycle is fetched before them and the build after.
|
|
110
|
+
const imageLines = (label: string, env: string): string[] => [`${chant} release images ${label} -o ${RELEASE_DIGESTS_FILE}`, env];
|
|
61
111
|
if (input.forge === "gitlab") {
|
|
62
112
|
const label = '"${CI_COMMIT_TAG#release/}"';
|
|
113
|
+
const fetches = [" - git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'", " - git fetch origin chant/lifecycle:chant/lifecycle"];
|
|
63
114
|
const lines = [
|
|
64
115
|
"chant-release-publish:",
|
|
65
116
|
" rules:",
|
|
@@ -70,15 +121,30 @@ export function renderReleaseWorkflow(input: ReleaseWorkflowInput): string {
|
|
|
70
121
|
" script:",
|
|
71
122
|
...(root ? [` - cd ${root}`] : []),
|
|
72
123
|
` - ${install}`,
|
|
124
|
+
...(images ? [...fetches, ...imageLines(label, `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`).map((l) => ` - ${l}`)] : []),
|
|
73
125
|
...(build ? [` - ${build}`] : []),
|
|
74
|
-
|
|
75
|
-
" - git fetch origin chant/lifecycle:chant/lifecycle",
|
|
126
|
+
...(images ? [] : fetches),
|
|
76
127
|
...(verify ? [` - ${chant} release verify ${label}`] : []),
|
|
77
128
|
` - ${chant} release publish ${label} ${flags}`,
|
|
78
129
|
];
|
|
130
|
+
if (after.length > 0) {
|
|
131
|
+
lines.push(
|
|
132
|
+
"",
|
|
133
|
+
"chant-release-after:",
|
|
134
|
+
" rules:",
|
|
135
|
+
" - if: $CI_COMMIT_TAG =~ /^release\\//",
|
|
136
|
+
" needs: [chant-release-publish]",
|
|
137
|
+
" script:",
|
|
138
|
+
' - export CHANT_RELEASE_LABEL="${CI_COMMIT_TAG#release/}"',
|
|
139
|
+
...(root ? [` - cd ${root}`] : []),
|
|
140
|
+
` - ${install}`,
|
|
141
|
+
...after.map((l) => ` - ${l}`),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
79
144
|
return `${lines.join("\n")}\n`;
|
|
80
145
|
}
|
|
81
146
|
const label = '"${GITHUB_REF_NAME#release/}"';
|
|
147
|
+
const fetches = [" - run: git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'", " - run: git fetch origin chant/lifecycle:chant/lifecycle"];
|
|
82
148
|
const lines = [
|
|
83
149
|
"name: chant release publish",
|
|
84
150
|
"on:",
|
|
@@ -92,23 +158,200 @@ export function renderReleaseWorkflow(input: ReleaseWorkflowInput): string {
|
|
|
92
158
|
" runs-on: ubuntu-latest",
|
|
93
159
|
...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []),
|
|
94
160
|
" steps:",
|
|
161
|
+
...githubSetup(),
|
|
162
|
+
` - run: ${install}`,
|
|
163
|
+
...(images ? [...fetches, ...imageLines(label, `echo "CHANT_RELEASE_DIGESTS=$PWD/${RELEASE_DIGESTS_FILE}" >> "$GITHUB_ENV"`).map((l) => ` - run: ${l}`)] : []),
|
|
164
|
+
...(build ? [` - run: ${build}`] : []),
|
|
165
|
+
...(images ? [] : fetches),
|
|
166
|
+
...(verify ? [` - run: ${chant} release verify ${label}`] : []),
|
|
167
|
+
` - run: ${chant} release publish ${label} ${flags}`,
|
|
168
|
+
];
|
|
169
|
+
if (after.length > 0) {
|
|
170
|
+
lines.push(
|
|
171
|
+
" after-release:",
|
|
172
|
+
" needs: publish",
|
|
173
|
+
" runs-on: ubuntu-latest",
|
|
174
|
+
...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []),
|
|
175
|
+
" steps:",
|
|
176
|
+
...githubSetup(),
|
|
177
|
+
' - run: echo "CHANT_RELEASE_LABEL=${GITHUB_REF_NAME#release/}" >> "$GITHUB_ENV"',
|
|
178
|
+
` - run: ${install}`,
|
|
179
|
+
...after.map((l) => ` - run: ${l}`),
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
return tagComments(`${lines.join("\n")}\n`);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The checkout and node setup a GitHub or Forgejo job starts with; `ref` checks out that commit. */
|
|
186
|
+
function githubSetup(ref?: string): string[] {
|
|
187
|
+
return [
|
|
95
188
|
` - uses: ${usesRef(ACTION_PINS.checkout4)}`,
|
|
96
189
|
" with:",
|
|
190
|
+
...(ref ? [` ref: ${ref}`] : []),
|
|
97
191
|
" fetch-depth: 0",
|
|
98
192
|
` - uses: ${usesRef(ACTION_PINS.setupNode4)}`,
|
|
99
193
|
" with:",
|
|
100
194
|
" node-version: 24",
|
|
101
195
|
" registry-url: https://registry.npmjs.org",
|
|
102
|
-
` - run: ${install}`,
|
|
103
|
-
...(build ? [` - run: ${build}`] : []),
|
|
104
|
-
" - run: git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'",
|
|
105
|
-
" - run: git fetch origin chant/lifecycle:chant/lifecycle",
|
|
106
|
-
...(verify ? [` - run: ${chant} release verify ${label}`] : []),
|
|
107
|
-
` - run: ${chant} release publish ${label} ${flags}`,
|
|
108
196
|
];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
interface DispatchInput {
|
|
200
|
+
chant: string;
|
|
201
|
+
install: string;
|
|
202
|
+
build: string | null;
|
|
203
|
+
root: string | null;
|
|
204
|
+
verify: boolean;
|
|
205
|
+
flags: string;
|
|
206
|
+
after: string[];
|
|
207
|
+
images: boolean;
|
|
208
|
+
gate: "last-green" | "head";
|
|
209
|
+
lane?: string;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** The node one-liner that prints a JSON document's field from stdin, or from the file its argument names. */
|
|
213
|
+
const field = (path: string): string =>
|
|
214
|
+
`node -e 'const f=process.argv[1];const t=f?require("fs").readFileSync(f,"utf8"):require("fs").readFileSync(0,"utf8");const d=JSON.parse(t);process.stdout.write(String(${path}??""))'`;
|
|
215
|
+
|
|
216
|
+
/** The gate's shell: the commit to cut, from `ci last-green`, refused when there is none or, under `head`, when it is not the dispatched one. */
|
|
217
|
+
function gateScript(o: DispatchInput, dispatched: string): string[] {
|
|
218
|
+
return [
|
|
219
|
+
`commit="$(${o.chant} ci last-green --from "${dispatched}"${o.lane ? ` --lane ${o.lane}` : ""} --json | ${field("d.commit?.sha")})"`,
|
|
220
|
+
`if [ -z "$commit" ]; then echo "no green commit at or below ${dispatched}, so no release is cut" >&2; exit 1; fi`,
|
|
221
|
+
...(o.gate === "head" ? [`if [ "$commit" != "${dispatched}" ]; then echo "${dispatched} is not green (the newest green commit below it is $commit), so no release is cut" >&2; exit 1; fi`] : []),
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** The cut's shell: cut the label at the gate's commit, then push the tag the cut made. */
|
|
226
|
+
function cutScript(o: DispatchInput, out: string): string[] {
|
|
227
|
+
return [
|
|
228
|
+
'git config user.name "chant release"',
|
|
229
|
+
'git config user.email "chant-release@localhost"',
|
|
230
|
+
`${o.chant} release cut "$CHANT_RELEASE_LABEL" --at "$CHANT_RELEASE_COMMIT" --yes${o.build ? ` --build ${sq(o.build)}` : ""}${o.lane ? ` --lane ${o.lane}` : ""} --json > ${out}`,
|
|
231
|
+
`tag="$(${field("d.tag?.name")} ${out})"`,
|
|
232
|
+
'if [ -n "$tag" ]; then git push origin "refs/tags/$tag"; fi',
|
|
233
|
+
];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** GitHub and Forgejo: the release started by hand with a label (#4656). */
|
|
237
|
+
function renderGithubDispatch(o: DispatchInput): string {
|
|
238
|
+
const defaults = o.root ? [" defaults:", " run:", ` working-directory: ${o.root}`] : [];
|
|
239
|
+
const commit = "${{ needs.gate.outputs.commit }}";
|
|
240
|
+
const fetches = [" - run: git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'", " - run: git fetch origin chant/lifecycle:chant/lifecycle"];
|
|
241
|
+
const block = (lines: string[]): string[] => [" - run: |", ...lines.map((l) => ` ${l}`)];
|
|
242
|
+
const lines = [
|
|
243
|
+
"name: chant release",
|
|
244
|
+
"on:",
|
|
245
|
+
" workflow_dispatch:",
|
|
246
|
+
" inputs:",
|
|
247
|
+
" label:",
|
|
248
|
+
" description: The release's label, such as v1.4.0",
|
|
249
|
+
" required: true",
|
|
250
|
+
" type: string",
|
|
251
|
+
"permissions:",
|
|
252
|
+
" contents: write",
|
|
253
|
+
" id-token: write",
|
|
254
|
+
"concurrency:",
|
|
255
|
+
" group: chant-release",
|
|
256
|
+
" cancel-in-progress: false",
|
|
257
|
+
"env:",
|
|
258
|
+
" CHANT_RELEASE_LABEL: ${{ inputs.label }}",
|
|
259
|
+
"jobs:",
|
|
260
|
+
" gate:",
|
|
261
|
+
" runs-on: ubuntu-latest",
|
|
262
|
+
...defaults,
|
|
263
|
+
" outputs:",
|
|
264
|
+
" commit: ${{ steps.green.outputs.commit }}",
|
|
265
|
+
" steps:",
|
|
266
|
+
...githubSetup(),
|
|
267
|
+
` - run: ${o.install}`,
|
|
268
|
+
fetches[0]!,
|
|
269
|
+
" - id: green",
|
|
270
|
+
" run: |",
|
|
271
|
+
...[...gateScript(o, "$GITHUB_SHA"), 'echo "commit=$commit" >> "$GITHUB_OUTPUT"'].map((l) => ` ${l}`),
|
|
272
|
+
" cut:",
|
|
273
|
+
" needs: gate",
|
|
274
|
+
" runs-on: ubuntu-latest",
|
|
275
|
+
...defaults,
|
|
276
|
+
" env:",
|
|
277
|
+
` CHANT_RELEASE_COMMIT: ${commit}`,
|
|
278
|
+
" steps:",
|
|
279
|
+
...githubSetup(commit),
|
|
280
|
+
` - run: ${o.install}`,
|
|
281
|
+
...fetches,
|
|
282
|
+
...block(cutScript(o, '"$RUNNER_TEMP/chant-cut.json"')),
|
|
283
|
+
" publish:",
|
|
284
|
+
" needs: [gate, cut]",
|
|
285
|
+
" runs-on: ubuntu-latest",
|
|
286
|
+
...defaults,
|
|
287
|
+
" steps:",
|
|
288
|
+
...githubSetup(commit),
|
|
289
|
+
` - run: ${o.install}`,
|
|
290
|
+
...fetches,
|
|
291
|
+
...(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
|
+
...(o.build ? [` - run: ${o.build}`] : []),
|
|
293
|
+
...(o.verify ? [` - run: ${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
|
|
294
|
+
` - run: ${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
|
|
295
|
+
];
|
|
296
|
+
if (o.after.length > 0) {
|
|
297
|
+
lines.push(" after-release:", " needs: [gate, publish]", " runs-on: ubuntu-latest", ...defaults, " steps:", ...githubSetup(commit), ` - run: ${o.install}`, ...o.after.map((l) => ` - run: ${l}`));
|
|
298
|
+
}
|
|
109
299
|
return tagComments(`${lines.join("\n")}\n`);
|
|
110
300
|
}
|
|
111
301
|
|
|
302
|
+
/**
|
|
303
|
+
* GitLab: the release started from "Run pipeline" with `CHANT_RELEASE_LABEL`
|
|
304
|
+
* set (#4656). The jobs follow each other by `needs`, in the file's default
|
|
305
|
+
* stage, so the including `.gitlab-ci.yml` keeps its own `stages`. A job
|
|
306
|
+
* token cannot push, so the cut and publish jobs push with
|
|
307
|
+
* `CHANT_RELEASE_TOKEN`, a project access token with `write_repository`.
|
|
308
|
+
*/
|
|
309
|
+
function renderGitlabDispatch(o: DispatchInput): string {
|
|
310
|
+
const cd = o.root ? [`cd ${o.root}`] : [];
|
|
311
|
+
const fetches = ["git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'", "git fetch origin chant/lifecycle:chant/lifecycle"];
|
|
312
|
+
const auth = [
|
|
313
|
+
`chant_auth="$(printf 'oauth2:%s' "$CHANT_RELEASE_TOKEN" | base64 | tr -d '\\n')"`,
|
|
314
|
+
'export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.extraheader GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $chant_auth"',
|
|
315
|
+
"unset chant_auth",
|
|
316
|
+
];
|
|
317
|
+
const job = (name: string, needs: string[], script: string[], extra: string[] = []): string[] => [
|
|
318
|
+
`${name}:`,
|
|
319
|
+
" rules:",
|
|
320
|
+
' - if: $CHANT_RELEASE_LABEL && $CI_PIPELINE_SOURCE =~ /^(web|api|trigger)$/',
|
|
321
|
+
" variables:",
|
|
322
|
+
' GIT_DEPTH: "0"',
|
|
323
|
+
...(needs.length > 0 ? [` needs: [${needs.join(", ")}]`] : []),
|
|
324
|
+
...extra,
|
|
325
|
+
" script:",
|
|
326
|
+
...script.map((l) => ` - ${JSON.stringify(l)}`),
|
|
327
|
+
];
|
|
328
|
+
const checkout = ['git checkout --detach "$CHANT_RELEASE_COMMIT"'];
|
|
329
|
+
const lines = [
|
|
330
|
+
...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
|
+
"",
|
|
332
|
+
...job("chant-release-cut", ["chant-release-gate"], [...checkout, ...cd, o.install, ...fetches, ...auth, ...cutScript(o, "/tmp/chant-cut.json")]),
|
|
333
|
+
"",
|
|
334
|
+
...job(
|
|
335
|
+
"chant-release-publish",
|
|
336
|
+
["chant-release-gate", "chant-release-cut"],
|
|
337
|
+
[
|
|
338
|
+
...checkout,
|
|
339
|
+
...cd,
|
|
340
|
+
o.install,
|
|
341
|
+
...fetches,
|
|
342
|
+
...auth,
|
|
343
|
+
...(o.images ? [`${o.chant} release images "$CHANT_RELEASE_LABEL" -o ${RELEASE_DIGESTS_FILE}`, `export CHANT_RELEASE_DIGESTS="$PWD/${RELEASE_DIGESTS_FILE}"`] : []),
|
|
344
|
+
...(o.build ? [o.build] : []),
|
|
345
|
+
...(o.verify ? [`${o.chant} release verify "$CHANT_RELEASE_LABEL"`] : []),
|
|
346
|
+
`${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
|
|
347
|
+
],
|
|
348
|
+
[" id_tokens:", " SIGSTORE_ID_TOKEN:", " aud: sigstore"],
|
|
349
|
+
),
|
|
350
|
+
];
|
|
351
|
+
if (o.after.length > 0) lines.push("", ...job("chant-release-after", ["chant-release-gate", "chant-release-publish"], [...checkout, ...cd, o.install, ...o.after]));
|
|
352
|
+
return `${lines.join("\n")}\n`;
|
|
353
|
+
}
|
|
354
|
+
|
|
112
355
|
/** The header that marks the file generated, naming the command that regenerates it. */
|
|
113
356
|
export function releaseWorkflowHeader(command: string): string {
|
|
114
357
|
return `# ${GENERATED_MARKER}. Regenerate with: ${command} (in the workspace root)\n`;
|
|
@@ -144,10 +387,23 @@ export async function runReleaseWorkflow(ctx: import("../cli/registry").CommandC
|
|
|
144
387
|
}
|
|
145
388
|
const groups = securityGroupsAt(root);
|
|
146
389
|
const workspaceRoot = relative(repoRoot, root).split(sep).join("/") || ".";
|
|
390
|
+
// #4656: release.workflow, release.images and release.lane in the root's chant.config.ts.
|
|
391
|
+
let release: import("../config").ChantConfig["release"];
|
|
392
|
+
try {
|
|
393
|
+
const { loadChantConfig } = await import("../config");
|
|
394
|
+
release = (await loadChantConfig(root)).config.release;
|
|
395
|
+
} catch (err) {
|
|
396
|
+
console.error(formatError({ message: `chant.config.ts at the workspace root could not be read: ${err instanceof Error ? err.message : String(err)}`, hint: usage }));
|
|
397
|
+
return 1;
|
|
398
|
+
}
|
|
147
399
|
const text = renderReleaseWorkflow({
|
|
148
400
|
forge,
|
|
149
401
|
groups,
|
|
150
402
|
workspaceRoot,
|
|
403
|
+
...(release?.workflow ? { pipeline: release.workflow } : {}),
|
|
404
|
+
// release.images (#4657) is read loosely, so this file renders with a config of either shape.
|
|
405
|
+
...(((release as { images?: unknown[] } | undefined)?.images?.length ?? 0) > 0 ? { images: true } : {}),
|
|
406
|
+
...(release?.lane ? { lane: release.lane } : {}),
|
|
151
407
|
...(args.ciInstall ? { install: args.ciInstall } : {}),
|
|
152
408
|
...(args.buildCommand ? { build: args.buildCommand } : {}),
|
|
153
409
|
...(args.ciChant ? { chant: args.ciChant } : {}),
|
|
@@ -162,7 +418,9 @@ export async function runReleaseWorkflow(ctx: import("../cli/registry").CommandC
|
|
|
162
418
|
writeFileSync(target, releaseWorkflowHeader(parts.map(shellArg).join(" ")) + text);
|
|
163
419
|
const shown = relative(process.cwd(), target).split(sep).join("/") || target;
|
|
164
420
|
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);
|
|
165
|
-
|
|
421
|
+
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
|
+
console.log(formatSuccess(`Wrote ${shown}: ${what}${extras.length > 0 ? `, and ${extras.join(" and ")}` : ""}.`));
|
|
166
423
|
if (forge === "gitlab") console.log(`Include it from .gitlab-ci.yml: include: [{ local: ${RELEASE_WORKFLOW_FILES.gitlab} }]`);
|
|
424
|
+
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.");
|
|
167
425
|
return 0;
|
|
168
426
|
}
|