@intentius/chant 0.124.102 → 0.124.103
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/cli/commands/onboard.js +8 -8
- package/dist/cli/handlers/release-init.js +3 -1
- package/dist/cli/main.js +13 -2
- package/dist/cli/parse-args.js +5 -0
- package/dist/cli/registry.d.ts +2 -0
- package/dist/cloud-lister/kubernetes-components.js +1 -2
- package/dist/floor-table.data.js +7 -6
- package/dist/lifecycle/publish-declaration.js +1 -2
- package/dist/lifecycle/publish-helm.js +1 -2
- package/dist/lifecycle/publish-maven.js +1 -2
- package/dist/lifecycle/publish-npm.js +1 -1
- package/dist/lifecycle/publish-nuget.js +1 -2
- package/dist/lifecycle/publish-rubygems.js +1 -2
- package/dist/lifecycle/release-artifacts.js +1 -2
- package/dist/lifecycle/release-init.js +10 -9
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +4 -4
- package/dist/workspace/release-train-workflow.d.ts +21 -3
- package/dist/workspace/release-train-workflow.js +129 -8
- package/dist/workspace/release-train.js +5 -1
- package/dist/workspace/release-workflow.d.ts +11 -0
- package/dist/workspace/release-workflow.js +42 -9
- package/dist/workspace/train-artifacts.d.ts +107 -0
- package/dist/workspace/train-artifacts.js +239 -0
- package/dist/workspace/train-cut.d.ts +12 -0
- package/dist/workspace/train-cut.js +22 -2
- package/dist/workspace/train-publish.d.ts +9 -0
- package/dist/workspace/train-publish.js +27 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReleaseGreenSource } from "../lifecycle/release-green.js";
|
|
2
2
|
import { type JobExtras, type ReleaseWorkflowForge } from "./release-workflow.js";
|
|
3
3
|
export interface TrainWorkflowInput {
|
|
4
|
-
forge:
|
|
4
|
+
forge: ReleaseWorkflowForge;
|
|
5
5
|
env: string;
|
|
6
6
|
trigger: "dispatch" | "tag";
|
|
7
7
|
chant: string;
|
|
@@ -22,6 +22,24 @@ export interface TrainWorkflowInput {
|
|
|
22
22
|
green: ReleaseGreenSource;
|
|
23
23
|
gate: "last-green" | "head";
|
|
24
24
|
lane?: string;
|
|
25
|
+
/**
|
|
26
|
+
* A member declares `release.images` or `release.artifacts` (#5216): the cut
|
|
27
|
+
* job stages what the cut built with `chant workspace train artifacts -o`
|
|
28
|
+
* and hands it to the publish job, which checks it (`--from`) after its
|
|
29
|
+
* build. A publish with nothing handed to it (a pushed train tag, a
|
|
30
|
+
* dispatched `train`) builds them again and checks them.
|
|
31
|
+
*/
|
|
32
|
+
files?: boolean;
|
|
33
|
+
/** Steps that set up goreleaser, in the cut and publish jobs, for a member's `release.artifacts` it builds (#5216); on GitLab, script lines. */
|
|
34
|
+
goreleaser?: string[];
|
|
35
|
+
/** GitLab: the publish signs with Sigstore, so a cut that runs the doctor gets `SIGSTORE_ID_TOKEN` to check it. */
|
|
36
|
+
signing?: boolean;
|
|
37
|
+
/** GitLab: entries the members' targets add under the publish job's `id_tokens:` beside `SIGSTORE_ID_TOKEN`, such as `PYPI_ID_TOKEN`. */
|
|
38
|
+
idTokens?: string[];
|
|
39
|
+
/** `chant release doctor` in each member before the cut (#5216): `--doctor` on the dispatched cut. */
|
|
40
|
+
doctor?: boolean;
|
|
41
|
+
/** `verified-releases`: `chant workspace train verify` before the publish (#5216). */
|
|
42
|
+
verify?: boolean;
|
|
25
43
|
}
|
|
26
44
|
/** The tag a train's cut pushes, as a GitHub tag filter: `*` stops at `/`, so a member's own tag starts nothing. */
|
|
27
45
|
export declare function trainTagFilter(env: string): string;
|
|
@@ -31,6 +49,6 @@ export declare function trainTagFilter(env: string): string;
|
|
|
31
49
|
* that was cut and recorded is never left unpublished by a skipped job. A
|
|
32
50
|
* file that is not JSON may still hold the id, and the error names it.
|
|
33
51
|
*/
|
|
34
|
-
export declare function trainIdScript(file: string): string;
|
|
35
|
-
/** GitHub and Forgejo
|
|
52
|
+
export declare function trainIdScript(file: string, forge?: ReleaseWorkflowForge): string;
|
|
53
|
+
/** The train workflow (#5154), for GitHub and Forgejo, or GitLab (#5216). */
|
|
36
54
|
export declare function renderTrainWorkflow(o: TrainWorkflowInput): string;
|
|
@@ -33,8 +33,11 @@
|
|
|
33
33
|
* the whole workflow. A tag the job's own token pushed starts nothing, so a
|
|
34
34
|
* dispatched run publishes in its own publish job.
|
|
35
35
|
*/
|
|
36
|
-
import { tagComments } from "../action-pins.js";
|
|
36
|
+
import { ACTION_PINS, tagComments, usesRef } from "../action-pins.js";
|
|
37
37
|
import { gateScript, githubSetup, jobPermissions, LEDGER_FETCH_FIRST } from "./release-workflow.js";
|
|
38
|
+
import { RELEASE_ARTIFACTS_ARTIFACT } from "./release-steps/artifacts.js";
|
|
39
|
+
/** Where the cut job stages the members' images and files, and the publish job finds them (#5216): outside the checkout. */
|
|
40
|
+
const TRAIN_STAGE = "$RUNNER_TEMP/chant-release-artifacts";
|
|
38
41
|
/** The tag a train's cut pushes, as a GitHub tag filter: `*` stops at `/`, so a member's own tag starts nothing. */
|
|
39
42
|
export function trainTagFilter(env) {
|
|
40
43
|
return `release-train/${env}/*`;
|
|
@@ -45,13 +48,15 @@ export function trainTagFilter(env) {
|
|
|
45
48
|
* that was cut and recorded is never left unpublished by a skipped job. A
|
|
46
49
|
* file that is not JSON may still hold the id, and the error names it.
|
|
47
50
|
*/
|
|
48
|
-
export function trainIdScript(file) {
|
|
51
|
+
export function trainIdScript(file, forge = "github") {
|
|
52
|
+
// How to publish a recorded train: dispatch the workflow with its id, or on GitLab run a pipeline with CHANT_RELEASE_TRAIN.
|
|
53
|
+
const rerun = (id) => (forge === "gitlab" ? `run a pipeline with CHANT_RELEASE_TRAIN=${id}` : `dispatch this workflow with train=${id}`);
|
|
49
54
|
const js = [
|
|
50
55
|
'const t=require("fs").readFileSync(process.argv[1],"utf8");',
|
|
51
56
|
"let d;",
|
|
52
57
|
"try{d=JSON.parse(t)}catch(e){",
|
|
53
58
|
'const m=/"id": *"(train-[^"]+)"/.exec(t);',
|
|
54
|
-
|
|
59
|
+
`console.error("the train cut printed more than its JSON document, so the train id can not be read ("+e.message+")."+(m?" The cut recorded "+m[1]+": ${rerun('"+m[1]+"')} to publish it.":" If it recorded a train, ${rerun("<id>")} to publish it."));`,
|
|
55
60
|
"process.exit(1)}",
|
|
56
61
|
'const id=d.train?.id??"";',
|
|
57
62
|
'if(!id&&d.released==null&&(d.members??[]).length>0){console.error("the train cut "+d.members.length+" member(s), and its JSON names no train id to publish");process.exit(1)}',
|
|
@@ -61,8 +66,10 @@ export function trainIdScript(file) {
|
|
|
61
66
|
}
|
|
62
67
|
/** The ref of a train's tag, as an expression: what the publish job checks out for a dispatched `train`. */
|
|
63
68
|
const dispatchedTrainRef = (env) => `format('refs/tags/release-train/${env}/{0}', inputs.train)`;
|
|
64
|
-
/** GitHub and Forgejo
|
|
69
|
+
/** The train workflow (#5154), for GitHub and Forgejo, or GitLab (#5216). */
|
|
65
70
|
export function renderTrainWorkflow(o) {
|
|
71
|
+
if (o.forge === "gitlab")
|
|
72
|
+
return renderGitlabTrainWorkflow(o);
|
|
66
73
|
const defaults = o.root ? [" defaults:", " run:", ` working-directory: ${o.root}`] : [];
|
|
67
74
|
const run = (l) => ` - run: ${l}`;
|
|
68
75
|
const block = (lines) => [" run: |", ...lines.map((l) => ` ${l}`)];
|
|
@@ -100,22 +107,136 @@ export function renderTrainWorkflow(o) {
|
|
|
100
107
|
"jobs:",
|
|
101
108
|
];
|
|
102
109
|
if (dispatch) {
|
|
103
|
-
lines.push(" gate:", " if: github.event_name == 'workflow_dispatch' && inputs.train == ''", " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "read" }, "gate"), ...defaults, " outputs:", " commit: ${{ steps.green.outputs.commit }}", " steps:", ...githubSetup(undefined, o.chantSetup), ...installLines, ciFetch, " - id: green", ...block([...gateScript(o, "$GITHUB_SHA"), 'echo "commit=$commit" >> "$GITHUB_OUTPUT"']), " cut:", " needs: gate", " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "write" }, "cut"), ...defaults, " outputs:", " train: ${{ steps.cut.outputs.train }}", ...o.extra.githubEnv([" CHANT_RELEASE_COMMIT: ${{ needs.gate.outputs.commit }}", " CHANT_RELEASE_LEVELS: ${{ inputs.levels }}", ...(o.cutToken ?? [])]), " steps:", ...githubSetup("${{ needs.gate.outputs.commit }}", o.fullSetup), ...installLines, ...o.extra.githubSteps, ciFetch, run(LEDGER_FETCH_FIRST), " - id: cut", ...block([
|
|
110
|
+
lines.push(" gate:", " if: github.event_name == 'workflow_dispatch' && inputs.train == ''", " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "read" }, "gate"), ...defaults, " outputs:", " commit: ${{ steps.green.outputs.commit }}", " steps:", ...githubSetup(undefined, o.chantSetup), ...installLines, ciFetch, " - id: green", ...block([...gateScript(o, "$GITHUB_SHA"), 'echo "commit=$commit" >> "$GITHUB_OUTPUT"']), " cut:", " needs: gate", " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "write" }, "cut"), ...defaults, " outputs:", " train: ${{ steps.cut.outputs.train }}", ...o.extra.githubEnv([" CHANT_RELEASE_COMMIT: ${{ needs.gate.outputs.commit }}", " CHANT_RELEASE_LEVELS: ${{ inputs.levels }}", ...new Set([...(o.cutToken ?? []), ...(o.doctor ? o.forgeToken : [])])]), " steps:", ...githubSetup("${{ needs.gate.outputs.commit }}", o.fullSetup), ...installLines, ...o.extra.githubSteps, ...(o.goreleaser ?? []), ciFetch, run(LEDGER_FETCH_FIRST), " - id: cut", ...block([
|
|
104
111
|
'git config user.name "chant release"',
|
|
105
112
|
'git config user.email "chant-release@localhost"',
|
|
106
|
-
`${o.chant} workspace train cut ${env} --at "$CHANT_RELEASE_COMMIT" --levels "\${CHANT_RELEASE_LEVELS:-auto}" --yes --json > "$RUNNER_TEMP/chant-train.json"`,
|
|
113
|
+
`${o.chant} workspace train cut ${env} --at "$CHANT_RELEASE_COMMIT" --levels "\${CHANT_RELEASE_LEVELS:-auto}"${o.doctor ? " --doctor" : ""} --yes --json > "$RUNNER_TEMP/chant-train.json"`,
|
|
107
114
|
`train="$(${trainIdScript("$RUNNER_TEMP/chant-train.json")})" || exit 1`,
|
|
108
115
|
'echo "train=$train" >> "$GITHUB_OUTPUT"',
|
|
109
|
-
])
|
|
116
|
+
]), ...(o.files
|
|
117
|
+
? [
|
|
118
|
+
" - if: steps.cut.outputs.train != ''",
|
|
119
|
+
` run: ${o.chant} workspace train artifacts ${env} "\${{ steps.cut.outputs.train }}" -o "${TRAIN_STAGE}"`,
|
|
120
|
+
" - if: steps.cut.outputs.train != ''",
|
|
121
|
+
` uses: ${usesRef(o.forge === "forgejo" ? ACTION_PINS.uploadArtifact3 : ACTION_PINS.uploadArtifact4)}`,
|
|
122
|
+
" with:",
|
|
123
|
+
` name: ${RELEASE_ARTIFACTS_ARTIFACT}`,
|
|
124
|
+
" path: ${{ runner.temp }}/chant-release-artifacts",
|
|
125
|
+
" if-no-files-found: error",
|
|
126
|
+
" retention-days: 1",
|
|
127
|
+
]
|
|
128
|
+
: []));
|
|
110
129
|
}
|
|
111
130
|
const publishIf = dispatch ? " if: ${{ always() && (github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.train != '') || (needs.cut.result == 'success' && needs.cut.outputs.train != '')) }}" : null;
|
|
112
131
|
// A dispatched `train` names the train itself, and its tag the commit to check out.
|
|
113
132
|
const dispatchedTrain = "${{ inputs.train || needs.cut.outputs.train }}";
|
|
114
133
|
const checkoutRef = `\${{ needs.gate.outputs.commit || (inputs.train != '' && ${dispatchedTrainRef(env)}) || github.sha }}`;
|
|
115
134
|
const trainFromRef = `echo "CHANT_RELEASE_TRAIN=\${CHANT_RELEASE_TRAIN:-\${GITHUB_REF_NAME#release-train/${env}/}}" >> "$GITHUB_ENV"`;
|
|
116
|
-
lines.push(" publish:", ...(dispatch ? [" needs: [gate, cut]", publishIf] : []), " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "write", "id-token": "write" }, "publish"), ...defaults, ...o.extra.githubEnv([...(dispatch ? [` CHANT_RELEASE_TRAIN: ${dispatchedTrain}`] : []), ...o.forgeToken]), " steps:", ...githubSetup(dispatch ? checkoutRef : undefined, o.fullSetup), ...installLines, ...o.extra.githubSteps, ciFetch, ledgerFetch, run(trainFromRef), run(`${o.chant} workspace train prepare ${env} "$CHANT_RELEASE_TRAIN"`), ...(o.build ? [run(o.build)] : []),
|
|
135
|
+
lines.push(" publish:", ...(dispatch ? [" needs: [gate, cut]", publishIf] : []), " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "write", "id-token": "write" }, "publish"), ...defaults, ...o.extra.githubEnv([...(dispatch ? [` CHANT_RELEASE_TRAIN: ${dispatchedTrain}`] : []), ...o.forgeToken]), " steps:", ...githubSetup(dispatch ? checkoutRef : undefined, o.fullSetup), ...installLines, ...o.extra.githubSteps, ...(o.goreleaser ?? []), ciFetch, ledgerFetch, run(trainFromRef), run(`${o.chant} workspace train prepare ${env} "$CHANT_RELEASE_TRAIN"`), ...(o.build ? [run(o.build)] : []), ...(o.files
|
|
136
|
+
? dispatch
|
|
137
|
+
? [
|
|
138
|
+
" - if: needs.cut.outputs.train != ''",
|
|
139
|
+
` uses: ${usesRef(o.forge === "forgejo" ? ACTION_PINS.downloadArtifact3 : ACTION_PINS.downloadArtifact4)}`,
|
|
140
|
+
" with:",
|
|
141
|
+
` name: ${RELEASE_ARTIFACTS_ARTIFACT}`,
|
|
142
|
+
" path: ${{ runner.temp }}/chant-release-artifacts",
|
|
143
|
+
run(`${o.chant} workspace train artifacts ${env} "$CHANT_RELEASE_TRAIN" --from "${TRAIN_STAGE}"`),
|
|
144
|
+
]
|
|
145
|
+
: [run(`${o.chant} workspace train artifacts ${env} "$CHANT_RELEASE_TRAIN"`)]
|
|
146
|
+
: []), ...(o.verify ? [run(`${o.chant} workspace train verify ${env} "$CHANT_RELEASE_TRAIN"`)] : []), run('git config user.name "chant release"'), run('git config user.email "chant-release@localhost"'), run(`${o.chant} workspace train publish ${env} "$CHANT_RELEASE_TRAIN" ${o.flags}`));
|
|
117
147
|
if (o.after.length > 0) {
|
|
118
148
|
lines.push(" after-release:", ` needs: ${dispatch ? "[gate, cut, publish]" : "publish"}`, ...(dispatch ? [" if: ${{ always() && needs.publish.result == 'success' }}"] : []), " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "read" }, "after"), ...defaults, ...(dispatch ? [" env:", ` CHANT_RELEASE_TRAIN: ${dispatchedTrain}`] : []), " steps:", ...githubSetup(dispatch ? checkoutRef : undefined, o.fullSetup), run(trainFromRef), ...installLines, ...o.after.map(run));
|
|
119
149
|
}
|
|
120
150
|
return tagComments(`${lines.join("\n")}\n`);
|
|
121
151
|
}
|
|
152
|
+
/** Where a GitLab cut job stages the members' files: GitLab keeps a job's artifacts only inside the project directory (#5216). */
|
|
153
|
+
const GITLAB_TRAIN_STAGE = "$CI_PROJECT_DIR/.chant-release-artifacts";
|
|
154
|
+
/** Where the GitLab publish job moves them, out of the checkout, before it checks out the train's commit. */
|
|
155
|
+
const GITLAB_TRAIN_FROM = "/tmp/chant-release-artifacts";
|
|
156
|
+
/**
|
|
157
|
+
* GitLab (#5216). With `trigger: "dispatch"` a person runs a pipeline
|
|
158
|
+
* ("Run pipeline", the API or a trigger) with `CHANT_RELEASE_LEVELS` set
|
|
159
|
+
* (`auto`, or the levels): the gate names the commit, the cut job cuts the
|
|
160
|
+
* train and pushes its tags with `CHANT_RELEASE_TOKEN` (a project access
|
|
161
|
+
* token with `write_repository`, since a job token cannot push), and the
|
|
162
|
+
* publish job publishes it. Run with `CHANT_RELEASE_TRAIN` set to a recorded
|
|
163
|
+
* train's id instead, the gate and cut are left out and the publish job
|
|
164
|
+
* publishes that train from its tag, resuming. The dispatched file has no
|
|
165
|
+
* tag rule: the cut's own push would start a second publish of the same
|
|
166
|
+
* train. With `trigger: "tag"` the file is one publish job on a pushed
|
|
167
|
+
* `release-train/<env>/*` tag.
|
|
168
|
+
*
|
|
169
|
+
* Every job's script runs in one shell, so a variable set on one line is
|
|
170
|
+
* there on the next. The publish job checks out the commit the train's tag
|
|
171
|
+
* names in every case.
|
|
172
|
+
*/
|
|
173
|
+
function renderGitlabTrainWorkflow(o) {
|
|
174
|
+
const env = o.env;
|
|
175
|
+
const q = (l) => ` - ${JSON.stringify(l)}`;
|
|
176
|
+
const cd = o.root ? [`cd ${o.root}`] : [];
|
|
177
|
+
const install = o.install ? [o.install] : [];
|
|
178
|
+
const ciFetch = "git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'";
|
|
179
|
+
const ledgerFetch = "git fetch origin chant/lifecycle:chant/lifecycle";
|
|
180
|
+
const auth = [
|
|
181
|
+
`chant_auth="$(printf 'oauth2:%s' "$CHANT_RELEASE_TOKEN" | base64 | tr -d '\\n')"`,
|
|
182
|
+
'export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.extraheader GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $chant_auth"',
|
|
183
|
+
"unset chant_auth",
|
|
184
|
+
];
|
|
185
|
+
const dispatch = o.trigger === "dispatch";
|
|
186
|
+
const manual = "$CI_PIPELINE_SOURCE =~ /^(web|api|trigger)$/";
|
|
187
|
+
const tagRule = `$CI_COMMIT_TAG =~ /^release-train\\/${env.replace(/[.*+?^${}()|[\]\\/]/g, (c) => `\\${c}`)}\\//`;
|
|
188
|
+
const cutRule = `$CHANT_RELEASE_LEVELS && ($CHANT_RELEASE_TRAIN == null || $CHANT_RELEASE_TRAIN == "") && ${manual}`;
|
|
189
|
+
const variables = (vars) => [" variables:", ' GIT_DEPTH: "0"', ...vars];
|
|
190
|
+
// The train: the one the pipeline names, else the one this pipeline's cut recorded, else the tag's. Then its commit, from its tag.
|
|
191
|
+
const trainLines = [
|
|
192
|
+
`export CHANT_RELEASE_TRAIN="\${CHANT_RELEASE_TRAIN:-\${CHANT_TRAIN_CUT:-\${CI_COMMIT_TAG#release-train/${env}/}}}"`,
|
|
193
|
+
'if [ -z "$CHANT_RELEASE_TRAIN" ]; then echo "no release train was cut or named, so there is nothing to publish"; exit 0; fi',
|
|
194
|
+
`git fetch origin "refs/tags/release-train/${env}/$CHANT_RELEASE_TRAIN"`,
|
|
195
|
+
"git checkout --detach FETCH_HEAD",
|
|
196
|
+
];
|
|
197
|
+
const lines = [];
|
|
198
|
+
if (dispatch) {
|
|
199
|
+
lines.push("chant-release-gate:", " rules:", ` - if: ${cutRule}`, ...variables([]), " artifacts:", " reports:", " dotenv: chant-release-gate.env", " script:", ...[...cd, ...install, ciFetch, ...gateScript(o, "$CI_COMMIT_SHA"), 'printf \'CHANT_RELEASE_COMMIT=%s\\n\' "$commit" > "$CI_PROJECT_DIR/chant-release-gate.env"'].map(q), "", "chant-release-cut:", " rules:", ` - if: ${cutRule}`, ...variables(o.extra.gitlabVariables), " needs: [chant-release-gate]", " artifacts:", ...(o.files ? [" paths:", ' - ".chant-release-artifacts/"', " expire_in: 1 day"] : []), " reports:", " dotenv: chant-release-train.env", ...(o.doctor && o.signing ? [" id_tokens:", " SIGSTORE_ID_TOKEN:", " aud: sigstore"] : []), " script:", ...[
|
|
200
|
+
'git checkout --detach "$CHANT_RELEASE_COMMIT"',
|
|
201
|
+
...cd,
|
|
202
|
+
...install,
|
|
203
|
+
...o.extra.gitlabScript,
|
|
204
|
+
...(o.goreleaser ?? []),
|
|
205
|
+
ciFetch,
|
|
206
|
+
...auth,
|
|
207
|
+
LEDGER_FETCH_FIRST,
|
|
208
|
+
'git config user.name "chant release"',
|
|
209
|
+
'git config user.email "chant-release@localhost"',
|
|
210
|
+
`${o.chant} workspace train cut ${env} --at "$CHANT_RELEASE_COMMIT" --levels "\${CHANT_RELEASE_LEVELS:-auto}"${o.doctor ? " --doctor" : ""} --yes --json > /tmp/chant-train.json`,
|
|
211
|
+
`train="$(${trainIdScript("/tmp/chant-train.json", "gitlab")})" || exit 1`,
|
|
212
|
+
'printf \'CHANT_TRAIN_CUT=%s\\n\' "$train" > "$CI_PROJECT_DIR/chant-release-train.env"',
|
|
213
|
+
...(o.files ? [`if [ -n "$train" ]; then ${o.chant} workspace train artifacts ${env} "$train" -o "${GITLAB_TRAIN_STAGE}"; fi`] : []),
|
|
214
|
+
].map(q), "");
|
|
215
|
+
}
|
|
216
|
+
const publishScript = (handed) => [
|
|
217
|
+
// The cut's staged files leave the checkout before it moves to the train's commit.
|
|
218
|
+
...(handed && o.files ? [`if [ -d "${GITLAB_TRAIN_STAGE}" ]; then mv "${GITLAB_TRAIN_STAGE}" ${GITLAB_TRAIN_FROM}; fi`] : []),
|
|
219
|
+
...trainLines,
|
|
220
|
+
...cd,
|
|
221
|
+
...install,
|
|
222
|
+
...o.extra.gitlabScript,
|
|
223
|
+
...(o.goreleaser ?? []),
|
|
224
|
+
ciFetch,
|
|
225
|
+
ledgerFetch,
|
|
226
|
+
...(dispatch ? auth : []),
|
|
227
|
+
`${o.chant} workspace train prepare ${env} "$CHANT_RELEASE_TRAIN"`,
|
|
228
|
+
...(o.build ? [o.build] : []),
|
|
229
|
+
...(o.files ? [`${o.chant} workspace train artifacts ${env} "$CHANT_RELEASE_TRAIN"${handed ? ` --from ${GITLAB_TRAIN_FROM}` : ""}`] : []),
|
|
230
|
+
...(o.verify ? [`${o.chant} workspace train verify ${env} "$CHANT_RELEASE_TRAIN"`] : []),
|
|
231
|
+
'git config user.name "chant release"',
|
|
232
|
+
'git config user.email "chant-release@localhost"',
|
|
233
|
+
`${o.chant} workspace train publish ${env} "$CHANT_RELEASE_TRAIN" ${o.flags}`,
|
|
234
|
+
];
|
|
235
|
+
const publishRules = dispatch ? [` - if: $CHANT_RELEASE_TRAIN && ${manual}`, ` - if: ${cutRule}`] : [` - if: ${tagRule}`];
|
|
236
|
+
const publishNeeds = dispatch ? [" needs:", " - job: chant-release-cut", " optional: true"] : [];
|
|
237
|
+
lines.push("chant-release-publish:", " rules:", ...publishRules, ...variables(o.extra.gitlabVariables), ...publishNeeds, " resource_group: chant-release", " id_tokens:", " SIGSTORE_ID_TOKEN:", " aud: sigstore", ...(o.idTokens ?? []), " script:", ...publishScript(dispatch).map(q));
|
|
238
|
+
if (o.after.length > 0) {
|
|
239
|
+
lines.push("", "chant-release-after:", " rules:", ...publishRules, ...variables([]), ...(dispatch ? [" needs:", " - job: chant-release-cut", " optional: true", " - job: chant-release-publish"] : [" needs: [chant-release-publish]"]), " script:", ...[...trainLines, ...cd, ...install].map(q), ...o.after.map((l) => ` - ${l}`));
|
|
240
|
+
}
|
|
241
|
+
return `${lines.join("\n")}\n`;
|
|
242
|
+
}
|
|
@@ -494,7 +494,7 @@ async function promoteAcrossRepos(query, train, now) {
|
|
|
494
494
|
}
|
|
495
495
|
return { kind: "ran", train, record, pending: null, approved: null, ledgerError };
|
|
496
496
|
}
|
|
497
|
-
const USAGE = "chant workspace train <env> [--pin <member>=<label|digest>]... [--dry-run] [--json] | chant workspace train list <env> [--json] | chant workspace train promote <env> [<train id|digest>] [--gate <name>] [--continue] [--dry-run] [--json] | chant workspace train cut <env> [--at <sha>] [--levels <levels>] [--yes] [--no-push] [--json] | chant workspace train prepare <env> [<train id|digest>] [--json] | chant workspace train publish <env> [<train id|digest>] [--yes] [--json]";
|
|
497
|
+
const USAGE = "chant workspace train <env> [--pin <member>=<label|digest>]... [--dry-run] [--json] | chant workspace train list <env> [--json] | chant workspace train promote <env> [<train id|digest>] [--gate <name>] [--continue] [--dry-run] [--json] | chant workspace train cut <env> [--at <sha>] [--levels <levels>] [--doctor] [--yes] [--no-push] [--json] | chant workspace train prepare <env> [<train id|digest>] [--json] | chant workspace train artifacts <env> [<train id|digest>] [--from <dir>] [-o <dir>] [--no-build] [--json] | chant workspace train verify <env> [<train id|digest>] [--json] | chant workspace train publish <env> [<train id|digest>] [--yes] [--json]";
|
|
498
498
|
/** Each train with the runs that promoted it, oldest first. */
|
|
499
499
|
export function trainsWithPromotions(trains, runs) {
|
|
500
500
|
const latest = latestRuns(runs);
|
|
@@ -525,6 +525,10 @@ export async function runWorkspaceTrain(ctx) {
|
|
|
525
525
|
const { runTrainPrepare } = await import("./train-prepare.js");
|
|
526
526
|
return runTrainPrepare(ctx, rest.slice(1));
|
|
527
527
|
}
|
|
528
|
+
if (rest[0] === "artifacts" || rest[0] === "verify") {
|
|
529
|
+
const m = await import("./train-artifacts.js");
|
|
530
|
+
return rest[0] === "artifacts" ? m.runTrainArtifacts(ctx, rest.slice(1)) : m.runTrainVerify(ctx, rest.slice(1));
|
|
531
|
+
}
|
|
528
532
|
if (rest[0] === "publish") {
|
|
529
533
|
const { runTrainPublish } = await import("./train-publish.js");
|
|
530
534
|
return runTrainPublish(ctx, rest.slice(1));
|
|
@@ -171,6 +171,17 @@ export interface ReleaseWorkflowInput {
|
|
|
171
171
|
*/
|
|
172
172
|
train?: {
|
|
173
173
|
env: string;
|
|
174
|
+
/**
|
|
175
|
+
* What the members declare (#5216): `release.images` (with the platforms
|
|
176
|
+
* they build, for QEMU), `release.artifacts`, and an artifact goreleaser
|
|
177
|
+
* builds. The jobs hand them from the cut to the publish.
|
|
178
|
+
*/
|
|
179
|
+
imagePlatforms?: string[];
|
|
180
|
+
images?: boolean;
|
|
181
|
+
artifacts?: boolean;
|
|
182
|
+
goreleaser?: boolean;
|
|
183
|
+
/** The directory, from the workspace root, of the member whose goreleaser build Go is set up for: its `go.mod` names the Go. */
|
|
184
|
+
goreleaserDir?: string;
|
|
174
185
|
};
|
|
175
186
|
}
|
|
176
187
|
/** What the generator reads of a `release.publish` target: enough to know which credentials and tools its job needs. */
|
|
@@ -54,6 +54,7 @@ import { releaseJobSteps, releaseSetupSteps } from "./release-steps/index.js";
|
|
|
54
54
|
import { packLine } from "./release-steps/builds.js";
|
|
55
55
|
import { RELEASE_BINFMT_IMAGE, qemuArchitectures } from "./release-steps/qemu.js";
|
|
56
56
|
import { targetExtras } from "./release-steps/targets.js";
|
|
57
|
+
import { goreleaserSetup } from "./release-steps/goreleaser.js";
|
|
57
58
|
import { renderTrainWorkflow } from "./release-train-workflow.js";
|
|
58
59
|
export const RELEASE_WORKFLOW_FORGES = ["github", "forgejo", "gitlab"];
|
|
59
60
|
/** Where each forge's publish workflow is written, relative to the repository root. */
|
|
@@ -143,12 +144,12 @@ export function renderReleaseWorkflow(input) {
|
|
|
143
144
|
: [];
|
|
144
145
|
// #5154: the root's members released as a train.
|
|
145
146
|
if (input.train) {
|
|
146
|
-
if (input.forge === "gitlab")
|
|
147
|
-
throw new Error("release.train: the train workflow renders for GitHub and Forgejo; on GitLab, run chant workspace train cut, prepare and publish from your own jobs");
|
|
148
147
|
if (builds.length > 0)
|
|
149
148
|
throw new Error("release.workflow.builds: a train cuts each member in one job, and per-platform builds are not handed to it; leave builds out of a train's workflow");
|
|
150
149
|
if (images || input.artifacts)
|
|
151
|
-
throw new Error("release.images and release.artifacts at the root: a train releases its members,
|
|
150
|
+
throw new Error("release.images and release.artifacts at the root: a train releases its members, not the root; declare them in the member that publishes them");
|
|
151
|
+
const t = input.train;
|
|
152
|
+
const trainContext = { forge: input.forge, shape: "dispatch", input: { ...input, imagePlatforms: t.imagePlatforms ?? [] }, pipeline: p, chant, root, verify: false, images: t.images === true, archives: [], artifacts: false, version: false, doctor: false, signing: input.signing === true, green, builds: [] };
|
|
152
153
|
return renderTrainWorkflow({
|
|
153
154
|
forge: input.forge,
|
|
154
155
|
env: input.train.env,
|
|
@@ -161,12 +162,19 @@ export function renderReleaseWorkflow(input) {
|
|
|
161
162
|
after,
|
|
162
163
|
chantSetup,
|
|
163
164
|
fullSetup,
|
|
164
|
-
extra: jobExtras({ ...p, ...(derived.permissions ? { permissions: { ...p.permissions, ...derived.permissions } } : {}), ...(derived.env ? { env: { ...p.env, ...derived.env } } : {}), setup: releaseSetupSteps(
|
|
165
|
+
extra: jobExtras({ ...p, ...(derived.permissions ? { permissions: { ...p.permissions, ...derived.permissions } } : {}), ...(derived.env ? { env: { ...p.env, ...derived.env } } : {}), setup: releaseSetupSteps(trainContext) }, input.forge),
|
|
165
166
|
forgeToken,
|
|
166
167
|
cutToken: green === "forge-checks" && p.env?.GITHUB_TOKEN === undefined ? [" GITHUB_TOKEN: ${{ github.token }}"] : [],
|
|
167
168
|
green,
|
|
168
169
|
gate: p.gate ?? "last-green",
|
|
169
170
|
...(input.lane ? { lane: input.lane } : {}),
|
|
171
|
+
// #5216: the members' images and files, from the cut to the publish; the doctor before the cut; verify before the publish.
|
|
172
|
+
files: t.images === true || t.artifacts === true,
|
|
173
|
+
...(t.artifacts && t.goreleaser ? { goreleaser: ((g) => (input.forge === "gitlab" ? g.gitlab : g.github))(goreleaserSetup(input.forge, [root, t.goreleaserDir].filter((d) => !!d && d !== ".").join("/") || null, p)) } : {}),
|
|
174
|
+
...(input.signing ? { signing: true } : {}),
|
|
175
|
+
...(input.forge === "gitlab" ? { idTokens: stepLines(releaseJobSteps({ ...trainContext, job: "publish", label: '"$CHANT_RELEASE_TRAIN"' })("idTokens"), (l) => l) } : {}),
|
|
176
|
+
doctor: p.trigger === "dispatch" && p.doctor !== false,
|
|
177
|
+
verify: input.groups.has("verified-releases"),
|
|
170
178
|
});
|
|
171
179
|
}
|
|
172
180
|
if (shape === "dispatch") {
|
|
@@ -800,6 +808,7 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
800
808
|
}
|
|
801
809
|
// #5154: a train publishes its members' targets, so their credentials, tools and signing are the workflow's.
|
|
802
810
|
const memberReleases = [];
|
|
811
|
+
let goreleaserDir;
|
|
803
812
|
if (release?.train) {
|
|
804
813
|
const { locateWorkspace } = await import("./which-chant.js");
|
|
805
814
|
const { readDeclaration } = await import("./declaration.js");
|
|
@@ -810,18 +819,32 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
810
819
|
const r = (await loadChantConfig(join(root, m.dir))).config.release;
|
|
811
820
|
if (r)
|
|
812
821
|
memberReleases.push(r);
|
|
822
|
+
if (r?.artifacts && goreleaserDir === undefined && (await import("../lifecycle/release-artifacts.js")).usesGoreleaser(r.artifacts))
|
|
823
|
+
goreleaserDir = m.dir.split(sep).join("/");
|
|
813
824
|
}
|
|
814
825
|
catch (err) {
|
|
815
826
|
console.error(formatError({ message: `member ${m.name}'s chant.config.ts could not be read: ${err instanceof Error ? err.message : String(err)}`, hint: usage }));
|
|
816
827
|
return 1;
|
|
817
828
|
}
|
|
818
829
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
830
|
+
// #5216: a member's files are built by its cut, in the train's cut job; a train has no per-platform build jobs for builtBy to name.
|
|
831
|
+
const { checkReleaseArtifacts, ReleaseArtifactError } = await import("../lifecycle/release-artifacts.js");
|
|
832
|
+
for (const r of memberReleases) {
|
|
833
|
+
if ((r.artifacts?.length ?? 0) === 0)
|
|
834
|
+
continue;
|
|
835
|
+
try {
|
|
836
|
+
checkReleaseArtifacts(r.artifacts, { builds: [] });
|
|
837
|
+
}
|
|
838
|
+
catch (err) {
|
|
839
|
+
if (!(err instanceof ReleaseArtifactError))
|
|
840
|
+
throw err;
|
|
841
|
+
console.error(formatError({ message: `release.train: a member's ${err.message} [${err.code}]`, hint: "A train's members build their files in the train's cut job: build them there rather than in release.workflow.builds." }));
|
|
842
|
+
return 1;
|
|
843
|
+
}
|
|
823
844
|
}
|
|
824
845
|
}
|
|
846
|
+
const memberImages = memberReleases.flatMap((r) => r.images ?? []);
|
|
847
|
+
const memberArtifacts = memberReleases.flatMap((r) => r.artifacts ?? []);
|
|
825
848
|
const allTargets = [...(release?.publish ?? []), ...memberReleases.flatMap((r) => r.publish ?? [])];
|
|
826
849
|
const { resolveSigning } = await import("../lifecycle/publish-signing.js");
|
|
827
850
|
const signs = [release, ...memberReleases].some((r) => resolveSigning(r?.signing, groups).on && (r?.publish ?? []).some((t) => t.type === "oci" || t.type === "forge" || t.type === "pypi"));
|
|
@@ -873,7 +896,15 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
873
896
|
...(release?.version ? { version: true } : {}),
|
|
874
897
|
...(signs ? { signing: true } : {}),
|
|
875
898
|
...(allTargets.length > 0 ? { publish: allTargets } : {}),
|
|
876
|
-
...(release?.train
|
|
899
|
+
...(release?.train
|
|
900
|
+
? {
|
|
901
|
+
train: {
|
|
902
|
+
env: release.train.env,
|
|
903
|
+
...(memberImages.length > 0 ? { images: true, imagePlatforms: releaseImagePlatforms(memberImages) } : {}),
|
|
904
|
+
...(memberArtifacts.length > 0 ? { artifacts: true, ...((await import("../lifecycle/release-artifacts.js")).usesGoreleaser(memberArtifacts) ? { goreleaser: true, ...(goreleaserDir ? { goreleaserDir } : {}) } : {}) } : {}),
|
|
905
|
+
},
|
|
906
|
+
}
|
|
907
|
+
: {}),
|
|
877
908
|
...(args.ciInstall ? { install: args.ciInstall } : {}),
|
|
878
909
|
...(args.buildCommand ? { build: args.buildCommand } : !hasBuildScript(root) && release?.workflow?.build === undefined ? { build: null } : {}),
|
|
879
910
|
...(args.ciChant ? { chant: args.ciChant } : {}),
|
|
@@ -931,5 +962,7 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
931
962
|
console.log("The job that builds release.artifacts runs goreleaser with the Go of the job's image: give it an image with the Go your go.mod names.");
|
|
932
963
|
if (forge === "gitlab" && release?.workflow?.trigger === "dispatch")
|
|
933
964
|
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.");
|
|
965
|
+
if (forge === "gitlab" && release?.train && release.workflow?.trigger === "dispatch")
|
|
966
|
+
console.log(`Start a train by running a pipeline with CHANT_RELEASE_LEVELS=auto (or the levels), and publish a recorded one with CHANT_RELEASE_TRAIN=<id>. A release-train/${release.train.env}/* tag pushed from a workstation starts nothing in this file: publish it with CHANT_RELEASE_TRAIN.`);
|
|
934
967
|
return 0;
|
|
935
968
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files a release train's members build at the cut, carried from the job
|
|
3
|
+
* that cut them to the job that publishes them (#5216), and the signature
|
|
4
|
+
* check of each member before the publish.
|
|
5
|
+
*
|
|
6
|
+
* `chant workspace train artifacts <env> [<train>] [--from <dir>] [-o <dir>]
|
|
7
|
+
* [--no-build] [--json]`, in a checkout of the train's commit: for each member
|
|
8
|
+
* the train cut from this commit that declares `release.images` or
|
|
9
|
+
* `release.artifacts`, the image archives and files the release records are
|
|
10
|
+
* checked against their recorded digests, as `chant release images` and
|
|
11
|
+
* `chant release artifacts` check one member's:
|
|
12
|
+
*
|
|
13
|
+
* - `--from <dir>` first copies each member's files from `<dir>/<member
|
|
14
|
+
* directory>/`, where an earlier job staged them;
|
|
15
|
+
* - a member whose files are all here is checked as they are; a member with
|
|
16
|
+
* one missing builds its images, or its files, again (`--no-build` refuses
|
|
17
|
+
* instead), and what it builds must have the recorded digests;
|
|
18
|
+
* - `-o <dir>` stages every member's checked files at `<dir>/<member
|
|
19
|
+
* directory>/<path>`, with `chant-train-artifacts.json` naming the members,
|
|
20
|
+
* for the next job's `--from`.
|
|
21
|
+
*
|
|
22
|
+
* `chant workspace train verify <env> [<train>] [--json]` runs `chant release
|
|
23
|
+
* verify` for each member the train cut from this commit, so a cut whose
|
|
24
|
+
* signature does not verify stops the publish (the `verified-releases`
|
|
25
|
+
* group).
|
|
26
|
+
*/
|
|
27
|
+
import { type ReadTrain } from "./release-train.js";
|
|
28
|
+
/** The first chant with `chant workspace train artifacts`, `train verify` and `train cut --doctor`, and a train publish that gives a member with images its digests in `CHANT_RELEASE_DIGESTS` (#5216): what the train workflow's cut and publish jobs run. */
|
|
29
|
+
export declare const TRAIN_ARTIFACTS_FLOOR = "0.124.103";
|
|
30
|
+
/** The file `-o` writes beside the staged files, naming the members staged. */
|
|
31
|
+
export declare const TRAIN_ARTIFACTS_INDEX = "chant-train-artifacts.json";
|
|
32
|
+
/** A member the train cut from this checkout's commit. */
|
|
33
|
+
export interface TrainMemberHere {
|
|
34
|
+
member: string;
|
|
35
|
+
/** The member's directory on disk. */
|
|
36
|
+
dir: string;
|
|
37
|
+
/** The member's directory from the workspace root, with `/`. */
|
|
38
|
+
rel: string;
|
|
39
|
+
/** The label, or the release digest for a release with none: what `chant release <command>` takes. */
|
|
40
|
+
ref: string;
|
|
41
|
+
releaseDigest: string;
|
|
42
|
+
}
|
|
43
|
+
/** The train, and its members cut from the commit checked out at the workspace root. */
|
|
44
|
+
export declare function trainMembersHere(cwd: string, env: string, ref?: string): Promise<{
|
|
45
|
+
root: string;
|
|
46
|
+
train: ReadTrain;
|
|
47
|
+
members: TrainMemberHere[];
|
|
48
|
+
}>;
|
|
49
|
+
/** Runs this chant with `args` in `cwd` and returns its exit code; its stdout goes to this process's stderr. */
|
|
50
|
+
export type MemberChant = (args: string[], cwd: string) => number;
|
|
51
|
+
/** The default {@link MemberChant}: this chant, its stdout on stderr so a `--json` caller's stdout stays one document. */
|
|
52
|
+
export declare const spawnMemberChant: MemberChant;
|
|
53
|
+
export interface TrainArtifactsQuery {
|
|
54
|
+
cwd: string;
|
|
55
|
+
env: string;
|
|
56
|
+
train?: string;
|
|
57
|
+
/** Copy each member's files from `<from>/<member directory>/` first. */
|
|
58
|
+
from?: string;
|
|
59
|
+
/** Stage each member's checked files at `<output>/<member directory>/`. */
|
|
60
|
+
output?: string;
|
|
61
|
+
/** Refuse a member with a file missing rather than build it again. */
|
|
62
|
+
noBuild?: boolean;
|
|
63
|
+
chant?: MemberChant;
|
|
64
|
+
say?: (line: string) => void;
|
|
65
|
+
}
|
|
66
|
+
/** One member's files, as checked. */
|
|
67
|
+
export interface TrainArtifactsMember {
|
|
68
|
+
member: string;
|
|
69
|
+
ref: string;
|
|
70
|
+
/** The image archives the release records, from the member's directory. */
|
|
71
|
+
images: string[];
|
|
72
|
+
/** The `release.artifacts` files the release records, from the member's directory. */
|
|
73
|
+
files: string[];
|
|
74
|
+
/** Whether the images, and the files, were built again here rather than checked as they were. */
|
|
75
|
+
built: {
|
|
76
|
+
images: boolean;
|
|
77
|
+
files: boolean;
|
|
78
|
+
};
|
|
79
|
+
/** How many of the paths `--from` copied. */
|
|
80
|
+
copied: number;
|
|
81
|
+
}
|
|
82
|
+
export interface TrainArtifactsOutcome {
|
|
83
|
+
train: ReadTrain;
|
|
84
|
+
members: TrainArtifactsMember[];
|
|
85
|
+
staged: string | null;
|
|
86
|
+
}
|
|
87
|
+
/** Check, build again where missing, and stage the images and files of every member the train cut here (#5216). */
|
|
88
|
+
export declare function trainArtifacts(q: TrainArtifactsQuery): Promise<TrainArtifactsOutcome>;
|
|
89
|
+
/** Run `chant release verify` for each member the train cut here (#5216); every failure is reported before the exit. */
|
|
90
|
+
export declare function trainVerify(q: {
|
|
91
|
+
cwd: string;
|
|
92
|
+
env: string;
|
|
93
|
+
train?: string;
|
|
94
|
+
chant?: MemberChant;
|
|
95
|
+
say?: (line: string) => void;
|
|
96
|
+
}): Promise<{
|
|
97
|
+
train: ReadTrain;
|
|
98
|
+
members: Array<{
|
|
99
|
+
member: string;
|
|
100
|
+
ref: string;
|
|
101
|
+
ok: boolean;
|
|
102
|
+
}>;
|
|
103
|
+
}>;
|
|
104
|
+
/** `chant workspace train artifacts <env> [<train>]` (#5216). */
|
|
105
|
+
export declare function runTrainArtifacts(ctx: import("../cli/registry.js").CommandContext, words: string[]): Promise<number>;
|
|
106
|
+
/** `chant workspace train verify <env> [<train>]` (#5216). */
|
|
107
|
+
export declare function runTrainVerify(ctx: import("../cli/registry.js").CommandContext, words: string[]): Promise<number>;
|