@intentius/chant 0.124.100 → 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/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/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 +42 -1
- package/dist/cli/handlers/release.js +656 -31
- 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 +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/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 +294 -9
- package/dist/config.js +100 -5
- package/dist/floor-table.data.js +15 -1
- 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/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 +8 -1
- package/dist/release-floors.js +9 -2
- package/dist/tool-pins.d.ts +38 -0
- package/dist/tool-pins.js +54 -0
- 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 +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 +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 +1 -1
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Files a release builds once, in its cut (#5151): binaries, archives of
|
|
3
|
+
* them, a checksums file, or what goreleaser writes.
|
|
4
|
+
*
|
|
5
|
+
* `release.artifacts` in `chant.config.ts` lists them, in order:
|
|
6
|
+
*
|
|
7
|
+
* - `{ name, build, outputs, platforms?, archive? }`: the cut runs `build` in
|
|
8
|
+
* the member's directory, once, or once per platform with
|
|
9
|
+
* `CHANT_RELEASE_OS`, `CHANT_RELEASE_ARCH` and `CHANT_RELEASE_EXT` set
|
|
10
|
+
* (`.exe` on Windows, else empty), and records each file `outputs` names.
|
|
11
|
+
* An output may hold `{os}`, `{arch}`, `{ext}`, `{label}` and `{version}`,
|
|
12
|
+
* and `*` or `?` within a path segment. With `archive`, chant packs each
|
|
13
|
+
* platform's outputs, with `archive.files` beside them, into a tar.gz
|
|
14
|
+
* (a zip on Windows), and the release records the archives in place of
|
|
15
|
+
* the outputs. chant writes the archives itself, every entry dated
|
|
16
|
+
* `SOURCE_DATE_EPOCH` and owned by root, so the same files pack to the
|
|
17
|
+
* same bytes.
|
|
18
|
+
* - `{ name, outputs, platforms?, archive?, builtBy? }`, with no `build`
|
|
19
|
+
* (#5183): files something else built, such as a `release.workflow.builds`
|
|
20
|
+
* job on another runner, whose archive the release workflow unpacks into
|
|
21
|
+
* the checkout before the cut. The cut runs nothing and records the files
|
|
22
|
+
* at `outputs`, per platform, packing them as above; one that is not there
|
|
23
|
+
* stops it (`release-artifact-not-built`). `builtBy` names the build jobs
|
|
24
|
+
* that write them, and `outputs` defaults to those jobs' outputs. Under
|
|
25
|
+
* `--at` the cut reads them from the checkout it runs in, which must be at
|
|
26
|
+
* the commit it cuts.
|
|
27
|
+
* - `{ name, goreleaser: { config?, dist?, types? } }`: the cut runs
|
|
28
|
+
* `goreleaser release --snapshot --clean --skip=publish`, so goreleaser
|
|
29
|
+
* builds and publishes nothing, checks that `<dist>/metadata.json` gives
|
|
30
|
+
* the release's label as the version (the config's
|
|
31
|
+
* `snapshot.version_template` is `{{ .Env.CHANT_RELEASE_LABEL }}`), and
|
|
32
|
+
* records the files `<dist>/artifacts.json` lists of `types`. chant's own
|
|
33
|
+
* targets publish them. The goreleaser run is `CHANT_GORELEASER` when set,
|
|
34
|
+
* which `chant release workflow` points at the version it pins
|
|
35
|
+
* (../tool-pins.ts), else `goreleaser` on the PATH.
|
|
36
|
+
* - `{ name, checksums, of? }`: a file of `<sha256> <file name>` lines, as
|
|
37
|
+
* `sha256sum` writes and checks them, over the files of the entries `of`
|
|
38
|
+
* names (default: every entry before it).
|
|
39
|
+
*
|
|
40
|
+
* Each file is recorded in the release as an `asset` artifact whose
|
|
41
|
+
* `component` is the entry's name, so a publish target that reads a file at
|
|
42
|
+
* a recorded path refuses one whose digest differs
|
|
43
|
+
* (`publish-artifact-digest-mismatch`, ./publish-targets.ts). A forge,
|
|
44
|
+
* homebrew or index target names an entry's files with `artifact:<name>` in its
|
|
45
|
+
* `assets`.
|
|
46
|
+
*
|
|
47
|
+
* A dispatched release workflow hands the files from the cut job to the
|
|
48
|
+
* publish job, which checks them against the record (`chant release
|
|
49
|
+
* artifacts --from`). A workflow on a release tag builds them again from
|
|
50
|
+
* the release's commit (`chant release artifacts <label>`) and refuses a
|
|
51
|
+
* file that differs, which needs builds that write the same bytes twice.
|
|
52
|
+
*/
|
|
53
|
+
import { spawnSync } from "node:child_process";
|
|
54
|
+
import { createHash } from "node:crypto";
|
|
55
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
56
|
+
import { dirname, isAbsolute, posix, relative, resolve } from "node:path";
|
|
57
|
+
import { deflateRawSync, gzipSync } from "node:zlib";
|
|
58
|
+
/** The first chant with `release.artifacts`, `chant release artifacts` and `artifact:<name>` in a forge or homebrew target's `assets` (#5151). */
|
|
59
|
+
export const RELEASE_ARTIFACTS_FLOOR = "0.124.101";
|
|
60
|
+
/** The variable naming the goreleaser binary the cut runs. */
|
|
61
|
+
export const GORELEASER_ENV = "CHANT_GORELEASER";
|
|
62
|
+
/**
|
|
63
|
+
* The `artifacts.json` types recorded from goreleaser by default: what its
|
|
64
|
+
* own release would upload. A `Binary` is recorded only when it sits at the
|
|
65
|
+
* top of `dist`, as goreleaser writes an uploadable binary; the binaries it
|
|
66
|
+
* builds for archives sit in a directory per target.
|
|
67
|
+
*/
|
|
68
|
+
export const GORELEASER_TYPES = ["Archive", "Binary", "Checksum", "File", "Linux Package", "SBOM", "Source"];
|
|
69
|
+
export class ReleaseArtifactError extends Error {
|
|
70
|
+
constructor(code, message, fix) {
|
|
71
|
+
super(message);
|
|
72
|
+
this.code = code;
|
|
73
|
+
this.fix = fix;
|
|
74
|
+
this.name = "ReleaseArtifactError";
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
78
|
+
const PLATFORM = /^[a-z0-9]+\/[a-z0-9_]+(?:\/[a-z0-9]+)?$/;
|
|
79
|
+
const PLACEHOLDER = /\{([a-z]+)\}/g;
|
|
80
|
+
const OUTPUT_KEYS = new Set(["os", "arch", "ext", "label", "version"]);
|
|
81
|
+
const ARCHIVE_KEYS = new Set(["name", "os", "arch", "label", "version"]);
|
|
82
|
+
const outside = (p) => isAbsolute(p) || p.split(/[\\/]/).includes("..");
|
|
83
|
+
const isGoreleaser = (a) => "goreleaser" in a && a.goreleaser !== undefined;
|
|
84
|
+
const isChecksums = (a) => "checksums" in a && a.checksums !== undefined;
|
|
85
|
+
/** An entry of files at `outputs`: built by its command, or (#5183) with no command, built before the cut. */
|
|
86
|
+
const isFiles = (a) => ("build" in a && a.build !== undefined) || ("outputs" in a && a.outputs !== undefined) || ("builtBy" in a && a.builtBy !== undefined);
|
|
87
|
+
const commandOf = (a) => ("build" in a ? a.build : undefined);
|
|
88
|
+
const builtByOf = (a) => {
|
|
89
|
+
const b = "builtBy" in a ? a.builtBy : undefined;
|
|
90
|
+
return b === undefined ? [] : Array.isArray(b) ? b : [b];
|
|
91
|
+
};
|
|
92
|
+
/** Whether the cut records an entry's files as something else built them, with no command of its own (#5183). */
|
|
93
|
+
export function isPrebuilt(a) {
|
|
94
|
+
return isFiles(a) && commandOf(a) === undefined;
|
|
95
|
+
}
|
|
96
|
+
/** An entry's outputs: its own, or the outputs of the build jobs `builtBy` names. */
|
|
97
|
+
function outputsOf(a, builds) {
|
|
98
|
+
if (a.outputs !== undefined)
|
|
99
|
+
return a.outputs;
|
|
100
|
+
return builtByOf(a).flatMap((n) => builds?.find((b) => b.name === n)?.outputs ?? []);
|
|
101
|
+
}
|
|
102
|
+
/** The label from its first digit, as a formula's and goreleaser's version reads it: `v1.4.0` is `1.4.0`. */
|
|
103
|
+
export function labelVersion(label) {
|
|
104
|
+
const at = label?.search(/\d/) ?? -1;
|
|
105
|
+
return label && at >= 0 ? label.slice(at) : null;
|
|
106
|
+
}
|
|
107
|
+
function placeholders(text) {
|
|
108
|
+
return [...text.matchAll(PLACEHOLDER)].map((m) => m[1]);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Check `release.artifacts`: names valid and unique and not an image's, one
|
|
112
|
+
* of `build`, `goreleaser` and `checksums`, paths inside the member,
|
|
113
|
+
* platforms of the form os/arch, placeholders chant fills, and a checksums
|
|
114
|
+
* entry's `of` naming entries before it.
|
|
115
|
+
*/
|
|
116
|
+
export function checkReleaseArtifacts(artifacts, o = {}) {
|
|
117
|
+
const seen = new Set();
|
|
118
|
+
const where = (a) => `release.artifacts "${a.name}"`;
|
|
119
|
+
const inside = (a, what, p) => {
|
|
120
|
+
if (p !== undefined && outside(p))
|
|
121
|
+
throw new ReleaseArtifactError("release-artifact-outside", `${where(a)}: ${what} ${p} is not a path inside the member`);
|
|
122
|
+
};
|
|
123
|
+
for (const a of artifacts) {
|
|
124
|
+
if (!NAME.test(a.name))
|
|
125
|
+
throw new ReleaseArtifactError("release-artifact-name-invalid", `release.artifacts: "${a.name}" is not a name of letters, digits, ".", "_" and "-"`);
|
|
126
|
+
if (seen.has(a.name))
|
|
127
|
+
throw new ReleaseArtifactError("release-artifact-name-taken", `release.artifacts names "${a.name}" twice`);
|
|
128
|
+
if (o.imageNames?.includes(a.name))
|
|
129
|
+
throw new ReleaseArtifactError("release-artifact-name-taken", `release.artifacts names "${a.name}", which release.images names too, and a release records each name once`, "Rename one of them.");
|
|
130
|
+
const kinds = [isFiles(a), isGoreleaser(a), isChecksums(a)].filter(Boolean).length;
|
|
131
|
+
if (kinds !== 1)
|
|
132
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)} names ${kinds === 0 ? "none" : "more than one"} of outputs, goreleaser and checksums; name one`);
|
|
133
|
+
if (isFiles(a)) {
|
|
134
|
+
const jobs = builtByOf(a);
|
|
135
|
+
if (jobs.length > 0 && commandOf(a) !== undefined)
|
|
136
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)} names both a build command and builtBy; the cut runs the command, or records what the build jobs wrote`, "Leave out build to record the files the build jobs hand to the cut.");
|
|
137
|
+
for (const j of jobs) {
|
|
138
|
+
if (!o.builds?.some((b) => b.name === j)) {
|
|
139
|
+
const known = (o.builds ?? []).map((b) => b.name);
|
|
140
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: builtBy names "${j}", which is not a release.workflow.builds job${known.length > 0 ? ` (they are ${known.join(", ")})` : ""}`, "Name a job of release.workflow.builds, or leave out builtBy and name the files in outputs.");
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (a.outputs === undefined && jobs.length === 0)
|
|
144
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)} names no outputs`);
|
|
145
|
+
if (a.outputs === undefined && a.platforms !== undefined)
|
|
146
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)} has platforms and no outputs; a build job's outputs name no platform`, "Name each platform's files in outputs with {os}, {arch} and {ext}.");
|
|
147
|
+
const outputs = outputsOf(a, o.builds);
|
|
148
|
+
if (outputs.length === 0)
|
|
149
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)} names no outputs`);
|
|
150
|
+
if (a.outputs === undefined) {
|
|
151
|
+
const bracket = outputs.find((p) => /[[\]]/.test(p));
|
|
152
|
+
if (bracket !== undefined)
|
|
153
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: the build job's output ${bracket} uses a [ ] glob, which an artifact's outputs do not`, "Name the files in outputs, with * and ?.");
|
|
154
|
+
}
|
|
155
|
+
if (a.platforms !== undefined && (a.platforms.length === 0 || !a.platforms.every((p) => PLATFORM.test(p)) || new Set(a.platforms).size !== a.platforms.length)) {
|
|
156
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: platforms is a list of distinct os/arch such as linux/amd64, not ${JSON.stringify(a.platforms)}`);
|
|
157
|
+
}
|
|
158
|
+
for (const out of outputs) {
|
|
159
|
+
inside(a, "the output", out);
|
|
160
|
+
const unknown = placeholders(out).filter((k) => !OUTPUT_KEYS.has(k));
|
|
161
|
+
if (unknown.length > 0)
|
|
162
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: the output ${out} names {${unknown[0]}}; an output may hold {os}, {arch}, {ext}, {label} and {version}`);
|
|
163
|
+
if (a.platforms === undefined && placeholders(out).some((k) => k === "os" || k === "arch" || k === "ext")) {
|
|
164
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: the output ${out} names a platform, and the entry has no platforms`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (a.archive !== undefined && a.archive !== true) {
|
|
168
|
+
inside(a, "the archive directory", a.archive.dir);
|
|
169
|
+
for (const f of a.archive.files ?? []) {
|
|
170
|
+
inside(a, "the archived file", f);
|
|
171
|
+
if (/[*?]/.test(f))
|
|
172
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: archive.files names ${f}; name each file`);
|
|
173
|
+
}
|
|
174
|
+
if (a.archive.name !== undefined) {
|
|
175
|
+
const unknown = placeholders(a.archive.name).filter((k) => !ARCHIVE_KEYS.has(k));
|
|
176
|
+
if (unknown.length > 0 || /[\\/]/.test(a.archive.name))
|
|
177
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: archive.name ${a.archive.name} is not a file name holding {name}, {os}, {arch}, {label} and {version}`);
|
|
178
|
+
}
|
|
179
|
+
if (a.archive.format !== undefined && a.archive.format !== "tar.gz" && a.archive.format !== "zip")
|
|
180
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: archive.format is tar.gz or zip`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else if (isGoreleaser(a)) {
|
|
184
|
+
inside(a, "the goreleaser config", a.goreleaser.config);
|
|
185
|
+
inside(a, "the dist directory", a.goreleaser.dist);
|
|
186
|
+
if (a.goreleaser.types !== undefined && a.goreleaser.types.length === 0)
|
|
187
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: goreleaser.types is empty, so nothing would be recorded`);
|
|
188
|
+
}
|
|
189
|
+
else if (isChecksums(a)) {
|
|
190
|
+
inside(a, "the checksums file", a.checksums);
|
|
191
|
+
for (const n of a.of ?? []) {
|
|
192
|
+
if (!seen.has(n))
|
|
193
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: of names "${n}", which is not an entry before it`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
seen.add(a.name);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** Every platform a Go-style `os/arch` names, with its Windows extension. */
|
|
200
|
+
function platformValues(platform) {
|
|
201
|
+
const [os, ...rest] = platform.split("/");
|
|
202
|
+
return { os: os, arch: rest.join("_"), ext: os === "windows" ? ".exe" : "" };
|
|
203
|
+
}
|
|
204
|
+
function fill(text, values, what) {
|
|
205
|
+
return text.replace(PLACEHOLDER, (m, k) => {
|
|
206
|
+
const v = values[k];
|
|
207
|
+
if (v === undefined) {
|
|
208
|
+
if (k === "label" || k === "version")
|
|
209
|
+
throw new ReleaseArtifactError("release-artifact-no-label", `${what} names {${k}}, and the cut has no label${k === "version" ? " with a digit" : ""}`, "Cut the release with a label such as v1.4.0.");
|
|
210
|
+
return m;
|
|
211
|
+
}
|
|
212
|
+
return v;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/** The files a path names, `*` and `?` matched within a segment, sorted. */
|
|
216
|
+
export function expandOutput(cwd, pattern) {
|
|
217
|
+
const parts = pattern.replace(/\\/g, "/").replace(/^\.\//, "").split("/").filter((s) => s !== "" && s !== ".");
|
|
218
|
+
let found = [""];
|
|
219
|
+
for (const [i, part] of parts.entries()) {
|
|
220
|
+
const last = i === parts.length - 1;
|
|
221
|
+
const next = [];
|
|
222
|
+
for (const base of found) {
|
|
223
|
+
if (!/[*?]/.test(part)) {
|
|
224
|
+
const p = base ? `${base}/${part}` : part;
|
|
225
|
+
if (existsSync(resolve(cwd, p)))
|
|
226
|
+
next.push(p);
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
const dir = resolve(cwd, base || ".");
|
|
230
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory())
|
|
231
|
+
continue;
|
|
232
|
+
const re = new RegExp(`^${part.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]")}$`);
|
|
233
|
+
for (const e of readdirSync(dir).sort())
|
|
234
|
+
if (re.test(e))
|
|
235
|
+
next.push(base ? `${base}/${e}` : e);
|
|
236
|
+
}
|
|
237
|
+
found = last ? next.filter((p) => statSync(resolve(cwd, p)).isFile()) : next.filter((p) => statSync(resolve(cwd, p)).isDirectory());
|
|
238
|
+
}
|
|
239
|
+
return found.sort();
|
|
240
|
+
}
|
|
241
|
+
const defaultRun = (command, o) => spawnSync(command, { cwd: o.cwd, env: o.env, shell: true, stdio: ["ignore", 2, 2] }).status;
|
|
242
|
+
const posixPath = (cwd, abs) => relative(cwd, abs).split("\\").join("/");
|
|
243
|
+
/** `sha256:<hex>` of a file. */
|
|
244
|
+
function digestOf(abs) {
|
|
245
|
+
return `sha256:${createHash("sha256").update(readFileSync(abs)).digest("hex")}`;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Build every entry, in order, and return each file as the release's asset
|
|
249
|
+
* artifact. A command that fails, an output it did not write, a goreleaser
|
|
250
|
+
* version that is not the label, or two entries writing one path stops the
|
|
251
|
+
* cut.
|
|
252
|
+
*/
|
|
253
|
+
export function buildReleaseArtifacts(i) {
|
|
254
|
+
checkReleaseArtifacts(i.artifacts, { ...(i.imageNames ? { imageNames: i.imageNames } : {}), ...(i.builds ? { builds: i.builds } : {}) });
|
|
255
|
+
const run = i.run ?? defaultRun;
|
|
256
|
+
const version = labelVersion(i.label);
|
|
257
|
+
const labelValues = { ...(i.label !== null ? { label: i.label } : {}), ...(version !== null ? { version } : {}) };
|
|
258
|
+
const baseEnv = () => {
|
|
259
|
+
const env = { ...(i.env ?? process.env), SOURCE_DATE_EPOCH: String(i.sourceDateEpoch) };
|
|
260
|
+
for (const k of ["CHANT_RELEASE_LABEL", "CHANT_RELEASE_OS", "CHANT_RELEASE_ARCH", "CHANT_RELEASE_EXT"])
|
|
261
|
+
delete env[k];
|
|
262
|
+
if (i.label !== null)
|
|
263
|
+
env.CHANT_RELEASE_LABEL = i.label;
|
|
264
|
+
return env;
|
|
265
|
+
};
|
|
266
|
+
const byEntry = new Map();
|
|
267
|
+
const owner = new Map();
|
|
268
|
+
const record = (entry, abs) => {
|
|
269
|
+
const path = posixPath(i.cwd, abs);
|
|
270
|
+
if (path.startsWith("..") || isAbsolute(path))
|
|
271
|
+
throw new ReleaseArtifactError("release-artifact-outside", `release.artifacts "${entry}": ${abs} is not inside the member`);
|
|
272
|
+
const prior = owner.get(path);
|
|
273
|
+
if (prior !== undefined)
|
|
274
|
+
throw new ReleaseArtifactError("release-artifact-output-taken", `release.artifacts "${entry}" writes ${path}, which ${prior === entry ? "it already wrote for another platform" : `"${prior}" wrote`}, and a release records each file once`);
|
|
275
|
+
owner.set(path, entry);
|
|
276
|
+
return { component: entry, kind: "asset", path, digest: digestOf(abs) };
|
|
277
|
+
};
|
|
278
|
+
const out = [];
|
|
279
|
+
for (const a of i.artifacts) {
|
|
280
|
+
const files = [];
|
|
281
|
+
if (isFiles(a)) {
|
|
282
|
+
const command = commandOf(a);
|
|
283
|
+
const outputs = outputsOf(a, i.builds);
|
|
284
|
+
for (const platform of a.platforms ?? [null]) {
|
|
285
|
+
const env = baseEnv();
|
|
286
|
+
const values = { ...labelValues };
|
|
287
|
+
if (platform !== null) {
|
|
288
|
+
const p = platformValues(platform);
|
|
289
|
+
Object.assign(values, p);
|
|
290
|
+
env.CHANT_RELEASE_OS = p.os;
|
|
291
|
+
env.CHANT_RELEASE_ARCH = p.arch;
|
|
292
|
+
env.CHANT_RELEASE_EXT = p.ext;
|
|
293
|
+
}
|
|
294
|
+
const on = platform !== null ? ` for ${platform}` : "";
|
|
295
|
+
if (command !== undefined) {
|
|
296
|
+
const status = run(command, { cwd: i.cwd, env });
|
|
297
|
+
if (status !== 0)
|
|
298
|
+
throw new ReleaseArtifactError("release-artifact-build-failed", `the build of artifact "${a.name}"${on} exited ${status ?? "with a signal"}: ${command}`);
|
|
299
|
+
}
|
|
300
|
+
// #5183: with no command, the files are read where something else left them, copied in first under --at.
|
|
301
|
+
const from = command === undefined && i.prebuiltFrom !== undefined ? i.prebuiltFrom : i.cwd;
|
|
302
|
+
const written = [];
|
|
303
|
+
for (const pattern of outputs) {
|
|
304
|
+
const path = fill(pattern, values, `release.artifacts "${a.name}"`);
|
|
305
|
+
const found = expandOutput(from, path);
|
|
306
|
+
if (found.length === 0) {
|
|
307
|
+
if (command !== undefined)
|
|
308
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `the build of artifact "${a.name}"${on} wrote no ${path}`, "Make the build write every file outputs names, or name the files it writes.");
|
|
309
|
+
const jobs = builtByOf(a);
|
|
310
|
+
throw new ReleaseArtifactError("release-artifact-not-built", `artifact "${a.name}"${on} has no ${path}: the entry has no build command, so the file must be there before the cut${jobs.length > 0 ? `, written by the build job${jobs.length > 1 ? "s" : ""} ${jobs.join(", ")}` : ""}`, jobs.length > 0 ? "Make the build job write every file outputs names, or name the files it writes." : "Build the file before the cut (a release.workflow.builds job, or a step before it), or give the entry a build command.");
|
|
311
|
+
}
|
|
312
|
+
if (from !== i.cwd)
|
|
313
|
+
copyArtifactFiles(found.map((f) => ({ path: f })), from, i.cwd);
|
|
314
|
+
written.push(...found);
|
|
315
|
+
}
|
|
316
|
+
if (a.archive === undefined) {
|
|
317
|
+
for (const w of written)
|
|
318
|
+
files.push(record(a.name, resolve(i.cwd, w)));
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
const spec = a.archive === true ? {} : a.archive;
|
|
322
|
+
const format = spec.format ?? (values.os === "windows" ? "zip" : "tar.gz");
|
|
323
|
+
const base = fill(spec.name ?? (platform !== null ? "{name}_{os}_{arch}" : "{name}"), { ...values, name: a.name }, `release.artifacts "${a.name}" archive.name`);
|
|
324
|
+
const archive = resolve(i.cwd, spec.dir ?? "dist", `${base}.${format}`);
|
|
325
|
+
const entries = [
|
|
326
|
+
...written.map((w) => ({ name: posix.basename(w), abs: resolve(i.cwd, w) })),
|
|
327
|
+
...(spec.files ?? []).map((f) => {
|
|
328
|
+
const abs = resolve(i.cwd, f);
|
|
329
|
+
if (!existsSync(abs) || !statSync(abs).isFile())
|
|
330
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `artifact "${a.name}" archives ${f}, which is not a file in the member`);
|
|
331
|
+
return { name: f.replace(/\\/g, "/").replace(/^\.\//, ""), abs };
|
|
332
|
+
}),
|
|
333
|
+
];
|
|
334
|
+
const names = new Set();
|
|
335
|
+
for (const e of entries) {
|
|
336
|
+
if (names.has(e.name))
|
|
337
|
+
throw new ReleaseArtifactError("release-artifact-output-taken", `artifact "${a.name}"${on} would put two files named ${e.name} in ${posixPath(i.cwd, archive)}`);
|
|
338
|
+
names.add(e.name);
|
|
339
|
+
}
|
|
340
|
+
mkdirSync(dirname(archive), { recursive: true });
|
|
341
|
+
writeFileSync(archive, format === "zip" ? zipArchive(entries, i.sourceDateEpoch) : tarGzArchive(entries, i.sourceDateEpoch));
|
|
342
|
+
files.push(record(a.name, archive));
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
else if (isGoreleaser(a)) {
|
|
346
|
+
files.push(...goreleaserFiles(a, i, baseEnv(), run).map((abs) => record(a.name, abs)));
|
|
347
|
+
}
|
|
348
|
+
else if (isChecksums(a)) {
|
|
349
|
+
const names = a.of ?? [...byEntry.keys()];
|
|
350
|
+
const covered = names.flatMap((n) => byEntry.get(n) ?? []);
|
|
351
|
+
const lines = new Map();
|
|
352
|
+
for (const c of covered) {
|
|
353
|
+
const base = posix.basename(c.path);
|
|
354
|
+
if (lines.has(base))
|
|
355
|
+
throw new ReleaseArtifactError("release-artifact-checksums-name-taken", `checksums "${a.name}" covers two files named ${base}, and a line names a file by its name`, "Name the entries whose files have distinct names in of.");
|
|
356
|
+
lines.set(base, `${c.digest.slice("sha256:".length)} ${base}`);
|
|
357
|
+
}
|
|
358
|
+
if (lines.size === 0)
|
|
359
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `checksums "${a.name}" covers no file`, "Declare it after the entries whose files it lists.");
|
|
360
|
+
const abs = resolve(i.cwd, a.checksums);
|
|
361
|
+
mkdirSync(dirname(abs), { recursive: true });
|
|
362
|
+
writeFileSync(abs, `${[...lines.keys()].sort().map((k) => lines.get(k)).join("\n")}\n`);
|
|
363
|
+
files.push(record(a.name, abs));
|
|
364
|
+
}
|
|
365
|
+
byEntry.set(a.name, files);
|
|
366
|
+
out.push(...files);
|
|
367
|
+
}
|
|
368
|
+
return out;
|
|
369
|
+
}
|
|
370
|
+
/** Run goreleaser in snapshot mode and list the files it wrote that the entry records. */
|
|
371
|
+
function goreleaserFiles(a, i, env, run) {
|
|
372
|
+
if (i.label === null)
|
|
373
|
+
throw new ReleaseArtifactError("release-artifact-no-label", `artifact "${a.name}" is built by goreleaser, whose binaries carry the release's label as their version, and the cut has no label`, "Cut the release with a label such as v1.4.0.");
|
|
374
|
+
const bin = env[GORELEASER_ENV] || "goreleaser";
|
|
375
|
+
const command = [bin === "goreleaser" ? bin : shellWord(bin), "release", "--snapshot", "--clean", "--skip=publish", ...(a.goreleaser.config ? ["--config", shellWord(a.goreleaser.config)] : [])].join(" ");
|
|
376
|
+
const status = run(command, { cwd: i.cwd, env });
|
|
377
|
+
if (status !== 0)
|
|
378
|
+
throw new ReleaseArtifactError("release-artifact-build-failed", `goreleaser for artifact "${a.name}" exited ${status ?? "with a signal"}: ${command}`);
|
|
379
|
+
const dist = a.goreleaser.dist ?? "dist";
|
|
380
|
+
const read = (file) => {
|
|
381
|
+
const abs = resolve(i.cwd, dist, file);
|
|
382
|
+
if (!existsSync(abs))
|
|
383
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `goreleaser for artifact "${a.name}" wrote no ${posix.join(dist, file)}`, `Set goreleaser.dist to the config's dist directory.`);
|
|
384
|
+
return JSON.parse(readFileSync(abs, "utf-8"));
|
|
385
|
+
};
|
|
386
|
+
const meta = read("metadata.json");
|
|
387
|
+
const want = [i.label, labelVersion(i.label)].filter((v) => v !== null);
|
|
388
|
+
if (typeof meta.version !== "string" || !want.includes(meta.version)) {
|
|
389
|
+
throw new ReleaseArtifactError("release-artifact-version-mismatch", `goreleaser built artifact "${a.name}" as version ${JSON.stringify(meta.version ?? null)}, and the release is labelled ${i.label}, so its binaries would not carry the release's version`, 'Set the snapshot version in the goreleaser config to the label chant passes: snapshot: { version_template: "{{ .Env.CHANT_RELEASE_LABEL }}" }.');
|
|
390
|
+
}
|
|
391
|
+
const listed = read("artifacts.json");
|
|
392
|
+
if (!Array.isArray(listed))
|
|
393
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `${posix.join(dist, "artifacts.json")} is not a list`);
|
|
394
|
+
const types = a.goreleaser.types ?? GORELEASER_TYPES;
|
|
395
|
+
const distAbs = resolve(i.cwd, dist);
|
|
396
|
+
const files = [];
|
|
397
|
+
for (const e of listed) {
|
|
398
|
+
if (typeof e.type !== "string" || typeof e.path !== "string" || !types.includes(e.type))
|
|
399
|
+
continue;
|
|
400
|
+
const abs = resolve(i.cwd, e.path);
|
|
401
|
+
if (a.goreleaser.types === undefined && e.type === "Binary" && dirname(abs) !== distAbs)
|
|
402
|
+
continue;
|
|
403
|
+
if (!existsSync(abs) || !statSync(abs).isFile())
|
|
404
|
+
continue;
|
|
405
|
+
if (!files.includes(abs))
|
|
406
|
+
files.push(abs);
|
|
407
|
+
}
|
|
408
|
+
if (files.length === 0)
|
|
409
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `goreleaser for artifact "${a.name}" listed no file of the types ${types.join(", ")}`);
|
|
410
|
+
return files.sort();
|
|
411
|
+
}
|
|
412
|
+
const shellWord = (s) => (/^[A-Za-z0-9_./:=,@+%-]+$/.test(s) ? s : `'${s.replace(/'/g, "'\\''")}'`);
|
|
413
|
+
const modeOf = (abs) => (statSync(abs).mode & 0o111 ? 0o755 : 0o644);
|
|
414
|
+
function tarHeader(name, size, mode, mtime) {
|
|
415
|
+
const h = Buffer.alloc(512);
|
|
416
|
+
let path = name;
|
|
417
|
+
let prefix = "";
|
|
418
|
+
if (Buffer.byteLength(path) > 100) {
|
|
419
|
+
const cut = path.lastIndexOf("/", path.length - 1);
|
|
420
|
+
prefix = cut > 0 ? path.slice(0, cut) : "";
|
|
421
|
+
path = cut > 0 ? path.slice(cut + 1) : path;
|
|
422
|
+
if (Buffer.byteLength(path) > 100 || Buffer.byteLength(prefix) > 155)
|
|
423
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${name} is too long a path for an archive entry`);
|
|
424
|
+
}
|
|
425
|
+
const octal = (n, width) => n.toString(8).padStart(width - 1, "0") + "\0";
|
|
426
|
+
h.write(path, 0, 100, "utf-8");
|
|
427
|
+
h.write(octal(mode, 8), 100, 8, "ascii");
|
|
428
|
+
h.write(octal(0, 8), 108, 8, "ascii");
|
|
429
|
+
h.write(octal(0, 8), 116, 8, "ascii");
|
|
430
|
+
h.write(octal(size, 12), 124, 12, "ascii");
|
|
431
|
+
h.write(octal(mtime, 12), 136, 12, "ascii");
|
|
432
|
+
h.write(" ", 148, 8, "ascii");
|
|
433
|
+
h.write("0", 156, 1, "ascii");
|
|
434
|
+
h.write("ustar\0", 257, 6, "ascii");
|
|
435
|
+
h.write("00", 263, 2, "ascii");
|
|
436
|
+
h.write(prefix, 345, 155, "utf-8");
|
|
437
|
+
let sum = 0;
|
|
438
|
+
for (const b of h)
|
|
439
|
+
sum += b;
|
|
440
|
+
h.write(`${sum.toString(8).padStart(6, "0")}\0 `, 148, 8, "ascii");
|
|
441
|
+
return h;
|
|
442
|
+
}
|
|
443
|
+
/** A gzipped ustar archive of the entries in order, each dated `mtime`, owned by uid and gid 0 and mode 0755 when executable, else 0644. */
|
|
444
|
+
export function tarGzArchive(entries, mtime) {
|
|
445
|
+
const parts = [];
|
|
446
|
+
for (const e of entries) {
|
|
447
|
+
const data = readFileSync(e.abs);
|
|
448
|
+
parts.push(tarHeader(e.name, data.length, modeOf(e.abs), mtime), data, Buffer.alloc((512 - (data.length % 512)) % 512));
|
|
449
|
+
}
|
|
450
|
+
parts.push(Buffer.alloc(1024));
|
|
451
|
+
const gz = gzipSync(Buffer.concat(parts), { level: 9 });
|
|
452
|
+
// The header's time is zero, and its OS byte is set to Unix so a macOS and a Linux zlib write the same bytes.
|
|
453
|
+
gz.writeUInt32LE(0, 4);
|
|
454
|
+
gz[9] = 3;
|
|
455
|
+
return gz;
|
|
456
|
+
}
|
|
457
|
+
const CRC_TABLE = (() => {
|
|
458
|
+
const t = new Uint32Array(256);
|
|
459
|
+
for (let n = 0; n < 256; n++) {
|
|
460
|
+
let c = n;
|
|
461
|
+
for (let k = 0; k < 8; k++)
|
|
462
|
+
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
463
|
+
t[n] = c >>> 0;
|
|
464
|
+
}
|
|
465
|
+
return t;
|
|
466
|
+
})();
|
|
467
|
+
function crc32(buf) {
|
|
468
|
+
let c = 0xffffffff;
|
|
469
|
+
for (const b of buf)
|
|
470
|
+
c = CRC_TABLE[(c ^ b) & 0xff] ^ (c >>> 8);
|
|
471
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
472
|
+
}
|
|
473
|
+
function dosTime(epoch) {
|
|
474
|
+
const d = new Date(Math.max(epoch, 315532800) * 1000);
|
|
475
|
+
return {
|
|
476
|
+
time: (d.getUTCHours() << 11) | (d.getUTCMinutes() << 5) | Math.floor(d.getUTCSeconds() / 2),
|
|
477
|
+
date: ((d.getUTCFullYear() - 1980) << 9) | ((d.getUTCMonth() + 1) << 5) | d.getUTCDate(),
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
/** A zip of the entries in order, deflated, each dated `mtime` (UTC) with its Unix mode. */
|
|
481
|
+
export function zipArchive(entries, mtime) {
|
|
482
|
+
const { time, date } = dosTime(mtime);
|
|
483
|
+
const locals = [];
|
|
484
|
+
const central = [];
|
|
485
|
+
let offset = 0;
|
|
486
|
+
for (const e of entries) {
|
|
487
|
+
const data = readFileSync(e.abs);
|
|
488
|
+
const packed = deflateRawSync(data, { level: 9 });
|
|
489
|
+
const name = Buffer.from(e.name, "utf-8");
|
|
490
|
+
const crc = crc32(data);
|
|
491
|
+
const local = Buffer.alloc(30);
|
|
492
|
+
local.writeUInt32LE(0x04034b50, 0);
|
|
493
|
+
local.writeUInt16LE(20, 4);
|
|
494
|
+
local.writeUInt16LE(0x0800, 6);
|
|
495
|
+
local.writeUInt16LE(8, 8);
|
|
496
|
+
local.writeUInt16LE(time, 10);
|
|
497
|
+
local.writeUInt16LE(date, 12);
|
|
498
|
+
local.writeUInt32LE(crc, 14);
|
|
499
|
+
local.writeUInt32LE(packed.length, 18);
|
|
500
|
+
local.writeUInt32LE(data.length, 22);
|
|
501
|
+
local.writeUInt16LE(name.length, 26);
|
|
502
|
+
local.writeUInt16LE(0, 28);
|
|
503
|
+
const c = Buffer.alloc(46);
|
|
504
|
+
c.writeUInt32LE(0x02014b50, 0);
|
|
505
|
+
c.writeUInt16LE((3 << 8) | 20, 4);
|
|
506
|
+
c.writeUInt16LE(20, 6);
|
|
507
|
+
c.writeUInt16LE(0x0800, 8);
|
|
508
|
+
c.writeUInt16LE(8, 10);
|
|
509
|
+
c.writeUInt16LE(time, 12);
|
|
510
|
+
c.writeUInt16LE(date, 14);
|
|
511
|
+
c.writeUInt32LE(crc, 16);
|
|
512
|
+
c.writeUInt32LE(packed.length, 20);
|
|
513
|
+
c.writeUInt32LE(data.length, 24);
|
|
514
|
+
c.writeUInt16LE(name.length, 28);
|
|
515
|
+
c.writeUInt32LE(((0o100000 | modeOf(e.abs)) << 16) >>> 0, 38);
|
|
516
|
+
c.writeUInt32LE(offset, 42);
|
|
517
|
+
locals.push(local, name, packed);
|
|
518
|
+
central.push(c, name);
|
|
519
|
+
offset += local.length + name.length + packed.length;
|
|
520
|
+
}
|
|
521
|
+
const dir = Buffer.concat(central);
|
|
522
|
+
const end = Buffer.alloc(22);
|
|
523
|
+
end.writeUInt32LE(0x06054b50, 0);
|
|
524
|
+
end.writeUInt16LE(entries.length, 8);
|
|
525
|
+
end.writeUInt16LE(entries.length, 10);
|
|
526
|
+
end.writeUInt32LE(dir.length, 12);
|
|
527
|
+
end.writeUInt32LE(offset, 16);
|
|
528
|
+
return Buffer.concat([...locals, dir, end]);
|
|
529
|
+
}
|
|
530
|
+
// ── the release's files ────────────────────────────────────────────────
|
|
531
|
+
/** The files the release records for `names`, the entries `release.artifacts` declares. */
|
|
532
|
+
export function releaseArtifactFiles(release, names) {
|
|
533
|
+
return release.artifactDigests.filter((a) => a.kind === "asset" && names.includes(a.component));
|
|
534
|
+
}
|
|
535
|
+
/** Where a recorded file differs from the release in `cwd`: missing, or another digest. */
|
|
536
|
+
export function artifactFileProblems(cwd, files) {
|
|
537
|
+
const out = [];
|
|
538
|
+
for (const f of files) {
|
|
539
|
+
const abs = resolve(cwd, f.path);
|
|
540
|
+
if (!existsSync(abs) || !statSync(abs).isFile()) {
|
|
541
|
+
out.push({ path: f.path, problem: "missing", recorded: f.digest });
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
const digest = digestOf(abs);
|
|
545
|
+
if (digest !== f.digest)
|
|
546
|
+
out.push({ path: f.path, problem: "digest", digest, recorded: f.digest });
|
|
547
|
+
}
|
|
548
|
+
return out;
|
|
549
|
+
}
|
|
550
|
+
/** Copy each file from `from` to the same path under `to`. A file missing from `from` is refused. */
|
|
551
|
+
export function copyArtifactFiles(files, from, to, o = {}) {
|
|
552
|
+
for (const f of files) {
|
|
553
|
+
const src = resolve(from, f.path);
|
|
554
|
+
if (!existsSync(src)) {
|
|
555
|
+
if (o.missingOk)
|
|
556
|
+
continue;
|
|
557
|
+
throw new ReleaseArtifactError("release-artifact-missing", `${f.path} is not in ${from}`, "Hand the job the files the cut staged, or build them again: chant release artifacts <label>.");
|
|
558
|
+
}
|
|
559
|
+
const dest = resolve(to, f.path);
|
|
560
|
+
if (dest === src)
|
|
561
|
+
continue;
|
|
562
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
563
|
+
copyFileSync(src, dest);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
/** Whether any entry is built by goreleaser, for the workflow's install step. */
|
|
567
|
+
export function usesGoreleaser(artifacts) {
|
|
568
|
+
return artifacts.some(isGoreleaser);
|
|
569
|
+
}
|
|
570
|
+
/** The `artifact:<name>` prefix a forge, homebrew or index target's `assets` names an entry's files with. */
|
|
571
|
+
export const ARTIFACT_REF = "artifact:";
|
|
@@ -28,9 +28,10 @@ export interface ReleaseChangelog {
|
|
|
28
28
|
/** The entries of each group, in the order given. */
|
|
29
29
|
groups: Record<ChangelogKind, CatalogChangelogEntry[]>;
|
|
30
30
|
}
|
|
31
|
-
/** The group, scope and description of one commit message. A subject that is not conventional is `other`, kept whole. */
|
|
31
|
+
/** The group, type, scope and description of one commit message. A subject that is not conventional is `other`, kept whole, with no type. */
|
|
32
32
|
export declare function classifyCommit(message: string): {
|
|
33
33
|
kind: ChangelogKind;
|
|
34
|
+
type?: string;
|
|
34
35
|
scope?: string;
|
|
35
36
|
subject: string;
|
|
36
37
|
};
|
|
@@ -38,3 +39,14 @@ export declare function classifyCommit(message: string): {
|
|
|
38
39
|
export declare function changelogBump(messages: readonly string[]): ReleaseBump;
|
|
39
40
|
/** Group `commits` and name their bump. */
|
|
40
41
|
export declare function releaseChangelog(commits: readonly ChangelogCommit[]): ReleaseChangelog;
|
|
42
|
+
/** The commit types a forge release's notes generated from commits list when none are declared (#5153). */
|
|
43
|
+
export declare const DEFAULT_NOTES_TYPES: readonly string[];
|
|
44
|
+
/**
|
|
45
|
+
* Release notes from `commits` (#5153), newest first as `git log` lists
|
|
46
|
+
* them: the commits whose conventional type is in `types`, grouped by
|
|
47
|
+
* {@link releaseChangelog} under a `###` heading each, one line per commit
|
|
48
|
+
* with its scope and short sha. A breaking change is listed whatever its
|
|
49
|
+
* type; `*` in `types` lists every commit, conventional or not. Empty when
|
|
50
|
+
* no commit is listed.
|
|
51
|
+
*/
|
|
52
|
+
export declare function changelogNotes(commits: readonly ChangelogCommit[], types?: readonly string[]): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const HEADER = /^(\w+)(?:\(([^)]*)\))?(!)?:\s*(.*)$/;
|
|
2
2
|
const BREAKING_FOOTER = /^BREAKING[ -]CHANGE:/m;
|
|
3
|
-
/** The group, scope and description of one commit message. A subject that is not conventional is `other`, kept whole. */
|
|
3
|
+
/** The group, type, scope and description of one commit message. A subject that is not conventional is `other`, kept whole, with no type. */
|
|
4
4
|
export function classifyCommit(message) {
|
|
5
5
|
const subject = message.split("\n", 1)[0].trim();
|
|
6
6
|
const m = HEADER.exec(subject);
|
|
@@ -10,7 +10,7 @@ export function classifyCommit(message) {
|
|
|
10
10
|
const type = m[1];
|
|
11
11
|
const scope = m[2] ? m[2].trim() : undefined;
|
|
12
12
|
const kind = breaking ? "breaking" : type === "feat" ? "feat" : type === "fix" ? "fix" : "other";
|
|
13
|
-
return { kind, ...(scope ? { scope } : {}), subject: m[4].trim() || subject };
|
|
13
|
+
return { kind, type, ...(scope ? { scope } : {}), subject: m[4].trim() || subject };
|
|
14
14
|
}
|
|
15
15
|
/** The bump a set of commit messages implies, as terragucci's `bumpFor` decides it. */
|
|
16
16
|
export function changelogBump(messages) {
|
|
@@ -36,3 +36,36 @@ export function releaseChangelog(commits) {
|
|
|
36
36
|
}
|
|
37
37
|
return { bump: changelogBump(commits.map((c) => c.message)), entries, groups };
|
|
38
38
|
}
|
|
39
|
+
/** The commit types a forge release's notes generated from commits list when none are declared (#5153). */
|
|
40
|
+
export const DEFAULT_NOTES_TYPES = ["feat", "fix", "perf"];
|
|
41
|
+
const NOTES_GROUPS = [
|
|
42
|
+
["breaking", "Breaking changes"],
|
|
43
|
+
["feat", "Features"],
|
|
44
|
+
["fix", "Fixes"],
|
|
45
|
+
["other", "Other changes"],
|
|
46
|
+
];
|
|
47
|
+
/**
|
|
48
|
+
* Release notes from `commits` (#5153), newest first as `git log` lists
|
|
49
|
+
* them: the commits whose conventional type is in `types`, grouped by
|
|
50
|
+
* {@link releaseChangelog} under a `###` heading each, one line per commit
|
|
51
|
+
* with its scope and short sha. A breaking change is listed whatever its
|
|
52
|
+
* type; `*` in `types` lists every commit, conventional or not. Empty when
|
|
53
|
+
* no commit is listed.
|
|
54
|
+
*/
|
|
55
|
+
export function changelogNotes(commits, types = DEFAULT_NOTES_TYPES) {
|
|
56
|
+
const all = types.includes("*");
|
|
57
|
+
const listed = commits.filter((c) => {
|
|
58
|
+
const { kind, type } = classifyCommit(c.message);
|
|
59
|
+
return all || kind === "breaking" || (type !== undefined && types.includes(type));
|
|
60
|
+
});
|
|
61
|
+
const { groups } = releaseChangelog(listed);
|
|
62
|
+
const out = [];
|
|
63
|
+
for (const [kind, title] of NOTES_GROUPS) {
|
|
64
|
+
if (groups[kind].length === 0)
|
|
65
|
+
continue;
|
|
66
|
+
if (out.length > 0)
|
|
67
|
+
out.push("");
|
|
68
|
+
out.push(`### ${title}`, "", ...groups[kind].map((e) => `- ${e.scope ? `${e.scope}: ` : ""}${e.subject} (${e.sha.slice(0, 7)})`));
|
|
69
|
+
}
|
|
70
|
+
return out.join("\n");
|
|
71
|
+
}
|