@intentius/chant 0.124.100 → 0.124.102
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/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-evidence-claims.d.ts +12 -0
- package/dist/ci-evidence-claims.js +12 -0
- package/dist/ci-system.d.ts +66 -0
- package/dist/ci-system.js +61 -0
- 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 +374 -0
- package/dist/cli/handlers/release.d.ts +43 -2
- package/dist/cli/handlers/release.js +667 -39
- package/dist/cli/handlers/run-generate.js +11 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +44 -101
- package/dist/cli/parse-args.js +48 -0
- package/dist/cli/registry.d.ts +16 -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 +50 -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 +19 -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 +15 -0
- package/dist/cloud-lister/index.d.ts +4 -1
- package/dist/cloud-lister/index.js +2 -1
- package/dist/cloud-lister/kubernetes-components.d.ts +56 -0
- package/dist/cloud-lister/kubernetes-components.js +642 -0
- package/dist/cloud-lister/kubernetes.d.ts +18 -0
- package/dist/cloud-lister/kubernetes.js +26 -1
- package/dist/cloud-lister/mask.d.ts +5 -1
- package/dist/cloud-lister/mask.js +14 -5
- 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-import.d.ts +1 -1
- package/dist/config-import.js +6 -2
- package/dist/config-sandbox.d.ts +1 -1
- package/dist/config-sandbox.js +3 -3
- package/dist/config.d.ts +369 -10
- package/dist/config.js +127 -7
- package/dist/deep-observation.js +9 -3
- package/dist/floor-table.data.js +21 -1
- package/dist/forge-remote.d.ts +13 -0
- package/dist/forge-remote.js +15 -0
- package/dist/lexicon.d.ts +45 -4
- package/dist/lifecycle/__fixtures__/package-files.d.ts +32 -0
- package/dist/lifecycle/__fixtures__/package-files.js +72 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +62 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.js +275 -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 +13 -0
- package/dist/lifecycle/publish-declaration.d.ts +322 -4
- package/dist/lifecycle/publish-declaration.js +340 -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-helm.d.ts +83 -0
- package/dist/lifecycle/publish-helm.js +452 -0
- 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-maven.d.ts +79 -0
- package/dist/lifecycle/publish-maven.js +364 -0
- package/dist/lifecycle/publish-mcp-registry.d.ts +66 -0
- package/dist/lifecycle/publish-mcp-registry.js +305 -0
- package/dist/lifecycle/publish-npm.d.ts +27 -1
- package/dist/lifecycle/publish-npm.js +216 -3
- package/dist/lifecycle/publish-nuget.d.ts +93 -0
- package/dist/lifecycle/publish-nuget.js +377 -0
- package/dist/lifecycle/publish-oci.d.ts +91 -2
- package/dist/lifecycle/publish-oci.js +247 -8
- package/dist/lifecycle/publish-package-files.d.ts +16 -0
- package/dist/lifecycle/publish-package-files.js +39 -0
- package/dist/lifecycle/publish-pypi.d.ts +138 -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-rubygems.d.ts +84 -0
- package/dist/lifecycle/publish-rubygems.js +366 -0
- package/dist/lifecycle/publish-signing.d.ts +147 -0
- package/dist/lifecycle/publish-signing.js +257 -0
- package/dist/lifecycle/publish-targets.d.ts +37 -1
- package/dist/lifecycle/publish-targets.js +102 -0
- package/dist/lifecycle/publish-tauri.js +43 -0
- package/dist/lifecycle/publish-train-names.d.ts +57 -0
- package/dist/lifecycle/publish-train-names.js +123 -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 +290 -0
- package/dist/lifecycle/release-artifacts.js +808 -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 +64 -4
- package/dist/lifecycle/release-cut.js +147 -34
- package/dist/lifecycle/release-doctor.d.ts +113 -0
- package/dist/lifecycle/release-doctor.js +1198 -0
- package/dist/lifecycle/release-green.d.ts +86 -0
- package/dist/lifecycle/release-green.js +286 -0
- package/dist/lifecycle/release-init-registries.d.ts +48 -0
- package/dist/lifecycle/release-init-registries.js +97 -0
- package/dist/lifecycle/release-init.d.ts +275 -0
- package/dist/lifecycle/release-init.js +984 -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 +251 -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 +247 -35
- 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 +322 -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/op/generate-pipeline.js +1 -1
- package/dist/op/local-executor.d.ts +1 -1
- package/dist/op/local-executor.js +2 -2
- package/dist/op/op-waves-evidence.js +9 -2
- 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 +8 -1
- package/dist/release-floors.js +9 -2
- package/dist/sensitive-key.d.ts +12 -0
- package/dist/sensitive-key.js +52 -0
- package/dist/tool-pins.d.ts +40 -0
- package/dist/tool-pins.js +66 -0
- package/dist/ts-loader.d.ts +8 -0
- package/dist/ts-loader.js +19 -0
- package/dist/wave-runtime.mjs +345 -342
- 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/lexicon-outputs.d.ts +1 -1
- package/dist/workspace/lexicon-outputs.js +1 -1
- package/dist/workspace/member-pipeline.d.ts +2 -1
- package/dist/workspace/member-pipeline.js +5 -2
- package/dist/workspace/reason-codes.d.ts +2 -0
- package/dist/workspace/reason-codes.js +3 -1
- package/dist/workspace/release-changed.d.ts +75 -4
- package/dist/workspace/release-changed.js +205 -34
- package/dist/workspace/release-changed.schema.json +20 -2
- 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 +50 -0
- package/dist/workspace/release-steps/nfpm.d.ts +13 -0
- package/dist/workspace/release-steps/nfpm.js +29 -0
- package/dist/workspace/release-steps/nuget.d.ts +14 -0
- package/dist/workspace/release-steps/nuget.js +16 -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 +36 -0
- package/dist/workspace/release-train-workflow.js +121 -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 +183 -59
- package/dist/workspace/release-workflow.js +570 -201
- 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 +504 -0
- package/dist/workspace/train-prepare.d.ts +64 -0
- package/dist/workspace/train-prepare.js +313 -0
- package/dist/workspace/train-publish.d.ts +177 -0
- package/dist/workspace/train-publish.js +574 -0
- package/dist/workspace/train-range-labels.d.ts +33 -0
- package/dist/workspace/train-range-labels.js +109 -0
- package/dist/workspace/train-shell.d.ts +5 -0
- package/dist/workspace/train-shell.js +17 -0
- package/dist/workspace/trust/check-evidence-report.d.ts +3 -7
- package/dist/workspace/trust/check-evidence-report.js +3 -7
- 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 +1 -1
|
@@ -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,97 +83,309 @@ 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:",
|
|
193
223
|
" push:",
|
|
194
224
|
' tags: ["release/**"]',
|
|
195
225
|
"permissions:",
|
|
196
|
-
" contents:
|
|
197
|
-
" id-token: write",
|
|
198
|
-
...extra.permissions,
|
|
226
|
+
" contents: read",
|
|
199
227
|
"jobs:",
|
|
200
228
|
" publish:",
|
|
201
229
|
" runs-on: ubuntu-latest",
|
|
230
|
+
...jobPermissions(extra, { contents: "write", "id-token": "write" }, "publish"),
|
|
202
231
|
...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []),
|
|
203
232
|
...extra.githubEnv(forgeToken),
|
|
204
233
|
" steps:",
|
|
205
|
-
...githubSetup(),
|
|
206
|
-
` - run: ${install}
|
|
234
|
+
...githubSetup(undefined, fullSetup),
|
|
235
|
+
...(install ? [` - run: ${install}`] : []),
|
|
207
236
|
...extra.githubSteps,
|
|
208
|
-
...(
|
|
209
|
-
...(
|
|
237
|
+
...step("prepare"),
|
|
238
|
+
...(beforeBuild.length > 0 ? fetches : []),
|
|
239
|
+
...beforeBuild,
|
|
210
240
|
...(build ? [` - run: ${build}`] : []),
|
|
211
|
-
...(
|
|
212
|
-
...(
|
|
241
|
+
...(beforeBuild.length > 0 ? [] : fetches),
|
|
242
|
+
...step("afterBuild"),
|
|
243
|
+
...step("beforePublish"),
|
|
213
244
|
` - run: ${chant} release publish ${label} ${flags}`,
|
|
214
245
|
];
|
|
215
246
|
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}
|
|
247
|
+
lines.push(" after-release:", " needs: publish", " runs-on: ubuntu-latest", ...jobPermissions(extra, { contents: "read" }, "after"), ...(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}`));
|
|
217
248
|
}
|
|
218
249
|
return tagComments(`${lines.join("\n")}\n`);
|
|
219
250
|
}
|
|
251
|
+
/** A job's steps as lines: each shell line as the job writes one, and each feature's own lines as they are. */
|
|
252
|
+
function stepLines(items, run) {
|
|
253
|
+
return items.flatMap((i) => (typeof i === "string" ? [run(i)] : i.lines));
|
|
254
|
+
}
|
|
255
|
+
/** A GitLab publish job's `id_tokens:`: `SIGSTORE_ID_TOKEN`, and the entries the features add. */
|
|
256
|
+
function publishIdTokens(extra) {
|
|
257
|
+
return [" id_tokens:", " SIGSTORE_ID_TOKEN:", " aud: sigstore", ...stepLines(extra, (l) => l)];
|
|
258
|
+
}
|
|
259
|
+
/** A glob character GitHub's and Forgejo's tag filters treat as special, escaped. */
|
|
260
|
+
function globLiteral(s) {
|
|
261
|
+
return s.replace(/[*?+[\]!\\]/g, (c) => `\\${c}`);
|
|
262
|
+
}
|
|
263
|
+
/** A literal for a GitLab (RE2) regex between slashes. */
|
|
264
|
+
function regexLiteral(s) {
|
|
265
|
+
return s.replace(/[.*+?^${}()|[\]\\/]/g, (c) => `\\${c}`);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* The filters for the tags a template makes (#5150): GitHub and Forgejo
|
|
269
|
+
* globs (the release tags, and a negated pattern for the floating tag so its
|
|
270
|
+
* move starts nothing), and GitLab's rule.
|
|
271
|
+
*/
|
|
272
|
+
export function releaseTagFilters(tags) {
|
|
273
|
+
const name = tagShape(tags.template.name, tags.place);
|
|
274
|
+
const floating = tags.template.floating ? tagShape(tags.template.floating, tags.place) : null;
|
|
275
|
+
const globs = [`${globLiteral(name.prefix)}*${globLiteral(name.suffix)}`, ...(floating ? [`!${globLiteral(floating.prefix)}[0-9]+${globLiteral(floating.suffix)}`] : [])];
|
|
276
|
+
const re = (s, v) => `/^${regexLiteral(s.prefix)}${v}${regexLiteral(s.suffix)}$/`;
|
|
277
|
+
const gitlabRule = `$CI_COMMIT_TAG =~ ${re(name, "[A-Za-z0-9._+-]+")}${floating ? ` && $CI_COMMIT_TAG !~ ${re(floating, "[0-9]+")}` : ""}`;
|
|
278
|
+
return { globs, gitlabRule };
|
|
279
|
+
}
|
|
280
|
+
/** The shell that reads the label of the tag `ref` names from the ledger and refuses a tag that names no release. */
|
|
281
|
+
function labelOfRefScript(chant, ref) {
|
|
282
|
+
return [
|
|
283
|
+
`label="$(${chant} release tag "${ref}" --json | ${field("d.label")})" || label=""`,
|
|
284
|
+
`if [ -z "$label" ]; then echo "${ref} names no release of this member, so nothing is published" >&2; exit 1; fi`,
|
|
285
|
+
];
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* The tag-triggered publish workflow for a `release.tag` template (#5150).
|
|
289
|
+
* It runs on the template's tags, fetches `chant/lifecycle` first, and
|
|
290
|
+
* reads the release's label from the ledger with `chant release tag`, since
|
|
291
|
+
* a tag is the label's rendering and is never parsed.
|
|
292
|
+
*/
|
|
293
|
+
function renderTemplatedTagWorkflow(input, o) {
|
|
294
|
+
const { chant, install, fullSetup, build, root, flags, after, extra, forgeToken } = o;
|
|
295
|
+
const filters = releaseTagFilters(o.tags);
|
|
296
|
+
const label = '"$CHANT_RELEASE_LABEL"';
|
|
297
|
+
const ciFetch = "git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'";
|
|
298
|
+
const ledgerFetch = "git fetch origin chant/lifecycle:chant/lifecycle";
|
|
299
|
+
const at = releaseJobSteps({ ...o.context, job: "publish", label });
|
|
300
|
+
if (input.forge === "gitlab") {
|
|
301
|
+
const q = (l) => ` - ${JSON.stringify(l)}`;
|
|
302
|
+
const step = (slot) => stepLines(at(slot), q);
|
|
303
|
+
const beforeBuild = step("beforeBuild");
|
|
304
|
+
const labelLines = [ledgerFetch, ...labelOfRefScript(chant, "$CI_COMMIT_TAG"), 'export CHANT_RELEASE_LABEL="$label"'];
|
|
305
|
+
const lines = [
|
|
306
|
+
"chant-release-publish:",
|
|
307
|
+
" rules:",
|
|
308
|
+
` - if: ${filters.gitlabRule}`,
|
|
309
|
+
...publishIdTokens(at("idTokens")),
|
|
310
|
+
...(extra.gitlabVariables.length > 0 ? [" variables:", ...extra.gitlabVariables] : []),
|
|
311
|
+
" script:",
|
|
312
|
+
...(root ? [q(`cd ${root}`)] : []),
|
|
313
|
+
...(install ? [q(install)] : []),
|
|
314
|
+
...extra.gitlabScript.map(q),
|
|
315
|
+
...labelLines.map(q),
|
|
316
|
+
...step("prepare"),
|
|
317
|
+
...(beforeBuild.length > 0 ? [q(ciFetch)] : []),
|
|
318
|
+
...beforeBuild,
|
|
319
|
+
...(build ? [q(build)] : []),
|
|
320
|
+
...(beforeBuild.length > 0 ? [] : [q(ciFetch)]),
|
|
321
|
+
...step("afterBuild"),
|
|
322
|
+
...step("beforePublish"),
|
|
323
|
+
q(`${chant} release publish ${label} ${flags}`),
|
|
324
|
+
];
|
|
325
|
+
if (after.length > 0) {
|
|
326
|
+
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}`));
|
|
327
|
+
}
|
|
328
|
+
return `${lines.join("\n")}\n`;
|
|
329
|
+
}
|
|
330
|
+
const run = (l) => ` - run: ${l}`;
|
|
331
|
+
const step = (slot) => stepLines(at(slot), run);
|
|
332
|
+
const beforeBuild = step("beforeBuild");
|
|
333
|
+
const lines = [
|
|
334
|
+
"name: chant release publish",
|
|
335
|
+
"on:",
|
|
336
|
+
" push:",
|
|
337
|
+
` tags: [${filters.globs.map((g) => JSON.stringify(g)).join(", ")}]`,
|
|
338
|
+
"permissions:",
|
|
339
|
+
" contents: read",
|
|
340
|
+
"jobs:",
|
|
341
|
+
" publish:",
|
|
342
|
+
" runs-on: ubuntu-latest",
|
|
343
|
+
...jobPermissions(extra, { contents: "write", "id-token": "write" }, "publish"),
|
|
344
|
+
...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []),
|
|
345
|
+
...(after.length > 0 ? [" outputs:", " label: ${{ steps.label.outputs.label }}"] : []),
|
|
346
|
+
...extra.githubEnv(forgeToken),
|
|
347
|
+
" steps:",
|
|
348
|
+
...githubSetup(undefined, fullSetup),
|
|
349
|
+
...(install ? [run(install)] : []),
|
|
350
|
+
...extra.githubSteps,
|
|
351
|
+
run(ledgerFetch),
|
|
352
|
+
" - id: label",
|
|
353
|
+
" run: |",
|
|
354
|
+
...[...labelOfRefScript(chant, "$GITHUB_REF_NAME"), 'echo "CHANT_RELEASE_LABEL=$label" >> "$GITHUB_ENV"', 'echo "label=$label" >> "$GITHUB_OUTPUT"'].map((l) => ` ${l}`),
|
|
355
|
+
...step("prepare"),
|
|
356
|
+
...(beforeBuild.length > 0 ? [run(ciFetch)] : []),
|
|
357
|
+
...beforeBuild,
|
|
358
|
+
...(build ? [run(build)] : []),
|
|
359
|
+
...(beforeBuild.length > 0 ? [] : [run(ciFetch)]),
|
|
360
|
+
...step("afterBuild"),
|
|
361
|
+
...step("beforePublish"),
|
|
362
|
+
run(`${chant} release publish ${label} ${flags}`),
|
|
363
|
+
];
|
|
364
|
+
if (after.length > 0) {
|
|
365
|
+
lines.push(" after-release:", " needs: publish", " runs-on: ubuntu-latest", ...jobPermissions(extra, { contents: "read" }, "after"), ...(root ? [" defaults:", " run:", ` working-directory: ${root}`] : []), " env:", " CHANT_RELEASE_LABEL: ${{ needs.publish.outputs.label }}", " steps:", ...githubSetup(undefined, fullSetup), ...(install ? [run(install)] : []), ...after.map(run));
|
|
366
|
+
}
|
|
367
|
+
return tagComments(`${lines.join("\n")}\n`);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* A job's `permissions:` block (#5234): the scopes it needs, then the config's
|
|
371
|
+
* and targets' extras it takes, one per line at the job's indent. The workflow
|
|
372
|
+
* itself grants `contents: read`, so no job holds a scope it does not name.
|
|
373
|
+
* The cut never takes `packages` (the publish pushes the images), and the
|
|
374
|
+
* extras the config set by hand go to both.
|
|
375
|
+
*/
|
|
376
|
+
export function jobPermissions(extra, base, job, indent = " ") {
|
|
377
|
+
const scopes = { ...base };
|
|
378
|
+
if (job === "cut" || job === "publish") {
|
|
379
|
+
for (const [k, v] of extra.permissions) {
|
|
380
|
+
if (job === "cut" && k === "packages")
|
|
381
|
+
continue;
|
|
382
|
+
scopes[k] = v;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return [`${indent}permissions:`, ...Object.entries(scopes).map(([k, v]) => `${indent} ${k}: ${v}`)];
|
|
386
|
+
}
|
|
220
387
|
/** `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) {
|
|
388
|
+
export function jobExtras(p, forge) {
|
|
222
389
|
const permissions = Object.entries(p.permissions ?? {});
|
|
223
390
|
const env = Object.entries(p.env ?? {});
|
|
224
391
|
const setup = p.setup ?? [];
|
|
@@ -257,47 +424,32 @@ function jobExtras(p, forge) {
|
|
|
257
424
|
...(s.env && Object.keys(s.env).length > 0 ? [" env:", ...map(" ", Object.entries(s.env))] : []),
|
|
258
425
|
]);
|
|
259
426
|
return {
|
|
260
|
-
permissions
|
|
427
|
+
permissions,
|
|
261
428
|
githubEnv: (base) => (base.length + env.length > 0 ? [" env:", ...base, ...map(" ", env)] : []),
|
|
262
429
|
githubSteps,
|
|
263
430
|
gitlabVariables: map(" ", env),
|
|
264
431
|
gitlabScript: setup.flatMap((s) => ("uses" in s ? [] : [...Object.entries(s.env ?? {}).map(([k, v]) => `export ${k}=${q(v)}`), s.run])),
|
|
265
432
|
};
|
|
266
433
|
}
|
|
267
|
-
/** The checkout and
|
|
268
|
-
function githubSetup(ref) {
|
|
434
|
+
/** The checkout and toolchain setup a GitHub or Forgejo job starts with (#5152); `ref` checks out that commit. */
|
|
435
|
+
export function githubSetup(ref, setup, persist = true) {
|
|
269
436
|
return [
|
|
270
437
|
` - uses: ${usesRef(ACTION_PINS.checkout4)}`,
|
|
271
438
|
" with:",
|
|
272
439
|
...(ref ? [` ref: ${ref}`] : []),
|
|
273
440
|
" fetch-depth: 0",
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
" node-version: 24",
|
|
277
|
-
" registry-url: https://registry.npmjs.org",
|
|
441
|
+
...(persist ? [] : [" persist-credentials: false"]),
|
|
442
|
+
...setup,
|
|
278
443
|
];
|
|
279
444
|
}
|
|
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"`;
|
|
445
|
+
/** The cut job's token lines: `forge-checks`' (#5149) and, when the doctor runs there (#5161), the publish job's forge token, once. */
|
|
446
|
+
function cutEnvToken(o) {
|
|
447
|
+
return [...new Set([...o.cutToken, ...(o.doctor ? o.forgeToken : [])])];
|
|
298
448
|
}
|
|
449
|
+
/** The label in a dispatched release's cut and publish jobs. */
|
|
450
|
+
const DISPATCH_LABEL = '"$CHANT_RELEASE_LABEL"';
|
|
299
451
|
/** 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}??""))'`;
|
|
452
|
+
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
453
|
/**
|
|
302
454
|
* GitHub refuses the job's token a ref on a commit whose workflow files differ
|
|
303
455
|
* from the default branch's (#4852). The gate checks before the cut builds
|
|
@@ -316,7 +468,10 @@ function workflowFilesCheck(dispatched) {
|
|
|
316
468
|
];
|
|
317
469
|
}
|
|
318
470
|
/** 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) {
|
|
471
|
+
export function gateScript(o, dispatched) {
|
|
472
|
+
// #5149: with no ci/green tags to search, the gate names the dispatched commit and the cut checks it.
|
|
473
|
+
if (o.green !== "chant")
|
|
474
|
+
return [`commit="${dispatched}"`];
|
|
320
475
|
return [
|
|
321
476
|
`commit="$(${o.chant} ci last-green --from "${dispatched}"${o.lane ? ` --lane ${o.lane}` : ""} --json | ${field("d.commit?.sha")})"`,
|
|
322
477
|
`if [ -z "$commit" ]; then echo "no green commit at or below ${dispatched}, so no release is cut" >&2; exit 1; fi`,
|
|
@@ -324,6 +479,21 @@ function gateScript(o, dispatched) {
|
|
|
324
479
|
...(o.forge === "github" && o.gate !== "head" ? workflowFilesCheck(dispatched) : []),
|
|
325
480
|
];
|
|
326
481
|
}
|
|
482
|
+
/**
|
|
483
|
+
* The gate's line that decides the label (#5159): the one dispatched, or for
|
|
484
|
+
* `auto` the one `chant release next` computes at the gate's commit from the
|
|
485
|
+
* commits and intent files since the member's previous release. One line,
|
|
486
|
+
* so GitLab runs it as one command.
|
|
487
|
+
*/
|
|
488
|
+
function labelScript(o) {
|
|
489
|
+
return [
|
|
490
|
+
'label="$CHANT_RELEASE_LABEL"',
|
|
491
|
+
`if [ "$label" = auto ]; then ${LEDGER_FETCH_FIRST}`,
|
|
492
|
+
`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; }`,
|
|
493
|
+
`label="$(printf '%s' "$next" | ${field("d.label")})"`,
|
|
494
|
+
"fi",
|
|
495
|
+
].join("; ");
|
|
496
|
+
}
|
|
327
497
|
/** The cut's shell: cut the label at the gate's commit, then push the tag the cut made. */
|
|
328
498
|
function cutScript(o, out) {
|
|
329
499
|
return [
|
|
@@ -340,26 +510,69 @@ function cutScript(o, out) {
|
|
|
340
510
|
* the branch is not an error here; any other failure of git still stops the
|
|
341
511
|
* job. The publish job runs after the cut has pushed it and fetches it plainly.
|
|
342
512
|
*/
|
|
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';
|
|
513
|
+
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';
|
|
514
|
+
/** The label the gate decided (#5159): the dispatched one, or the one `auto` resolved to. */
|
|
515
|
+
const GATE_LABEL = "${{ needs.gate.outputs.label }}";
|
|
344
516
|
/** GitHub and Forgejo: the release started by hand with a label (#4656). */
|
|
345
517
|
function renderGithubDispatch(o) {
|
|
346
518
|
const defaults = o.root ? [" defaults:", " run:", ` working-directory: ${o.root}`] : [];
|
|
347
519
|
const commit = "${{ needs.gate.outputs.commit }}";
|
|
348
520
|
const fetches = [" - run: git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'", " - run: git fetch origin chant/lifecycle:chant/lifecycle"];
|
|
349
521
|
const block = (lines) => [" - run: |", ...lines.map((l) => ` ${l}`)];
|
|
522
|
+
const installLines = o.install ? [` - run: ${o.install}`] : [];
|
|
523
|
+
const q = (v) => JSON.stringify(v);
|
|
524
|
+
const upload = usesRef(o.forge === "forgejo" ? ACTION_PINS.uploadArtifact3 : ACTION_PINS.uploadArtifact4);
|
|
525
|
+
// #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.
|
|
526
|
+
const buildJobs = o.builds.flatMap((b) => {
|
|
527
|
+
const install = b.install === false ? null : (b.install ?? o.install);
|
|
528
|
+
const runner = Array.isArray(b.runner) ? `[${b.runner.map(q).join(", ")}]` : q(b.runner);
|
|
529
|
+
const env = Object.entries(b.env ?? {});
|
|
530
|
+
for (const [k] of env)
|
|
531
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k))
|
|
532
|
+
throw new Error(`release.workflow.builds.${b.name}.env: ${JSON.stringify(k)} is not a variable name`);
|
|
533
|
+
return [
|
|
534
|
+
` build-${b.name}:`,
|
|
535
|
+
" needs: gate",
|
|
536
|
+
` runs-on: ${runner}`,
|
|
537
|
+
" permissions:",
|
|
538
|
+
" contents: read",
|
|
539
|
+
" defaults:",
|
|
540
|
+
" run:",
|
|
541
|
+
" shell: bash",
|
|
542
|
+
...(o.root ? [` working-directory: ${o.root}`] : []),
|
|
543
|
+
" env:",
|
|
544
|
+
` CHANT_RELEASE_LABEL: ${GATE_LABEL}`,
|
|
545
|
+
...env.map(([k, v]) => ` ${k}: ${q(v)}`),
|
|
546
|
+
" steps:",
|
|
547
|
+
...githubSetup(commit, b.setup, false),
|
|
548
|
+
...(install ? [` - run: ${install}`] : []),
|
|
549
|
+
` - run: ${q(b.build)}`,
|
|
550
|
+
` - run: ${q(packLine(b))}`,
|
|
551
|
+
` - uses: ${upload}`,
|
|
552
|
+
" with:",
|
|
553
|
+
` name: ${releaseBuildArtifact(b.name)}`,
|
|
554
|
+
` path: ${o.root ? `${o.root}/` : ""}${releaseBuildArchive(b.name)}`,
|
|
555
|
+
" if-no-files-found: error",
|
|
556
|
+
" retention-days: 1",
|
|
557
|
+
];
|
|
558
|
+
});
|
|
559
|
+
const run = (l) => ` - run: ${l}`;
|
|
560
|
+
const cut = releaseJobSteps({ ...o.context, job: "cut", label: DISPATCH_LABEL });
|
|
561
|
+
const publish = releaseJobSteps({ ...o.context, job: "publish", label: DISPATCH_LABEL });
|
|
562
|
+
const cutStep = (slot) => stepLines(cut(slot), run);
|
|
563
|
+
const publishStep = (slot) => stepLines(publish(slot), run);
|
|
564
|
+
const built = o.builds.map((b) => `build-${b.name}`);
|
|
350
565
|
const lines = [
|
|
351
566
|
"name: chant release",
|
|
352
567
|
"on:",
|
|
353
568
|
" workflow_dispatch:",
|
|
354
569
|
" inputs:",
|
|
355
570
|
" label:",
|
|
356
|
-
" description: The release's label, such as v1.4.0",
|
|
571
|
+
" description: The release's label, such as v1.4.0, or auto for the one chant release next computes",
|
|
357
572
|
" required: true",
|
|
358
573
|
" type: string",
|
|
359
574
|
"permissions:",
|
|
360
|
-
" contents:
|
|
361
|
-
" id-token: write",
|
|
362
|
-
...o.extra.permissions,
|
|
575
|
+
" contents: read",
|
|
363
576
|
"concurrency:",
|
|
364
577
|
" group: chant-release",
|
|
365
578
|
" cancel-in-progress: false",
|
|
@@ -368,60 +581,55 @@ function renderGithubDispatch(o) {
|
|
|
368
581
|
"jobs:",
|
|
369
582
|
" gate:",
|
|
370
583
|
" runs-on: ubuntu-latest",
|
|
584
|
+
...jobPermissions(o.extra, { contents: "read" }, "gate"),
|
|
371
585
|
...defaults,
|
|
372
586
|
" outputs:",
|
|
373
587
|
" commit: ${{ steps.green.outputs.commit }}",
|
|
588
|
+
" label: ${{ steps.green.outputs.label }}",
|
|
374
589
|
" steps:",
|
|
375
|
-
...githubSetup(),
|
|
376
|
-
|
|
590
|
+
...githubSetup(undefined, o.chantSetup),
|
|
591
|
+
...installLines,
|
|
377
592
|
fetches[0],
|
|
378
593
|
" - id: green",
|
|
379
594
|
" run: |",
|
|
380
|
-
...[...gateScript(o, "$GITHUB_SHA"), 'echo "commit=$commit" >> "$GITHUB_OUTPUT"'].map((l) => ` ${l}`),
|
|
595
|
+
...[...gateScript(o, "$GITHUB_SHA"), labelScript(o), 'echo "commit=$commit" >> "$GITHUB_OUTPUT"', 'echo "label=$label" >> "$GITHUB_OUTPUT"'].map((l) => ` ${l}`),
|
|
596
|
+
...buildJobs,
|
|
381
597
|
" cut:",
|
|
382
|
-
|
|
598
|
+
` needs: ${built.length > 0 ? `[gate, ${built.join(", ")}]` : "gate"}`,
|
|
383
599
|
" runs-on: ubuntu-latest",
|
|
600
|
+
...jobPermissions(o.extra, { contents: "write", ...(o.context.signing && o.context.doctor ? { "id-token": "write" } : {}) }, "cut"),
|
|
384
601
|
...defaults,
|
|
385
|
-
...o.extra.githubEnv([` CHANT_RELEASE_COMMIT: ${commit}`]),
|
|
602
|
+
...o.extra.githubEnv([` CHANT_RELEASE_COMMIT: ${commit}`, ` CHANT_RELEASE_LABEL: ${GATE_LABEL}`, ...cutEnvToken(o)]),
|
|
386
603
|
" steps:",
|
|
387
|
-
...githubSetup(commit),
|
|
388
|
-
|
|
604
|
+
...githubSetup(commit, o.fullSetup),
|
|
605
|
+
...installLines,
|
|
389
606
|
...o.extra.githubSteps,
|
|
607
|
+
...cutStep("prepare"),
|
|
390
608
|
fetches[0],
|
|
391
609
|
` - run: ${LEDGER_FETCH_FIRST}`,
|
|
610
|
+
...cutStep("beforeCut"),
|
|
392
611
|
...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
|
-
: []),
|
|
612
|
+
...cutStep("afterCut"),
|
|
404
613
|
" publish:",
|
|
405
|
-
|
|
614
|
+
` needs: [gate, cut${built.map((b) => `, ${b}`).join("")}]`,
|
|
406
615
|
" runs-on: ubuntu-latest",
|
|
616
|
+
...jobPermissions(o.extra, { contents: "write", "id-token": "write" }, "publish"),
|
|
407
617
|
...defaults,
|
|
408
|
-
...o.extra.githubEnv(o.forgeToken),
|
|
618
|
+
...o.extra.githubEnv([` CHANT_RELEASE_LABEL: ${GATE_LABEL}`, ...o.forgeToken]),
|
|
409
619
|
" steps:",
|
|
410
|
-
...githubSetup(commit),
|
|
411
|
-
|
|
620
|
+
...githubSetup(commit, o.fullSetup),
|
|
621
|
+
...installLines,
|
|
412
622
|
...o.extra.githubSteps,
|
|
413
623
|
...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"`] : []),
|
|
624
|
+
...publishStep("prepare"),
|
|
625
|
+
...publishStep("beforeBuild"),
|
|
419
626
|
...(o.build ? [` - run: ${o.build}`] : []),
|
|
420
|
-
...(
|
|
627
|
+
...publishStep("afterBuild"),
|
|
628
|
+
...publishStep("beforePublish"),
|
|
421
629
|
` - run: ${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
|
|
422
630
|
];
|
|
423
631
|
if (o.after.length > 0) {
|
|
424
|
-
lines.push(" after-release:", " needs: [gate, publish]", " runs-on: ubuntu-latest", ...defaults, " steps:", ...githubSetup(commit
|
|
632
|
+
lines.push(" after-release:", " needs: [gate, publish]", " runs-on: ubuntu-latest", ...jobPermissions(o.extra, { contents: "read" }, "after"), ...defaults, " env:", ` CHANT_RELEASE_LABEL: ${GATE_LABEL}`, " steps:", ...githubSetup(commit, o.fullSetup), ...installLines, ...o.after.map((l) => ` - run: ${l}`));
|
|
425
633
|
}
|
|
426
634
|
return tagComments(`${lines.join("\n")}\n`);
|
|
427
635
|
}
|
|
@@ -434,6 +642,7 @@ function renderGithubDispatch(o) {
|
|
|
434
642
|
*/
|
|
435
643
|
function renderGitlabDispatch(o) {
|
|
436
644
|
const cd = o.root ? [`cd ${o.root}`] : [];
|
|
645
|
+
const install = o.install ? [o.install] : [];
|
|
437
646
|
const fetches = ["git fetch origin 'refs/tags/ci/*:refs/tags/ci/*'", "git fetch origin chant/lifecycle:chant/lifecycle"];
|
|
438
647
|
const auth = [
|
|
439
648
|
`chant_auth="$(printf 'oauth2:%s' "$CHANT_RELEASE_TOKEN" | base64 | tr -d '\\n')"`,
|
|
@@ -450,32 +659,87 @@ function renderGitlabDispatch(o) {
|
|
|
450
659
|
...(needs.length > 0 ? [` needs: [${needs.join(", ")}]`] : []),
|
|
451
660
|
...extra,
|
|
452
661
|
" script:",
|
|
453
|
-
|
|
662
|
+
// #5159: a pipeline variable outranks the gate's dotenv, so the label the gate decided comes in as CHANT_RELEASE_NEXT.
|
|
663
|
+
...stepLines([...(needs.length > 0 ? ['export CHANT_RELEASE_LABEL="$CHANT_RELEASE_NEXT"'] : []), ...script], (l) => ` - ${JSON.stringify(l)}`),
|
|
454
664
|
];
|
|
455
665
|
const checkout = ['git checkout --detach "$CHANT_RELEASE_COMMIT"'];
|
|
666
|
+
// #5152: a build job per runner (tags), whose archive GitLab hands to the jobs that need it, in the project directory.
|
|
667
|
+
const built = o.builds.map((b) => `chant-release-build-${b.name}`);
|
|
668
|
+
const buildJobs = o.builds.flatMap((b) => {
|
|
669
|
+
const binstall = b.install === false ? [] : b.install ? [b.install] : install;
|
|
670
|
+
const env = Object.entries(b.env ?? {});
|
|
671
|
+
for (const [k] of env)
|
|
672
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(k))
|
|
673
|
+
throw new Error(`release.workflow.builds.${b.name}.env: ${JSON.stringify(k)} is not a variable name`);
|
|
674
|
+
const tags = Array.isArray(b.runner) ? b.runner : [b.runner];
|
|
675
|
+
return [
|
|
676
|
+
"",
|
|
677
|
+
...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)}`)),
|
|
678
|
+
];
|
|
679
|
+
});
|
|
680
|
+
const cut = releaseJobSteps({ ...o.context, job: "cut", label: DISPATCH_LABEL });
|
|
681
|
+
const publish = releaseJobSteps({ ...o.context, job: "publish", label: DISPATCH_LABEL });
|
|
682
|
+
const artifactPaths = cut("artifactPaths").flatMap((i) => (typeof i === "string" ? [` - ${JSON.stringify(i)}`] : i.lines));
|
|
456
683
|
const lines = [
|
|
457
|
-
...job("chant-release-gate", [], [...cd,
|
|
684
|
+
...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"]),
|
|
685
|
+
...buildJobs,
|
|
458
686
|
"",
|
|
459
|
-
...job("chant-release-cut", ["chant-release-gate"
|
|
687
|
+
...job("chant-release-cut", ["chant-release-gate", ...built], [
|
|
688
|
+
...checkout,
|
|
689
|
+
...cd,
|
|
690
|
+
...install,
|
|
691
|
+
...o.extra.gitlabScript,
|
|
692
|
+
...cut("prepare"),
|
|
693
|
+
fetches[0],
|
|
694
|
+
...auth,
|
|
695
|
+
LEDGER_FETCH_FIRST,
|
|
696
|
+
...cut("beforeCut"),
|
|
697
|
+
...cutScript(o, "/tmp/chant-cut.json"),
|
|
698
|
+
...cut("afterCut"),
|
|
699
|
+
], [...(artifactPaths.length > 0 ? [" artifacts:", " paths:", ...artifactPaths, " expire_in: 1 day"] : []), ...stepLines(cut("jobKeys"), (l) => l)], o.extra.gitlabVariables),
|
|
460
700
|
"",
|
|
461
|
-
...job("chant-release-publish", ["chant-release-gate", "chant-release-cut"], [
|
|
701
|
+
...job("chant-release-publish", ["chant-release-gate", "chant-release-cut", ...built], [
|
|
462
702
|
...checkout,
|
|
703
|
+
...publish("afterCheckout"),
|
|
463
704
|
...cd,
|
|
464
|
-
|
|
705
|
+
...install,
|
|
465
706
|
...o.extra.gitlabScript,
|
|
466
707
|
...fetches,
|
|
467
708
|
...auth,
|
|
468
|
-
...(
|
|
469
|
-
...(
|
|
709
|
+
...publish("prepare"),
|
|
710
|
+
...publish("beforeBuild"),
|
|
470
711
|
...(o.build ? [o.build] : []),
|
|
471
|
-
...(
|
|
712
|
+
...publish("afterBuild"),
|
|
713
|
+
...publish("beforePublish"),
|
|
472
714
|
`${o.chant} release publish "$CHANT_RELEASE_LABEL" ${o.flags}`,
|
|
473
|
-
],
|
|
715
|
+
], publishIdTokens(publish("idTokens")), o.extra.gitlabVariables),
|
|
474
716
|
];
|
|
475
717
|
if (o.after.length > 0)
|
|
476
|
-
lines.push("", ...job("chant-release-after", ["chant-release-gate", "chant-release-publish"], [...checkout, ...cd,
|
|
718
|
+
lines.push("", ...job("chant-release-after", ["chant-release-gate", "chant-release-publish"], [...checkout, ...cd, ...install, ...o.after]));
|
|
477
719
|
return `${lines.join("\n")}\n`;
|
|
478
720
|
}
|
|
721
|
+
/**
|
|
722
|
+
* Whether the default build, `npm run build`, has a script to run at `root`
|
|
723
|
+
* (#5149): a package.json with a `build` script. A package with no build
|
|
724
|
+
* script, and a project with no package.json (#5152), get no build step
|
|
725
|
+
* rather than one that fails.
|
|
726
|
+
*/
|
|
727
|
+
function hasBuildScript(root) {
|
|
728
|
+
let text;
|
|
729
|
+
try {
|
|
730
|
+
text = readFileSync(`${root}/package.json`, "utf-8");
|
|
731
|
+
}
|
|
732
|
+
catch {
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
try {
|
|
736
|
+
const pkg = JSON.parse(text);
|
|
737
|
+
return typeof pkg.scripts?.build === "string";
|
|
738
|
+
}
|
|
739
|
+
catch {
|
|
740
|
+
return true;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
479
743
|
/** The header that marks the file generated, naming the command that regenerates it. */
|
|
480
744
|
export function releaseWorkflowHeader(command) {
|
|
481
745
|
return `# ${GENERATED_MARKER}. Regenerate with: ${command} (in the workspace root)\n`;
|
|
@@ -493,14 +757,16 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
493
757
|
const { gitTop } = await import("./tree.js");
|
|
494
758
|
const { securityGroupsAt } = await import("./security.js");
|
|
495
759
|
const { shellArg } = await import("./member-pipeline.js");
|
|
496
|
-
const usage = "chant release workflow [--forge github|gitlab|forgejo] [--install <command>] [--build <command>] [--chant <command>] [--output <file>]";
|
|
760
|
+
const usage = "chant release workflow [--forge github|gitlab|forgejo] [--install <command>] [--build <command>] [--chant <command>] [--output <file>] [--force]";
|
|
497
761
|
const { args } = ctx;
|
|
762
|
+
// #5149: a project with only a chant.config.ts, and no chant.workspace.json, renders its release workflow too.
|
|
498
763
|
const found = findWorkspaceRoot(process.cwd());
|
|
499
|
-
|
|
500
|
-
|
|
764
|
+
const projectDir = found?.dir ?? (["chant.config.ts", "chant.config.json"].some((f) => existsSync(join(process.cwd(), f))) ? process.cwd() : null);
|
|
765
|
+
if (!projectDir) {
|
|
766
|
+
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
767
|
return 1;
|
|
502
768
|
}
|
|
503
|
-
const root = realpathSync(
|
|
769
|
+
const root = realpathSync(projectDir);
|
|
504
770
|
const repoRoot = gitTop(root) ?? root;
|
|
505
771
|
const forge = (args.forge ??
|
|
506
772
|
(existsSync(join(repoRoot, ".github", "workflows")) ? "github" : existsSync(join(repoRoot, ".forgejo", "workflows")) ? "forgejo" : existsSync(join(repoRoot, ".gitlab-ci.yml")) ? "gitlab" : "github"));
|
|
@@ -520,19 +786,103 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
520
786
|
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
787
|
return 1;
|
|
522
788
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
789
|
+
// #5150: release.tag decides the tags the workflow runs on, refused when another member's can make the same tag.
|
|
790
|
+
let tags;
|
|
791
|
+
try {
|
|
792
|
+
const { memberTags, checkTagCollisions } = await import("../lifecycle/release-tag.js");
|
|
793
|
+
tags = await memberTags(root, { config: release?.tag, top: repoRoot });
|
|
794
|
+
await checkTagCollisions(root, tags);
|
|
795
|
+
}
|
|
796
|
+
catch (err) {
|
|
797
|
+
const code = err.code;
|
|
798
|
+
console.error(formatError({ message: `${err instanceof Error ? err.message : String(err)}${typeof code === "string" ? ` [${code}]` : ""}`, hint: usage }));
|
|
799
|
+
return 1;
|
|
800
|
+
}
|
|
801
|
+
// #5154: a train publishes its members' targets, so their credentials, tools and signing are the workflow's.
|
|
802
|
+
const memberReleases = [];
|
|
803
|
+
if (release?.train) {
|
|
804
|
+
const { locateWorkspace } = await import("./which-chant.js");
|
|
805
|
+
const { readDeclaration } = await import("./declaration.js");
|
|
806
|
+
const { loadChantConfig } = await import("../config.js");
|
|
807
|
+
const located = locateWorkspace(root);
|
|
808
|
+
for (const m of readDeclaration(located.tree, "", { rootChant: true }).members.filter((x) => x.kind === "chant" && x.dir !== ".")) {
|
|
809
|
+
try {
|
|
810
|
+
const r = (await loadChantConfig(join(root, m.dir))).config.release;
|
|
811
|
+
if (r)
|
|
812
|
+
memberReleases.push(r);
|
|
813
|
+
}
|
|
814
|
+
catch (err) {
|
|
815
|
+
console.error(formatError({ message: `member ${m.name}'s chant.config.ts could not be read: ${err instanceof Error ? err.message : String(err)}`, hint: usage }));
|
|
816
|
+
return 1;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
const shipped = memberReleases.find((r) => (r.images?.length ?? 0) > 0 || (r.artifacts?.length ?? 0) > 0);
|
|
820
|
+
if (shipped) {
|
|
821
|
+
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." }));
|
|
822
|
+
return 1;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
const allTargets = [...(release?.publish ?? []), ...memberReleases.flatMap((r) => r.publish ?? [])];
|
|
826
|
+
const { resolveSigning } = await import("../lifecycle/publish-signing.js");
|
|
827
|
+
const signs = [release, ...memberReleases].some((r) => resolveSigning(r?.signing, groups).on && (r?.publish ?? []).some((t) => t.type === "oci" || t.type === "forge" || t.type === "pypi"));
|
|
828
|
+
// #5152: the toolchains the project's root files name, and chant from npm for a project with no package.json.
|
|
829
|
+
const { TOOLCHAIN_MARKERS, detectToolchains } = await import("./release-toolchains.js");
|
|
830
|
+
const projectFiles = TOOLCHAIN_MARKERS.filter((f) => existsSync(join(root, f)));
|
|
831
|
+
const node = projectFiles.includes("package.json");
|
|
832
|
+
const { readerVersion } = await import("./declaration.js");
|
|
833
|
+
let text;
|
|
834
|
+
// #5183: an artifact's builtBy names a job of release.workflow.builds, so a workflow without it is refused here, not at the cut.
|
|
835
|
+
if ((release?.artifacts?.length ?? 0) > 0) {
|
|
836
|
+
const { checkReleaseArtifacts, ReleaseArtifactError } = await import("../lifecycle/release-artifacts.js");
|
|
837
|
+
try {
|
|
838
|
+
checkReleaseArtifacts(release.artifacts, { builds: release?.workflow?.builds ?? [] });
|
|
839
|
+
}
|
|
840
|
+
catch (err) {
|
|
841
|
+
if (!(err instanceof ReleaseArtifactError))
|
|
842
|
+
throw err;
|
|
843
|
+
console.error(formatError({ message: `${err.message} [${err.code}]`, hint: err.fix ?? "Fix release.artifacts in chant.config.ts." }));
|
|
844
|
+
return 1;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
try {
|
|
848
|
+
text = renderReleaseWorkflow({
|
|
849
|
+
forge,
|
|
850
|
+
projectFiles,
|
|
851
|
+
...(node || args.ciInstall || release?.workflow?.install !== undefined ? {} : { install: null }),
|
|
852
|
+
...(node || args.ciChant || release?.workflow?.chant !== undefined ? {} : { chant: `npx --yes @intentius/chant@${readerVersion()}` }),
|
|
853
|
+
groups,
|
|
854
|
+
workspaceRoot,
|
|
855
|
+
tags,
|
|
856
|
+
...(release?.workflow ? { pipeline: release.workflow } : {}),
|
|
857
|
+
...((release?.images?.length ?? 0) > 0 ? { images: true, imageArchives: resolveReleaseImages(release.images).map((i) => i.archive), imagePlatforms: releaseImagePlatforms(release.images) } : {}),
|
|
858
|
+
...((release?.artifacts?.length ?? 0) > 0 ? { artifacts: true, ...((await import("../lifecycle/release-artifacts.js")).usesGoreleaser(release.artifacts) ? { goreleaser: true } : {}), ...((await import("../lifecycle/release-artifacts.js")).usesNfpm(release.artifacts) ? { nfpm: true } : {}) } : {}),
|
|
859
|
+
...(release?.lane ? { lane: release.lane } : {}),
|
|
860
|
+
green: await (async () => {
|
|
861
|
+
const { resolveGreenSource } = await import("../lifecycle/release-green.js");
|
|
862
|
+
const { scopeSource } = await import("./write-scope.js");
|
|
863
|
+
const { execFileSync } = await import("node:child_process");
|
|
864
|
+
let greenTags = "";
|
|
865
|
+
try {
|
|
866
|
+
greenTags = execFileSync("git", ["tag", "--list", "ci/green/*", "ci/green-*/*"], { cwd: root, encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
867
|
+
}
|
|
868
|
+
catch {
|
|
869
|
+
greenTags = "";
|
|
870
|
+
}
|
|
871
|
+
return resolveGreenSource(release?.green, (scopeSource(root).declaration?.ci?.green ?? null) !== null, release?.green === undefined && greenTags !== "");
|
|
872
|
+
})(),
|
|
873
|
+
...(release?.version ? { version: true } : {}),
|
|
874
|
+
...(signs ? { signing: true } : {}),
|
|
875
|
+
...(allTargets.length > 0 ? { publish: allTargets } : {}),
|
|
876
|
+
...(release?.train ? { train: { env: release.train.env } } : {}),
|
|
877
|
+
...(args.ciInstall ? { install: args.ciInstall } : {}),
|
|
878
|
+
...(args.buildCommand ? { build: args.buildCommand } : !hasBuildScript(root) && release?.workflow?.build === undefined ? { build: null } : {}),
|
|
879
|
+
...(args.ciChant ? { chant: args.ciChant } : {}),
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
catch (err) {
|
|
883
|
+
console.error(formatError({ message: err instanceof Error ? err.message : String(err), hint: "Fix release.workflow in chant.config.ts." }));
|
|
884
|
+
return 1;
|
|
885
|
+
}
|
|
536
886
|
// #4909: under `chant dev generated-check` the header names the committed file the render stands for.
|
|
537
887
|
// #4950: with no --output the file goes to the render tree too, so a render needs no `--output {out}/...`.
|
|
538
888
|
const { committedPathOf, isRenderPath, renderPathOf } = await import("../generated-check.js");
|
|
@@ -548,11 +898,23 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
548
898
|
parts.push("--chant", args.ciChant);
|
|
549
899
|
if (args.output && !(isRenderPath(target) && asCommitted === defaultTarget))
|
|
550
900
|
parts.push("--output", relative(root, asCommitted).split(sep).join("/"));
|
|
901
|
+
// A file a person wrote, such as the npm publish workflow release.workflow.file names, is replaced only with --force.
|
|
902
|
+
if (args.force !== true && existsSync(target) && !readFileSync(target, "utf-8").includes(GENERATED_MARKER)) {
|
|
903
|
+
const shownTarget = relative(process.cwd(), target).split(sep).join("/") || target;
|
|
904
|
+
console.error(formatError({ message: `${shownTarget} exists and chant did not write it [release-workflow-exists]`, hint: "Run again with --force to replace it." }));
|
|
905
|
+
return 1;
|
|
906
|
+
}
|
|
551
907
|
mkdirSync(dirname(target), { recursive: true });
|
|
552
908
|
writeFileSync(target, releaseWorkflowHeader(parts.map(shellArg).join(" ")) + text);
|
|
553
909
|
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?.
|
|
910
|
+
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);
|
|
911
|
+
const what = release?.train
|
|
912
|
+
? release.workflow?.trigger === "dispatch"
|
|
913
|
+
? `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`
|
|
914
|
+
: `publishes the release train a release-train/${release.train.env}/* tag names`
|
|
915
|
+
: release?.workflow?.trigger === "dispatch"
|
|
916
|
+
? "cuts and publishes a release started by hand with its label, from a green commit"
|
|
917
|
+
: `publishes the release a ${tags.template.legacy ? "release/**" : releaseTagFilters(tags).globs[0]} tag names`;
|
|
556
918
|
console.log(formatSuccess(`Wrote ${shown}: ${what}${extras.length > 0 ? `, and ${extras.join(" and ")}` : ""}.`));
|
|
557
919
|
if (forge === "gitlab")
|
|
558
920
|
console.log(`Include it from .gitlab-ci.yml: include: [{ local: ${release?.workflow?.file ?? RELEASE_WORKFLOW_FILES.gitlab} }]`);
|
|
@@ -560,6 +922,13 @@ export async function runReleaseWorkflow(ctx) {
|
|
|
560
922
|
const archs = (release?.images?.length ?? 0) > 0 ? qemuArchitectures(releaseImagePlatforms(release.images)) : [];
|
|
561
923
|
if (forge === "gitlab" && archs.length > 0 && text.includes(`${RELEASE_BINFMT_IMAGE} --install`))
|
|
562
924
|
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.`);
|
|
925
|
+
const others = detectToolchains(new Set(projectFiles)).filter((t) => t !== "node");
|
|
926
|
+
if (forge === "gitlab" && others.length > 0 && release?.workflow?.toolchains === undefined)
|
|
927
|
+
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.`);
|
|
928
|
+
if (forge === "gitlab" && release?.workflow?.trigger !== "dispatch" && tags.template.floating)
|
|
929
|
+
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.`);
|
|
930
|
+
if (forge === "gitlab" && text.includes("CHANT_GORELEASER=/tmp/goreleaser"))
|
|
931
|
+
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
932
|
if (forge === "gitlab" && release?.workflow?.trigger === "dispatch")
|
|
564
933
|
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
934
|
return 0;
|