@intentius/chant 0.124.102 → 0.124.104
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/audit/secrets.d.ts +6 -0
- package/dist/audit/secrets.js +9 -2
- package/dist/cli/commands/import-index.d.ts +15 -0
- package/dist/cli/commands/import-index.js +37 -3
- package/dist/cli/commands/onboard.js +8 -8
- package/dist/cli/handlers/lifecycle.js +6 -0
- package/dist/cli/handlers/release-config.d.ts +15 -0
- package/dist/cli/handlers/release-config.js +58 -0
- package/dist/cli/handlers/release-init.js +3 -1
- package/dist/cli/handlers/release.js +36 -3
- package/dist/cli/main.js +24 -3
- package/dist/cli/parse-args.js +12 -0
- package/dist/cli/registry.d.ts +4 -0
- package/dist/cli/release-commands/cut.js +3 -0
- package/dist/cloud-lister/kubernetes-components.js +1 -2
- package/dist/config-import.js +26 -4
- package/dist/config.d.ts +14 -0
- package/dist/config.js +4 -0
- package/dist/floor-table.data.js +13 -11
- package/dist/floor-table.js +3 -1
- package/dist/graph-refs.d.ts +9 -0
- package/dist/graph-refs.js +9 -7
- package/dist/lifecycle/cloud-index.d.ts +6 -0
- package/dist/lifecycle/cloud-index.js +32 -5
- package/dist/lifecycle/identity-match.d.ts +18 -2
- package/dist/lifecycle/identity-match.js +10 -5
- package/dist/lifecycle/index-drift.d.ts +13 -0
- package/dist/lifecycle/index-drift.js +21 -3
- package/dist/lifecycle/index-import.d.ts +15 -0
- package/dist/lifecycle/index-import.js +25 -2
- package/dist/lifecycle/index-join.d.ts +1 -1
- package/dist/lifecycle/index-join.js +1 -1
- package/dist/lifecycle/publish-declaration.d.ts +6 -0
- package/dist/lifecycle/publish-declaration.js +19 -3
- package/dist/lifecycle/publish-forge.d.ts +2 -0
- package/dist/lifecycle/publish-forge.js +3 -1
- 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-oci.d.ts +27 -0
- package/dist/lifecycle/publish-oci.js +63 -8
- package/dist/lifecycle/publish-rubygems.js +1 -2
- package/dist/lifecycle/release-artifacts.js +1 -2
- package/dist/lifecycle/release-changelog.d.ts +18 -5
- package/dist/lifecycle/release-changelog.js +22 -10
- package/dist/lifecycle/release-cut.d.ts +13 -1
- package/dist/lifecycle/release-cut.js +3 -0
- package/dist/lifecycle/release-images.d.ts +32 -2
- package/dist/lifecycle/release-images.js +70 -2
- package/dist/lifecycle/release-init-goreleaser-images.d.ts +21 -0
- package/dist/lifecycle/release-init-goreleaser-images.js +160 -0
- package/dist/lifecycle/release-init.d.ts +22 -0
- package/dist/lifecycle/release-init.js +96 -16
- package/dist/local-chant.d.ts +3 -0
- package/dist/local-chant.js +28 -2
- package/dist/release-floors.d.ts +10 -6
- package/dist/release-floors.js +10 -6
- package/dist/ts-loader.d.ts +12 -3
- package/dist/ts-loader.js +27 -11
- package/dist/wave-runtime.mjs +291 -290
- package/dist/workspace/catalog-edges.d.ts +22 -0
- package/dist/workspace/catalog-edges.js +23 -0
- package/dist/workspace/release-steps/goreleaser.d.ts +6 -3
- package/dist/workspace/release-steps/goreleaser.js +12 -6
- package/dist/workspace/release-toolchains.d.ts +6 -0
- package/dist/workspace/release-toolchains.js +8 -0
- package/dist/workspace/release-train-workflow.d.ts +39 -3
- package/dist/workspace/release-train-workflow.js +258 -9
- package/dist/workspace/release-train.js +5 -1
- package/dist/workspace/release-workflow.d.ts +37 -0
- package/dist/workspace/release-workflow.js +97 -16
- package/dist/workspace/train-artifacts.d.ts +107 -0
- package/dist/workspace/train-artifacts.js +238 -0
- package/dist/workspace/train-cut.d.ts +34 -1
- package/dist/workspace/train-cut.js +98 -14
- package/dist/workspace/train-publish.d.ts +9 -0
- package/dist/workspace/train-publish.js +27 -1
- package/package.json +2 -2
|
@@ -33,6 +33,21 @@
|
|
|
33
33
|
* where it will be applied, and the objects one member applies together go to
|
|
34
34
|
* one namespace far more often than not.
|
|
35
35
|
*
|
|
36
|
+
* ## A cloud index beside the workspace (#5245)
|
|
37
|
+
*
|
|
38
|
+
* A caller that reads a cluster and a cloud index together (behold's joined
|
|
39
|
+
* read) hands the index's nodes to {@link runCatalogPass} as one more member,
|
|
40
|
+
* through {@link indexedMemberNodes}: the member is the index document's
|
|
41
|
+
* scope key. The cloud kinds are scoped by no catalog, so they sit in the
|
|
42
|
+
* workspace scope with no namespace, which every namespaced holder reaches
|
|
43
|
+
* (`scopeOf` below, and the account-only key `reconstructIndexedEdges`
|
|
44
|
+
* looks a holder's value up under). The index's own account and region are
|
|
45
|
+
* not part of that scope, so a rule that joins a cluster object to an
|
|
46
|
+
* indexed node checks them itself: the IRSA rule keeps a role of the
|
|
47
|
+
* annotation's account, the ExternalSecret rule a secret of the store's
|
|
48
|
+
* region. `deriveEdgesAcross` (../lifecycle/derive-edges.ts) does not join
|
|
49
|
+
* the two: it reads one cloud account, and refuses a cluster source.
|
|
50
|
+
*
|
|
36
51
|
* ## Declared nodes the rules are not written against
|
|
37
52
|
*
|
|
38
53
|
* A catalog's `declaredNode` gives the node the rules read, for a lexicon
|
|
@@ -80,6 +95,7 @@
|
|
|
80
95
|
import { type ContainmentPair, type RepoPathRef, type NamedCatalog } from "../graph-refs.js";
|
|
81
96
|
import { type DetailLevel } from "../graph-detail.js";
|
|
82
97
|
import type { CatalogRuleEntry, ComposedAmbiguous, ComposedDangling, ComposedEdge, ComposedNode, NodeExpansion, WorkspaceGraph } from "./compose-graph.js";
|
|
98
|
+
import type { IndexDocument } from "../lifecycle/index-document.js";
|
|
83
99
|
/** The scope every node of a declared workspace graph sits in. */
|
|
84
100
|
export declare const WORKSPACE_SCOPE = "workspace";
|
|
85
101
|
/** What the catalog pass found, on the ids of the nodes it read. */
|
|
@@ -116,6 +132,12 @@ export declare function catalogRules(catalogs: readonly NamedCatalog[]): Record<
|
|
|
116
132
|
* it no such file is read.
|
|
117
133
|
*/
|
|
118
134
|
export declare function runCatalogPass(nodes: readonly ComposedNode[], catalogs: readonly NamedCatalog[], members?: readonly string[], lookPath?: LookPath, readFile?: ReadFile): CatalogPass;
|
|
135
|
+
/**
|
|
136
|
+
* An index document's nodes as members of a catalog pass (#5245): each in the
|
|
137
|
+
* member the document's scope key names, so they sit beside a cluster's
|
|
138
|
+
* objects or a workspace's members in one {@link runCatalogPass}.
|
|
139
|
+
*/
|
|
140
|
+
export declare function indexedMemberNodes(doc: IndexDocument): ComposedNode[];
|
|
119
141
|
/**
|
|
120
142
|
* Write a pass into the document. `placed` maps an id the pass read to the
|
|
121
143
|
* id of the node the document draws it as at its detail tier; an id it does
|
|
@@ -33,6 +33,21 @@
|
|
|
33
33
|
* where it will be applied, and the objects one member applies together go to
|
|
34
34
|
* one namespace far more often than not.
|
|
35
35
|
*
|
|
36
|
+
* ## A cloud index beside the workspace (#5245)
|
|
37
|
+
*
|
|
38
|
+
* A caller that reads a cluster and a cloud index together (behold's joined
|
|
39
|
+
* read) hands the index's nodes to {@link runCatalogPass} as one more member,
|
|
40
|
+
* through {@link indexedMemberNodes}: the member is the index document's
|
|
41
|
+
* scope key. The cloud kinds are scoped by no catalog, so they sit in the
|
|
42
|
+
* workspace scope with no namespace, which every namespaced holder reaches
|
|
43
|
+
* (`scopeOf` below, and the account-only key `reconstructIndexedEdges`
|
|
44
|
+
* looks a holder's value up under). The index's own account and region are
|
|
45
|
+
* not part of that scope, so a rule that joins a cluster object to an
|
|
46
|
+
* indexed node checks them itself: the IRSA rule keeps a role of the
|
|
47
|
+
* annotation's account, the ExternalSecret rule a secret of the store's
|
|
48
|
+
* region. `deriveEdgesAcross` (../lifecycle/derive-edges.ts) does not join
|
|
49
|
+
* the two: it reads one cloud account, and refuses a cluster source.
|
|
50
|
+
*
|
|
36
51
|
* ## Declared nodes the rules are not written against
|
|
37
52
|
*
|
|
38
53
|
* A catalog's `declaredNode` gives the node the rules read, for a lexicon
|
|
@@ -274,6 +289,14 @@ export function runCatalogPass(nodes, catalogs, members, lookPath, readFile) {
|
|
|
274
289
|
expansions,
|
|
275
290
|
};
|
|
276
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* An index document's nodes as members of a catalog pass (#5245): each in the
|
|
294
|
+
* member the document's scope key names, so they sit beside a cluster's
|
|
295
|
+
* objects or a workspace's members in one {@link runCatalogPass}.
|
|
296
|
+
*/
|
|
297
|
+
export function indexedMemberNodes(doc) {
|
|
298
|
+
return doc.graph.nodes.map((n) => ({ ...n, member: doc.stamp.scopeKey }));
|
|
299
|
+
}
|
|
277
300
|
/** A rule path's first step, the `viaAttr` an edge it draws carries, as the pass's own rules do. */
|
|
278
301
|
const refViaAttr = (path) => path.split(/[.[]/)[0] || path;
|
|
279
302
|
/** The repository paths the nodes name that `lookPath` does not find (#5102). */
|
|
@@ -2,15 +2,18 @@ import type { ReleasePipelineConfig, ReleaseWorkflowForge } from "../release-wor
|
|
|
2
2
|
import { type ReleaseWorkflowFeature } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* What a job that builds goreleaser entries runs first (#5151): Go from the
|
|
5
|
-
* member's `go.mod` (GitHub and Forgejo, unless
|
|
6
|
-
* names `actions/setup-go`),
|
|
5
|
+
* member's `go.mod` (GitHub and Forgejo, unless the job's toolchains set Go
|
|
6
|
+
* up already or `release.workflow.setup` names `actions/setup-go`), without
|
|
7
|
+
* a cache like every other setup step, then the pinned goreleaser, downloaded, checked
|
|
7
8
|
* by SHA-256 and named by `CHANT_GORELEASER`. A config that sets
|
|
8
9
|
* `CHANT_GORELEASER` in `release.workflow.env` gets no install. GitLab
|
|
9
10
|
* jobs run in the project's image, which brings its own Go.
|
|
10
11
|
*/
|
|
11
|
-
export declare function goreleaserSetup(forge: ReleaseWorkflowForge, root: string | null, p: ReleasePipelineConfig): {
|
|
12
|
+
export declare function goreleaserSetup(forge: ReleaseWorkflowForge, root: string | null, p: ReleasePipelineConfig, goSetUp?: boolean): {
|
|
12
13
|
github: string[];
|
|
13
14
|
gitlab: string[];
|
|
14
15
|
};
|
|
16
|
+
/** The job's toolchains (#5152) set Go up already, from `release.workflow.toolchains` or a `go.mod` at the project's root (#5268). */
|
|
17
|
+
export declare function setsUpGo(p: ReleasePipelineConfig, projectFiles: readonly string[] | undefined, root: string | null): boolean;
|
|
15
18
|
/** In the job that builds the files: a dispatched release's cut, or a tag's publish. */
|
|
16
19
|
export declare const goreleaserFeature: ReleaseWorkflowFeature;
|
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
/** goreleaser for the `release.artifacts` entries it builds (#5151). */
|
|
2
2
|
import { ACTION_PINS, usesRef } from "../../action-pins.js";
|
|
3
3
|
import { TOOL_PINS, toolInstallLine } from "../../tool-pins.js";
|
|
4
|
+
import { buildJobToolchains } from "../release-toolchains.js";
|
|
4
5
|
import { RELEASE_RUNNER_PLATFORM } from "./types.js";
|
|
5
6
|
/**
|
|
6
7
|
* What a job that builds goreleaser entries runs first (#5151): Go from the
|
|
7
|
-
* member's `go.mod` (GitHub and Forgejo, unless
|
|
8
|
-
* names `actions/setup-go`),
|
|
8
|
+
* member's `go.mod` (GitHub and Forgejo, unless the job's toolchains set Go
|
|
9
|
+
* up already or `release.workflow.setup` names `actions/setup-go`), without
|
|
10
|
+
* a cache like every other setup step, then the pinned goreleaser, downloaded, checked
|
|
9
11
|
* by SHA-256 and named by `CHANT_GORELEASER`. A config that sets
|
|
10
12
|
* `CHANT_GORELEASER` in `release.workflow.env` gets no install. GitLab
|
|
11
13
|
* jobs run in the project's image, which brings its own Go.
|
|
12
14
|
*/
|
|
13
|
-
export function goreleaserSetup(forge, root, p) {
|
|
15
|
+
export function goreleaserSetup(forge, root, p, goSetUp = false) {
|
|
14
16
|
const install = p.env?.CHANT_GORELEASER === undefined;
|
|
15
17
|
if (forge === "gitlab") {
|
|
16
18
|
return { github: [], gitlab: install ? [`${toolInstallLine(TOOL_PINS.goreleaser, RELEASE_RUNNER_PLATFORM, "/tmp/goreleaser")} && export CHANT_GORELEASER=/tmp/goreleaser/goreleaser`] : [] };
|
|
17
19
|
}
|
|
18
|
-
const go = (p.setup ?? []).some((s) => "uses" in s && /^actions\/setup-go@/.test(s.uses))
|
|
20
|
+
const go = goSetUp || (p.setup ?? []).some((s) => "uses" in s && /^actions\/setup-go@/.test(s.uses))
|
|
19
21
|
? []
|
|
20
|
-
: [` - uses: ${usesRef(ACTION_PINS.setupGo7)}`, " with:", ` go-version-file: ${root ? `${root}/` : ""}go.mod
|
|
22
|
+
: [` - uses: ${usesRef(ACTION_PINS.setupGo7)}`, " with:", ` go-version-file: ${root ? `${root}/` : ""}go.mod`, " cache: false"];
|
|
21
23
|
const line = `${toolInstallLine(TOOL_PINS.goreleaser, RELEASE_RUNNER_PLATFORM, "$RUNNER_TEMP/goreleaser")} && echo "CHANT_GORELEASER=$RUNNER_TEMP/goreleaser/goreleaser" >> "$GITHUB_ENV"`;
|
|
22
24
|
return { github: [...go, ...(install ? [` - name: goreleaser ${TOOL_PINS.goreleaser.version}`, ` run: ${JSON.stringify(line)}`] : [])], gitlab: [] };
|
|
23
25
|
}
|
|
26
|
+
/** The job's toolchains (#5152) set Go up already, from `release.workflow.toolchains` or a `go.mod` at the project's root (#5268). */
|
|
27
|
+
export function setsUpGo(p, projectFiles, root) {
|
|
28
|
+
return buildJobToolchains(p.toolchains, projectFiles, root).some((t) => t.name === "go");
|
|
29
|
+
}
|
|
24
30
|
/** In the job that builds the files: a dispatched release's cut, or a tag's publish. */
|
|
25
31
|
export const goreleaserFeature = {
|
|
26
32
|
name: "goreleaser",
|
|
@@ -29,7 +35,7 @@ export const goreleaserFeature = {
|
|
|
29
35
|
return [];
|
|
30
36
|
if (c.job !== (c.shape === "dispatch" ? "cut" : "publish"))
|
|
31
37
|
return [];
|
|
32
|
-
const g = goreleaserSetup(c.forge, c.root, c.pipeline);
|
|
38
|
+
const g = goreleaserSetup(c.forge, c.root, c.pipeline, setsUpGo(c.pipeline, c.input.projectFiles, c.root));
|
|
33
39
|
const items = c.forge !== "gitlab" ? [{ lines: g.github }] : c.shape === "dispatch" ? g.gitlab : [{ lines: g.gitlab.map((l) => ` - ${JSON.stringify(l)}`) }];
|
|
34
40
|
return [{ slot: "prepare", order: 20, items }];
|
|
35
41
|
},
|
|
@@ -30,6 +30,12 @@ export declare function toolchainStep(decl: ReleaseToolchainDecl, files: Readonl
|
|
|
30
30
|
* first for a job that runs chant, at the declared version when there is one.
|
|
31
31
|
*/
|
|
32
32
|
export declare function resolveToolchains(decl: readonly ReleaseToolchainDecl[] | false | undefined, files: ReadonlySet<string>, root: string | null, withNode: boolean): ToolchainStep[];
|
|
33
|
+
/**
|
|
34
|
+
* The toolchains a job that builds sets up (#5152): `release.workflow.toolchains`,
|
|
35
|
+
* or those the project's root files name, with Node first. A caller that
|
|
36
|
+
* knows no project files sets up Node alone.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildJobToolchains(decl: readonly ReleaseToolchainDecl[] | false | undefined, projectFiles: readonly string[] | undefined, root: string | null): ToolchainStep[];
|
|
33
39
|
/** A step's lines in a GitHub or Forgejo job. Node renders as it always has: its inputs unquoted. */
|
|
34
40
|
export declare function toolchainLines(steps: readonly ToolchainStep[]): string[];
|
|
35
41
|
/**
|
|
@@ -96,6 +96,14 @@ export function resolveToolchains(decl, files, root, withNode) {
|
|
|
96
96
|
list.sort((a, b) => (named(a) === "node" ? -1 : named(b) === "node" ? 1 : 0));
|
|
97
97
|
return list.map((d) => toolchainStep(d, files, root));
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* The toolchains a job that builds sets up (#5152): `release.workflow.toolchains`,
|
|
101
|
+
* or those the project's root files name, with Node first. A caller that
|
|
102
|
+
* knows no project files sets up Node alone.
|
|
103
|
+
*/
|
|
104
|
+
export function buildJobToolchains(decl, projectFiles, root) {
|
|
105
|
+
return resolveToolchains(decl, new Set(projectFiles ?? (decl === undefined ? ["package.json"] : [])), root, true);
|
|
106
|
+
}
|
|
99
107
|
/** A step's lines in a GitHub or Forgejo job. Node renders as it always has: its inputs unquoted. */
|
|
100
108
|
export function toolchainLines(steps) {
|
|
101
109
|
return steps.flatMap((s) => [
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ReleaseGreenSource } from "../lifecycle/release-green.js";
|
|
2
2
|
import { type JobExtras, type ReleaseWorkflowForge } from "./release-workflow.js";
|
|
3
|
+
import { type ReleaseBuildConfig } from "./release-toolchains.js";
|
|
3
4
|
export interface TrainWorkflowInput {
|
|
4
|
-
forge:
|
|
5
|
+
forge: ReleaseWorkflowForge;
|
|
5
6
|
env: string;
|
|
6
7
|
trigger: "dispatch" | "tag";
|
|
7
8
|
chant: string;
|
|
@@ -22,7 +23,42 @@ export interface TrainWorkflowInput {
|
|
|
22
23
|
green: ReleaseGreenSource;
|
|
23
24
|
gate: "last-green" | "head";
|
|
24
25
|
lane?: string;
|
|
26
|
+
/**
|
|
27
|
+
* A member declares `release.images` or `release.artifacts` (#5216): the cut
|
|
28
|
+
* job stages what the cut built with `chant workspace train artifacts -o`
|
|
29
|
+
* and hands it to the publish job, which checks it (`--from`) after its
|
|
30
|
+
* build. A publish with nothing handed to it (a pushed train tag, a
|
|
31
|
+
* dispatched `train`) builds them again and checks them.
|
|
32
|
+
*/
|
|
33
|
+
files?: boolean;
|
|
34
|
+
/** Steps that set up goreleaser, in the cut and publish jobs, for a member's `release.artifacts` it builds (#5216); on GitLab, script lines. */
|
|
35
|
+
goreleaser?: string[];
|
|
36
|
+
/** GitLab: the publish signs with Sigstore, so a cut that runs the doctor gets `SIGSTORE_ID_TOKEN` to check it. */
|
|
37
|
+
signing?: boolean;
|
|
38
|
+
/** GitLab: entries the members' targets add under the publish job's `id_tokens:` beside `SIGSTORE_ID_TOKEN`, such as `PYPI_ID_TOKEN`. */
|
|
39
|
+
idTokens?: string[];
|
|
40
|
+
/** `chant release doctor` in each member before the cut (#5216): `--doctor` on the dispatched cut. */
|
|
41
|
+
doctor?: boolean;
|
|
42
|
+
/** `verified-releases`: `chant workspace train verify` before the publish (#5216). */
|
|
43
|
+
verify?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The members' per-platform builds (#5237), with `trigger: "dispatch"`
|
|
46
|
+
* only. The gate plans the train (`train cut --plan-only`) and gives each
|
|
47
|
+
* build job the label its member is planned at; a member not in the train
|
|
48
|
+
* builds nothing. The cut job unpacks each archive into its member and
|
|
49
|
+
* cuts with `--planned`, so a train labelled otherwise than the builds
|
|
50
|
+
* were is refused with nothing cut. The publish job of the same run
|
|
51
|
+
* unpacks them again.
|
|
52
|
+
*/
|
|
53
|
+
builds?: TrainBuild[];
|
|
25
54
|
}
|
|
55
|
+
/** A member's build job (#5237): the member, its directory from the workspace root, the directory it runs in from the checkout, and its toolchain steps. */
|
|
56
|
+
export type TrainBuild = ReleaseBuildConfig & {
|
|
57
|
+
member: string;
|
|
58
|
+
memberDir: string;
|
|
59
|
+
path: string;
|
|
60
|
+
setup: string[];
|
|
61
|
+
};
|
|
26
62
|
/** The tag a train's cut pushes, as a GitHub tag filter: `*` stops at `/`, so a member's own tag starts nothing. */
|
|
27
63
|
export declare function trainTagFilter(env: string): string;
|
|
28
64
|
/**
|
|
@@ -31,6 +67,6 @@ export declare function trainTagFilter(env: string): string;
|
|
|
31
67
|
* that was cut and recorded is never left unpublished by a skipped job. A
|
|
32
68
|
* file that is not JSON may still hold the id, and the error names it.
|
|
33
69
|
*/
|
|
34
|
-
export declare function trainIdScript(file: string): string;
|
|
35
|
-
/** GitHub and Forgejo
|
|
70
|
+
export declare function trainIdScript(file: string, forge?: ReleaseWorkflowForge): string;
|
|
71
|
+
/** The train workflow (#5154), for GitHub and Forgejo, or GitLab (#5216). */
|
|
36
72
|
export declare function renderTrainWorkflow(o: TrainWorkflowInput): string;
|
|
@@ -33,8 +33,22 @@
|
|
|
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";
|
|
37
|
-
import { gateScript, githubSetup, jobPermissions, LEDGER_FETCH_FIRST } from "./release-workflow.js";
|
|
36
|
+
import { ACTION_PINS, tagComments, usesRef } from "../action-pins.js";
|
|
37
|
+
import { field, gateScript, GIT_TOKEN_ENV, githubSetup, jobPermissions, LEDGER_FETCH_FIRST } from "./release-workflow.js";
|
|
38
|
+
import { RELEASE_ARTIFACTS_ARTIFACT } from "./release-steps/artifacts.js";
|
|
39
|
+
import { packLine, unpackLine } from "./release-steps/builds.js";
|
|
40
|
+
import { releaseBuildArchive, releaseBuildArtifact } from "./release-toolchains.js";
|
|
41
|
+
/** The gate's output, and GitLab variable, that carries the label a build job's member is planned at. */
|
|
42
|
+
const labelOutput = (b) => `label-${b.name}`;
|
|
43
|
+
const labelVariable = (b) => `CHANT_TRAIN_LABEL_${b.name.toUpperCase().replaceAll("-", "_")}`;
|
|
44
|
+
/** The plan's label of a build's member, read from the plan file: empty when the member is not in the train. */
|
|
45
|
+
const plannedLabel = (b, file) => `${field(`d.members.find((m)=>m.member===${JSON.stringify(b.member)})?.label`)} ${file}`;
|
|
46
|
+
/** The gate's plan (#5237): the train's members and labels at the gate's commit, with no member's dry run. */
|
|
47
|
+
const planLine = (o, file) => `${o.chant} workspace train cut ${o.env} --at "$commit" --levels "\${CHANT_RELEASE_LEVELS:-auto}" --plan-only --json > ${file}`;
|
|
48
|
+
/** A shell word for a directory. */
|
|
49
|
+
const sq = (s) => (/^[A-Za-z0-9_./@+-]+$/.test(s) ? s : `'${s.replaceAll("'", "'\\''")}'`);
|
|
50
|
+
/** Where the cut job stages the members' images and files, and the publish job finds them (#5216): outside the checkout. */
|
|
51
|
+
const TRAIN_STAGE = "$RUNNER_TEMP/chant-release-artifacts";
|
|
38
52
|
/** The tag a train's cut pushes, as a GitHub tag filter: `*` stops at `/`, so a member's own tag starts nothing. */
|
|
39
53
|
export function trainTagFilter(env) {
|
|
40
54
|
return `release-train/${env}/*`;
|
|
@@ -45,13 +59,15 @@ export function trainTagFilter(env) {
|
|
|
45
59
|
* that was cut and recorded is never left unpublished by a skipped job. A
|
|
46
60
|
* file that is not JSON may still hold the id, and the error names it.
|
|
47
61
|
*/
|
|
48
|
-
export function trainIdScript(file) {
|
|
62
|
+
export function trainIdScript(file, forge = "github") {
|
|
63
|
+
// How to publish a recorded train: dispatch the workflow with its id, or on GitLab run a pipeline with CHANT_RELEASE_TRAIN.
|
|
64
|
+
const rerun = (id) => (forge === "gitlab" ? `run a pipeline with CHANT_RELEASE_TRAIN=${id}` : `dispatch this workflow with train=${id}`);
|
|
49
65
|
const js = [
|
|
50
66
|
'const t=require("fs").readFileSync(process.argv[1],"utf8");',
|
|
51
67
|
"let d;",
|
|
52
68
|
"try{d=JSON.parse(t)}catch(e){",
|
|
53
69
|
'const m=/"id": *"(train-[^"]+)"/.exec(t);',
|
|
54
|
-
|
|
70
|
+
`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
71
|
"process.exit(1)}",
|
|
56
72
|
'const id=d.train?.id??"";',
|
|
57
73
|
'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 +77,10 @@ export function trainIdScript(file) {
|
|
|
61
77
|
}
|
|
62
78
|
/** The ref of a train's tag, as an expression: what the publish job checks out for a dispatched `train`. */
|
|
63
79
|
const dispatchedTrainRef = (env) => `format('refs/tags/release-train/${env}/{0}', inputs.train)`;
|
|
64
|
-
/** GitHub and Forgejo
|
|
80
|
+
/** The train workflow (#5154), for GitHub and Forgejo, or GitLab (#5216). */
|
|
65
81
|
export function renderTrainWorkflow(o) {
|
|
82
|
+
if (o.forge === "gitlab")
|
|
83
|
+
return renderGitlabTrainWorkflow(o);
|
|
66
84
|
const defaults = o.root ? [" defaults:", " run:", ` working-directory: ${o.root}`] : [];
|
|
67
85
|
const run = (l) => ` - run: ${l}`;
|
|
68
86
|
const block = (lines) => [" run: |", ...lines.map((l) => ` ${l}`)];
|
|
@@ -71,6 +89,54 @@ export function renderTrainWorkflow(o) {
|
|
|
71
89
|
const ledgerFetch = run("git fetch origin chant/lifecycle:chant/lifecycle");
|
|
72
90
|
const dispatch = o.trigger === "dispatch";
|
|
73
91
|
const env = o.env;
|
|
92
|
+
const builds = dispatch ? (o.builds ?? []) : [];
|
|
93
|
+
const download = usesRef(o.forge === "forgejo" ? ACTION_PINS.downloadArtifact3 : ACTION_PINS.downloadArtifact4);
|
|
94
|
+
const built = (b) => `needs.build-${b.name}.result == 'success'`;
|
|
95
|
+
// #5237: each build's archive, from the run's build job, unpacked into its member: in the cut with -k, so it replaces no file of the commit.
|
|
96
|
+
const unpackSteps = (cut) => builds.flatMap((b) => [
|
|
97
|
+
` - if: ${built(b)}`,
|
|
98
|
+
` uses: ${download}`,
|
|
99
|
+
" with:",
|
|
100
|
+
` name: ${releaseBuildArtifact(b.name)}`,
|
|
101
|
+
" path: ${{ runner.temp }}/chant-release-builds",
|
|
102
|
+
` - if: ${built(b)}`,
|
|
103
|
+
` run: ${unpackLine(`"$RUNNER_TEMP/chant-release-builds/${releaseBuildArchive(b.name)}"`, cut)} -C ${sq(b.memberDir)}`,
|
|
104
|
+
]);
|
|
105
|
+
const q = (v) => JSON.stringify(v);
|
|
106
|
+
const buildJobs = builds.flatMap((b) => {
|
|
107
|
+
const install = b.install === false ? [] : b.install !== undefined ? [run(b.install)] : o.install ? [run(o.install), ` working-directory: ${o.root ?? "."}`] : [];
|
|
108
|
+
const runner = Array.isArray(b.runner) ? `[${b.runner.map(q).join(", ")}]` : q(b.runner);
|
|
109
|
+
const vars = Object.entries(b.env ?? {});
|
|
110
|
+
for (const [k] of vars)
|
|
111
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k))
|
|
112
|
+
throw new Error(`release.workflow.builds.${b.name}.env: ${JSON.stringify(k)} is not a variable name`);
|
|
113
|
+
return [
|
|
114
|
+
` build-${b.name}:`,
|
|
115
|
+
" needs: gate",
|
|
116
|
+
` if: needs.gate.outputs.${labelOutput(b)} != ''`,
|
|
117
|
+
` runs-on: ${runner}`,
|
|
118
|
+
" permissions:",
|
|
119
|
+
" contents: read",
|
|
120
|
+
" defaults:",
|
|
121
|
+
" run:",
|
|
122
|
+
" shell: bash",
|
|
123
|
+
` working-directory: ${b.path}`,
|
|
124
|
+
" env:",
|
|
125
|
+
` CHANT_RELEASE_LABEL: \${{ needs.gate.outputs.${labelOutput(b)} }}`,
|
|
126
|
+
...vars.map(([k, v]) => ` ${k}: ${q(v)}`),
|
|
127
|
+
" steps:",
|
|
128
|
+
...githubSetup("${{ needs.gate.outputs.commit }}", b.setup, false),
|
|
129
|
+
...install,
|
|
130
|
+
` - run: ${q(b.build)}`,
|
|
131
|
+
` - run: ${q(packLine(b))}`,
|
|
132
|
+
` - uses: ${usesRef(o.forge === "forgejo" ? ACTION_PINS.uploadArtifact3 : ACTION_PINS.uploadArtifact4)}`,
|
|
133
|
+
" with:",
|
|
134
|
+
` name: ${releaseBuildArtifact(b.name)}`,
|
|
135
|
+
` path: ${b.path === "." ? "" : `${b.path}/`}${releaseBuildArchive(b.name)}`,
|
|
136
|
+
" if-no-files-found: error",
|
|
137
|
+
" retention-days: 1",
|
|
138
|
+
];
|
|
139
|
+
});
|
|
74
140
|
const lines = [
|
|
75
141
|
"name: chant release train",
|
|
76
142
|
"on:",
|
|
@@ -100,22 +166,205 @@ export function renderTrainWorkflow(o) {
|
|
|
100
166
|
"jobs:",
|
|
101
167
|
];
|
|
102
168
|
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 }}",
|
|
169
|
+
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 }}", ...(builds.length > 0 ? [" planned: ${{ steps.green.outputs.planned }}", ...builds.map((b) => ` ${labelOutput(b)}: \${{ steps.green.outputs.${labelOutput(b)} }}`)] : []), ...(builds.length > 0 ? [" env:", " CHANT_RELEASE_LEVELS: ${{ inputs.levels }}"] : []), " steps:", ...githubSetup(undefined, o.chantSetup), ...installLines, ciFetch, " - id: green", ...block([
|
|
170
|
+
...gateScript(o, "$GITHUB_SHA"),
|
|
171
|
+
'echo "commit=$commit" >> "$GITHUB_OUTPUT"',
|
|
172
|
+
// #5237: the plan, so each build job builds with the label its member is cut at.
|
|
173
|
+
...(builds.length > 0
|
|
174
|
+
? [
|
|
175
|
+
planLine(o, '"$RUNNER_TEMP/chant-train-plan.json"'),
|
|
176
|
+
`echo "planned=$(${field("d.planned")} "$RUNNER_TEMP/chant-train-plan.json")" >> "$GITHUB_OUTPUT"`,
|
|
177
|
+
...builds.map((b) => `echo "${labelOutput(b)}=$(${plannedLabel(b, '"$RUNNER_TEMP/chant-train-plan.json"')})" >> "$GITHUB_OUTPUT"`),
|
|
178
|
+
]
|
|
179
|
+
: []),
|
|
180
|
+
]), ...buildJobs, " cut:", ...(builds.length > 0 ? [` needs: [gate, ${builds.map((b) => `build-${b.name}`).join(", ")}]`, " if: ${{ !cancelled() && needs.gate.result == 'success' && !contains(needs.*.result, 'failure') }}"] : [" 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 }}", ...(builds.length > 0 ? [" CHANT_TRAIN_PLANNED: ${{ needs.gate.outputs.planned }}"] : []), ...new Set([...(o.cutToken ?? []), ...(o.doctor ? o.forgeToken : [])]), ...(o.files ? GIT_TOKEN_ENV : [])]), " steps:",
|
|
181
|
+
// #5268: a cut that hands files on keeps no token in .git/config.
|
|
182
|
+
...githubSetup("${{ needs.gate.outputs.commit }}", o.fullSetup, !o.files), ...installLines, ...o.extra.githubSteps, ...(o.goreleaser ?? []), ciFetch, run(LEDGER_FETCH_FIRST), ...unpackSteps(true), " - id: cut", ...block([
|
|
104
183
|
'git config user.name "chant release"',
|
|
105
184
|
'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"`,
|
|
185
|
+
`${o.chant} workspace train cut ${env} --at "$CHANT_RELEASE_COMMIT" --levels "\${CHANT_RELEASE_LEVELS:-auto}"${builds.length > 0 ? ' --planned "$CHANT_TRAIN_PLANNED"' : ""}${o.doctor ? " --doctor" : ""} --yes --json > "$RUNNER_TEMP/chant-train.json"`,
|
|
107
186
|
`train="$(${trainIdScript("$RUNNER_TEMP/chant-train.json")})" || exit 1`,
|
|
108
187
|
'echo "train=$train" >> "$GITHUB_OUTPUT"',
|
|
109
|
-
])
|
|
188
|
+
]), ...(o.files
|
|
189
|
+
? [
|
|
190
|
+
" - if: steps.cut.outputs.train != ''",
|
|
191
|
+
` run: ${o.chant} workspace train artifacts ${env} "\${{ steps.cut.outputs.train }}" -o "${TRAIN_STAGE}"`,
|
|
192
|
+
" - if: steps.cut.outputs.train != ''",
|
|
193
|
+
` uses: ${usesRef(o.forge === "forgejo" ? ACTION_PINS.uploadArtifact3 : ACTION_PINS.uploadArtifact4)}`,
|
|
194
|
+
" with:",
|
|
195
|
+
` name: ${RELEASE_ARTIFACTS_ARTIFACT}`,
|
|
196
|
+
" path: ${{ runner.temp }}/chant-release-artifacts",
|
|
197
|
+
" if-no-files-found: error",
|
|
198
|
+
" retention-days: 1",
|
|
199
|
+
]
|
|
200
|
+
: []));
|
|
110
201
|
}
|
|
111
202
|
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
203
|
// A dispatched `train` names the train itself, and its tag the commit to check out.
|
|
113
204
|
const dispatchedTrain = "${{ inputs.train || needs.cut.outputs.train }}";
|
|
114
205
|
const checkoutRef = `\${{ needs.gate.outputs.commit || (inputs.train != '' && ${dispatchedTrainRef(env)}) || github.sha }}`;
|
|
115
206
|
const trainFromRef = `echo "CHANT_RELEASE_TRAIN=\${CHANT_RELEASE_TRAIN:-\${GITHUB_REF_NAME#release-train/${env}/}}" >> "$GITHUB_ENV"`;
|
|
116
|
-
lines.push(" publish:", ...(dispatch ? [
|
|
207
|
+
lines.push(" publish:", ...(dispatch ? [` needs: [gate, cut${builds.map((b) => `, build-${b.name}`).join("")}]`, 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), ...unpackSteps(false), run(`${o.chant} workspace train prepare ${env} "$CHANT_RELEASE_TRAIN"`), ...(o.build ? [run(o.build)] : []), ...(o.files
|
|
208
|
+
? dispatch
|
|
209
|
+
? [
|
|
210
|
+
" - if: needs.cut.outputs.train != ''",
|
|
211
|
+
` uses: ${usesRef(o.forge === "forgejo" ? ACTION_PINS.downloadArtifact3 : ACTION_PINS.downloadArtifact4)}`,
|
|
212
|
+
" with:",
|
|
213
|
+
` name: ${RELEASE_ARTIFACTS_ARTIFACT}`,
|
|
214
|
+
" path: ${{ runner.temp }}/chant-release-artifacts",
|
|
215
|
+
run(`${o.chant} workspace train artifacts ${env} "$CHANT_RELEASE_TRAIN" --from "${TRAIN_STAGE}"`),
|
|
216
|
+
]
|
|
217
|
+
: [run(`${o.chant} workspace train artifacts ${env} "$CHANT_RELEASE_TRAIN"`)]
|
|
218
|
+
: []), ...(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
219
|
if (o.after.length > 0) {
|
|
118
220
|
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
221
|
}
|
|
120
222
|
return tagComments(`${lines.join("\n")}\n`);
|
|
121
223
|
}
|
|
224
|
+
/** Where a GitLab cut job stages the members' files: GitLab keeps a job's artifacts only inside the project directory (#5216). */
|
|
225
|
+
const GITLAB_TRAIN_STAGE = "$CI_PROJECT_DIR/.chant-release-artifacts";
|
|
226
|
+
/** Where the GitLab publish job moves them, out of the checkout, before it checks out the train's commit. */
|
|
227
|
+
const GITLAB_TRAIN_FROM = "/tmp/chant-release-artifacts";
|
|
228
|
+
/**
|
|
229
|
+
* GitLab (#5216). With `trigger: "dispatch"` a person runs a pipeline
|
|
230
|
+
* ("Run pipeline", the API or a trigger) with `CHANT_RELEASE_LEVELS` set
|
|
231
|
+
* (`auto`, or the levels): the gate names the commit, the cut job cuts the
|
|
232
|
+
* train and pushes its tags with `CHANT_RELEASE_TOKEN` (a project access
|
|
233
|
+
* token with `write_repository`, since a job token cannot push), and the
|
|
234
|
+
* publish job publishes it. Run with `CHANT_RELEASE_TRAIN` set to a recorded
|
|
235
|
+
* train's id instead, the gate and cut are left out and the publish job
|
|
236
|
+
* publishes that train from its tag, resuming. The dispatched file has no
|
|
237
|
+
* tag rule: the cut's own push would start a second publish of the same
|
|
238
|
+
* train. With `trigger: "tag"` the file is one publish job on a pushed
|
|
239
|
+
* `release-train/<env>/*` tag.
|
|
240
|
+
*
|
|
241
|
+
* Every job's script runs in one shell, so a variable set on one line is
|
|
242
|
+
* there on the next. The publish job checks out the commit the train's tag
|
|
243
|
+
* names in every case.
|
|
244
|
+
*/
|
|
245
|
+
function renderGitlabTrainWorkflow(o) {
|
|
246
|
+
const env = o.env;
|
|
247
|
+
const q = (l) => ` - ${JSON.stringify(l)}`;
|
|
248
|
+
const cd = o.root ? [`cd ${o.root}`] : [];
|
|
249
|
+
const install = o.install ? [o.install] : [];
|
|
250
|
+
const ciFetch = "git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'";
|
|
251
|
+
const ledgerFetch = "git fetch origin chant/lifecycle:chant/lifecycle";
|
|
252
|
+
const auth = [
|
|
253
|
+
`chant_auth="$(printf 'oauth2:%s' "$CHANT_RELEASE_TOKEN" | base64 | tr -d '\\n')"`,
|
|
254
|
+
'export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.extraheader GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $chant_auth"',
|
|
255
|
+
"unset chant_auth",
|
|
256
|
+
];
|
|
257
|
+
const dispatch = o.trigger === "dispatch";
|
|
258
|
+
const manual = "$CI_PIPELINE_SOURCE =~ /^(web|api|trigger)$/";
|
|
259
|
+
const tagRule = `$CI_COMMIT_TAG =~ /^release-train\\/${env.replace(/[.*+?^${}()|[\]\\/]/g, (c) => `\\${c}`)}\\//`;
|
|
260
|
+
const cutRule = `$CHANT_RELEASE_LEVELS && ($CHANT_RELEASE_TRAIN == null || $CHANT_RELEASE_TRAIN == "") && ${manual}`;
|
|
261
|
+
const variables = (vars) => [" variables:", ' GIT_DEPTH: "0"', ...vars];
|
|
262
|
+
// 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.
|
|
263
|
+
const trainLines = [
|
|
264
|
+
`export CHANT_RELEASE_TRAIN="\${CHANT_RELEASE_TRAIN:-\${CHANT_TRAIN_CUT:-\${CI_COMMIT_TAG#release-train/${env}/}}}"`,
|
|
265
|
+
'if [ -z "$CHANT_RELEASE_TRAIN" ]; then echo "no release train was cut or named, so there is nothing to publish"; exit 0; fi',
|
|
266
|
+
`git fetch origin "refs/tags/release-train/${env}/$CHANT_RELEASE_TRAIN"`,
|
|
267
|
+
"git checkout --detach FETCH_HEAD",
|
|
268
|
+
];
|
|
269
|
+
const lines = [];
|
|
270
|
+
const builds = dispatch ? (o.builds ?? []) : [];
|
|
271
|
+
const archiveIn = (b) => `${b.memberDir === "." ? "" : `${b.memberDir}/`}${releaseBuildArchive(b.name)}`;
|
|
272
|
+
// #5237: GitLab hands each build's archive into the project directory, in its member; it is unpacked there and moved out, from the workspace root.
|
|
273
|
+
const unpack = (b, cut) => `if [ ${cut ? `-n "$${labelVariable(b)}"` : `-f ${sq(archiveIn(b))}`} ]; then ${unpackLine(sq(archiveIn(b)), cut)} -C ${sq(b.memberDir)}; mv ${sq(archiveIn(b))} /tmp/; fi`;
|
|
274
|
+
const buildJobs = builds.flatMap((b) => {
|
|
275
|
+
const install = b.install === false ? [] : b.install !== undefined ? [b.install] : o.install ? [o.install] : [];
|
|
276
|
+
const vars = Object.entries(b.env ?? {});
|
|
277
|
+
for (const [k] of vars)
|
|
278
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k))
|
|
279
|
+
throw new Error(`release.workflow.builds.${b.name}.env: ${JSON.stringify(k)} is not a variable name`);
|
|
280
|
+
const tags = Array.isArray(b.runner) ? b.runner : [b.runner];
|
|
281
|
+
const cdMember = b.memberDir === "." ? [] : [`cd ${sq(b.memberDir)}`];
|
|
282
|
+
return [
|
|
283
|
+
`chant-release-build-${b.name}:`,
|
|
284
|
+
" rules:",
|
|
285
|
+
` - if: ${cutRule}`,
|
|
286
|
+
...variables(vars.map(([k, v]) => ` ${k}: ${JSON.stringify(v)}`)),
|
|
287
|
+
" needs: [chant-release-gate]",
|
|
288
|
+
` tags: [${tags.map((t) => JSON.stringify(t)).join(", ")}]`,
|
|
289
|
+
" artifacts:",
|
|
290
|
+
" paths:",
|
|
291
|
+
` - ${JSON.stringify(`${b.path === "." ? "" : `${b.path}/`}${releaseBuildArchive(b.name)}`)}`,
|
|
292
|
+
" expire_in: 1 day",
|
|
293
|
+
" script:",
|
|
294
|
+
...[
|
|
295
|
+
`export CHANT_RELEASE_LABEL="$${labelVariable(b)}"`,
|
|
296
|
+
`if [ -z "$CHANT_RELEASE_LABEL" ]; then echo "${b.member} is not in this train, so build-${b.name} builds nothing"; exit 0; fi`,
|
|
297
|
+
'git checkout --detach "$CHANT_RELEASE_COMMIT"',
|
|
298
|
+
...cd,
|
|
299
|
+
// The workflow's install runs at the workspace root, a build's own in its member.
|
|
300
|
+
...(b.install === undefined ? install : []),
|
|
301
|
+
...cdMember,
|
|
302
|
+
...(b.install !== undefined ? install : []),
|
|
303
|
+
b.build,
|
|
304
|
+
packLine(b),
|
|
305
|
+
].map(q),
|
|
306
|
+
"",
|
|
307
|
+
];
|
|
308
|
+
});
|
|
309
|
+
if (dispatch) {
|
|
310
|
+
const plan = "/tmp/chant-train-plan.json";
|
|
311
|
+
lines.push("chant-release-gate:", " rules:", ` - if: ${cutRule}`, ...variables([]), " artifacts:", " reports:", " dotenv: chant-release-gate.env", " script:", ...[
|
|
312
|
+
...cd,
|
|
313
|
+
...install,
|
|
314
|
+
ciFetch,
|
|
315
|
+
...gateScript(o, "$CI_COMMIT_SHA"),
|
|
316
|
+
'printf \'CHANT_RELEASE_COMMIT=%s\\n\' "$commit" > "$CI_PROJECT_DIR/chant-release-gate.env"',
|
|
317
|
+
// #5237: the plan, so each build job builds with the label its member is cut at.
|
|
318
|
+
...(builds.length > 0
|
|
319
|
+
? [
|
|
320
|
+
planLine(o, plan),
|
|
321
|
+
`printf 'CHANT_TRAIN_PLANNED=%s\\n' "$(${field("d.planned")} ${plan})" >> "$CI_PROJECT_DIR/chant-release-gate.env"`,
|
|
322
|
+
...builds.map((b) => `printf '${labelVariable(b)}=%s\\n' "$(${plannedLabel(b, plan)})" >> "$CI_PROJECT_DIR/chant-release-gate.env"`),
|
|
323
|
+
]
|
|
324
|
+
: []),
|
|
325
|
+
].map(q), "", ...buildJobs, "chant-release-cut:", " rules:", ` - if: ${cutRule}`, ...variables(o.extra.gitlabVariables), ` needs: [chant-release-gate${builds.map((b) => `, chant-release-build-${b.name}`).join("")}]`, " 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:", ...[
|
|
326
|
+
'git checkout --detach "$CHANT_RELEASE_COMMIT"',
|
|
327
|
+
...cd,
|
|
328
|
+
...install,
|
|
329
|
+
...o.extra.gitlabScript,
|
|
330
|
+
...(o.goreleaser ?? []),
|
|
331
|
+
ciFetch,
|
|
332
|
+
...auth,
|
|
333
|
+
LEDGER_FETCH_FIRST,
|
|
334
|
+
...builds.map((b) => unpack(b, true)),
|
|
335
|
+
'git config user.name "chant release"',
|
|
336
|
+
'git config user.email "chant-release@localhost"',
|
|
337
|
+
`${o.chant} workspace train cut ${env} --at "$CHANT_RELEASE_COMMIT" --levels "\${CHANT_RELEASE_LEVELS:-auto}"${builds.length > 0 ? ' --planned "$CHANT_TRAIN_PLANNED"' : ""}${o.doctor ? " --doctor" : ""} --yes --json > /tmp/chant-train.json`,
|
|
338
|
+
`train="$(${trainIdScript("/tmp/chant-train.json", "gitlab")})" || exit 1`,
|
|
339
|
+
'printf \'CHANT_TRAIN_CUT=%s\\n\' "$train" > "$CI_PROJECT_DIR/chant-release-train.env"',
|
|
340
|
+
...(o.files ? [`if [ -n "$train" ]; then ${o.chant} workspace train artifacts ${env} "$train" -o "${GITLAB_TRAIN_STAGE}"; fi`] : []),
|
|
341
|
+
].map(q), "");
|
|
342
|
+
}
|
|
343
|
+
const publishScript = (handed) => [
|
|
344
|
+
// The cut's staged files leave the checkout before it moves to the train's commit.
|
|
345
|
+
...(handed && o.files ? [`if [ -d "${GITLAB_TRAIN_STAGE}" ]; then mv "${GITLAB_TRAIN_STAGE}" ${GITLAB_TRAIN_FROM}; fi`] : []),
|
|
346
|
+
...trainLines,
|
|
347
|
+
...cd,
|
|
348
|
+
...install,
|
|
349
|
+
...o.extra.gitlabScript,
|
|
350
|
+
...(o.goreleaser ?? []),
|
|
351
|
+
ciFetch,
|
|
352
|
+
ledgerFetch,
|
|
353
|
+
...(dispatch ? auth : []),
|
|
354
|
+
...(handed ? builds.map((b) => unpack(b, false)) : []),
|
|
355
|
+
`${o.chant} workspace train prepare ${env} "$CHANT_RELEASE_TRAIN"`,
|
|
356
|
+
...(o.build ? [o.build] : []),
|
|
357
|
+
...(o.files ? [`${o.chant} workspace train artifacts ${env} "$CHANT_RELEASE_TRAIN"${handed ? ` --from ${GITLAB_TRAIN_FROM}` : ""}`] : []),
|
|
358
|
+
...(o.verify ? [`${o.chant} workspace train verify ${env} "$CHANT_RELEASE_TRAIN"`] : []),
|
|
359
|
+
'git config user.name "chant release"',
|
|
360
|
+
'git config user.email "chant-release@localhost"',
|
|
361
|
+
`${o.chant} workspace train publish ${env} "$CHANT_RELEASE_TRAIN" ${o.flags}`,
|
|
362
|
+
];
|
|
363
|
+
const publishRules = dispatch ? [` - if: $CHANT_RELEASE_TRAIN && ${manual}`, ` - if: ${cutRule}`] : [` - if: ${tagRule}`];
|
|
364
|
+
const publishNeeds = dispatch ? [" needs:", " - job: chant-release-cut", " optional: true", ...builds.flatMap((b) => [` - job: chant-release-build-${b.name}`, " optional: true"])] : [];
|
|
365
|
+
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));
|
|
366
|
+
if (o.after.length > 0) {
|
|
367
|
+
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}`));
|
|
368
|
+
}
|
|
369
|
+
return `${lines.join("\n")}\n`;
|
|
370
|
+
}
|
|
@@ -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>] [--plan-only] [--planned <member=label ...|none>] [--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));
|