@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
|
@@ -0,0 +1,808 @@
|
|
|
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, helm: { chart, dir?, appVersion? } }` (#5233): chant packs the
|
|
37
|
+
* Helm chart in the directory `chart` into `<dir>/<chart name>-<version>.tgz`
|
|
38
|
+
* itself, as `helm package` lays it out (the chart's files under a
|
|
39
|
+
* directory named for it, less what `.helmignore` and helm's own default
|
|
40
|
+
* leave out), with `version` in `Chart.yaml` set to the label from its first
|
|
41
|
+
* digit and, with `appVersion`, `appVersion` set to the label. Every entry is
|
|
42
|
+
* dated `SOURCE_DATE_EPOCH`, so the same chart packs to the same bytes. No
|
|
43
|
+
* helm is needed; a chart's dependencies are packed as they sit in its
|
|
44
|
+
* `charts/` directory.
|
|
45
|
+
* - `{ name, nfpm: { config?, packagers?, platforms?, dir?, fileName? } }`
|
|
46
|
+
* (#5233): the cut runs nfpm once per packager (`deb` and `rpm` by default)
|
|
47
|
+
* and platform, with `CHANT_RELEASE_VERSION` (the label from its first
|
|
48
|
+
* digit), `CHANT_RELEASE_LABEL`, `CHANT_RELEASE_OS` and `CHANT_RELEASE_ARCH`
|
|
49
|
+
* set for the config to read, and records each package. The config's
|
|
50
|
+
* `version` must name `${CHANT_RELEASE_VERSION}` or `${CHANT_RELEASE_LABEL}`
|
|
51
|
+
* (`release-artifact-version-mismatch`). The nfpm run is `CHANT_NFPM` when
|
|
52
|
+
* set, which `chant release workflow` points at the version it pins
|
|
53
|
+
* (../tool-pins.ts), else `nfpm` on the PATH.
|
|
54
|
+
* - `{ name, checksums, of? }`: a file of `<sha256> <file name>` lines, as
|
|
55
|
+
* `sha256sum` writes and checks them, over the files of the entries `of`
|
|
56
|
+
* names (default: every entry before it).
|
|
57
|
+
*
|
|
58
|
+
* Each file is recorded in the release as an `asset` artifact whose
|
|
59
|
+
* `component` is the entry's name, so a publish target that reads a file at
|
|
60
|
+
* a recorded path refuses one whose digest differs
|
|
61
|
+
* (`publish-artifact-digest-mismatch`, ./publish-targets.ts). A forge,
|
|
62
|
+
* homebrew or index target names an entry's files with `artifact:<name>` in its
|
|
63
|
+
* `assets`.
|
|
64
|
+
*
|
|
65
|
+
* A dispatched release workflow hands the files from the cut job to the
|
|
66
|
+
* publish job, which checks them against the record (`chant release
|
|
67
|
+
* artifacts --from`). A workflow on a release tag builds them again from
|
|
68
|
+
* the release's commit (`chant release artifacts <label>`) and refuses a
|
|
69
|
+
* file that differs, which needs builds that write the same bytes twice.
|
|
70
|
+
*/
|
|
71
|
+
import { spawnSync } from "node:child_process";
|
|
72
|
+
import { createHash } from "node:crypto";
|
|
73
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
74
|
+
import { dirname, isAbsolute, posix, relative, resolve } from "node:path";
|
|
75
|
+
import { deflateRawSync, gzipSync } from "node:zlib";
|
|
76
|
+
import { NEXT_RELEASE } from "../release-floors.js";
|
|
77
|
+
import { stampVersionFile } from "./release-version-formats.js";
|
|
78
|
+
import { parseYAML } from "../yaml.js";
|
|
79
|
+
/** The first chant with `release.artifacts`, `chant release artifacts` and `artifact:<name>` in a forge or homebrew target's `assets` (#5151). */
|
|
80
|
+
export const RELEASE_ARTIFACTS_FLOOR = "0.124.101";
|
|
81
|
+
/** The variable naming the goreleaser binary the cut runs. */
|
|
82
|
+
export const GORELEASER_ENV = "CHANT_GORELEASER";
|
|
83
|
+
/** The first chant with `helm` and `nfpm` entries in `release.artifacts` (#5233). */
|
|
84
|
+
export const RELEASE_ARTIFACTS_PACKAGES_FLOOR = NEXT_RELEASE;
|
|
85
|
+
/** The variable naming the nfpm binary the cut runs (#5233). */
|
|
86
|
+
export const NFPM_ENV = "CHANT_NFPM";
|
|
87
|
+
/** The package formats an nfpm entry builds. */
|
|
88
|
+
export const NFPM_PACKAGERS = ["deb", "rpm", "apk", "archlinux", "ipk"];
|
|
89
|
+
/** Each packager's file extension. */
|
|
90
|
+
const NFPM_EXTENSIONS = { deb: "deb", rpm: "rpm", apk: "apk", archlinux: "pkg.tar.zst", ipk: "ipk" };
|
|
91
|
+
/**
|
|
92
|
+
* The `artifacts.json` types recorded from goreleaser by default: what its
|
|
93
|
+
* own release would upload. A `Binary` is recorded only when it sits at the
|
|
94
|
+
* top of `dist`, as goreleaser writes an uploadable binary; the binaries it
|
|
95
|
+
* builds for archives sit in a directory per target.
|
|
96
|
+
*/
|
|
97
|
+
export const GORELEASER_TYPES = ["Archive", "Binary", "Checksum", "File", "Linux Package", "SBOM", "Source"];
|
|
98
|
+
export class ReleaseArtifactError extends Error {
|
|
99
|
+
constructor(code, message, fix) {
|
|
100
|
+
super(message);
|
|
101
|
+
this.code = code;
|
|
102
|
+
this.fix = fix;
|
|
103
|
+
this.name = "ReleaseArtifactError";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
|
|
107
|
+
const PLATFORM = /^[a-z0-9]+\/[a-z0-9_]+(?:\/[a-z0-9]+)?$/;
|
|
108
|
+
const PLACEHOLDER = /\{([a-z]+)\}/g;
|
|
109
|
+
const OUTPUT_KEYS = new Set(["os", "arch", "ext", "label", "version"]);
|
|
110
|
+
const ARCHIVE_KEYS = new Set(["name", "os", "arch", "label", "version"]);
|
|
111
|
+
const NFPM_NAME_KEYS = new Set(["name", "version", "label", "os", "arch", "packager"]);
|
|
112
|
+
const outside = (p) => isAbsolute(p) || p.split(/[\\/]/).includes("..");
|
|
113
|
+
const isGoreleaser = (a) => "goreleaser" in a && a.goreleaser !== undefined;
|
|
114
|
+
const isChecksums = (a) => "checksums" in a && a.checksums !== undefined;
|
|
115
|
+
const isHelm = (a) => "helm" in a && a.helm !== undefined;
|
|
116
|
+
const isNfpm = (a) => "nfpm" in a && a.nfpm !== undefined;
|
|
117
|
+
/** An entry of files at `outputs`: built by its command, or (#5183) with no command, built before the cut. */
|
|
118
|
+
const isFiles = (a) => ("build" in a && a.build !== undefined) || ("outputs" in a && a.outputs !== undefined) || ("builtBy" in a && a.builtBy !== undefined);
|
|
119
|
+
const commandOf = (a) => ("build" in a ? a.build : undefined);
|
|
120
|
+
const builtByOf = (a) => {
|
|
121
|
+
const b = "builtBy" in a ? a.builtBy : undefined;
|
|
122
|
+
return b === undefined ? [] : Array.isArray(b) ? b : [b];
|
|
123
|
+
};
|
|
124
|
+
/** Whether the cut records an entry's files as something else built them, with no command of its own (#5183). */
|
|
125
|
+
export function isPrebuilt(a) {
|
|
126
|
+
return isFiles(a) && commandOf(a) === undefined;
|
|
127
|
+
}
|
|
128
|
+
/** An entry's outputs: its own, or the outputs of the build jobs `builtBy` names. */
|
|
129
|
+
function outputsOf(a, builds) {
|
|
130
|
+
if (a.outputs !== undefined)
|
|
131
|
+
return a.outputs;
|
|
132
|
+
return builtByOf(a).flatMap((n) => builds?.find((b) => b.name === n)?.outputs ?? []);
|
|
133
|
+
}
|
|
134
|
+
/** The label from its first digit, as a formula's and goreleaser's version reads it: `v1.4.0` is `1.4.0`. */
|
|
135
|
+
export function labelVersion(label) {
|
|
136
|
+
const at = label?.search(/\d/) ?? -1;
|
|
137
|
+
return label && at >= 0 ? label.slice(at) : null;
|
|
138
|
+
}
|
|
139
|
+
function placeholders(text) {
|
|
140
|
+
return [...text.matchAll(PLACEHOLDER)].map((m) => m[1]);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Check `release.artifacts`: names valid and unique and not an image's, one
|
|
144
|
+
* of `build`, `goreleaser` and `checksums`, paths inside the member,
|
|
145
|
+
* platforms of the form os/arch, placeholders chant fills, and a checksums
|
|
146
|
+
* entry's `of` naming entries before it.
|
|
147
|
+
*/
|
|
148
|
+
export function checkReleaseArtifacts(artifacts, o = {}) {
|
|
149
|
+
const seen = new Set();
|
|
150
|
+
const where = (a) => `release.artifacts "${a.name}"`;
|
|
151
|
+
const inside = (a, what, p) => {
|
|
152
|
+
if (p !== undefined && outside(p))
|
|
153
|
+
throw new ReleaseArtifactError("release-artifact-outside", `${where(a)}: ${what} ${p} is not a path inside the member`);
|
|
154
|
+
};
|
|
155
|
+
for (const a of artifacts) {
|
|
156
|
+
if (!NAME.test(a.name))
|
|
157
|
+
throw new ReleaseArtifactError("release-artifact-name-invalid", `release.artifacts: "${a.name}" is not a name of letters, digits, ".", "_" and "-"`);
|
|
158
|
+
if (seen.has(a.name))
|
|
159
|
+
throw new ReleaseArtifactError("release-artifact-name-taken", `release.artifacts names "${a.name}" twice`);
|
|
160
|
+
if (o.imageNames?.includes(a.name))
|
|
161
|
+
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.");
|
|
162
|
+
const kinds = [isFiles(a), isGoreleaser(a), isChecksums(a), isHelm(a), isNfpm(a)].filter(Boolean).length;
|
|
163
|
+
if (kinds !== 1)
|
|
164
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)} names ${kinds === 0 ? "none" : "more than one"} of outputs, goreleaser, helm, nfpm and checksums; name one`);
|
|
165
|
+
if (isFiles(a)) {
|
|
166
|
+
const jobs = builtByOf(a);
|
|
167
|
+
if (jobs.length > 0 && commandOf(a) !== undefined)
|
|
168
|
+
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.");
|
|
169
|
+
for (const j of jobs) {
|
|
170
|
+
if (!o.builds?.some((b) => b.name === j)) {
|
|
171
|
+
const known = (o.builds ?? []).map((b) => b.name);
|
|
172
|
+
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.");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (a.outputs === undefined && jobs.length === 0)
|
|
176
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)} names no outputs`);
|
|
177
|
+
if (a.outputs === undefined && a.platforms !== undefined)
|
|
178
|
+
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}.");
|
|
179
|
+
const outputs = outputsOf(a, o.builds);
|
|
180
|
+
if (outputs.length === 0)
|
|
181
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)} names no outputs`);
|
|
182
|
+
if (a.outputs === undefined) {
|
|
183
|
+
const bracket = outputs.find((p) => /[[\]]/.test(p));
|
|
184
|
+
if (bracket !== undefined)
|
|
185
|
+
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 ?.");
|
|
186
|
+
}
|
|
187
|
+
if (a.platforms !== undefined && (a.platforms.length === 0 || !a.platforms.every((p) => PLATFORM.test(p)) || new Set(a.platforms).size !== a.platforms.length)) {
|
|
188
|
+
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)}`);
|
|
189
|
+
}
|
|
190
|
+
for (const out of outputs) {
|
|
191
|
+
inside(a, "the output", out);
|
|
192
|
+
const unknown = placeholders(out).filter((k) => !OUTPUT_KEYS.has(k));
|
|
193
|
+
if (unknown.length > 0)
|
|
194
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: the output ${out} names {${unknown[0]}}; an output may hold {os}, {arch}, {ext}, {label} and {version}`);
|
|
195
|
+
if (a.platforms === undefined && placeholders(out).some((k) => k === "os" || k === "arch" || k === "ext")) {
|
|
196
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: the output ${out} names a platform, and the entry has no platforms`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (a.archive !== undefined && a.archive !== true) {
|
|
200
|
+
inside(a, "the archive directory", a.archive.dir);
|
|
201
|
+
for (const f of a.archive.files ?? []) {
|
|
202
|
+
inside(a, "the archived file", f);
|
|
203
|
+
if (/[*?]/.test(f))
|
|
204
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: archive.files names ${f}; name each file`);
|
|
205
|
+
}
|
|
206
|
+
if (a.archive.name !== undefined) {
|
|
207
|
+
const unknown = placeholders(a.archive.name).filter((k) => !ARCHIVE_KEYS.has(k));
|
|
208
|
+
if (unknown.length > 0 || /[\\/]/.test(a.archive.name))
|
|
209
|
+
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}`);
|
|
210
|
+
}
|
|
211
|
+
if (a.archive.format !== undefined && a.archive.format !== "tar.gz" && a.archive.format !== "zip")
|
|
212
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: archive.format is tar.gz or zip`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else if (isGoreleaser(a)) {
|
|
216
|
+
inside(a, "the goreleaser config", a.goreleaser.config);
|
|
217
|
+
inside(a, "the dist directory", a.goreleaser.dist);
|
|
218
|
+
if (a.goreleaser.types !== undefined && a.goreleaser.types.length === 0)
|
|
219
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: goreleaser.types is empty, so nothing would be recorded`);
|
|
220
|
+
}
|
|
221
|
+
else if (isHelm(a)) {
|
|
222
|
+
inside(a, "the chart directory", a.helm.chart);
|
|
223
|
+
inside(a, "the chart archive directory", a.helm.dir);
|
|
224
|
+
}
|
|
225
|
+
else if (isNfpm(a)) {
|
|
226
|
+
inside(a, "the nfpm config", a.nfpm.config);
|
|
227
|
+
inside(a, "the package directory", a.nfpm.dir);
|
|
228
|
+
const packagers = a.nfpm.packagers;
|
|
229
|
+
if (packagers !== undefined && (packagers.length === 0 || !packagers.every((p) => NFPM_PACKAGERS.includes(p)) || new Set(packagers).size !== packagers.length)) {
|
|
230
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: nfpm.packagers is a list of distinct ${NFPM_PACKAGERS.join(", ")}, not ${JSON.stringify(packagers)}`);
|
|
231
|
+
}
|
|
232
|
+
if (a.nfpm.platforms !== undefined && (a.nfpm.platforms.length === 0 || !a.nfpm.platforms.every((p) => PLATFORM.test(p)) || new Set(a.nfpm.platforms).size !== a.nfpm.platforms.length)) {
|
|
233
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: nfpm.platforms is a list of distinct os/arch such as linux/amd64, not ${JSON.stringify(a.nfpm.platforms)}`);
|
|
234
|
+
}
|
|
235
|
+
if (a.nfpm.fileName !== undefined) {
|
|
236
|
+
const unknown = placeholders(a.nfpm.fileName).filter((k) => !NFPM_NAME_KEYS.has(k));
|
|
237
|
+
if (unknown.length > 0 || /[\\/]/.test(a.nfpm.fileName))
|
|
238
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: nfpm.fileName ${a.nfpm.fileName} is not a file name holding {name}, {version}, {label}, {os}, {arch} and {packager}`);
|
|
239
|
+
if (a.nfpm.platforms === undefined && placeholders(a.nfpm.fileName).some((k) => k === "os" || k === "arch"))
|
|
240
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: nfpm.fileName ${a.nfpm.fileName} names a platform, and the entry has no platforms`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
else if (isChecksums(a)) {
|
|
244
|
+
inside(a, "the checksums file", a.checksums);
|
|
245
|
+
for (const n of a.of ?? []) {
|
|
246
|
+
if (!seen.has(n))
|
|
247
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where(a)}: of names "${n}", which is not an entry before it`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
seen.add(a.name);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/** Every platform a Go-style `os/arch` names, with its Windows extension. */
|
|
254
|
+
function platformValues(platform) {
|
|
255
|
+
const [os, ...rest] = platform.split("/");
|
|
256
|
+
return { os: os, arch: rest.join("_"), ext: os === "windows" ? ".exe" : "" };
|
|
257
|
+
}
|
|
258
|
+
function fill(text, values, what) {
|
|
259
|
+
return text.replace(PLACEHOLDER, (m, k) => {
|
|
260
|
+
const v = values[k];
|
|
261
|
+
if (v === undefined) {
|
|
262
|
+
if (k === "label" || k === "version")
|
|
263
|
+
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.");
|
|
264
|
+
return m;
|
|
265
|
+
}
|
|
266
|
+
return v;
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/** The files a path names, `*` and `?` matched within a segment, sorted. */
|
|
270
|
+
export function expandOutput(cwd, pattern) {
|
|
271
|
+
const parts = pattern.replace(/\\/g, "/").replace(/^\.\//, "").split("/").filter((s) => s !== "" && s !== ".");
|
|
272
|
+
let found = [""];
|
|
273
|
+
for (const [i, part] of parts.entries()) {
|
|
274
|
+
const last = i === parts.length - 1;
|
|
275
|
+
const next = [];
|
|
276
|
+
for (const base of found) {
|
|
277
|
+
if (!/[*?]/.test(part)) {
|
|
278
|
+
const p = base ? `${base}/${part}` : part;
|
|
279
|
+
if (existsSync(resolve(cwd, p)))
|
|
280
|
+
next.push(p);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const dir = resolve(cwd, base || ".");
|
|
284
|
+
if (!existsSync(dir) || !statSync(dir).isDirectory())
|
|
285
|
+
continue;
|
|
286
|
+
const re = new RegExp(`^${part.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]")}$`);
|
|
287
|
+
for (const e of readdirSync(dir).sort())
|
|
288
|
+
if (re.test(e))
|
|
289
|
+
next.push(base ? `${base}/${e}` : e);
|
|
290
|
+
}
|
|
291
|
+
found = last ? next.filter((p) => statSync(resolve(cwd, p)).isFile()) : next.filter((p) => statSync(resolve(cwd, p)).isDirectory());
|
|
292
|
+
}
|
|
293
|
+
return found.sort();
|
|
294
|
+
}
|
|
295
|
+
const defaultRun = (command, o) => spawnSync(command, { cwd: o.cwd, env: o.env, shell: true, stdio: ["ignore", 2, 2] }).status;
|
|
296
|
+
const posixPath = (cwd, abs) => relative(cwd, abs).split("\\").join("/");
|
|
297
|
+
/** `sha256:<hex>` of a file. */
|
|
298
|
+
function digestOf(abs) {
|
|
299
|
+
return `sha256:${createHash("sha256").update(readFileSync(abs)).digest("hex")}`;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Build every entry, in order, and return each file as the release's asset
|
|
303
|
+
* artifact. A command that fails, an output it did not write, a goreleaser
|
|
304
|
+
* version that is not the label, or two entries writing one path stops the
|
|
305
|
+
* cut.
|
|
306
|
+
*/
|
|
307
|
+
export function buildReleaseArtifacts(i) {
|
|
308
|
+
checkReleaseArtifacts(i.artifacts, { ...(i.imageNames ? { imageNames: i.imageNames } : {}), ...(i.builds ? { builds: i.builds } : {}) });
|
|
309
|
+
const run = i.run ?? defaultRun;
|
|
310
|
+
const version = labelVersion(i.label);
|
|
311
|
+
const labelValues = { ...(i.label !== null ? { label: i.label } : {}), ...(version !== null ? { version } : {}) };
|
|
312
|
+
const baseEnv = () => {
|
|
313
|
+
const env = { ...(i.env ?? process.env), SOURCE_DATE_EPOCH: String(i.sourceDateEpoch) };
|
|
314
|
+
for (const k of ["CHANT_RELEASE_LABEL", "CHANT_RELEASE_OS", "CHANT_RELEASE_ARCH", "CHANT_RELEASE_EXT"])
|
|
315
|
+
delete env[k];
|
|
316
|
+
if (i.label !== null)
|
|
317
|
+
env.CHANT_RELEASE_LABEL = i.label;
|
|
318
|
+
return env;
|
|
319
|
+
};
|
|
320
|
+
const byEntry = new Map();
|
|
321
|
+
const owner = new Map();
|
|
322
|
+
const record = (entry, abs) => {
|
|
323
|
+
const path = posixPath(i.cwd, abs);
|
|
324
|
+
if (path.startsWith("..") || isAbsolute(path))
|
|
325
|
+
throw new ReleaseArtifactError("release-artifact-outside", `release.artifacts "${entry}": ${abs} is not inside the member`);
|
|
326
|
+
const prior = owner.get(path);
|
|
327
|
+
if (prior !== undefined)
|
|
328
|
+
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`);
|
|
329
|
+
owner.set(path, entry);
|
|
330
|
+
return { component: entry, kind: "asset", path, digest: digestOf(abs) };
|
|
331
|
+
};
|
|
332
|
+
const out = [];
|
|
333
|
+
for (const a of i.artifacts) {
|
|
334
|
+
const files = [];
|
|
335
|
+
if (isFiles(a)) {
|
|
336
|
+
const command = commandOf(a);
|
|
337
|
+
const outputs = outputsOf(a, i.builds);
|
|
338
|
+
for (const platform of a.platforms ?? [null]) {
|
|
339
|
+
const env = baseEnv();
|
|
340
|
+
const values = { ...labelValues };
|
|
341
|
+
if (platform !== null) {
|
|
342
|
+
const p = platformValues(platform);
|
|
343
|
+
Object.assign(values, p);
|
|
344
|
+
env.CHANT_RELEASE_OS = p.os;
|
|
345
|
+
env.CHANT_RELEASE_ARCH = p.arch;
|
|
346
|
+
env.CHANT_RELEASE_EXT = p.ext;
|
|
347
|
+
}
|
|
348
|
+
const on = platform !== null ? ` for ${platform}` : "";
|
|
349
|
+
if (command !== undefined) {
|
|
350
|
+
const status = run(command, { cwd: i.cwd, env });
|
|
351
|
+
if (status !== 0)
|
|
352
|
+
throw new ReleaseArtifactError("release-artifact-build-failed", `the build of artifact "${a.name}"${on} exited ${status ?? "with a signal"}: ${command}`);
|
|
353
|
+
}
|
|
354
|
+
// #5183: with no command, the files are read where something else left them, copied in first under --at.
|
|
355
|
+
const from = command === undefined && i.prebuiltFrom !== undefined ? i.prebuiltFrom : i.cwd;
|
|
356
|
+
const written = [];
|
|
357
|
+
for (const pattern of outputs) {
|
|
358
|
+
const path = fill(pattern, values, `release.artifacts "${a.name}"`);
|
|
359
|
+
const found = expandOutput(from, path);
|
|
360
|
+
if (found.length === 0) {
|
|
361
|
+
if (command !== undefined)
|
|
362
|
+
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.");
|
|
363
|
+
const jobs = builtByOf(a);
|
|
364
|
+
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.");
|
|
365
|
+
}
|
|
366
|
+
if (from !== i.cwd)
|
|
367
|
+
copyArtifactFiles(found.map((f) => ({ path: f })), from, i.cwd);
|
|
368
|
+
written.push(...found);
|
|
369
|
+
}
|
|
370
|
+
if (a.archive === undefined) {
|
|
371
|
+
for (const w of written)
|
|
372
|
+
files.push(record(a.name, resolve(i.cwd, w)));
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
const spec = a.archive === true ? {} : a.archive;
|
|
376
|
+
const format = spec.format ?? (values.os === "windows" ? "zip" : "tar.gz");
|
|
377
|
+
const base = fill(spec.name ?? (platform !== null ? "{name}_{os}_{arch}" : "{name}"), { ...values, name: a.name }, `release.artifacts "${a.name}" archive.name`);
|
|
378
|
+
const archive = resolve(i.cwd, spec.dir ?? "dist", `${base}.${format}`);
|
|
379
|
+
const entries = [
|
|
380
|
+
...written.map((w) => ({ name: posix.basename(w), abs: resolve(i.cwd, w) })),
|
|
381
|
+
...(spec.files ?? []).map((f) => {
|
|
382
|
+
const abs = resolve(i.cwd, f);
|
|
383
|
+
if (!existsSync(abs) || !statSync(abs).isFile())
|
|
384
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `artifact "${a.name}" archives ${f}, which is not a file in the member`);
|
|
385
|
+
return { name: f.replace(/\\/g, "/").replace(/^\.\//, ""), abs };
|
|
386
|
+
}),
|
|
387
|
+
];
|
|
388
|
+
const names = new Set();
|
|
389
|
+
for (const e of entries) {
|
|
390
|
+
if (names.has(e.name))
|
|
391
|
+
throw new ReleaseArtifactError("release-artifact-output-taken", `artifact "${a.name}"${on} would put two files named ${e.name} in ${posixPath(i.cwd, archive)}`);
|
|
392
|
+
names.add(e.name);
|
|
393
|
+
}
|
|
394
|
+
mkdirSync(dirname(archive), { recursive: true });
|
|
395
|
+
writeFileSync(archive, format === "zip" ? zipArchive(entries, i.sourceDateEpoch) : tarGzArchive(entries, i.sourceDateEpoch));
|
|
396
|
+
files.push(record(a.name, archive));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
else if (isGoreleaser(a)) {
|
|
400
|
+
files.push(...goreleaserFiles(a, i, baseEnv(), run).map((abs) => record(a.name, abs)));
|
|
401
|
+
}
|
|
402
|
+
else if (isHelm(a)) {
|
|
403
|
+
files.push(record(a.name, packHelmChart(a, i)));
|
|
404
|
+
}
|
|
405
|
+
else if (isNfpm(a)) {
|
|
406
|
+
files.push(...nfpmFiles(a, i, baseEnv, run).map((abs) => record(a.name, abs)));
|
|
407
|
+
}
|
|
408
|
+
else if (isChecksums(a)) {
|
|
409
|
+
const names = a.of ?? [...byEntry.keys()];
|
|
410
|
+
const covered = names.flatMap((n) => byEntry.get(n) ?? []);
|
|
411
|
+
const lines = new Map();
|
|
412
|
+
for (const c of covered) {
|
|
413
|
+
const base = posix.basename(c.path);
|
|
414
|
+
if (lines.has(base))
|
|
415
|
+
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.");
|
|
416
|
+
lines.set(base, `${c.digest.slice("sha256:".length)} ${base}`);
|
|
417
|
+
}
|
|
418
|
+
if (lines.size === 0)
|
|
419
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `checksums "${a.name}" covers no file`, "Declare it after the entries whose files it lists.");
|
|
420
|
+
const abs = resolve(i.cwd, a.checksums);
|
|
421
|
+
mkdirSync(dirname(abs), { recursive: true });
|
|
422
|
+
writeFileSync(abs, `${[...lines.keys()].sort().map((k) => lines.get(k)).join("\n")}\n`);
|
|
423
|
+
files.push(record(a.name, abs));
|
|
424
|
+
}
|
|
425
|
+
byEntry.set(a.name, files);
|
|
426
|
+
out.push(...files);
|
|
427
|
+
}
|
|
428
|
+
return out;
|
|
429
|
+
}
|
|
430
|
+
/** Run goreleaser in snapshot mode and list the files it wrote that the entry records. */
|
|
431
|
+
function goreleaserFiles(a, i, env, run) {
|
|
432
|
+
if (i.label === null)
|
|
433
|
+
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.");
|
|
434
|
+
const bin = env[GORELEASER_ENV] || "goreleaser";
|
|
435
|
+
const command = [bin === "goreleaser" ? bin : shellWord(bin), "release", "--snapshot", "--clean", "--skip=publish", ...(a.goreleaser.config ? ["--config", shellWord(a.goreleaser.config)] : [])].join(" ");
|
|
436
|
+
const status = run(command, { cwd: i.cwd, env });
|
|
437
|
+
if (status !== 0)
|
|
438
|
+
throw new ReleaseArtifactError("release-artifact-build-failed", `goreleaser for artifact "${a.name}" exited ${status ?? "with a signal"}: ${command}`);
|
|
439
|
+
const dist = a.goreleaser.dist ?? "dist";
|
|
440
|
+
const read = (file) => {
|
|
441
|
+
const abs = resolve(i.cwd, dist, file);
|
|
442
|
+
if (!existsSync(abs))
|
|
443
|
+
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.`);
|
|
444
|
+
return JSON.parse(readFileSync(abs, "utf-8"));
|
|
445
|
+
};
|
|
446
|
+
const meta = read("metadata.json");
|
|
447
|
+
const want = [i.label, labelVersion(i.label)].filter((v) => v !== null);
|
|
448
|
+
if (typeof meta.version !== "string" || !want.includes(meta.version)) {
|
|
449
|
+
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 }}" }.');
|
|
450
|
+
}
|
|
451
|
+
const listed = read("artifacts.json");
|
|
452
|
+
if (!Array.isArray(listed))
|
|
453
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `${posix.join(dist, "artifacts.json")} is not a list`);
|
|
454
|
+
const types = a.goreleaser.types ?? GORELEASER_TYPES;
|
|
455
|
+
const distAbs = resolve(i.cwd, dist);
|
|
456
|
+
const files = [];
|
|
457
|
+
for (const e of listed) {
|
|
458
|
+
if (typeof e.type !== "string" || typeof e.path !== "string" || !types.includes(e.type))
|
|
459
|
+
continue;
|
|
460
|
+
const abs = resolve(i.cwd, e.path);
|
|
461
|
+
if (a.goreleaser.types === undefined && e.type === "Binary" && dirname(abs) !== distAbs)
|
|
462
|
+
continue;
|
|
463
|
+
if (!existsSync(abs) || !statSync(abs).isFile())
|
|
464
|
+
continue;
|
|
465
|
+
if (!files.includes(abs))
|
|
466
|
+
files.push(abs);
|
|
467
|
+
}
|
|
468
|
+
if (files.length === 0)
|
|
469
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `goreleaser for artifact "${a.name}" listed no file of the types ${types.join(", ")}`);
|
|
470
|
+
return files.sort();
|
|
471
|
+
}
|
|
472
|
+
const shellWord = (s) => (/^[A-Za-z0-9_./:=,@+%-]+$/.test(s) ? s : `'${s.replace(/'/g, "'\\''")}'`);
|
|
473
|
+
/** A `filepath.Match` pattern as a regular expression: `*` and `?` within a segment, `[...]` a class. */
|
|
474
|
+
function globSegmentRe(pattern) {
|
|
475
|
+
let out = "";
|
|
476
|
+
for (let k = 0; k < pattern.length; k++) {
|
|
477
|
+
const c = pattern[k];
|
|
478
|
+
if (c === "*")
|
|
479
|
+
out += "[^/]*";
|
|
480
|
+
else if (c === "?")
|
|
481
|
+
out += "[^/]";
|
|
482
|
+
else if (c === "\\" && k + 1 < pattern.length)
|
|
483
|
+
out += `\\${pattern[++k]}`;
|
|
484
|
+
else if (c === "[") {
|
|
485
|
+
const end = pattern.indexOf("]", k + 1);
|
|
486
|
+
if (end < 0)
|
|
487
|
+
out += "\\[";
|
|
488
|
+
else {
|
|
489
|
+
out += `[${pattern.slice(k + 1, end).replace(/\\/g, "\\\\")}]`;
|
|
490
|
+
k = end;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
else
|
|
494
|
+
out += c.replace(/[.+^${}()|\]\\]/g, "\\$&");
|
|
495
|
+
}
|
|
496
|
+
return new RegExp(`^${out}$`);
|
|
497
|
+
}
|
|
498
|
+
/** The rules of a `.helmignore`, after helm's default. A `**` is refused, as helm refuses it. */
|
|
499
|
+
export function helmIgnoreRules(text, where) {
|
|
500
|
+
const rules = [];
|
|
501
|
+
for (const raw of ["templates/.?*", ...(text ?? "").split(/\r?\n/)]) {
|
|
502
|
+
let line = raw.trim();
|
|
503
|
+
if (line === "" || line.startsWith("#"))
|
|
504
|
+
continue;
|
|
505
|
+
if (line.includes("**"))
|
|
506
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where}: .helmignore has ${line}, and helm does not read **`, "Name the paths with * and ?, as helm does.");
|
|
507
|
+
const negate = line.startsWith("!");
|
|
508
|
+
if (negate)
|
|
509
|
+
line = line.slice(1);
|
|
510
|
+
const dirOnly = line.endsWith("/");
|
|
511
|
+
if (dirOnly)
|
|
512
|
+
line = line.replace(/\/+$/, "");
|
|
513
|
+
line = line.replace(/^\//, "");
|
|
514
|
+
if (line === "")
|
|
515
|
+
continue;
|
|
516
|
+
rules.push({ re: globSegmentRe(line), negate, dirOnly, base: !line.includes("/") });
|
|
517
|
+
}
|
|
518
|
+
return rules;
|
|
519
|
+
}
|
|
520
|
+
/** Whether helm leaves `rel` (a path from the chart's directory) out of the chart, as its ignore package decides. */
|
|
521
|
+
export function helmIgnored(rules, rel, dir) {
|
|
522
|
+
const name = rel.includes("/") ? rel.slice(rel.lastIndexOf("/") + 1) : rel;
|
|
523
|
+
for (const r of rules) {
|
|
524
|
+
if (r.dirOnly && !dir)
|
|
525
|
+
continue;
|
|
526
|
+
const hit = r.re.test(r.base ? name : rel);
|
|
527
|
+
if (r.negate ? !hit : hit)
|
|
528
|
+
return true;
|
|
529
|
+
}
|
|
530
|
+
return false;
|
|
531
|
+
}
|
|
532
|
+
/** Every file of the chart at `abs` that helm packs, from the chart's directory, sorted, `Chart.yaml` first. */
|
|
533
|
+
function helmChartFiles(abs, rules) {
|
|
534
|
+
const out = [];
|
|
535
|
+
const walk = (rel) => {
|
|
536
|
+
for (const e of readdirSync(rel ? resolve(abs, rel) : abs).sort()) {
|
|
537
|
+
const p = rel ? `${rel}/${e}` : e;
|
|
538
|
+
const st = statSync(resolve(abs, p));
|
|
539
|
+
if (helmIgnored(rules, p, st.isDirectory()))
|
|
540
|
+
continue;
|
|
541
|
+
if (st.isDirectory())
|
|
542
|
+
walk(p);
|
|
543
|
+
else if (st.isFile())
|
|
544
|
+
out.push(p);
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
walk("");
|
|
548
|
+
return [...out.filter((p) => p === "Chart.yaml"), ...out.filter((p) => p !== "Chart.yaml")];
|
|
549
|
+
}
|
|
550
|
+
/** Pack a `helm` entry's chart into `<dir>/<name>-<version>.tgz`, as `helm package --version` would, every entry dated `SOURCE_DATE_EPOCH`. Returns the archive. */
|
|
551
|
+
function packHelmChart(a, i) {
|
|
552
|
+
const where = `release.artifacts "${a.name}"`;
|
|
553
|
+
const version = labelVersion(i.label);
|
|
554
|
+
if (i.label === null || version === null)
|
|
555
|
+
throw new ReleaseArtifactError("release-artifact-no-label", `${where} packs a Helm chart, whose version is the release's label from its first digit, and the cut has ${i.label === null ? "no label" : `the label ${i.label}, which has no digit`}`, "Cut the release with a label such as v1.4.0.");
|
|
556
|
+
const dir = resolve(i.cwd, a.helm.chart);
|
|
557
|
+
const chartFile = resolve(dir, "Chart.yaml");
|
|
558
|
+
if (!existsSync(chartFile))
|
|
559
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `${where}: ${posix.join(a.helm.chart, "Chart.yaml")} does not exist, so ${a.helm.chart} is not a Helm chart`, "Set helm.chart to the directory that holds the chart's Chart.yaml.");
|
|
560
|
+
const text = readFileSync(chartFile, "utf-8");
|
|
561
|
+
let name;
|
|
562
|
+
try {
|
|
563
|
+
name = parseYAML(text).name;
|
|
564
|
+
}
|
|
565
|
+
catch (err) {
|
|
566
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where}: ${posix.join(a.helm.chart, "Chart.yaml")} is not YAML chant can read: ${err instanceof Error ? err.message : String(err)}`);
|
|
567
|
+
}
|
|
568
|
+
if (typeof name !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(name))
|
|
569
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where}: ${posix.join(a.helm.chart, "Chart.yaml")} names no chart name helm takes`, "Give the chart a name of letters, digits, '.', '_' and '-'.");
|
|
570
|
+
let chart;
|
|
571
|
+
try {
|
|
572
|
+
chart = stampVersionFile({ path: "Chart.yaml", field: "version" }, text, version);
|
|
573
|
+
if (a.helm.appVersion)
|
|
574
|
+
chart = stampVersionFile({ path: "Chart.yaml", field: "appVersion" }, chart, i.label);
|
|
575
|
+
}
|
|
576
|
+
catch (err) {
|
|
577
|
+
const e = err;
|
|
578
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${where}: ${e.message ?? String(err)}`, e.fix);
|
|
579
|
+
}
|
|
580
|
+
const ignore = existsSync(resolve(dir, ".helmignore")) ? readFileSync(resolve(dir, ".helmignore"), "utf-8") : null;
|
|
581
|
+
const files = helmChartFiles(dir, helmIgnoreRules(ignore, where));
|
|
582
|
+
const entries = files.map((f) => ({ name: `${name}/${f}`, abs: resolve(dir, f), ...(f === "Chart.yaml" ? { bytes: Buffer.from(chart, "utf-8") } : {}) }));
|
|
583
|
+
const archive = resolve(i.cwd, a.helm.dir ?? "dist", `${name}-${version}.tgz`);
|
|
584
|
+
mkdirSync(dirname(archive), { recursive: true });
|
|
585
|
+
writeFileSync(archive, tarGzArchive(entries, i.sourceDateEpoch));
|
|
586
|
+
return archive;
|
|
587
|
+
}
|
|
588
|
+
/** The top-level `version` of an nfpm config, unquoted, or null. */
|
|
589
|
+
export function nfpmConfigVersion(text) {
|
|
590
|
+
const m = /^version:[ \t]*(.*?)[ \t]*(?:#.*)?$/m.exec(text);
|
|
591
|
+
if (!m)
|
|
592
|
+
return null;
|
|
593
|
+
return m[1].replace(/^(["'])(.*)\1$/, "$2");
|
|
594
|
+
}
|
|
595
|
+
/** Whether an nfpm config's version carries the release's: it names the variable chant sets, or is the label or its version. */
|
|
596
|
+
export function nfpmVersionFollowsLabel(version, label, labelVer) {
|
|
597
|
+
if (version === null)
|
|
598
|
+
return false;
|
|
599
|
+
return /\$\{?CHANT_RELEASE_(VERSION|LABEL)\}?/.test(version) || version === label || version === labelVer;
|
|
600
|
+
}
|
|
601
|
+
/** Run nfpm for each platform and packager of an `nfpm` entry and list the packages it wrote. */
|
|
602
|
+
function nfpmFiles(a, i, baseEnv, run) {
|
|
603
|
+
const where = `release.artifacts "${a.name}"`;
|
|
604
|
+
const version = labelVersion(i.label);
|
|
605
|
+
if (i.label === null || version === null)
|
|
606
|
+
throw new ReleaseArtifactError("release-artifact-no-label", `${where} is packaged by nfpm, whose packages carry the release's label as their version, and the cut has ${i.label === null ? "no label" : `the label ${i.label}, which has no digit`}`, "Cut the release with a label such as v1.4.0.");
|
|
607
|
+
const config = a.nfpm.config ?? "nfpm.yaml";
|
|
608
|
+
const configAbs = resolve(i.cwd, config);
|
|
609
|
+
if (!existsSync(configAbs))
|
|
610
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `${where}: the nfpm config ${config} does not exist`, "Set nfpm.config to the member's nfpm config.");
|
|
611
|
+
const declared = nfpmConfigVersion(readFileSync(configAbs, "utf-8"));
|
|
612
|
+
if (!nfpmVersionFollowsLabel(declared, i.label, version)) {
|
|
613
|
+
throw new ReleaseArtifactError("release-artifact-version-mismatch", `${where}: ${config} gives the packages the version ${JSON.stringify(declared)}, and the release is labelled ${i.label}, so they would not carry the release's version`, 'Set the version in the nfpm config to the one chant passes: version: "${CHANT_RELEASE_VERSION}".');
|
|
614
|
+
}
|
|
615
|
+
const env0 = baseEnv();
|
|
616
|
+
const bin = env0[NFPM_ENV] || "nfpm";
|
|
617
|
+
const files = [];
|
|
618
|
+
for (const platform of a.nfpm.platforms ?? [null]) {
|
|
619
|
+
for (const packager of a.nfpm.packagers ?? ["deb", "rpm"]) {
|
|
620
|
+
const env = baseEnv();
|
|
621
|
+
env.CHANT_RELEASE_VERSION = version;
|
|
622
|
+
const values = { name: a.name, label: i.label, version, packager };
|
|
623
|
+
if (platform !== null) {
|
|
624
|
+
const p = platformValues(platform);
|
|
625
|
+
Object.assign(values, { os: p.os, arch: p.arch });
|
|
626
|
+
env.CHANT_RELEASE_OS = p.os;
|
|
627
|
+
env.CHANT_RELEASE_ARCH = p.arch;
|
|
628
|
+
env.CHANT_RELEASE_EXT = p.ext;
|
|
629
|
+
}
|
|
630
|
+
const base = fill(a.nfpm.fileName ?? (platform !== null ? "{name}_{version}_{arch}" : "{name}_{version}"), values, `${where} nfpm.fileName`);
|
|
631
|
+
const target = posix.join((a.nfpm.dir ?? "dist").replace(/\\/g, "/"), `${base}.${NFPM_EXTENSIONS[packager]}`);
|
|
632
|
+
mkdirSync(dirname(resolve(i.cwd, target)), { recursive: true });
|
|
633
|
+
const command = [bin === "nfpm" ? bin : shellWord(bin), "package", "--config", shellWord(config), "--packager", packager, "--target", shellWord(target)].join(" ");
|
|
634
|
+
const on = `${packager}${platform !== null ? ` for ${platform}` : ""}`;
|
|
635
|
+
const status = run(command, { cwd: i.cwd, env });
|
|
636
|
+
if (status !== 0)
|
|
637
|
+
throw new ReleaseArtifactError("release-artifact-build-failed", `nfpm for artifact "${a.name}" (${on}) exited ${status ?? "with a signal"}: ${command}`);
|
|
638
|
+
const abs = resolve(i.cwd, target);
|
|
639
|
+
if (!existsSync(abs) || !statSync(abs).isFile())
|
|
640
|
+
throw new ReleaseArtifactError("release-artifact-no-output", `nfpm for artifact "${a.name}" (${on}) wrote no ${target}`);
|
|
641
|
+
files.push(abs);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
return files;
|
|
645
|
+
}
|
|
646
|
+
const modeOf = (abs) => (statSync(abs).mode & 0o111 ? 0o755 : 0o644);
|
|
647
|
+
function tarHeader(name, size, mode, mtime) {
|
|
648
|
+
const h = Buffer.alloc(512);
|
|
649
|
+
let path = name;
|
|
650
|
+
let prefix = "";
|
|
651
|
+
if (Buffer.byteLength(path) > 100) {
|
|
652
|
+
const cut = path.lastIndexOf("/", path.length - 1);
|
|
653
|
+
prefix = cut > 0 ? path.slice(0, cut) : "";
|
|
654
|
+
path = cut > 0 ? path.slice(cut + 1) : path;
|
|
655
|
+
if (Buffer.byteLength(path) > 100 || Buffer.byteLength(prefix) > 155)
|
|
656
|
+
throw new ReleaseArtifactError("release-artifact-invalid", `${name} is too long a path for an archive entry`);
|
|
657
|
+
}
|
|
658
|
+
const octal = (n, width) => n.toString(8).padStart(width - 1, "0") + "\0";
|
|
659
|
+
h.write(path, 0, 100, "utf-8");
|
|
660
|
+
h.write(octal(mode, 8), 100, 8, "ascii");
|
|
661
|
+
h.write(octal(0, 8), 108, 8, "ascii");
|
|
662
|
+
h.write(octal(0, 8), 116, 8, "ascii");
|
|
663
|
+
h.write(octal(size, 12), 124, 12, "ascii");
|
|
664
|
+
h.write(octal(mtime, 12), 136, 12, "ascii");
|
|
665
|
+
h.write(" ", 148, 8, "ascii");
|
|
666
|
+
h.write("0", 156, 1, "ascii");
|
|
667
|
+
h.write("ustar\0", 257, 6, "ascii");
|
|
668
|
+
h.write("00", 263, 2, "ascii");
|
|
669
|
+
h.write(prefix, 345, 155, "utf-8");
|
|
670
|
+
let sum = 0;
|
|
671
|
+
for (const b of h)
|
|
672
|
+
sum += b;
|
|
673
|
+
h.write(`${sum.toString(8).padStart(6, "0")}\0 `, 148, 8, "ascii");
|
|
674
|
+
return h;
|
|
675
|
+
}
|
|
676
|
+
/** 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. */
|
|
677
|
+
export function tarGzArchive(entries, mtime) {
|
|
678
|
+
const parts = [];
|
|
679
|
+
for (const e of entries) {
|
|
680
|
+
const data = e.bytes ?? readFileSync(e.abs);
|
|
681
|
+
parts.push(tarHeader(e.name, data.length, modeOf(e.abs), mtime), data, Buffer.alloc((512 - (data.length % 512)) % 512));
|
|
682
|
+
}
|
|
683
|
+
parts.push(Buffer.alloc(1024));
|
|
684
|
+
const gz = gzipSync(Buffer.concat(parts), { level: 9 });
|
|
685
|
+
// 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.
|
|
686
|
+
gz.writeUInt32LE(0, 4);
|
|
687
|
+
gz[9] = 3;
|
|
688
|
+
return gz;
|
|
689
|
+
}
|
|
690
|
+
const CRC_TABLE = (() => {
|
|
691
|
+
const t = new Uint32Array(256);
|
|
692
|
+
for (let n = 0; n < 256; n++) {
|
|
693
|
+
let c = n;
|
|
694
|
+
for (let k = 0; k < 8; k++)
|
|
695
|
+
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
696
|
+
t[n] = c >>> 0;
|
|
697
|
+
}
|
|
698
|
+
return t;
|
|
699
|
+
})();
|
|
700
|
+
function crc32(buf) {
|
|
701
|
+
let c = 0xffffffff;
|
|
702
|
+
for (const b of buf)
|
|
703
|
+
c = CRC_TABLE[(c ^ b) & 0xff] ^ (c >>> 8);
|
|
704
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
705
|
+
}
|
|
706
|
+
function dosTime(epoch) {
|
|
707
|
+
const d = new Date(Math.max(epoch, 315532800) * 1000);
|
|
708
|
+
return {
|
|
709
|
+
time: (d.getUTCHours() << 11) | (d.getUTCMinutes() << 5) | Math.floor(d.getUTCSeconds() / 2),
|
|
710
|
+
date: ((d.getUTCFullYear() - 1980) << 9) | ((d.getUTCMonth() + 1) << 5) | d.getUTCDate(),
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
/** A zip of the entries in order, deflated, each dated `mtime` (UTC) with its Unix mode. */
|
|
714
|
+
export function zipArchive(entries, mtime) {
|
|
715
|
+
const { time, date } = dosTime(mtime);
|
|
716
|
+
const locals = [];
|
|
717
|
+
const central = [];
|
|
718
|
+
let offset = 0;
|
|
719
|
+
for (const e of entries) {
|
|
720
|
+
const data = "abs" in e ? (e.bytes ?? readFileSync(e.abs)) : e.bytes;
|
|
721
|
+
const packed = deflateRawSync(data, { level: 9 });
|
|
722
|
+
const name = Buffer.from(e.name, "utf-8");
|
|
723
|
+
const crc = crc32(data);
|
|
724
|
+
const local = Buffer.alloc(30);
|
|
725
|
+
local.writeUInt32LE(0x04034b50, 0);
|
|
726
|
+
local.writeUInt16LE(20, 4);
|
|
727
|
+
local.writeUInt16LE(0x0800, 6);
|
|
728
|
+
local.writeUInt16LE(8, 8);
|
|
729
|
+
local.writeUInt16LE(time, 10);
|
|
730
|
+
local.writeUInt16LE(date, 12);
|
|
731
|
+
local.writeUInt32LE(crc, 14);
|
|
732
|
+
local.writeUInt32LE(packed.length, 18);
|
|
733
|
+
local.writeUInt32LE(data.length, 22);
|
|
734
|
+
local.writeUInt16LE(name.length, 26);
|
|
735
|
+
local.writeUInt16LE(0, 28);
|
|
736
|
+
const c = Buffer.alloc(46);
|
|
737
|
+
c.writeUInt32LE(0x02014b50, 0);
|
|
738
|
+
c.writeUInt16LE((3 << 8) | 20, 4);
|
|
739
|
+
c.writeUInt16LE(20, 6);
|
|
740
|
+
c.writeUInt16LE(0x0800, 8);
|
|
741
|
+
c.writeUInt16LE(8, 10);
|
|
742
|
+
c.writeUInt16LE(time, 12);
|
|
743
|
+
c.writeUInt16LE(date, 14);
|
|
744
|
+
c.writeUInt32LE(crc, 16);
|
|
745
|
+
c.writeUInt32LE(packed.length, 20);
|
|
746
|
+
c.writeUInt32LE(data.length, 24);
|
|
747
|
+
c.writeUInt16LE(name.length, 28);
|
|
748
|
+
c.writeUInt32LE(((0o100000 | ("abs" in e ? modeOf(e.abs) : 0o644)) << 16) >>> 0, 38);
|
|
749
|
+
c.writeUInt32LE(offset, 42);
|
|
750
|
+
locals.push(local, name, packed);
|
|
751
|
+
central.push(c, name);
|
|
752
|
+
offset += local.length + name.length + packed.length;
|
|
753
|
+
}
|
|
754
|
+
const dir = Buffer.concat(central);
|
|
755
|
+
const end = Buffer.alloc(22);
|
|
756
|
+
end.writeUInt32LE(0x06054b50, 0);
|
|
757
|
+
end.writeUInt16LE(entries.length, 8);
|
|
758
|
+
end.writeUInt16LE(entries.length, 10);
|
|
759
|
+
end.writeUInt32LE(dir.length, 12);
|
|
760
|
+
end.writeUInt32LE(offset, 16);
|
|
761
|
+
return Buffer.concat([...locals, dir, end]);
|
|
762
|
+
}
|
|
763
|
+
// ── the release's files ────────────────────────────────────────────────
|
|
764
|
+
/** The files the release records for `names`, the entries `release.artifacts` declares. */
|
|
765
|
+
export function releaseArtifactFiles(release, names) {
|
|
766
|
+
return release.artifactDigests.filter((a) => a.kind === "asset" && names.includes(a.component));
|
|
767
|
+
}
|
|
768
|
+
/** Where a recorded file differs from the release in `cwd`: missing, or another digest. */
|
|
769
|
+
export function artifactFileProblems(cwd, files) {
|
|
770
|
+
const out = [];
|
|
771
|
+
for (const f of files) {
|
|
772
|
+
const abs = resolve(cwd, f.path);
|
|
773
|
+
if (!existsSync(abs) || !statSync(abs).isFile()) {
|
|
774
|
+
out.push({ path: f.path, problem: "missing", recorded: f.digest });
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
const digest = digestOf(abs);
|
|
778
|
+
if (digest !== f.digest)
|
|
779
|
+
out.push({ path: f.path, problem: "digest", digest, recorded: f.digest });
|
|
780
|
+
}
|
|
781
|
+
return out;
|
|
782
|
+
}
|
|
783
|
+
/** Copy each file from `from` to the same path under `to`. A file missing from `from` is refused. */
|
|
784
|
+
export function copyArtifactFiles(files, from, to, o = {}) {
|
|
785
|
+
for (const f of files) {
|
|
786
|
+
const src = resolve(from, f.path);
|
|
787
|
+
if (!existsSync(src)) {
|
|
788
|
+
if (o.missingOk)
|
|
789
|
+
continue;
|
|
790
|
+
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>.");
|
|
791
|
+
}
|
|
792
|
+
const dest = resolve(to, f.path);
|
|
793
|
+
if (dest === src)
|
|
794
|
+
continue;
|
|
795
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
796
|
+
copyFileSync(src, dest);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
/** Whether any entry is packaged by nfpm, for the workflow's install step (#5233). */
|
|
800
|
+
export function usesNfpm(artifacts) {
|
|
801
|
+
return artifacts.some(isNfpm);
|
|
802
|
+
}
|
|
803
|
+
/** Whether any entry is built by goreleaser, for the workflow's install step. */
|
|
804
|
+
export function usesGoreleaser(artifacts) {
|
|
805
|
+
return artifacts.some(isGoreleaser);
|
|
806
|
+
}
|
|
807
|
+
/** The `artifact:<name>` prefix a forge, homebrew or index target's `assets` names an entry's files with. */
|
|
808
|
+
export const ARTIFACT_REF = "artifact:";
|