@intentius/chant 0.124.99 → 0.124.101
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/bin/chant +3 -3
- package/dist/action-pins.d.ts +2 -0
- package/dist/action-pins.js +3 -0
- package/dist/ci-detect.d.ts +13 -0
- package/dist/ci-detect.js +12 -0
- package/dist/ci-system.d.ts +66 -0
- package/dist/ci-system.js +61 -0
- package/dist/cli/commands/carve-emit.js +2 -2
- package/dist/cli/commands/check-lexicon-plugin.d.ts +2 -2
- package/dist/cli/commands/check-lexicon-plugin.js +3 -3
- package/dist/cli/commands/check-lexicon.js +4 -4
- package/dist/cli/commands/init-lexicon/templates/project.d.ts +1 -1
- package/dist/cli/commands/init-lexicon/templates/project.js +4 -4
- package/dist/cli/commands/init.d.ts +13 -0
- package/dist/cli/commands/init.js +30 -2
- package/dist/cli/handlers/build.js +27 -0
- package/dist/cli/handlers/release-doctor.d.ts +12 -0
- package/dist/cli/handlers/release-doctor.js +118 -0
- package/dist/cli/handlers/release-init.d.ts +10 -0
- package/dist/cli/handlers/release-init.js +342 -0
- package/dist/cli/handlers/release.d.ts +50 -1
- package/dist/cli/handlers/release.js +688 -30
- package/dist/cli/handlers/run-generate.js +11 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +45 -97
- package/dist/cli/parse-args.js +55 -0
- package/dist/cli/registry.d.ts +18 -0
- package/dist/cli/release-commands/artifacts.d.ts +3 -0
- package/dist/cli/release-commands/artifacts.js +14 -0
- package/dist/cli/release-commands/candidates.d.ts +3 -0
- package/dist/cli/release-commands/candidates.js +16 -0
- package/dist/cli/release-commands/changed.d.ts +3 -0
- package/dist/cli/release-commands/changed.js +14 -0
- package/dist/cli/release-commands/compose.d.ts +3 -0
- package/dist/cli/release-commands/compose.js +16 -0
- package/dist/cli/release-commands/cut.d.ts +3 -0
- package/dist/cli/release-commands/cut.js +49 -0
- package/dist/cli/release-commands/doctor.d.ts +3 -0
- package/dist/cli/release-commands/doctor.js +14 -0
- package/dist/cli/release-commands/export.d.ts +3 -0
- package/dist/cli/release-commands/export.js +12 -0
- package/dist/cli/release-commands/images.d.ts +3 -0
- package/dist/cli/release-commands/images.js +13 -0
- package/dist/cli/release-commands/index.d.ts +8 -0
- package/dist/cli/release-commands/index.js +52 -0
- package/dist/cli/release-commands/init.d.ts +3 -0
- package/dist/cli/release-commands/init.js +16 -0
- package/dist/cli/release-commands/list.d.ts +3 -0
- package/dist/cli/release-commands/list.js +10 -0
- package/dist/cli/release-commands/next.d.ts +3 -0
- package/dist/cli/release-commands/next.js +13 -0
- package/dist/cli/release-commands/publish.d.ts +3 -0
- package/dist/cli/release-commands/publish.js +22 -0
- package/dist/cli/release-commands/stamp.d.ts +3 -0
- package/dist/cli/release-commands/stamp.js +15 -0
- package/dist/cli/release-commands/status.d.ts +3 -0
- package/dist/cli/release-commands/status.js +17 -0
- package/dist/cli/release-commands/tag.d.ts +3 -0
- package/dist/cli/release-commands/tag.js +12 -0
- package/dist/cli/release-commands/types.d.ts +20 -0
- package/dist/cli/release-commands/types.js +1 -0
- package/dist/cli/release-commands/verify.d.ts +3 -0
- package/dist/cli/release-commands/verify.js +15 -0
- package/dist/cli/release-commands/workflow.d.ts +3 -0
- package/dist/cli/release-commands/workflow.js +13 -0
- package/dist/codegen/pinned-upgrade.js +1 -1
- package/dist/components/capability-plugin.d.ts +1 -1
- package/dist/components/capability-plugin.js +1 -1
- package/dist/components/cli-support.d.ts +1 -1
- package/dist/components/cli-support.js +1 -1
- package/dist/config-environments.d.ts +8 -1
- package/dist/config-environments.js +2 -0
- package/dist/config.d.ts +299 -6
- package/dist/config.js +102 -5
- package/dist/dead-guards.d.ts +5 -1
- package/dist/dead-guards.js +34 -23
- package/dist/discovery/sandbox/driver.js +1 -1
- package/dist/discovery/specifier-resolve.js +1 -1
- package/dist/floor-table.d.ts +3 -1
- package/dist/floor-table.data.js +23 -3
- package/dist/floor-table.js +4 -3
- package/dist/forge-remote.d.ts +13 -0
- package/dist/forge-remote.js +15 -0
- package/dist/lexicon.d.ts +41 -2
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +62 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.js +270 -3
- package/dist/lifecycle/publish-attachments.d.ts +2 -1
- package/dist/lifecycle/publish-attachments.js +19 -2
- package/dist/lifecycle/publish-cargo.d.ts +99 -0
- package/dist/lifecycle/publish-cargo.js +412 -0
- package/dist/lifecycle/publish-credentials.d.ts +1 -1
- package/dist/lifecycle/publish-credentials.js +8 -0
- package/dist/lifecycle/publish-declaration.d.ts +199 -4
- package/dist/lifecycle/publish-declaration.js +200 -9
- package/dist/lifecycle/publish-forge.d.ts +45 -2
- package/dist/lifecycle/publish-forge.js +434 -34
- package/dist/lifecycle/publish-git-ssh.d.ts +15 -0
- package/dist/lifecycle/publish-git-ssh.js +30 -4
- package/dist/lifecycle/publish-github.d.ts +40 -2
- package/dist/lifecycle/publish-github.js +100 -3
- package/dist/lifecycle/publish-homebrew.d.ts +7 -9
- package/dist/lifecycle/publish-homebrew.js +34 -197
- package/dist/lifecycle/publish-index.d.ts +141 -0
- package/dist/lifecycle/publish-index.js +719 -0
- package/dist/lifecycle/publish-marketplace.js +77 -0
- package/dist/lifecycle/publish-mcp-registry.d.ts +66 -0
- package/dist/lifecycle/publish-mcp-registry.js +306 -0
- package/dist/lifecycle/publish-npm.js +165 -2
- package/dist/lifecycle/publish-oci.d.ts +34 -1
- package/dist/lifecycle/publish-oci.js +246 -7
- package/dist/lifecycle/publish-pypi.d.ts +136 -0
- package/dist/lifecycle/publish-pypi.js +657 -0
- package/dist/lifecycle/publish-record.d.ts +6 -3
- package/dist/lifecycle/publish-record.js +6 -3
- package/dist/lifecycle/publish-signing.d.ts +147 -0
- package/dist/lifecycle/publish-signing.js +257 -0
- package/dist/lifecycle/publish-targets.d.ts +27 -1
- package/dist/lifecycle/publish-targets.js +80 -0
- package/dist/lifecycle/publish-tauri.js +43 -0
- package/dist/lifecycle/publish-train-names.d.ts +54 -0
- package/dist/lifecycle/publish-train-names.js +118 -0
- package/dist/lifecycle/publish-verify.d.ts +121 -0
- package/dist/lifecycle/publish-verify.js +130 -0
- package/dist/lifecycle/query.js +8 -0
- package/dist/lifecycle/release-artifacts.d.ts +212 -0
- package/dist/lifecycle/release-artifacts.js +571 -0
- package/dist/lifecycle/release-changelog.d.ts +13 -1
- package/dist/lifecycle/release-changelog.js +35 -2
- package/dist/lifecycle/release-cut.d.ts +58 -3
- package/dist/lifecycle/release-cut.js +132 -34
- package/dist/lifecycle/release-doctor.d.ts +113 -0
- package/dist/lifecycle/release-doctor.js +996 -0
- package/dist/lifecycle/release-green.d.ts +86 -0
- package/dist/lifecycle/release-green.js +286 -0
- package/dist/lifecycle/release-init.d.ts +255 -0
- package/dist/lifecycle/release-init.js +859 -0
- package/dist/lifecycle/release-intents.d.ts +73 -0
- package/dist/lifecycle/release-intents.js +128 -0
- package/dist/lifecycle/release-next.d.ts +111 -0
- package/dist/lifecycle/release-next.js +252 -0
- package/dist/lifecycle/release-prerelease.d.ts +19 -0
- package/dist/lifecycle/release-prerelease.js +30 -0
- package/dist/lifecycle/release-publish.d.ts +256 -10
- package/dist/lifecycle/release-publish.js +246 -34
- package/dist/lifecycle/release-status-change.d.ts +226 -0
- package/dist/lifecycle/release-status-change.js +478 -0
- package/dist/lifecycle/release-status.d.ts +11 -0
- package/dist/lifecycle/release-status.js +1 -1
- package/dist/lifecycle/release-store.d.ts +73 -2
- package/dist/lifecycle/release-store.js +32 -1
- package/dist/lifecycle/release-tag.d.ts +142 -0
- package/dist/lifecycle/release-tag.js +323 -0
- package/dist/lifecycle/release-verify.d.ts +73 -1
- package/dist/lifecycle/release-verify.js +117 -2
- package/dist/lifecycle/release-version-formats.d.ts +73 -0
- package/dist/lifecycle/release-version-formats.js +570 -0
- package/dist/lifecycle/release-version.d.ts +58 -10
- package/dist/lifecycle/release-version.js +164 -36
- package/dist/lifecycle/release-workstation.d.ts +3 -2
- package/dist/lifecycle/release-workstation.js +3 -2
- package/dist/module-source.d.ts +2 -2
- package/dist/module-source.js +8 -8
- package/dist/op/generate-pipeline.js +1 -1
- package/dist/pr-forge-base.js +4 -2
- package/dist/pr-forge.d.ts +20 -2
- package/dist/pr-forge.js +46 -10
- package/dist/release-floors.d.ts +10 -1
- package/dist/release-floors.js +10 -1
- package/dist/tool-pins.d.ts +38 -0
- package/dist/tool-pins.js +54 -0
- package/dist/ts-loader.d.ts +1 -1
- package/dist/ts-loader.js +6 -6
- package/dist/wave-runtime.mjs +337 -334
- package/dist/workspace/ci-forge.d.ts +17 -0
- package/dist/workspace/ci-forge.js +17 -0
- package/dist/workspace/ci-init.js +1 -1
- package/dist/workspace/composites.schema.json +1 -0
- package/dist/workspace/declaration.d.ts +8 -0
- package/dist/workspace/declaration.js +12 -0
- package/dist/workspace/declaration.schema.json +8 -0
- package/dist/workspace/environments.d.ts +2 -0
- package/dist/workspace/environments.js +1 -1
- package/dist/workspace/identity-gate-rule.d.ts +61 -5
- package/dist/workspace/identity-gate-rule.js +81 -12
- package/dist/workspace/member-pipeline.d.ts +2 -1
- package/dist/workspace/member-pipeline.js +5 -2
- package/dist/workspace/reason-codes.d.ts +6 -0
- package/dist/workspace/reason-codes.js +8 -1
- package/dist/workspace/release-changed.d.ts +179 -0
- package/dist/workspace/release-changed.js +625 -0
- package/dist/workspace/release-changed.schema.json +206 -0
- package/dist/workspace/release-steps/artifacts.d.ts +7 -0
- package/dist/workspace/release-steps/artifacts.js +45 -0
- package/dist/workspace/release-steps/builds.d.ts +12 -0
- package/dist/workspace/release-steps/builds.js +38 -0
- package/dist/workspace/release-steps/doctor.d.ts +8 -0
- package/dist/workspace/release-steps/doctor.js +14 -0
- package/dist/workspace/release-steps/goreleaser.d.ts +16 -0
- package/dist/workspace/release-steps/goreleaser.js +36 -0
- package/dist/workspace/release-steps/green.d.ts +3 -0
- package/dist/workspace/release-steps/green.js +6 -0
- package/dist/workspace/release-steps/images.d.ts +22 -0
- package/dist/workspace/release-steps/images.js +59 -0
- package/dist/workspace/release-steps/index.d.ts +9 -0
- package/dist/workspace/release-steps/index.js +46 -0
- package/dist/workspace/release-steps/pypi.d.ts +15 -0
- package/dist/workspace/release-steps/pypi.js +21 -0
- package/dist/workspace/release-steps/qemu.d.ts +21 -0
- package/dist/workspace/release-steps/qemu.js +35 -0
- package/dist/workspace/release-steps/signing.d.ts +18 -0
- package/dist/workspace/release-steps/signing.js +30 -0
- package/dist/workspace/release-steps/stamp.d.ts +3 -0
- package/dist/workspace/release-steps/stamp.js +4 -0
- package/dist/workspace/release-steps/targets.d.ts +31 -0
- package/dist/workspace/release-steps/targets.js +40 -0
- package/dist/workspace/release-steps/types.d.ts +104 -0
- package/dist/workspace/release-steps/types.js +2 -0
- package/dist/workspace/release-steps/verify.d.ts +3 -0
- package/dist/workspace/release-steps/verify.js +4 -0
- package/dist/workspace/release-toolchains.d.ts +59 -0
- package/dist/workspace/release-toolchains.js +133 -0
- package/dist/workspace/release-train-workflow.d.ts +29 -0
- package/dist/workspace/release-train-workflow.js +85 -0
- package/dist/workspace/release-train.d.ts +3 -1
- package/dist/workspace/release-train.js +20 -3
- package/dist/workspace/release-workflow.d.ts +160 -61
- package/dist/workspace/release-workflow.js +539 -193
- package/dist/workspace/releases.schema.json +70 -1
- package/dist/workspace/search-contract.d.ts +1 -1
- package/dist/workspace/security.js +9 -2
- package/dist/workspace/train-cut.d.ts +182 -0
- package/dist/workspace/train-cut.js +482 -0
- package/dist/workspace/train-prepare.d.ts +61 -0
- package/dist/workspace/train-prepare.js +267 -0
- package/dist/workspace/train-publish.d.ts +177 -0
- package/dist/workspace/train-publish.js +575 -0
- package/dist/workspace/train-range-labels.d.ts +33 -0
- package/dist/workspace/train-range-labels.js +109 -0
- package/dist/workspace/trust/seal.d.ts +13 -3
- package/dist/workspace/trust/seal.js +14 -4
- package/dist/workspace/work-cli.d.ts +3 -2
- package/dist/workspace/work-cli.js +3 -2
- package/dist/workspace/workspace-ledger.d.ts +14 -1
- package/dist/workspace/workspace-ledger.js +33 -7
- package/package.json +26 -26
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
*
|
|
6
6
|
* The job runs on a `release/**` tag, checks the tag out, fetches the ci tags
|
|
7
7
|
* and `chant/lifecycle`, builds what the targets upload, and runs `chant
|
|
8
|
-
* release publish` for the label the tag names.
|
|
8
|
+
* release publish` for the label the tag names. With `release.tag` (#5150)
|
|
9
|
+
* it runs on the tags the template makes instead, and reads the label from
|
|
10
|
+
* the ledger with `chant release tag`. The security groups decide
|
|
9
11
|
* the rest, and nothing is on without one (#4168 section 8):
|
|
10
12
|
*
|
|
11
13
|
* - `supply-chain` adds `--require-provenance`, so a run with no OIDC token
|
|
@@ -26,11 +28,33 @@
|
|
|
26
28
|
* `release.images` (#4657) the publish job builds the images again with
|
|
27
29
|
* `chant release images` before the build. A config with only `publish`
|
|
28
30
|
* renders the tag-triggered file it always did.
|
|
31
|
+
*
|
|
32
|
+
* `chant release doctor` (#5161) runs in the cut job before the cut of a
|
|
33
|
+
* dispatched release, unless `doctor: false`, and in the tag-triggered
|
|
34
|
+
* publish job before the build under `doctor: true`.
|
|
35
|
+
*
|
|
36
|
+
* `release.train` at the root (#5154) renders a train instead: the root's
|
|
37
|
+
* members cut together by `chant workspace train cut` and published by
|
|
38
|
+
* `chant workspace train publish` (./release-train-workflow.ts).
|
|
39
|
+
*
|
|
40
|
+
* The cut and publish jobs here are a frame of named slots (#5196). Each
|
|
41
|
+
* feature's steps (doctor, goreleaser, stamp, images, artifacts, builds,
|
|
42
|
+
* verify, signing, QEMU, the targets' setup) come from its own file under
|
|
43
|
+
* ./release-steps, which says which slot of which job they go in; a new
|
|
44
|
+
* feature adds a file there rather than lines in these functions.
|
|
29
45
|
*/
|
|
46
|
+
import { readFileSync } from "node:fs";
|
|
30
47
|
import { ACTION_PINS, tagComments, usesRef } from "../action-pins.js";
|
|
31
|
-
import {
|
|
48
|
+
import { TOOL_PINS } from "../tool-pins.js";
|
|
32
49
|
import { releaseImagePlatforms, resolveReleaseImages } from "../lifecycle/release-images.js";
|
|
33
50
|
import { GENERATED_MARKER } from "../discovery/files.js";
|
|
51
|
+
import { tagShape } from "../lifecycle/release-tag.js";
|
|
52
|
+
import { checkBuilds, releaseBuildArchive, releaseBuildArtifact, resolveToolchains, toolchainLines } from "./release-toolchains.js";
|
|
53
|
+
import { releaseJobSteps, releaseSetupSteps } from "./release-steps/index.js";
|
|
54
|
+
import { packLine } from "./release-steps/builds.js";
|
|
55
|
+
import { RELEASE_BINFMT_IMAGE, qemuArchitectures } from "./release-steps/qemu.js";
|
|
56
|
+
import { targetExtras } from "./release-steps/targets.js";
|
|
57
|
+
import { renderTrainWorkflow } from "./release-train-workflow.js";
|
|
34
58
|
export const RELEASE_WORKFLOW_FORGES = ["github", "forgejo", "gitlab"];
|
|
35
59
|
/** Where each forge's publish workflow is written, relative to the repository root. */
|
|
36
60
|
export const RELEASE_WORKFLOW_FILES = {
|
|
@@ -39,87 +63,18 @@ export const RELEASE_WORKFLOW_FILES = {
|
|
|
39
63
|
// GitLab reads one .gitlab-ci.yml, which includes this file: `include: { local: .gitlab/chant-release.yml }`.
|
|
40
64
|
gitlab: ".gitlab/chant-release.yml",
|
|
41
65
|
};
|
|
42
|
-
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*/
|
|
51
|
-
export const NPM_TRUSTED_PUBLISHING_SETUP = `have="$(npm --version)"; if [ "$(printf '%s\\n' "${NPM_TRUSTED_PUBLISHING_MIN}" "$have" | sort -V | head -n1)" != "${NPM_TRUSTED_PUBLISHING_MIN}" ]; then npm install -g npm@${NPM_TRUSTED_PUBLISHING_VERSION}; fi; npm --version`;
|
|
52
|
-
/**
|
|
53
|
-
* What a GitHub release workflow needs for its targets, worked out from them
|
|
54
|
-
* (#4786), so no product wires it by hand:
|
|
55
|
-
*
|
|
56
|
-
* - an `oci` target on `ghcr.io` that names no credentials pushes with the
|
|
57
|
-
* job's token: `packages: write`, and `OCI_USERNAME` and `OCI_PASSWORD`
|
|
58
|
-
* from `github.actor` and `github.token`;
|
|
59
|
-
* - an `npm` target on npmjs publishes with trusted publishing, which needs
|
|
60
|
-
* npm {@link NPM_TRUSTED_PUBLISHING_MIN}: the jobs upgrade npm when the
|
|
61
|
-
* runner's is older.
|
|
62
|
-
*
|
|
63
|
-
* `release.workflow` wins: a scope, variable or the same setup line it names
|
|
64
|
-
* is not added again. Other forges, and configs without such targets, get
|
|
65
|
-
* nothing.
|
|
66
|
-
*/
|
|
67
|
-
export function targetExtras(forge, targets, p) {
|
|
68
|
-
if (forge !== "github")
|
|
69
|
-
return {};
|
|
70
|
-
const ghcr = targets.some((t) => t.type === "oci" && /^ghcr\.io\//.test(t.repository ?? "") && !t.usernameEnv && !t.passwordEnv);
|
|
71
|
-
const npm = targets.some((t) => t.type === "npm" && (t.registry === undefined || /^https:\/\/registry\.npmjs\.org\/?$/.test(t.registry)));
|
|
72
|
-
const permissions = ghcr && p.permissions?.packages === undefined ? { packages: "write" } : undefined;
|
|
73
|
-
const env = ghcr ? Object.fromEntries(["OCI_USERNAME", "OCI_PASSWORD"].filter((k) => p.env?.[k] === undefined).map((k) => [k, k === "OCI_USERNAME" ? "${{ github.actor }}" : "${{ github.token }}"])) : {};
|
|
74
|
-
const setup = npm && !(p.setup ?? []).some((s) => !("uses" in s) && s.run === NPM_TRUSTED_PUBLISHING_SETUP) ? [{ run: NPM_TRUSTED_PUBLISHING_SETUP }] : [];
|
|
75
|
-
return { ...(permissions ? { permissions } : {}), ...(Object.keys(env).length > 0 ? { env } : {}), ...(setup.length > 0 ? { setup } : {}) };
|
|
76
|
-
}
|
|
77
|
-
/** The platform the jobs `chant release workflow` writes run on: GitHub's and Forgejo's `ubuntu-latest`, and a GitLab runner's default (#4876). */
|
|
78
|
-
export const RELEASE_RUNNER_PLATFORM = "linux/amd64";
|
|
79
|
-
/** The binfmt image a GitLab job installs QEMU's handlers with (#4876): the repository, which a config's own setup line is recognised by. */
|
|
80
|
-
export const RELEASE_BINFMT_IMAGE = IMAGE_PINS.binfmt.repository;
|
|
81
|
-
/** The architectures among `platforms` the runner can't run, as QEMU names them (`linux/arm/v7` is `arm`), each once. */
|
|
82
|
-
export function qemuArchitectures(platforms) {
|
|
83
|
-
return [...new Set(platforms.filter((p) => p.split("/").slice(0, 2).join("/") !== RELEASE_RUNNER_PLATFORM).map((p) => p.split("/")[1] ?? p))].sort();
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* QEMU's binfmt setup for the platforms `release.images` builds that the
|
|
87
|
-
* runner can't, such as `linux/arm64` on an amd64 runner (#4876), so no
|
|
88
|
-
* product names it in `release.workflow.setup`. GitHub and Forgejo get
|
|
89
|
-
* `docker/setup-qemu-action` at its pin; GitLab a `docker run --privileged`
|
|
90
|
-
* of {@link RELEASE_BINFMT_IMAGE} by the digest `IMAGE_PINS.binfmt` records
|
|
91
|
-
* (#4941, ../image-pins.ts), which `chant release workflow` notes needs
|
|
92
|
-
* an executor that runs privileged containers. A config whose `setup` names
|
|
93
|
-
* the action or the binfmt image already gets nothing more, so its file
|
|
94
|
-
* renders as it did.
|
|
95
|
-
*/
|
|
96
|
-
export function qemuSetup(forge, platforms, p) {
|
|
97
|
-
const archs = qemuArchitectures(platforms);
|
|
98
|
-
if (archs.length === 0)
|
|
99
|
-
return [];
|
|
100
|
-
const named = (p.setup ?? []).some((s) => ("uses" in s ? /^docker\/setup-qemu-action@/.test(s.uses) : s.run.includes(RELEASE_BINFMT_IMAGE)));
|
|
101
|
-
if (named)
|
|
102
|
-
return [];
|
|
103
|
-
return forge === "gitlab" ? [{ run: `docker run --privileged --rm ${imageRef(IMAGE_PINS.binfmt)} --install ${archs.join(",")}` }] : [{ uses: usesRef(ACTION_PINS.dockerSetupQemu4), with: { platforms: archs.join(",") } }];
|
|
104
|
-
}
|
|
66
|
+
// #5196: each feature's helpers and constants live with its steps in ./release-steps; these keep their names here.
|
|
67
|
+
export { RELEASE_RUNNER_PLATFORM } from "./release-steps/types.js";
|
|
68
|
+
export { NPM_TRUSTED_PUBLISHING_MIN, NPM_TRUSTED_PUBLISHING_SETUP, NPM_TRUSTED_PUBLISHING_VERSION, targetExtras } from "./release-steps/targets.js";
|
|
69
|
+
export { RELEASE_BINFMT_IMAGE, qemuArchitectures, qemuSetup } from "./release-steps/qemu.js";
|
|
70
|
+
export { RELEASE_ARTIFACTS_ARTIFACT, RELEASE_ARTIFACTS_STAGE } from "./release-steps/artifacts.js";
|
|
71
|
+
export { goreleaserSetup } from "./release-steps/goreleaser.js";
|
|
72
|
+
export { cosignSetup } from "./release-steps/signing.js";
|
|
73
|
+
export { RELEASE_DIGESTS_FILE, RELEASE_DIGESTS_PATHS, RELEASE_IMAGES_ARTIFACT } from "./release-steps/images.js";
|
|
105
74
|
/** The flags `chant release publish` gets under the groups. */
|
|
106
75
|
export function publishFlags(groups) {
|
|
107
76
|
return [...(groups.has("supply-chain") ? ["--require-provenance"] : []), "--yes"];
|
|
108
77
|
}
|
|
109
|
-
/** Where `chant release images` writes the digests the publish job's build reads (#4657), by default and at a workstation. */
|
|
110
|
-
export const RELEASE_DIGESTS_FILE = ".chant/release-digests.json";
|
|
111
|
-
/**
|
|
112
|
-
* Where a generated publish job writes the digests: the runner's temp
|
|
113
|
-
* directory, outside the checkout, so `chant release publish` finds the tree
|
|
114
|
-
* as the cut left it (#4853). A repository that commits files under `.chant/`
|
|
115
|
-
* can't ignore the directory, and a digests file there made the publish
|
|
116
|
-
* refuse with `release-worktree-dirty`.
|
|
117
|
-
*/
|
|
118
|
-
export const RELEASE_DIGESTS_PATHS = {
|
|
119
|
-
github: "$RUNNER_TEMP/chant-release-digests.json",
|
|
120
|
-
forgejo: "$RUNNER_TEMP/chant-release-digests.json",
|
|
121
|
-
gitlab: "/tmp/chant-release-digests.json",
|
|
122
|
-
};
|
|
123
78
|
/** A string as a single-quoted shell word. */
|
|
124
79
|
function sq(s) {
|
|
125
80
|
return `'${s.replaceAll("'", "'\\''")}'`;
|
|
@@ -128,65 +83,140 @@ function sq(s) {
|
|
|
128
83
|
export function renderReleaseWorkflow(input) {
|
|
129
84
|
const p = input.pipeline ?? {};
|
|
130
85
|
const chant = input.chant ?? p.chant ?? "npx chant";
|
|
131
|
-
const install = input.install
|
|
86
|
+
const install = input.install !== undefined ? input.install : p.install === false ? null : (p.install ?? "npm ci");
|
|
132
87
|
const build = input.build !== undefined ? input.build : p.build === false ? null : (p.build ?? "npm run build");
|
|
133
88
|
const root = input.workspaceRoot && input.workspaceRoot !== "." ? input.workspaceRoot : null;
|
|
134
|
-
const verify = input.groups.has("verified-releases");
|
|
135
89
|
const flags = publishFlags(input.groups).join(" ");
|
|
136
90
|
const after = p.after ?? [];
|
|
137
91
|
const images = input.images === true;
|
|
138
|
-
|
|
92
|
+
// #5152: the toolchains each job sets up, and the per-platform builds.
|
|
93
|
+
const files = new Set(input.projectFiles ?? (p.toolchains === undefined ? ["package.json"] : []));
|
|
94
|
+
if (input.forge === "gitlab" && p.toolchains && p.toolchains.some((t) => (typeof t === "string" ? t : t.name) !== "node")) {
|
|
95
|
+
throw new Error("release.workflow.toolchains: a GitLab job runs in its runner's image, which brings the toolchain; name the image in .gitlab-ci.yml (default: image:) and leave toolchains out");
|
|
96
|
+
}
|
|
97
|
+
const chantSetup = toolchainLines(resolveToolchains(p.toolchains === false ? false : (p.toolchains ?? []).filter((t) => (typeof t === "string" ? t : t.name) === "node"), new Set(), root, p.toolchains !== false));
|
|
98
|
+
const fullSetup = toolchainLines(resolveToolchains(p.toolchains, files, root, true));
|
|
99
|
+
const builds = p.builds ?? [];
|
|
100
|
+
if (builds.length > 0) {
|
|
101
|
+
if (p.trigger !== "dispatch")
|
|
102
|
+
throw new Error('release.workflow.builds: the tag trigger publishes a release cut before the workflow ran, so nothing built here would be in it; use trigger: "dispatch"');
|
|
103
|
+
checkBuilds(builds);
|
|
104
|
+
}
|
|
139
105
|
// #4786: the targets' own needs first, then the config's, so a config that set them by hand renders the same file without them.
|
|
140
106
|
const derived = targetExtras(input.forge, input.publish ?? [], p);
|
|
141
|
-
// #
|
|
142
|
-
const
|
|
107
|
+
// #5149: the cut asks the forge for the commit's checks with the run's token.
|
|
108
|
+
const green = input.green ?? "chant";
|
|
109
|
+
if (green === "forge-checks" && p.trigger === "dispatch" && input.forge === "github") {
|
|
110
|
+
const reads = Object.fromEntries(["checks", "statuses"].filter((k) => p.permissions?.[k] === undefined).map((k) => [k, "read"]));
|
|
111
|
+
if (Object.keys(reads).length > 0)
|
|
112
|
+
derived.permissions = { ...derived.permissions, ...reads };
|
|
113
|
+
}
|
|
114
|
+
const shape = p.trigger === "dispatch" ? "dispatch" : input.tags && !input.tags.template.legacy ? "templated" : "tag";
|
|
115
|
+
// #5196: what each feature reads; ./release-steps decides where its steps go.
|
|
116
|
+
const context = {
|
|
117
|
+
forge: input.forge,
|
|
118
|
+
shape,
|
|
119
|
+
input,
|
|
120
|
+
pipeline: p,
|
|
121
|
+
chant,
|
|
122
|
+
root,
|
|
123
|
+
verify: input.groups.has("verified-releases"),
|
|
124
|
+
images,
|
|
125
|
+
archives: shape === "dispatch" && images ? (input.imageArchives ?? []).map((a) => (root ? `${root}/${a.replace(/^\.\//, "")}` : a.replace(/^\.\//, ""))) : [],
|
|
126
|
+
artifacts: input.artifacts === true,
|
|
127
|
+
version: input.version === true,
|
|
128
|
+
doctor: shape === "dispatch" ? p.doctor !== false : p.doctor === true,
|
|
129
|
+
signing: input.signing === true,
|
|
130
|
+
green,
|
|
131
|
+
builds,
|
|
132
|
+
...(input.tags ? { tags: input.tags } : {}),
|
|
133
|
+
};
|
|
143
134
|
const extra = jobExtras({
|
|
144
135
|
...p,
|
|
145
136
|
...(derived.permissions ? { permissions: { ...p.permissions, ...derived.permissions } } : {}),
|
|
146
137
|
...(derived.env ? { env: { ...p.env, ...derived.env } } : {}),
|
|
147
|
-
|
|
138
|
+
setup: releaseSetupSteps(context),
|
|
148
139
|
}, input.forge);
|
|
149
140
|
// #4767: Forgejo's job token is not a GitHub token, and GitLab has no such expression.
|
|
150
141
|
const forgeToken = input.forge === "github" && p.env?.GITHUB_TOKEN === undefined && (input.publish ?? []).some((t) => t.type === "forge" && t.forge === "github" && !t.tokenEnv)
|
|
151
142
|
? [" GITHUB_TOKEN: ${{ github.token }}"]
|
|
152
143
|
: [];
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
144
|
+
// #5154: the root's members released as a train.
|
|
145
|
+
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
|
+
if (builds.length > 0)
|
|
149
|
+
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
|
+
if (images || input.artifacts)
|
|
151
|
+
throw new Error("release.images and release.artifacts at the root: a train releases its members, and the workflow hands no image or file between its jobs; declare them in a member and release that member on its own");
|
|
152
|
+
return renderTrainWorkflow({
|
|
153
|
+
forge: input.forge,
|
|
154
|
+
env: input.train.env,
|
|
155
|
+
trigger: p.trigger === "dispatch" ? "dispatch" : "tag",
|
|
156
|
+
chant,
|
|
157
|
+
install,
|
|
158
|
+
build,
|
|
159
|
+
root,
|
|
160
|
+
flags,
|
|
161
|
+
after,
|
|
162
|
+
chantSetup,
|
|
163
|
+
fullSetup,
|
|
164
|
+
extra: jobExtras({ ...p, ...(derived.permissions ? { permissions: { ...p.permissions, ...derived.permissions } } : {}), ...(derived.env ? { env: { ...p.env, ...derived.env } } : {}), setup: releaseSetupSteps({ forge: input.forge, shape: "dispatch", input, pipeline: p, chant, root, verify: false, images: false, archives: [], artifacts: false, version: false, doctor: false, signing: input.signing === true, green, builds: [] }) }, input.forge),
|
|
165
|
+
forgeToken,
|
|
166
|
+
cutToken: green === "forge-checks" && p.env?.GITHUB_TOKEN === undefined ? [" GITHUB_TOKEN: ${{ github.token }}"] : [],
|
|
167
|
+
green,
|
|
168
|
+
gate: p.gate ?? "last-green",
|
|
169
|
+
...(input.lane ? { lane: input.lane } : {}),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (shape === "dispatch") {
|
|
173
|
+
const cutToken = green === "forge-checks" && input.forge !== "gitlab" && p.env?.GITHUB_TOKEN === undefined ? [" GITHUB_TOKEN: ${{ github.token }}"] : [];
|
|
174
|
+
const buildJobs = builds.map((b) => ({ ...b, setup: toolchainLines(resolveToolchains(b.toolchains !== undefined ? b.toolchains : p.toolchains, files, root, false)) }));
|
|
175
|
+
if (input.forge === "gitlab" && builds.some((b) => b.toolchains && b.toolchains.length > 0))
|
|
176
|
+
throw new Error("release.workflow.builds: toolchains: a GitLab job runs in its runner's image, which brings the toolchain; leave toolchains out");
|
|
177
|
+
const o = { context, chant, install, chantSetup, fullSetup, builds: buildJobs, build, root, flags, after, forge: input.forge, extra, forgeToken, cutToken, green, doctor: context.doctor, gate: p.gate ?? "last-green", ...(input.lane ? { lane: input.lane } : {}) };
|
|
156
178
|
return input.forge === "gitlab" ? renderGitlabDispatch(o) : renderGithubDispatch(o);
|
|
157
179
|
}
|
|
158
|
-
// #
|
|
159
|
-
|
|
160
|
-
|
|
180
|
+
// #5150: a release.tag template triggers on its own tags.
|
|
181
|
+
if (shape === "templated") {
|
|
182
|
+
return renderTemplatedTagWorkflow(input, { context, chant, install, fullSetup, build, root, flags, after, extra, forgeToken, tags: input.tags });
|
|
183
|
+
}
|
|
184
|
+
// #4657: steps that read the release (the images, the artifacts) fetch the ci tags and chant/lifecycle before them, and the build runs after.
|
|
161
185
|
if (input.forge === "gitlab") {
|
|
162
186
|
const label = '"${CI_COMMIT_TAG#release/}"';
|
|
163
187
|
const fetches = [" - git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'", " - git fetch origin chant/lifecycle:chant/lifecycle"];
|
|
188
|
+
const at = releaseJobSteps({ ...context, job: "publish", label });
|
|
189
|
+
const step = (slot) => stepLines(at(slot), (l) => ` - ${l}`);
|
|
190
|
+
const beforeBuild = step("beforeBuild");
|
|
164
191
|
const lines = [
|
|
165
192
|
"chant-release-publish:",
|
|
166
193
|
" rules:",
|
|
167
194
|
" - if: $CI_COMMIT_TAG =~ /^release\\//",
|
|
168
|
-
"
|
|
169
|
-
" SIGSTORE_ID_TOKEN:",
|
|
170
|
-
" aud: sigstore",
|
|
195
|
+
...publishIdTokens(at("idTokens")),
|
|
171
196
|
...(extra.gitlabVariables.length > 0 ? [" variables:", ...extra.gitlabVariables] : []),
|
|
172
197
|
" script:",
|
|
173
198
|
...(root ? [` - cd ${root}`] : []),
|
|
174
|
-
` - ${install}
|
|
199
|
+
...(install ? [` - ${install}`] : []),
|
|
175
200
|
...extra.gitlabScript.map((l) => ` - ${l}`),
|
|
176
|
-
...(
|
|
177
|
-
...(
|
|
201
|
+
...step("prepare"),
|
|
202
|
+
...(beforeBuild.length > 0 ? fetches : []),
|
|
203
|
+
...beforeBuild,
|
|
178
204
|
...(build ? [` - ${build}`] : []),
|
|
179
|
-
...(
|
|
180
|
-
...(
|
|
205
|
+
...(beforeBuild.length > 0 ? [] : fetches),
|
|
206
|
+
...step("afterBuild"),
|
|
207
|
+
...step("beforePublish"),
|
|
181
208
|
` - ${chant} release publish ${label} ${flags}`,
|
|
182
209
|
];
|
|
183
210
|
if (after.length > 0) {
|
|
184
|
-
lines.push("", "chant-release-after:", " rules:", " - if: $CI_COMMIT_TAG =~ /^release\\//", " needs: [chant-release-publish]", " script:", ' - export CHANT_RELEASE_LABEL="${CI_COMMIT_TAG#release/}"', ...(root ? [` - cd ${root}`] : []), ` - ${install}
|
|
211
|
+
lines.push("", "chant-release-after:", " rules:", " - if: $CI_COMMIT_TAG =~ /^release\\//", " needs: [chant-release-publish]", " script:", ' - export CHANT_RELEASE_LABEL="${CI_COMMIT_TAG#release/}"', ...(root ? [` - cd ${root}`] : []), ...(install ? [` - ${install}`] : []), ...after.map((l) => ` - ${l}`));
|
|
185
212
|
}
|
|
186
213
|
return `${lines.join("\n")}\n`;
|
|
187
214
|
}
|
|
188
215
|
const label = '"${GITHUB_REF_NAME#release/}"';
|
|
189
216
|
const fetches = [" - run: git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'", " - run: git fetch origin chant/lifecycle:chant/lifecycle"];
|
|
217
|
+
const at = releaseJobSteps({ ...context, job: "publish", label });
|
|
218
|
+
const step = (slot) => stepLines(at(slot), (l) => ` - run: ${l}`);
|
|
219
|
+
const beforeBuild = step("beforeBuild");
|
|
190
220
|
const lines = [
|
|
191
221
|
"name: chant release publish",
|
|
192
222
|
"on:",
|
|
@@ -202,23 +232,144 @@ export function renderReleaseWorkflow(input) {
|
|
|
202
232
|
...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []),
|
|
203
233
|
...extra.githubEnv(forgeToken),
|
|
204
234
|
" steps:",
|
|
205
|
-
...githubSetup(),
|
|
206
|
-
` - run: ${install}
|
|
235
|
+
...githubSetup(undefined, fullSetup),
|
|
236
|
+
...(install ? [` - run: ${install}`] : []),
|
|
207
237
|
...extra.githubSteps,
|
|
208
|
-
...(
|
|
209
|
-
...(
|
|
238
|
+
...step("prepare"),
|
|
239
|
+
...(beforeBuild.length > 0 ? fetches : []),
|
|
240
|
+
...beforeBuild,
|
|
210
241
|
...(build ? [` - run: ${build}`] : []),
|
|
211
|
-
...(
|
|
212
|
-
...(
|
|
242
|
+
...(beforeBuild.length > 0 ? [] : fetches),
|
|
243
|
+
...step("afterBuild"),
|
|
244
|
+
...step("beforePublish"),
|
|
213
245
|
` - run: ${chant} release publish ${label} ${flags}`,
|
|
214
246
|
];
|
|
215
247
|
if (after.length > 0) {
|
|
216
|
-
lines.push(" after-release:", " needs: publish", " runs-on: ubuntu-latest", ...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []), " steps:", ...githubSetup(), ' - run: echo "CHANT_RELEASE_LABEL=${GITHUB_REF_NAME#release/}" >> "$GITHUB_ENV"', ` - run: ${install}
|
|
248
|
+
lines.push(" after-release:", " needs: publish", " runs-on: ubuntu-latest", ...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []), " steps:", ...githubSetup(undefined, fullSetup), ' - run: echo "CHANT_RELEASE_LABEL=${GITHUB_REF_NAME#release/}" >> "$GITHUB_ENV"', ...(install ? [` - run: ${install}`] : []), ...after.map((l) => ` - run: ${l}`));
|
|
249
|
+
}
|
|
250
|
+
return tagComments(`${lines.join("\n")}\n`);
|
|
251
|
+
}
|
|
252
|
+
/** A job's steps as lines: each shell line as the job writes one, and each feature's own lines as they are. */
|
|
253
|
+
function stepLines(items, run) {
|
|
254
|
+
return items.flatMap((i) => (typeof i === "string" ? [run(i)] : i.lines));
|
|
255
|
+
}
|
|
256
|
+
/** A GitLab publish job's `id_tokens:`: `SIGSTORE_ID_TOKEN`, and the entries the features add. */
|
|
257
|
+
function publishIdTokens(extra) {
|
|
258
|
+
return [" id_tokens:", " SIGSTORE_ID_TOKEN:", " aud: sigstore", ...stepLines(extra, (l) => l)];
|
|
259
|
+
}
|
|
260
|
+
/** A glob character GitHub's and Forgejo's tag filters treat as special, escaped. */
|
|
261
|
+
function globLiteral(s) {
|
|
262
|
+
return s.replace(/[*?+[\]!\\]/g, (c) => `\\${c}`);
|
|
263
|
+
}
|
|
264
|
+
/** A literal for a GitLab (RE2) regex between slashes. */
|
|
265
|
+
function regexLiteral(s) {
|
|
266
|
+
return s.replace(/[.*+?^${}()|[\]\\/]/g, (c) => `\\${c}`);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* The filters for the tags a template makes (#5150): GitHub and Forgejo
|
|
270
|
+
* globs (the release tags, and a negated pattern for the floating tag so its
|
|
271
|
+
* move starts nothing), and GitLab's rule.
|
|
272
|
+
*/
|
|
273
|
+
export function releaseTagFilters(tags) {
|
|
274
|
+
const name = tagShape(tags.template.name, tags.place);
|
|
275
|
+
const floating = tags.template.floating ? tagShape(tags.template.floating, tags.place) : null;
|
|
276
|
+
const globs = [`${globLiteral(name.prefix)}*${globLiteral(name.suffix)}`, ...(floating ? [`!${globLiteral(floating.prefix)}[0-9]+${globLiteral(floating.suffix)}`] : [])];
|
|
277
|
+
const re = (s, v) => `/^${regexLiteral(s.prefix)}${v}${regexLiteral(s.suffix)}$/`;
|
|
278
|
+
const gitlabRule = `$CI_COMMIT_TAG =~ ${re(name, "[A-Za-z0-9._+-]+")}${floating ? ` && $CI_COMMIT_TAG !~ ${re(floating, "[0-9]+")}` : ""}`;
|
|
279
|
+
return { globs, gitlabRule };
|
|
280
|
+
}
|
|
281
|
+
/** The shell that reads the label of the tag `ref` names from the ledger and refuses a tag that names no release. */
|
|
282
|
+
function labelOfRefScript(chant, ref) {
|
|
283
|
+
return [
|
|
284
|
+
`label="$(${chant} release tag "${ref}" --json | ${field("d.label")})" || label=""`,
|
|
285
|
+
`if [ -z "$label" ]; then echo "${ref} names no release of this member, so nothing is published" >&2; exit 1; fi`,
|
|
286
|
+
];
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* The tag-triggered publish workflow for a `release.tag` template (#5150).
|
|
290
|
+
* It runs on the template's tags, fetches `chant/lifecycle` first, and
|
|
291
|
+
* reads the release's label from the ledger with `chant release tag`, since
|
|
292
|
+
* a tag is the label's rendering and is never parsed.
|
|
293
|
+
*/
|
|
294
|
+
function renderTemplatedTagWorkflow(input, o) {
|
|
295
|
+
const { chant, install, fullSetup, build, root, flags, after, extra, forgeToken } = o;
|
|
296
|
+
const filters = releaseTagFilters(o.tags);
|
|
297
|
+
const label = '"$CHANT_RELEASE_LABEL"';
|
|
298
|
+
const ciFetch = "git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'";
|
|
299
|
+
const ledgerFetch = "git fetch origin chant/lifecycle:chant/lifecycle";
|
|
300
|
+
const at = releaseJobSteps({ ...o.context, job: "publish", label });
|
|
301
|
+
if (input.forge === "gitlab") {
|
|
302
|
+
const q = (l) => ` - ${JSON.stringify(l)}`;
|
|
303
|
+
const step = (slot) => stepLines(at(slot), q);
|
|
304
|
+
const beforeBuild = step("beforeBuild");
|
|
305
|
+
const labelLines = [ledgerFetch, ...labelOfRefScript(chant, "$CI_COMMIT_TAG"), 'export CHANT_RELEASE_LABEL="$label"'];
|
|
306
|
+
const lines = [
|
|
307
|
+
"chant-release-publish:",
|
|
308
|
+
" rules:",
|
|
309
|
+
` - if: ${filters.gitlabRule}`,
|
|
310
|
+
...publishIdTokens(at("idTokens")),
|
|
311
|
+
...(extra.gitlabVariables.length > 0 ? [" variables:", ...extra.gitlabVariables] : []),
|
|
312
|
+
" script:",
|
|
313
|
+
...(root ? [q(`cd ${root}`)] : []),
|
|
314
|
+
...(install ? [q(install)] : []),
|
|
315
|
+
...extra.gitlabScript.map(q),
|
|
316
|
+
...labelLines.map(q),
|
|
317
|
+
...step("prepare"),
|
|
318
|
+
...(beforeBuild.length > 0 ? [q(ciFetch)] : []),
|
|
319
|
+
...beforeBuild,
|
|
320
|
+
...(build ? [q(build)] : []),
|
|
321
|
+
...(beforeBuild.length > 0 ? [] : [q(ciFetch)]),
|
|
322
|
+
...step("afterBuild"),
|
|
323
|
+
...step("beforePublish"),
|
|
324
|
+
q(`${chant} release publish ${label} ${flags}`),
|
|
325
|
+
];
|
|
326
|
+
if (after.length > 0) {
|
|
327
|
+
lines.push("", "chant-release-after:", " rules:", ` - if: ${filters.gitlabRule}`, " needs: [chant-release-publish]", " script:", ...(root ? [q(`cd ${root}`)] : []), ...(install ? [q(install)] : []), ...labelLines.map(q), ...after.map((l) => ` - ${l}`));
|
|
328
|
+
}
|
|
329
|
+
return `${lines.join("\n")}\n`;
|
|
330
|
+
}
|
|
331
|
+
const run = (l) => ` - run: ${l}`;
|
|
332
|
+
const step = (slot) => stepLines(at(slot), run);
|
|
333
|
+
const beforeBuild = step("beforeBuild");
|
|
334
|
+
const lines = [
|
|
335
|
+
"name: chant release publish",
|
|
336
|
+
"on:",
|
|
337
|
+
" push:",
|
|
338
|
+
` tags: [${filters.globs.map((g) => JSON.stringify(g)).join(", ")}]`,
|
|
339
|
+
"permissions:",
|
|
340
|
+
" contents: write",
|
|
341
|
+
" id-token: write",
|
|
342
|
+
...extra.permissions,
|
|
343
|
+
"jobs:",
|
|
344
|
+
" publish:",
|
|
345
|
+
" runs-on: ubuntu-latest",
|
|
346
|
+
...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []),
|
|
347
|
+
...(after.length > 0 ? [" outputs:", " label: ${{ steps.label.outputs.label }}"] : []),
|
|
348
|
+
...extra.githubEnv(forgeToken),
|
|
349
|
+
" steps:",
|
|
350
|
+
...githubSetup(undefined, fullSetup),
|
|
351
|
+
...(install ? [run(install)] : []),
|
|
352
|
+
...extra.githubSteps,
|
|
353
|
+
run(ledgerFetch),
|
|
354
|
+
" - id: label",
|
|
355
|
+
" run: |",
|
|
356
|
+
...[...labelOfRefScript(chant, "$GITHUB_REF_NAME"), 'echo "CHANT_RELEASE_LABEL=$label" >> "$GITHUB_ENV"', 'echo "label=$label" >> "$GITHUB_OUTPUT"'].map((l) => ` ${l}`),
|
|
357
|
+
...step("prepare"),
|
|
358
|
+
...(beforeBuild.length > 0 ? [run(ciFetch)] : []),
|
|
359
|
+
...beforeBuild,
|
|
360
|
+
...(build ? [run(build)] : []),
|
|
361
|
+
...(beforeBuild.length > 0 ? [] : [run(ciFetch)]),
|
|
362
|
+
...step("afterBuild"),
|
|
363
|
+
...step("beforePublish"),
|
|
364
|
+
run(`${chant} release publish ${label} ${flags}`),
|
|
365
|
+
];
|
|
366
|
+
if (after.length > 0) {
|
|
367
|
+
lines.push(" after-release:", " needs: publish", " runs-on: ubuntu-latest", ...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []), " env:", " CHANT_RELEASE_LABEL: ${{ needs.publish.outputs.label }}", " steps:", ...githubSetup(undefined, fullSetup), ...(install ? [run(install)] : []), ...after.map(run));
|
|
217
368
|
}
|
|
218
369
|
return tagComments(`${lines.join("\n")}\n`);
|
|
219
370
|
}
|
|
220
371
|
/** `release.workflow`'s `permissions`, `env` and `setup` (#4751) as lines of the forge's file. Empty for a config without them, so its file is what it was. */
|
|
221
|
-
function jobExtras(p, forge) {
|
|
372
|
+
export function jobExtras(p, forge) {
|
|
222
373
|
const permissions = Object.entries(p.permissions ?? {});
|
|
223
374
|
const env = Object.entries(p.env ?? {});
|
|
224
375
|
const setup = p.setup ?? [];
|
|
@@ -264,40 +415,25 @@ function jobExtras(p, forge) {
|
|
|
264
415
|
gitlabScript: setup.flatMap((s) => ("uses" in s ? [] : [...Object.entries(s.env ?? {}).map(([k, v]) => `export ${k}=${q(v)}`), s.run])),
|
|
265
416
|
};
|
|
266
417
|
}
|
|
267
|
-
/** The checkout and
|
|
268
|
-
function githubSetup(ref) {
|
|
418
|
+
/** The checkout and toolchain setup a GitHub or Forgejo job starts with (#5152); `ref` checks out that commit. */
|
|
419
|
+
export function githubSetup(ref, setup, persist = true) {
|
|
269
420
|
return [
|
|
270
421
|
` - uses: ${usesRef(ACTION_PINS.checkout4)}`,
|
|
271
422
|
" with:",
|
|
272
423
|
...(ref ? [` ref: ${ref}`] : []),
|
|
273
424
|
" fetch-depth: 0",
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
" node-version: 24",
|
|
277
|
-
" registry-url: https://registry.npmjs.org",
|
|
425
|
+
...(persist ? [] : [" persist-credentials: false"]),
|
|
426
|
+
...setup,
|
|
278
427
|
];
|
|
279
428
|
}
|
|
280
|
-
/** The
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
function commonDir(paths) {
|
|
284
|
-
const dirs = paths.map((p) => p.split("/").slice(0, -1));
|
|
285
|
-
const first = dirs[0] ?? [];
|
|
286
|
-
let n = 0;
|
|
287
|
-
while (n < first.length && dirs.every((d) => d[n] === first[n]))
|
|
288
|
-
n++;
|
|
289
|
-
return first.slice(0, n).join("/") || ".";
|
|
290
|
-
}
|
|
291
|
-
/** The `release images` line of a publish job: checking the archives handed on, or building them again. */
|
|
292
|
-
function imagesLine(o) {
|
|
293
|
-
return `${o.chant} release images "$CHANT_RELEASE_LABEL"${o.archives.length > 0 ? " --no-build" : ""} -o "${RELEASE_DIGESTS_PATHS[o.forge]}"`;
|
|
294
|
-
}
|
|
295
|
-
/** The publish job's `release stamp` line (#4840). */
|
|
296
|
-
function stampLine(o) {
|
|
297
|
-
return `${o.chant} release stamp "$CHANT_RELEASE_LABEL"`;
|
|
429
|
+
/** The cut job's token lines: `forge-checks`' (#5149) and, when the doctor runs there (#5161), the publish job's forge token, once. */
|
|
430
|
+
function cutEnvToken(o) {
|
|
431
|
+
return [...new Set([...o.cutToken, ...(o.doctor ? o.forgeToken : [])])];
|
|
298
432
|
}
|
|
433
|
+
/** The label in a dispatched release's cut and publish jobs. */
|
|
434
|
+
const DISPATCH_LABEL = '"$CHANT_RELEASE_LABEL"';
|
|
299
435
|
/** The node one-liner that prints a JSON document's field from stdin, or from the file its argument names. */
|
|
300
|
-
const field = (path) => `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}??""))'`;
|
|
436
|
+
export const field = (path) => `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}??""))'`;
|
|
301
437
|
/**
|
|
302
438
|
* GitHub refuses the job's token a ref on a commit whose workflow files differ
|
|
303
439
|
* from the default branch's (#4852). The gate checks before the cut builds
|
|
@@ -316,7 +452,10 @@ function workflowFilesCheck(dispatched) {
|
|
|
316
452
|
];
|
|
317
453
|
}
|
|
318
454
|
/** 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. */
|
|
319
|
-
function gateScript(o, dispatched) {
|
|
455
|
+
export function gateScript(o, dispatched) {
|
|
456
|
+
// #5149: with no ci/green tags to search, the gate names the dispatched commit and the cut checks it.
|
|
457
|
+
if (o.green !== "chant")
|
|
458
|
+
return [`commit="${dispatched}"`];
|
|
320
459
|
return [
|
|
321
460
|
`commit="$(${o.chant} ci last-green --from "${dispatched}"${o.lane ? ` --lane ${o.lane}` : ""} --json | ${field("d.commit?.sha")})"`,
|
|
322
461
|
`if [ -z "$commit" ]; then echo "no green commit at or below ${dispatched}, so no release is cut" >&2; exit 1; fi`,
|
|
@@ -324,6 +463,21 @@ function gateScript(o, dispatched) {
|
|
|
324
463
|
...(o.forge === "github" && o.gate !== "head" ? workflowFilesCheck(dispatched) : []),
|
|
325
464
|
];
|
|
326
465
|
}
|
|
466
|
+
/**
|
|
467
|
+
* The gate's line that decides the label (#5159): the one dispatched, or for
|
|
468
|
+
* `auto` the one `chant release next` computes at the gate's commit from the
|
|
469
|
+
* commits and intent files since the member's previous release. One line,
|
|
470
|
+
* so GitLab runs it as one command.
|
|
471
|
+
*/
|
|
472
|
+
function labelScript(o) {
|
|
473
|
+
return [
|
|
474
|
+
'label="$CHANT_RELEASE_LABEL"',
|
|
475
|
+
`if [ "$label" = auto ]; then ${LEDGER_FETCH_FIRST}`,
|
|
476
|
+
`next="$(${o.chant} release next --at "$commit" --json)" || { echo "release next found no label for $commit, so no release is cut: $next" >&2; exit 1; }`,
|
|
477
|
+
`label="$(printf '%s' "$next" | ${field("d.label")})"`,
|
|
478
|
+
"fi",
|
|
479
|
+
].join("; ");
|
|
480
|
+
}
|
|
327
481
|
/** The cut's shell: cut the label at the gate's commit, then push the tag the cut made. */
|
|
328
482
|
function cutScript(o, out) {
|
|
329
483
|
return [
|
|
@@ -340,20 +494,65 @@ function cutScript(o, out) {
|
|
|
340
494
|
* the branch is not an error here; any other failure of git still stops the
|
|
341
495
|
* job. The publish job runs after the cut has pushed it and fetches it plainly.
|
|
342
496
|
*/
|
|
343
|
-
const LEDGER_FETCH_FIRST = 'rc=0; git ls-remote --exit-code --heads origin chant/lifecycle >/dev/null || rc=$?; if [ "$rc" = 0 ]; then git fetch origin chant/lifecycle:chant/lifecycle; elif [ "$rc" != 2 ]; then exit "$rc"; fi';
|
|
497
|
+
export const LEDGER_FETCH_FIRST = 'rc=0; git ls-remote --exit-code --heads origin chant/lifecycle >/dev/null || rc=$?; if [ "$rc" = 0 ]; then git fetch origin chant/lifecycle:chant/lifecycle; elif [ "$rc" != 2 ]; then exit "$rc"; fi';
|
|
498
|
+
/** The label the gate decided (#5159): the dispatched one, or the one `auto` resolved to. */
|
|
499
|
+
const GATE_LABEL = "${{ needs.gate.outputs.label }}";
|
|
344
500
|
/** GitHub and Forgejo: the release started by hand with a label (#4656). */
|
|
345
501
|
function renderGithubDispatch(o) {
|
|
346
502
|
const defaults = o.root ? [" defaults:", " run:", ` working-directory: ${o.root}`] : [];
|
|
347
503
|
const commit = "${{ needs.gate.outputs.commit }}";
|
|
348
504
|
const fetches = [" - run: git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'", " - run: git fetch origin chant/lifecycle:chant/lifecycle"];
|
|
349
505
|
const block = (lines) => [" - run: |", ...lines.map((l) => ` ${l}`)];
|
|
506
|
+
const installLines = o.install ? [` - run: ${o.install}`] : [];
|
|
507
|
+
const q = (v) => JSON.stringify(v);
|
|
508
|
+
const upload = usesRef(o.forge === "forgejo" ? ACTION_PINS.uploadArtifact3 : ACTION_PINS.uploadArtifact4);
|
|
509
|
+
// #5152: each build job runs on its own runner with the commit, its toolchains and nothing else: no secrets, and a token that can only read.
|
|
510
|
+
const buildJobs = o.builds.flatMap((b) => {
|
|
511
|
+
const install = b.install === false ? null : (b.install ?? o.install);
|
|
512
|
+
const runner = Array.isArray(b.runner) ? `[${b.runner.map(q).join(", ")}]` : q(b.runner);
|
|
513
|
+
const env = Object.entries(b.env ?? {});
|
|
514
|
+
for (const [k] of env)
|
|
515
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k))
|
|
516
|
+
throw new Error(`release.workflow.builds.${b.name}.env: ${JSON.stringify(k)} is not a variable name`);
|
|
517
|
+
return [
|
|
518
|
+
` build-${b.name}:`,
|
|
519
|
+
" needs: gate",
|
|
520
|
+
` runs-on: ${runner}`,
|
|
521
|
+
" permissions:",
|
|
522
|
+
" contents: read",
|
|
523
|
+
" defaults:",
|
|
524
|
+
" run:",
|
|
525
|
+
" shell: bash",
|
|
526
|
+
...(o.root ? [` working-directory: ${o.root}`] : []),
|
|
527
|
+
" env:",
|
|
528
|
+
` CHANT_RELEASE_LABEL: ${GATE_LABEL}`,
|
|
529
|
+
...env.map(([k, v]) => ` ${k}: ${q(v)}`),
|
|
530
|
+
" steps:",
|
|
531
|
+
...githubSetup(commit, b.setup, false),
|
|
532
|
+
...(install ? [` - run: ${install}`] : []),
|
|
533
|
+
` - run: ${q(b.build)}`,
|
|
534
|
+
` - run: ${q(packLine(b))}`,
|
|
535
|
+
` - uses: ${upload}`,
|
|
536
|
+
" with:",
|
|
537
|
+
` name: ${releaseBuildArtifact(b.name)}`,
|
|
538
|
+
` path: ${o.root ? `${o.root}/` : ""}${releaseBuildArchive(b.name)}`,
|
|
539
|
+
" if-no-files-found: error",
|
|
540
|
+
" retention-days: 1",
|
|
541
|
+
];
|
|
542
|
+
});
|
|
543
|
+
const run = (l) => ` - run: ${l}`;
|
|
544
|
+
const cut = releaseJobSteps({ ...o.context, job: "cut", label: DISPATCH_LABEL });
|
|
545
|
+
const publish = releaseJobSteps({ ...o.context, job: "publish", label: DISPATCH_LABEL });
|
|
546
|
+
const cutStep = (slot) => stepLines(cut(slot), run);
|
|
547
|
+
const publishStep = (slot) => stepLines(publish(slot), run);
|
|
548
|
+
const built = o.builds.map((b) => `build-${b.name}`);
|
|
350
549
|
const lines = [
|
|
351
550
|
"name: chant release",
|
|
352
551
|
"on:",
|
|
353
552
|
" workflow_dispatch:",
|
|
354
553
|
" inputs:",
|
|
355
554
|
" label:",
|
|
356
|
-
" description: The release's label, such as v1.4.0",
|
|
555
|
+
" description: The release's label, such as v1.4.0, or auto for the one chant release next computes",
|
|
357
556
|
" required: true",
|
|
358
557
|
" type: string",
|
|
359
558
|
"permissions:",
|
|
@@ -371,57 +570,49 @@ function renderGithubDispatch(o) {
|
|
|
371
570
|
...defaults,
|
|
372
571
|
" outputs:",
|
|
373
572
|
" commit: ${{ steps.green.outputs.commit }}",
|
|
573
|
+
" label: ${{ steps.green.outputs.label }}",
|
|
374
574
|
" steps:",
|
|
375
|
-
...githubSetup(),
|
|
376
|
-
|
|
575
|
+
...githubSetup(undefined, o.chantSetup),
|
|
576
|
+
...installLines,
|
|
377
577
|
fetches[0],
|
|
378
578
|
" - id: green",
|
|
379
579
|
" run: |",
|
|
380
|
-
...[...gateScript(o, "$GITHUB_SHA"), 'echo "commit=$commit" >> "$GITHUB_OUTPUT"'].map((l) => ` ${l}`),
|
|
580
|
+
...[...gateScript(o, "$GITHUB_SHA"), labelScript(o), 'echo "commit=$commit" >> "$GITHUB_OUTPUT"', 'echo "label=$label" >> "$GITHUB_OUTPUT"'].map((l) => ` ${l}`),
|
|
581
|
+
...buildJobs,
|
|
381
582
|
" cut:",
|
|
382
|
-
|
|
583
|
+
` needs: ${built.length > 0 ? `[gate, ${built.join(", ")}]` : "gate"}`,
|
|
383
584
|
" runs-on: ubuntu-latest",
|
|
384
585
|
...defaults,
|
|
385
|
-
...o.extra.githubEnv([` CHANT_RELEASE_COMMIT: ${commit}`]),
|
|
586
|
+
...o.extra.githubEnv([` CHANT_RELEASE_COMMIT: ${commit}`, ` CHANT_RELEASE_LABEL: ${GATE_LABEL}`, ...cutEnvToken(o)]),
|
|
386
587
|
" steps:",
|
|
387
|
-
...githubSetup(commit),
|
|
388
|
-
|
|
588
|
+
...githubSetup(commit, o.fullSetup),
|
|
589
|
+
...installLines,
|
|
389
590
|
...o.extra.githubSteps,
|
|
591
|
+
...cutStep("prepare"),
|
|
390
592
|
fetches[0],
|
|
391
593
|
` - run: ${LEDGER_FETCH_FIRST}`,
|
|
594
|
+
...cutStep("beforeCut"),
|
|
392
595
|
...block(cutScript(o, '"$RUNNER_TEMP/chant-cut.json"')),
|
|
393
|
-
...(
|
|
394
|
-
? [
|
|
395
|
-
` - uses: ${usesRef(o.forge === "forgejo" ? ACTION_PINS.uploadArtifact3 : ACTION_PINS.uploadArtifact4)}`,
|
|
396
|
-
" with:",
|
|
397
|
-
` name: ${RELEASE_IMAGES_ARTIFACT}`,
|
|
398
|
-
" path: |",
|
|
399
|
-
...o.archives.map((a) => ` ${a}`),
|
|
400
|
-
" if-no-files-found: error",
|
|
401
|
-
" retention-days: 1",
|
|
402
|
-
]
|
|
403
|
-
: []),
|
|
596
|
+
...cutStep("afterCut"),
|
|
404
597
|
" publish:",
|
|
405
|
-
|
|
598
|
+
` needs: [gate, cut${built.map((b) => `, ${b}`).join("")}]`,
|
|
406
599
|
" runs-on: ubuntu-latest",
|
|
407
600
|
...defaults,
|
|
408
|
-
...o.extra.githubEnv(o.forgeToken),
|
|
601
|
+
...o.extra.githubEnv([` CHANT_RELEASE_LABEL: ${GATE_LABEL}`, ...o.forgeToken]),
|
|
409
602
|
" steps:",
|
|
410
|
-
...githubSetup(commit),
|
|
411
|
-
|
|
603
|
+
...githubSetup(commit, o.fullSetup),
|
|
604
|
+
...installLines,
|
|
412
605
|
...o.extra.githubSteps,
|
|
413
606
|
...fetches,
|
|
414
|
-
...(
|
|
415
|
-
|
|
416
|
-
: []),
|
|
417
|
-
...(o.version ? [` - run: ${stampLine(o)}`] : []),
|
|
418
|
-
...(o.images ? [` - run: ${imagesLine(o)}`, ` - run: echo "CHANT_RELEASE_DIGESTS=${RELEASE_DIGESTS_PATHS[o.forge]}" >> "$GITHUB_ENV"`] : []),
|
|
607
|
+
...publishStep("prepare"),
|
|
608
|
+
...publishStep("beforeBuild"),
|
|
419
609
|
...(o.build ? [` - run: ${o.build}`] : []),
|
|
420
|
-
...(
|
|
610
|
+
...publishStep("afterBuild"),
|
|
611
|
+
...publishStep("beforePublish"),
|
|
421
612
|
` - run: ${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
|
|
422
613
|
];
|
|
423
614
|
if (o.after.length > 0) {
|
|
424
|
-
lines.push(" after-release:", " needs: [gate, publish]", " runs-on: ubuntu-latest", ...defaults, " steps:", ...githubSetup(commit
|
|
615
|
+
lines.push(" after-release:", " needs: [gate, publish]", " runs-on: ubuntu-latest", ...defaults, " env:", ` CHANT_RELEASE_LABEL: ${GATE_LABEL}`, " steps:", ...githubSetup(commit, o.fullSetup), ...installLines, ...o.after.map((l) => ` - run: ${l}`));
|
|
425
616
|
}
|
|
426
617
|
return tagComments(`${lines.join("\n")}\n`);
|
|
427
618
|
}
|
|
@@ -434,6 +625,7 @@ function renderGithubDispatch(o) {
|
|
|
434
625
|
*/
|
|
435
626
|
function renderGitlabDispatch(o) {
|
|
436
627
|
const cd = o.root ? [`cd ${o.root}`] : [];
|
|
628
|
+
const install = o.install ? [o.install] : [];
|
|
437
629
|
const fetches = ["git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'", "git fetch origin chant/lifecycle:chant/lifecycle"];
|
|
438
630
|
const auth = [
|
|
439
631
|
`chant_auth="$(printf 'oauth2:%s' "$CHANT_RELEASE_TOKEN" | base64 | tr -d '\\n')"`,
|
|
@@ -450,32 +642,87 @@ function renderGitlabDispatch(o) {
|
|
|
450
642
|
...(needs.length > 0 ? [` needs: [${needs.join(", ")}]`] : []),
|
|
451
643
|
...extra,
|
|
452
644
|
" script:",
|
|
453
|
-
|
|
645
|
+
// #5159: a pipeline variable outranks the gate's dotenv, so the label the gate decided comes in as CHANT_RELEASE_NEXT.
|
|
646
|
+
...stepLines([...(needs.length > 0 ? ['export CHANT_RELEASE_LABEL="$CHANT_RELEASE_NEXT"'] : []), ...script], (l) => ` - ${JSON.stringify(l)}`),
|
|
454
647
|
];
|
|
455
648
|
const checkout = ['git checkout --detach "$CHANT_RELEASE_COMMIT"'];
|
|
649
|
+
// #5152: a build job per runner (tags), whose archive GitLab hands to the jobs that need it, in the project directory.
|
|
650
|
+
const built = o.builds.map((b) => `chant-release-build-${b.name}`);
|
|
651
|
+
const buildJobs = o.builds.flatMap((b) => {
|
|
652
|
+
const binstall = b.install === false ? [] : b.install ? [b.install] : install;
|
|
653
|
+
const env = Object.entries(b.env ?? {});
|
|
654
|
+
for (const [k] of env)
|
|
655
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k))
|
|
656
|
+
throw new Error(`release.workflow.builds.${b.name}.env: ${JSON.stringify(k)} is not a variable name`);
|
|
657
|
+
const tags = Array.isArray(b.runner) ? b.runner : [b.runner];
|
|
658
|
+
return [
|
|
659
|
+
"",
|
|
660
|
+
...job(`chant-release-build-${b.name}`, ["chant-release-gate"], [...checkout, ...cd, ...binstall, b.build, packLine(b)], [` tags: [${tags.map((t) => JSON.stringify(t)).join(", ")}]`, " artifacts:", " paths:", ` - ${JSON.stringify(`${o.root ? `${o.root}/` : ""}${releaseBuildArchive(b.name)}`)}`, " expire_in: 1 day"], env.map(([k, v]) => ` ${k}: ${JSON.stringify(v)}`)),
|
|
661
|
+
];
|
|
662
|
+
});
|
|
663
|
+
const cut = releaseJobSteps({ ...o.context, job: "cut", label: DISPATCH_LABEL });
|
|
664
|
+
const publish = releaseJobSteps({ ...o.context, job: "publish", label: DISPATCH_LABEL });
|
|
665
|
+
const artifactPaths = cut("artifactPaths").flatMap((i) => (typeof i === "string" ? [` - ${JSON.stringify(i)}`] : i.lines));
|
|
456
666
|
const lines = [
|
|
457
|
-
...job("chant-release-gate", [], [...cd,
|
|
667
|
+
...job("chant-release-gate", [], [...cd, ...install, fetches[0], ...gateScript(o, "$CI_COMMIT_SHA"), labelScript(o), 'printf \'CHANT_RELEASE_COMMIT=%s\\nCHANT_RELEASE_NEXT=%s\\n\' "$commit" "$label" > "$CI_PROJECT_DIR/chant-release-gate.env"'], [" artifacts:", " reports:", " dotenv: chant-release-gate.env"]),
|
|
668
|
+
...buildJobs,
|
|
458
669
|
"",
|
|
459
|
-
...job("chant-release-cut", ["chant-release-gate"
|
|
670
|
+
...job("chant-release-cut", ["chant-release-gate", ...built], [
|
|
671
|
+
...checkout,
|
|
672
|
+
...cd,
|
|
673
|
+
...install,
|
|
674
|
+
...o.extra.gitlabScript,
|
|
675
|
+
...cut("prepare"),
|
|
676
|
+
fetches[0],
|
|
677
|
+
...auth,
|
|
678
|
+
LEDGER_FETCH_FIRST,
|
|
679
|
+
...cut("beforeCut"),
|
|
680
|
+
...cutScript(o, "/tmp/chant-cut.json"),
|
|
681
|
+
...cut("afterCut"),
|
|
682
|
+
], [...(artifactPaths.length > 0 ? [" artifacts:", " paths:", ...artifactPaths, " expire_in: 1 day"] : []), ...stepLines(cut("jobKeys"), (l) => l)], o.extra.gitlabVariables),
|
|
460
683
|
"",
|
|
461
|
-
...job("chant-release-publish", ["chant-release-gate", "chant-release-cut"], [
|
|
684
|
+
...job("chant-release-publish", ["chant-release-gate", "chant-release-cut", ...built], [
|
|
462
685
|
...checkout,
|
|
686
|
+
...publish("afterCheckout"),
|
|
463
687
|
...cd,
|
|
464
|
-
|
|
688
|
+
...install,
|
|
465
689
|
...o.extra.gitlabScript,
|
|
466
690
|
...fetches,
|
|
467
691
|
...auth,
|
|
468
|
-
...(
|
|
469
|
-
...(
|
|
692
|
+
...publish("prepare"),
|
|
693
|
+
...publish("beforeBuild"),
|
|
470
694
|
...(o.build ? [o.build] : []),
|
|
471
|
-
...(
|
|
695
|
+
...publish("afterBuild"),
|
|
696
|
+
...publish("beforePublish"),
|
|
472
697
|
`${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
|
|
473
|
-
],
|
|
698
|
+
], publishIdTokens(publish("idTokens")), o.extra.gitlabVariables),
|
|
474
699
|
];
|
|
475
700
|
if (o.after.length > 0)
|
|
476
|
-
lines.push("", ...job("chant-release-after", ["chant-release-gate", "chant-release-publish"], [...checkout, ...cd,
|
|
701
|
+
lines.push("", ...job("chant-release-after", ["chant-release-gate", "chant-release-publish"], [...checkout, ...cd, ...install, ...o.after]));
|
|
477
702
|
return `${lines.join("\n")}\n`;
|
|
478
703
|
}
|
|
704
|
+
/**
|
|
705
|
+
* Whether the default build, `npm run build`, has a script to run at `root`
|
|
706
|
+
* (#5149): a package.json with a `build` script. A package with no build
|
|
707
|
+
* script, and a project with no package.json (#5152), get no build step
|
|
708
|
+
* rather than one that fails.
|
|
709
|
+
*/
|
|
710
|
+
function hasBuildScript(root) {
|
|
711
|
+
let text;
|
|
712
|
+
try {
|
|
713
|
+
text = readFileSync(`${root}/package.json`, "utf-8");
|
|
714
|
+
}
|
|
715
|
+
catch {
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
try {
|
|
719
|
+
const pkg = JSON.parse(text);
|
|
720
|
+
return typeof pkg.scripts?.build === "string";
|
|
721
|
+
}
|
|
722
|
+
catch {
|
|
723
|
+
return true;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
479
726
|
/** The header that marks the file generated, naming the command that regenerates it. */
|
|
480
727
|
export function releaseWorkflowHeader(command) {
|
|
481
728
|
return `# ${GENERATED_MARKER}. Regenerate with: ${command} (in the workspace root)\n`;
|
|
@@ -495,12 +742,14 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
495
742
|
const { shellArg } = await import("./member-pipeline.js");
|
|
496
743
|
const usage = "chant release workflow [--forge github|gitlab|forgejo] [--install <command>] [--build <command>] [--chant <command>] [--output <file>]";
|
|
497
744
|
const { args } = ctx;
|
|
745
|
+
// #5149: a project with only a chant.config.ts, and no chant.workspace.json, renders its release workflow too.
|
|
498
746
|
const found = findWorkspaceRoot(process.cwd());
|
|
499
|
-
|
|
500
|
-
|
|
747
|
+
const projectDir = found?.dir ?? (["chant.config.ts", "chant.config.json"].some((f) => existsSync(join(process.cwd(), f))) ? process.cwd() : null);
|
|
748
|
+
if (!projectDir) {
|
|
749
|
+
console.error(formatError({ message: "no chant.workspace.json between this directory and the git root, and no chant.config.ts or chant.config.json here", hint: usage }));
|
|
501
750
|
return 1;
|
|
502
751
|
}
|
|
503
|
-
const root = realpathSync(
|
|
752
|
+
const root = realpathSync(projectDir);
|
|
504
753
|
const repoRoot = gitTop(root) ?? root;
|
|
505
754
|
const forge = (args.forge ??
|
|
506
755
|
(existsSync(join(repoRoot, ".github", "workflows")) ? "github" : existsSync(join(repoRoot, ".forgejo", "workflows")) ? "forgejo" : existsSync(join(repoRoot, ".gitlab-ci.yml")) ? "gitlab" : "github"));
|
|
@@ -520,19 +769,103 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
520
769
|
console.error(formatError({ message: `chant.config.ts at the workspace root could not be read: ${err instanceof Error ? err.message : String(err)}`, hint: usage }));
|
|
521
770
|
return 1;
|
|
522
771
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
772
|
+
// #5150: release.tag decides the tags the workflow runs on, refused when another member's can make the same tag.
|
|
773
|
+
let tags;
|
|
774
|
+
try {
|
|
775
|
+
const { memberTags, checkTagCollisions } = await import("../lifecycle/release-tag.js");
|
|
776
|
+
tags = await memberTags(root, { config: release?.tag, top: repoRoot });
|
|
777
|
+
await checkTagCollisions(root, tags);
|
|
778
|
+
}
|
|
779
|
+
catch (err) {
|
|
780
|
+
const code = err.code;
|
|
781
|
+
console.error(formatError({ message: `${err instanceof Error ? err.message : String(err)}${typeof code === "string" ? ` [${code}]` : ""}`, hint: usage }));
|
|
782
|
+
return 1;
|
|
783
|
+
}
|
|
784
|
+
// #5154: a train publishes its members' targets, so their credentials, tools and signing are the workflow's.
|
|
785
|
+
const memberReleases = [];
|
|
786
|
+
if (release?.train) {
|
|
787
|
+
const { locateWorkspace } = await import("./which-chant.js");
|
|
788
|
+
const { readDeclaration } = await import("./declaration.js");
|
|
789
|
+
const { loadChantConfig } = await import("../config.js");
|
|
790
|
+
const located = locateWorkspace(root);
|
|
791
|
+
for (const m of readDeclaration(located.tree, "", { rootChant: true }).members.filter((x) => x.kind === "chant" && x.dir !== ".")) {
|
|
792
|
+
try {
|
|
793
|
+
const r = (await loadChantConfig(join(root, m.dir))).config.release;
|
|
794
|
+
if (r)
|
|
795
|
+
memberReleases.push(r);
|
|
796
|
+
}
|
|
797
|
+
catch (err) {
|
|
798
|
+
console.error(formatError({ message: `member ${m.name}'s chant.config.ts could not be read: ${err instanceof Error ? err.message : String(err)}`, hint: usage }));
|
|
799
|
+
return 1;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
const shipped = memberReleases.find((r) => (r.images?.length ?? 0) > 0 || (r.artifacts?.length ?? 0) > 0);
|
|
803
|
+
if (shipped) {
|
|
804
|
+
console.error(formatError({ message: "release.train: a member declares release.images or release.artifacts, and the train workflow hands no image or file from its cut job to its publish job", hint: "Release that member with its own workflow, or publish its images and files from its npm package." }));
|
|
805
|
+
return 1;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
const allTargets = [...(release?.publish ?? []), ...memberReleases.flatMap((r) => r.publish ?? [])];
|
|
809
|
+
const { resolveSigning } = await import("../lifecycle/publish-signing.js");
|
|
810
|
+
const signs = [release, ...memberReleases].some((r) => resolveSigning(r?.signing, groups).on && (r?.publish ?? []).some((t) => t.type === "oci" || t.type === "forge" || t.type === "pypi"));
|
|
811
|
+
// #5152: the toolchains the project's root files name, and chant from npm for a project with no package.json.
|
|
812
|
+
const { TOOLCHAIN_MARKERS, detectToolchains } = await import("./release-toolchains.js");
|
|
813
|
+
const projectFiles = TOOLCHAIN_MARKERS.filter((f) => existsSync(join(root, f)));
|
|
814
|
+
const node = projectFiles.includes("package.json");
|
|
815
|
+
const { readerVersion } = await import("./declaration.js");
|
|
816
|
+
let text;
|
|
817
|
+
// #5183: an artifact's builtBy names a job of release.workflow.builds, so a workflow without it is refused here, not at the cut.
|
|
818
|
+
if ((release?.artifacts?.length ?? 0) > 0) {
|
|
819
|
+
const { checkReleaseArtifacts, ReleaseArtifactError } = await import("../lifecycle/release-artifacts.js");
|
|
820
|
+
try {
|
|
821
|
+
checkReleaseArtifacts(release.artifacts, { builds: release?.workflow?.builds ?? [] });
|
|
822
|
+
}
|
|
823
|
+
catch (err) {
|
|
824
|
+
if (!(err instanceof ReleaseArtifactError))
|
|
825
|
+
throw err;
|
|
826
|
+
console.error(formatError({ message: `${err.message} [${err.code}]`, hint: err.fix ?? "Fix release.artifacts in chant.config.ts." }));
|
|
827
|
+
return 1;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
try {
|
|
831
|
+
text = renderReleaseWorkflow({
|
|
832
|
+
forge,
|
|
833
|
+
projectFiles,
|
|
834
|
+
...(node || args.ciInstall || release?.workflow?.install !== undefined ? {} : { install: null }),
|
|
835
|
+
...(node || args.ciChant || release?.workflow?.chant !== undefined ? {} : { chant: `npx --yes @intentius/chant@${readerVersion()}` }),
|
|
836
|
+
groups,
|
|
837
|
+
workspaceRoot,
|
|
838
|
+
tags,
|
|
839
|
+
...(release?.workflow ? { pipeline: release.workflow } : {}),
|
|
840
|
+
...((release?.images?.length ?? 0) > 0 ? { images: true, imageArchives: resolveReleaseImages(release.images).map((i) => i.archive), imagePlatforms: releaseImagePlatforms(release.images) } : {}),
|
|
841
|
+
...((release?.artifacts?.length ?? 0) > 0 ? { artifacts: true, ...((await import("../lifecycle/release-artifacts.js")).usesGoreleaser(release.artifacts) ? { goreleaser: true } : {}) } : {}),
|
|
842
|
+
...(release?.lane ? { lane: release.lane } : {}),
|
|
843
|
+
green: await (async () => {
|
|
844
|
+
const { resolveGreenSource } = await import("../lifecycle/release-green.js");
|
|
845
|
+
const { scopeSource } = await import("./write-scope.js");
|
|
846
|
+
const { execFileSync } = await import("node:child_process");
|
|
847
|
+
let greenTags = "";
|
|
848
|
+
try {
|
|
849
|
+
greenTags = execFileSync("git", ["tag", "--list", "ci/green/*", "ci/green-*/*"], { cwd: root, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
850
|
+
}
|
|
851
|
+
catch {
|
|
852
|
+
greenTags = "";
|
|
853
|
+
}
|
|
854
|
+
return resolveGreenSource(release?.green, (scopeSource(root).declaration?.ci?.green ?? null) !== null, release?.green === undefined && greenTags !== "");
|
|
855
|
+
})(),
|
|
856
|
+
...(release?.version ? { version: true } : {}),
|
|
857
|
+
...(signs ? { signing: true } : {}),
|
|
858
|
+
...(allTargets.length > 0 ? { publish: allTargets } : {}),
|
|
859
|
+
...(release?.train ? { train: { env: release.train.env } } : {}),
|
|
860
|
+
...(args.ciInstall ? { install: args.ciInstall } : {}),
|
|
861
|
+
...(args.buildCommand ? { build: args.buildCommand } : !hasBuildScript(root) && release?.workflow?.build === undefined ? { build: null } : {}),
|
|
862
|
+
...(args.ciChant ? { chant: args.ciChant } : {}),
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
catch (err) {
|
|
866
|
+
console.error(formatError({ message: err instanceof Error ? err.message : String(err), hint: "Fix release.workflow in chant.config.ts." }));
|
|
867
|
+
return 1;
|
|
868
|
+
}
|
|
536
869
|
// #4909: under `chant dev generated-check` the header names the committed file the render stands for.
|
|
537
870
|
// #4950: with no --output the file goes to the render tree too, so a render needs no `--output {out}/...`.
|
|
538
871
|
const { committedPathOf, isRenderPath, renderPathOf } = await import("../generated-check.js");
|
|
@@ -551,8 +884,14 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
551
884
|
mkdirSync(dirname(target), { recursive: true });
|
|
552
885
|
writeFileSync(target, releaseWorkflowHeader(parts.map(shellArg).join(" ")) + text);
|
|
553
886
|
const shown = relative(process.cwd(), target).split(sep).join("/") || target;
|
|
554
|
-
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);
|
|
555
|
-
const what = release?.
|
|
887
|
+
const extras = [groups.has("supply-chain") ? "requires OIDC provenance (supply-chain)" : null, groups.has("verified-releases") ? "verifies the release first (verified-releases)" : null, signs ? `signs with Sigstore, with cosign ${TOOL_PINS.cosign.version} pinned by SHA-256` : null].filter(Boolean);
|
|
888
|
+
const what = release?.train
|
|
889
|
+
? release.workflow?.trigger === "dispatch"
|
|
890
|
+
? `cuts and publishes a release train for ${release.train.env} started by hand, from a green commit, and publishes one a release-train/${release.train.env}/* tag names`
|
|
891
|
+
: `publishes the release train a release-train/${release.train.env}/* tag names`
|
|
892
|
+
: release?.workflow?.trigger === "dispatch"
|
|
893
|
+
? "cuts and publishes a release started by hand with its label, from a green commit"
|
|
894
|
+
: `publishes the release a ${tags.template.legacy ? "release/**" : releaseTagFilters(tags).globs[0]} tag names`;
|
|
556
895
|
console.log(formatSuccess(`Wrote ${shown}: ${what}${extras.length > 0 ? `, and ${extras.join(" and ")}` : ""}.`));
|
|
557
896
|
if (forge === "gitlab")
|
|
558
897
|
console.log(`Include it from .gitlab-ci.yml: include: [{ local: ${release?.workflow?.file ?? RELEASE_WORKFLOW_FILES.gitlab} }]`);
|
|
@@ -560,6 +899,13 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
560
899
|
const archs = (release?.images?.length ?? 0) > 0 ? qemuArchitectures(releaseImagePlatforms(release.images)) : [];
|
|
561
900
|
if (forge === "gitlab" && archs.length > 0 && text.includes(`${RELEASE_BINFMT_IMAGE} --install`))
|
|
562
901
|
console.log(`The cut and publish jobs install QEMU's binfmt handlers for ${archs.join(", ")} with docker run --privileged ${RELEASE_BINFMT_IMAGE}: the runner's executor must run privileged containers, or have the handlers installed on its host.`);
|
|
902
|
+
const others = detectToolchains(new Set(projectFiles)).filter((t) => t !== "node");
|
|
903
|
+
if (forge === "gitlab" && others.length > 0 && release?.workflow?.toolchains === undefined)
|
|
904
|
+
console.log(`The jobs build with ${others.join(", ")}: a GitLab job takes its toolchain from the runner's image, so name an image that has it, and Node for chant, in .gitlab-ci.yml.`);
|
|
905
|
+
if (forge === "gitlab" && release?.workflow?.trigger !== "dispatch" && tags.template.floating)
|
|
906
|
+
console.log(`The publish job moves the floating tag (${tags.template.floating}) with git push, which a GitLab job token can't do: use release.workflow.trigger "dispatch", whose jobs push with CHANT_RELEASE_TOKEN, or move it by hand.`);
|
|
907
|
+
if (forge === "gitlab" && text.includes("CHANT_GORELEASER=/tmp/goreleaser"))
|
|
908
|
+
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.");
|
|
563
909
|
if (forge === "gitlab" && release?.workflow?.trigger === "dispatch")
|
|
564
910
|
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.");
|
|
565
911
|
return 0;
|