@intentius/chant 0.124.99 → 0.124.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/chant +3 -3
- package/dist/action-pins.d.ts +2 -0
- package/dist/action-pins.js +3 -0
- package/dist/ci-detect.d.ts +13 -0
- package/dist/ci-detect.js +12 -0
- package/dist/ci-system.d.ts +66 -0
- package/dist/ci-system.js +61 -0
- package/dist/cli/commands/carve-emit.js +2 -2
- package/dist/cli/commands/check-lexicon-plugin.d.ts +2 -2
- package/dist/cli/commands/check-lexicon-plugin.js +3 -3
- package/dist/cli/commands/check-lexicon.js +4 -4
- package/dist/cli/commands/init-lexicon/templates/project.d.ts +1 -1
- package/dist/cli/commands/init-lexicon/templates/project.js +4 -4
- package/dist/cli/commands/init.d.ts +13 -0
- package/dist/cli/commands/init.js +30 -2
- package/dist/cli/handlers/build.js +27 -0
- package/dist/cli/handlers/release-doctor.d.ts +12 -0
- package/dist/cli/handlers/release-doctor.js +118 -0
- package/dist/cli/handlers/release-init.d.ts +10 -0
- package/dist/cli/handlers/release-init.js +342 -0
- package/dist/cli/handlers/release.d.ts +50 -1
- package/dist/cli/handlers/release.js +688 -30
- package/dist/cli/handlers/run-generate.js +11 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +45 -97
- package/dist/cli/parse-args.js +55 -0
- package/dist/cli/registry.d.ts +18 -0
- package/dist/cli/release-commands/artifacts.d.ts +3 -0
- package/dist/cli/release-commands/artifacts.js +14 -0
- package/dist/cli/release-commands/candidates.d.ts +3 -0
- package/dist/cli/release-commands/candidates.js +16 -0
- package/dist/cli/release-commands/changed.d.ts +3 -0
- package/dist/cli/release-commands/changed.js +14 -0
- package/dist/cli/release-commands/compose.d.ts +3 -0
- package/dist/cli/release-commands/compose.js +16 -0
- package/dist/cli/release-commands/cut.d.ts +3 -0
- package/dist/cli/release-commands/cut.js +49 -0
- package/dist/cli/release-commands/doctor.d.ts +3 -0
- package/dist/cli/release-commands/doctor.js +14 -0
- package/dist/cli/release-commands/export.d.ts +3 -0
- package/dist/cli/release-commands/export.js +12 -0
- package/dist/cli/release-commands/images.d.ts +3 -0
- package/dist/cli/release-commands/images.js +13 -0
- package/dist/cli/release-commands/index.d.ts +8 -0
- package/dist/cli/release-commands/index.js +52 -0
- package/dist/cli/release-commands/init.d.ts +3 -0
- package/dist/cli/release-commands/init.js +16 -0
- package/dist/cli/release-commands/list.d.ts +3 -0
- package/dist/cli/release-commands/list.js +10 -0
- package/dist/cli/release-commands/next.d.ts +3 -0
- package/dist/cli/release-commands/next.js +13 -0
- package/dist/cli/release-commands/publish.d.ts +3 -0
- package/dist/cli/release-commands/publish.js +22 -0
- package/dist/cli/release-commands/stamp.d.ts +3 -0
- package/dist/cli/release-commands/stamp.js +15 -0
- package/dist/cli/release-commands/status.d.ts +3 -0
- package/dist/cli/release-commands/status.js +17 -0
- package/dist/cli/release-commands/tag.d.ts +3 -0
- package/dist/cli/release-commands/tag.js +12 -0
- package/dist/cli/release-commands/types.d.ts +20 -0
- package/dist/cli/release-commands/types.js +1 -0
- package/dist/cli/release-commands/verify.d.ts +3 -0
- package/dist/cli/release-commands/verify.js +15 -0
- package/dist/cli/release-commands/workflow.d.ts +3 -0
- package/dist/cli/release-commands/workflow.js +13 -0
- package/dist/codegen/pinned-upgrade.js +1 -1
- package/dist/components/capability-plugin.d.ts +1 -1
- package/dist/components/capability-plugin.js +1 -1
- package/dist/components/cli-support.d.ts +1 -1
- package/dist/components/cli-support.js +1 -1
- package/dist/config-environments.d.ts +8 -1
- package/dist/config-environments.js +2 -0
- package/dist/config.d.ts +299 -6
- package/dist/config.js +102 -5
- package/dist/dead-guards.d.ts +5 -1
- package/dist/dead-guards.js +34 -23
- package/dist/discovery/sandbox/driver.js +1 -1
- package/dist/discovery/specifier-resolve.js +1 -1
- package/dist/floor-table.d.ts +3 -1
- package/dist/floor-table.data.js +23 -3
- package/dist/floor-table.js +4 -3
- package/dist/forge-remote.d.ts +13 -0
- package/dist/forge-remote.js +15 -0
- package/dist/lexicon.d.ts +41 -2
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +62 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.js +270 -3
- package/dist/lifecycle/publish-attachments.d.ts +2 -1
- package/dist/lifecycle/publish-attachments.js +19 -2
- package/dist/lifecycle/publish-cargo.d.ts +99 -0
- package/dist/lifecycle/publish-cargo.js +412 -0
- package/dist/lifecycle/publish-credentials.d.ts +1 -1
- package/dist/lifecycle/publish-credentials.js +8 -0
- package/dist/lifecycle/publish-declaration.d.ts +199 -4
- package/dist/lifecycle/publish-declaration.js +200 -9
- package/dist/lifecycle/publish-forge.d.ts +45 -2
- package/dist/lifecycle/publish-forge.js +434 -34
- package/dist/lifecycle/publish-git-ssh.d.ts +15 -0
- package/dist/lifecycle/publish-git-ssh.js +30 -4
- package/dist/lifecycle/publish-github.d.ts +40 -2
- package/dist/lifecycle/publish-github.js +100 -3
- package/dist/lifecycle/publish-homebrew.d.ts +7 -9
- package/dist/lifecycle/publish-homebrew.js +34 -197
- package/dist/lifecycle/publish-index.d.ts +141 -0
- package/dist/lifecycle/publish-index.js +719 -0
- package/dist/lifecycle/publish-marketplace.js +77 -0
- package/dist/lifecycle/publish-mcp-registry.d.ts +66 -0
- package/dist/lifecycle/publish-mcp-registry.js +306 -0
- package/dist/lifecycle/publish-npm.js +165 -2
- package/dist/lifecycle/publish-oci.d.ts +34 -1
- package/dist/lifecycle/publish-oci.js +246 -7
- package/dist/lifecycle/publish-pypi.d.ts +136 -0
- package/dist/lifecycle/publish-pypi.js +657 -0
- package/dist/lifecycle/publish-record.d.ts +6 -3
- package/dist/lifecycle/publish-record.js +6 -3
- package/dist/lifecycle/publish-signing.d.ts +147 -0
- package/dist/lifecycle/publish-signing.js +257 -0
- package/dist/lifecycle/publish-targets.d.ts +27 -1
- package/dist/lifecycle/publish-targets.js +80 -0
- package/dist/lifecycle/publish-tauri.js +43 -0
- package/dist/lifecycle/publish-train-names.d.ts +54 -0
- package/dist/lifecycle/publish-train-names.js +118 -0
- package/dist/lifecycle/publish-verify.d.ts +121 -0
- package/dist/lifecycle/publish-verify.js +130 -0
- package/dist/lifecycle/query.js +8 -0
- package/dist/lifecycle/release-artifacts.d.ts +212 -0
- package/dist/lifecycle/release-artifacts.js +571 -0
- package/dist/lifecycle/release-changelog.d.ts +13 -1
- package/dist/lifecycle/release-changelog.js +35 -2
- package/dist/lifecycle/release-cut.d.ts +58 -3
- package/dist/lifecycle/release-cut.js +132 -34
- package/dist/lifecycle/release-doctor.d.ts +113 -0
- package/dist/lifecycle/release-doctor.js +996 -0
- package/dist/lifecycle/release-green.d.ts +86 -0
- package/dist/lifecycle/release-green.js +286 -0
- package/dist/lifecycle/release-init.d.ts +255 -0
- package/dist/lifecycle/release-init.js +859 -0
- package/dist/lifecycle/release-intents.d.ts +73 -0
- package/dist/lifecycle/release-intents.js +128 -0
- package/dist/lifecycle/release-next.d.ts +111 -0
- package/dist/lifecycle/release-next.js +252 -0
- package/dist/lifecycle/release-prerelease.d.ts +19 -0
- package/dist/lifecycle/release-prerelease.js +30 -0
- package/dist/lifecycle/release-publish.d.ts +256 -10
- package/dist/lifecycle/release-publish.js +246 -34
- package/dist/lifecycle/release-status-change.d.ts +226 -0
- package/dist/lifecycle/release-status-change.js +478 -0
- package/dist/lifecycle/release-status.d.ts +11 -0
- package/dist/lifecycle/release-status.js +1 -1
- package/dist/lifecycle/release-store.d.ts +73 -2
- package/dist/lifecycle/release-store.js +32 -1
- package/dist/lifecycle/release-tag.d.ts +142 -0
- package/dist/lifecycle/release-tag.js +323 -0
- package/dist/lifecycle/release-verify.d.ts +73 -1
- package/dist/lifecycle/release-verify.js +117 -2
- package/dist/lifecycle/release-version-formats.d.ts +73 -0
- package/dist/lifecycle/release-version-formats.js +570 -0
- package/dist/lifecycle/release-version.d.ts +58 -10
- package/dist/lifecycle/release-version.js +164 -36
- package/dist/lifecycle/release-workstation.d.ts +3 -2
- package/dist/lifecycle/release-workstation.js +3 -2
- package/dist/module-source.d.ts +2 -2
- package/dist/module-source.js +8 -8
- package/dist/op/generate-pipeline.js +1 -1
- package/dist/pr-forge-base.js +4 -2
- package/dist/pr-forge.d.ts +20 -2
- package/dist/pr-forge.js +46 -10
- package/dist/release-floors.d.ts +10 -1
- package/dist/release-floors.js +10 -1
- package/dist/tool-pins.d.ts +38 -0
- package/dist/tool-pins.js +54 -0
- package/dist/ts-loader.d.ts +1 -1
- package/dist/ts-loader.js +6 -6
- package/dist/wave-runtime.mjs +337 -334
- package/dist/workspace/ci-forge.d.ts +17 -0
- package/dist/workspace/ci-forge.js +17 -0
- package/dist/workspace/ci-init.js +1 -1
- package/dist/workspace/composites.schema.json +1 -0
- package/dist/workspace/declaration.d.ts +8 -0
- package/dist/workspace/declaration.js +12 -0
- package/dist/workspace/declaration.schema.json +8 -0
- package/dist/workspace/environments.d.ts +2 -0
- package/dist/workspace/environments.js +1 -1
- package/dist/workspace/identity-gate-rule.d.ts +61 -5
- package/dist/workspace/identity-gate-rule.js +81 -12
- package/dist/workspace/member-pipeline.d.ts +2 -1
- package/dist/workspace/member-pipeline.js +5 -2
- package/dist/workspace/reason-codes.d.ts +6 -0
- package/dist/workspace/reason-codes.js +8 -1
- package/dist/workspace/release-changed.d.ts +179 -0
- package/dist/workspace/release-changed.js +625 -0
- package/dist/workspace/release-changed.schema.json +206 -0
- package/dist/workspace/release-steps/artifacts.d.ts +7 -0
- package/dist/workspace/release-steps/artifacts.js +45 -0
- package/dist/workspace/release-steps/builds.d.ts +12 -0
- package/dist/workspace/release-steps/builds.js +38 -0
- package/dist/workspace/release-steps/doctor.d.ts +8 -0
- package/dist/workspace/release-steps/doctor.js +14 -0
- package/dist/workspace/release-steps/goreleaser.d.ts +16 -0
- package/dist/workspace/release-steps/goreleaser.js +36 -0
- package/dist/workspace/release-steps/green.d.ts +3 -0
- package/dist/workspace/release-steps/green.js +6 -0
- package/dist/workspace/release-steps/images.d.ts +22 -0
- package/dist/workspace/release-steps/images.js +59 -0
- package/dist/workspace/release-steps/index.d.ts +9 -0
- package/dist/workspace/release-steps/index.js +46 -0
- package/dist/workspace/release-steps/pypi.d.ts +15 -0
- package/dist/workspace/release-steps/pypi.js +21 -0
- package/dist/workspace/release-steps/qemu.d.ts +21 -0
- package/dist/workspace/release-steps/qemu.js +35 -0
- package/dist/workspace/release-steps/signing.d.ts +18 -0
- package/dist/workspace/release-steps/signing.js +30 -0
- package/dist/workspace/release-steps/stamp.d.ts +3 -0
- package/dist/workspace/release-steps/stamp.js +4 -0
- package/dist/workspace/release-steps/targets.d.ts +31 -0
- package/dist/workspace/release-steps/targets.js +40 -0
- package/dist/workspace/release-steps/types.d.ts +104 -0
- package/dist/workspace/release-steps/types.js +2 -0
- package/dist/workspace/release-steps/verify.d.ts +3 -0
- package/dist/workspace/release-steps/verify.js +4 -0
- package/dist/workspace/release-toolchains.d.ts +59 -0
- package/dist/workspace/release-toolchains.js +133 -0
- package/dist/workspace/release-train-workflow.d.ts +29 -0
- package/dist/workspace/release-train-workflow.js +85 -0
- package/dist/workspace/release-train.d.ts +3 -1
- package/dist/workspace/release-train.js +20 -3
- package/dist/workspace/release-workflow.d.ts +160 -61
- package/dist/workspace/release-workflow.js +539 -193
- package/dist/workspace/releases.schema.json +70 -1
- package/dist/workspace/search-contract.d.ts +1 -1
- package/dist/workspace/security.js +9 -2
- package/dist/workspace/train-cut.d.ts +182 -0
- package/dist/workspace/train-cut.js +482 -0
- package/dist/workspace/train-prepare.d.ts +61 -0
- package/dist/workspace/train-prepare.js +267 -0
- package/dist/workspace/train-publish.d.ts +177 -0
- package/dist/workspace/train-publish.js +575 -0
- package/dist/workspace/train-range-labels.d.ts +33 -0
- package/dist/workspace/train-range-labels.js +109 -0
- package/dist/workspace/trust/seal.d.ts +13 -3
- package/dist/workspace/trust/seal.js +14 -4
- package/dist/workspace/work-cli.d.ts +3 -2
- package/dist/workspace/work-cli.js +3 -2
- package/dist/workspace/workspace-ledger.d.ts +14 -1
- package/dist/workspace/workspace-ledger.js +33 -7
- package/package.json +26 -26
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The index-repository target (#5158): manifests in a repository on GitHub
|
|
3
|
+
* that a package manager or a directory reads, rendered from templates in
|
|
4
|
+
* the member, and either committed to a repository the publisher may push
|
|
5
|
+
* to or proposed in a pull request on one it can't.
|
|
6
|
+
*
|
|
7
|
+
* Presets fill in what a known index needs (./publish-declaration.ts,
|
|
8
|
+
* `INDEX_PRESETS`):
|
|
9
|
+
*
|
|
10
|
+
* | Preset | Repository | Mode | Manifest |
|
|
11
|
+
* |---|---|---|---|
|
|
12
|
+
* | `krew` | kubernetes-sigs/krew-index | pull-request | `plugins/{name}.yaml` |
|
|
13
|
+
* | `winget` | microsoft/winget-pkgs | pull-request | `files`, under `manifests/{letter}/{namePath}/{version}/` |
|
|
14
|
+
* | `scoop` | yours | commit | `bucket/{name}.json` |
|
|
15
|
+
* | `homebrew-core` | Homebrew/homebrew-core | pull-request | `Formula/{letter}/{name}.rb` |
|
|
16
|
+
* | `homebrew-tap` | yours | commit | `Formula/{name}.rb` |
|
|
17
|
+
* | `zed` | zed-industries/extensions | pull-request | `version` in `extensions.toml`, and the `extensions/{name}` submodule at the release's commit |
|
|
18
|
+
* | `artifacthub` | yours | commit | `{name}/{version}/artifacthub-pkg.yml` |
|
|
19
|
+
*
|
|
20
|
+
* The templates take the `homebrew` target's placeholders (`{{version}}`,
|
|
21
|
+
* `{{label}}`, `{{tag}}`, `{{url:<asset>}}`, `{{sha256:<asset>}}`) and
|
|
22
|
+
* `{{name}}` and `{{commit}}`. Each asset is one the release records, named
|
|
23
|
+
* by `artifact:<name>` (#5151) or by its path, and its SHA-256 is the one the
|
|
24
|
+
* release records: the file is never read or hashed again.
|
|
25
|
+
*
|
|
26
|
+
* `mode: "commit"` is the tap's two steps (./publish-homebrew.ts): the stage
|
|
27
|
+
* commits to `chant-publish/<name>-<version>` beside the branch, and the
|
|
28
|
+
* reveal fast-forwards the branch. `mode: "pull-request"` stages the same
|
|
29
|
+
* commit on a branch of the publisher's fork (made when there is none), and
|
|
30
|
+
* the reveal opens the pull request. A resume finds the pull request it
|
|
31
|
+
* opened, open or merged, and opens none again; one the index closed without
|
|
32
|
+
* merging is a refusal. An index that already holds the manifests as
|
|
33
|
+
* rendered, such as one a bot updated, gets nothing.
|
|
34
|
+
*
|
|
35
|
+
* The target reveals last (`revealsLast`, as the MCP Registry does): it
|
|
36
|
+
* stages with the other targets, onto a branch no consumer reads, and
|
|
37
|
+
* reveals after every other target, since the index points at files those
|
|
38
|
+
* targets make downloadable. Targets that reveal last go in the order
|
|
39
|
+
* declared. A refusal is a warning unless `onRefusal: "fail"`
|
|
40
|
+
* (`refusalWarns`).
|
|
41
|
+
*
|
|
42
|
+
* The `homebrew` target is this target's `homebrew-tap` preset with its own
|
|
43
|
+
* fields, kind and codes, staged and revealed in the order declared as
|
|
44
|
+
* before, its hashes read from the checkout and checked against the record.
|
|
45
|
+
*
|
|
46
|
+
* Status changes (#5163, `chant release yank|restore`): an index has no
|
|
47
|
+
* per-version deprecation, so deprecate changes nothing. In `mode: "commit"`
|
|
48
|
+
* a yank puts back each manifest as the head release (the newest active one
|
|
49
|
+
* of the channel) published it, found by its digest among the last 100
|
|
50
|
+
* commits of the branch that touch it, when the branch still holds this
|
|
51
|
+
* release's; a manifest the head release did not publish, such as Artifact
|
|
52
|
+
* Hub's `{name}/{version}/artifacthub-pkg.yml`, is removed. A restore puts
|
|
53
|
+
* this release's manifests back, from the same history, where no newer
|
|
54
|
+
* active release holds the path. One commit either way. In
|
|
55
|
+
* `mode: "pull-request"` the index's maintainers merge what changes, so a
|
|
56
|
+
* yank or restore is refused (`release-status-index-pull-request`).
|
|
57
|
+
*/
|
|
58
|
+
import { readFileSync } from "node:fs";
|
|
59
|
+
import { basename, isAbsolute } from "node:path";
|
|
60
|
+
import { readCredential } from "./publish-credentials.js";
|
|
61
|
+
import { SshGitRepo } from "./publish-git-ssh.js";
|
|
62
|
+
import { GitHubRepo, githubApi } from "./publish-github.js";
|
|
63
|
+
import { bytesDigest, checkReleaseDigest, expandArtifactAssets, memberFile, publishTargetKey, releaseArtifactAt } from "./publish-targets.js";
|
|
64
|
+
import { PublishTargetError } from "./release-publish.js";
|
|
65
|
+
import { prereleaseOf } from "./release-prerelease.js";
|
|
66
|
+
import { trainName, waitUntilServed } from "./publish-train-names.js";
|
|
67
|
+
/** The first chant that publishes an `index` target (#5158). */
|
|
68
|
+
export const PUBLISH_INDEX_FLOOR = "0.124.101";
|
|
69
|
+
/** The variable an index target reads its token from when the declaration names none. */
|
|
70
|
+
export const INDEX_TOKEN_ENV = "INDEX_TOKEN";
|
|
71
|
+
/** What each preset fills in. */
|
|
72
|
+
export const INDEX_PRESET_DEFAULTS = {
|
|
73
|
+
krew: { repo: "kubernetes-sigs/krew-index", mode: "pull-request", path: "plugins/{name}.yaml", title: "Update {name} to {version}" },
|
|
74
|
+
winget: { repo: "microsoft/winget-pkgs", mode: "pull-request", title: "New version: {name} version {version}" },
|
|
75
|
+
scoop: { mode: "commit", path: "bucket/{name}.json", title: "{name}: Update to version {version}" },
|
|
76
|
+
"homebrew-core": { repo: "Homebrew/homebrew-core", mode: "pull-request", path: "Formula/{letter}/{name}.rb", title: "{name} {version}" },
|
|
77
|
+
"homebrew-tap": { mode: "commit", path: "Formula/{name}.rb", title: "{name} {version}", tokenEnv: "HOMEBREW_TAP_TOKEN" },
|
|
78
|
+
zed: { repo: "zed-industries/extensions", mode: "pull-request", title: "Update {name} to {version}" },
|
|
79
|
+
artifacthub: { mode: "commit", path: "{name}/{version}/artifacthub-pkg.yml", title: "{name} {version}" },
|
|
80
|
+
};
|
|
81
|
+
/** A release's version for a package manager: its label from the first digit on, or null when the label has no digit. */
|
|
82
|
+
export function releaseVersion(label) {
|
|
83
|
+
const at = label?.search(/\d/) ?? -1;
|
|
84
|
+
return label && at >= 0 ? label.slice(at) : null;
|
|
85
|
+
}
|
|
86
|
+
/** `pattern` with `{tag}`, `{label}`, `{version}` and `{name}` filled in, each URL-encoded except the tag's slashes. */
|
|
87
|
+
export function fillUrl(pattern, values) {
|
|
88
|
+
return pattern.replace(/\{(tag|label|version|name)\}/g, (_, k) => k === "tag" ? values.tag.split("/").map(encodeURIComponent).join("/") : encodeURIComponent(values[k]));
|
|
89
|
+
}
|
|
90
|
+
/** Render a manifest template with `values` (each `{{key}}`) and each asset's `{{url:<name>}}` and `{{sha256:<name>}}`, or name what it can't fill, refused with `code`. */
|
|
91
|
+
export function renderManifest(template, values, assets, code, what = "the template") {
|
|
92
|
+
return template.replace(/\{\{\s*([^}]*?)\s*\}\}/g, (whole, inner) => {
|
|
93
|
+
if (Object.prototype.hasOwnProperty.call(values, inner))
|
|
94
|
+
return values[inner];
|
|
95
|
+
const m = /^(url|sha256):(.+)$/.exec(inner);
|
|
96
|
+
const asset = m ? assets.get(m[2].trim()) : undefined;
|
|
97
|
+
if (m && asset)
|
|
98
|
+
return m[1] === "url" ? asset.url : asset.sha256;
|
|
99
|
+
throw new PublishTargetError(code, m ? `${what} names ${whole}, and no declared asset is named ${m[2].trim()}` : `${what} has ${whole}, which chant does not fill`, `The placeholders are ${Object.keys(values).map((k) => `{{${k}}}`).join(", ")}, and {{url:<name>}} and {{sha256:<name>}} for an asset in assets: ${[...assets.keys()].join(", ")}.`);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/** An index path with `{name}`, `{version}`, `{label}`, `{letter}` and `{namePath}` filled in, refused when it names anything else or leaves the repository. */
|
|
103
|
+
export function fillIndexPath(pattern, values, code) {
|
|
104
|
+
const all = { ...values, letter: values.name.charAt(0).toLowerCase(), namePath: values.name.split(".").join("/") };
|
|
105
|
+
const out = pattern.replace(/\{([A-Za-z]+)\}/g, (whole, k) => {
|
|
106
|
+
if (Object.prototype.hasOwnProperty.call(all, k))
|
|
107
|
+
return all[k];
|
|
108
|
+
throw new PublishTargetError(code, `the index path ${pattern} names ${whole}`, "A path may hold {name}, {version}, {label}, {letter} and {namePath}.");
|
|
109
|
+
});
|
|
110
|
+
if (isAbsolute(out) || out.startsWith("/") || out.split("/").some((s) => s === ".." || s === "." || s === "")) {
|
|
111
|
+
throw new PublishTargetError(code, `the index path ${out} is not a path inside the repository`);
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* `text` with `version = "<version>"` set in the TOML table `[<table>]`, the
|
|
117
|
+
* rest of the file as it was. Null when the file has no such table.
|
|
118
|
+
*/
|
|
119
|
+
export function setTomlTableVersion(text, table, version) {
|
|
120
|
+
const lines = text.split("\n");
|
|
121
|
+
const header = (l) => /^\s*\[/.test(l);
|
|
122
|
+
const start = lines.findIndex((l) => {
|
|
123
|
+
const m = /^\s*\[\s*("?)([^"\]]+)\1\s*\]\s*(#.*)?$/.exec(l);
|
|
124
|
+
return m !== null && m[2] === table;
|
|
125
|
+
});
|
|
126
|
+
if (start < 0)
|
|
127
|
+
return null;
|
|
128
|
+
let end = start + 1;
|
|
129
|
+
while (end < lines.length && !header(lines[end]))
|
|
130
|
+
end++;
|
|
131
|
+
const line = `version = "${version}"`;
|
|
132
|
+
const at = lines.slice(start + 1, end).findIndex((l) => /^\s*version\s*=/.test(l));
|
|
133
|
+
if (at >= 0)
|
|
134
|
+
lines[start + 1 + at] = line;
|
|
135
|
+
else
|
|
136
|
+
lines.splice(start + 1, 0, line);
|
|
137
|
+
return lines.join("\n");
|
|
138
|
+
}
|
|
139
|
+
const apiReader = (repo) => ({
|
|
140
|
+
file: (ref, path) => repo.file(path, ref),
|
|
141
|
+
gitlink: (ref, path) => repo.submodule(path, ref),
|
|
142
|
+
});
|
|
143
|
+
const sshReader = (repo) => ({
|
|
144
|
+
file: async (ref, path) => {
|
|
145
|
+
const bytes = await repo.file(ref, path);
|
|
146
|
+
return bytes ? { bytes, sha: null } : null;
|
|
147
|
+
},
|
|
148
|
+
gitlink: (ref, path) => repo.gitlink(ref, path),
|
|
149
|
+
});
|
|
150
|
+
/** The settings of an `index` declaration, its preset filled in. Refuses a declaration that can't publish (`publish-index-invalid`). */
|
|
151
|
+
export function indexSettings(decl) {
|
|
152
|
+
const preset = decl.preset ? INDEX_PRESET_DEFAULTS[decl.preset] : undefined;
|
|
153
|
+
const invalid = (message, fix) => {
|
|
154
|
+
throw new PublishTargetError("publish-index-invalid", `the index target for ${decl.name}: ${message}`, fix);
|
|
155
|
+
};
|
|
156
|
+
const repo = decl.repo ?? preset?.repo ?? invalid(`it names no repo${decl.preset ? `, and the ${decl.preset} preset has none` : ""}`, "Set repo to the index repository, owner/name.");
|
|
157
|
+
const mode = decl.mode ?? preset?.mode ?? "pull-request";
|
|
158
|
+
if (mode === "pull-request" && decl.sshKeyEnv)
|
|
159
|
+
invalid("sshKeyEnv pushes over SSH, and a pull request is opened through the API", "Keep sshKeyEnv for mode: \"commit\", or use tokenEnv.");
|
|
160
|
+
if (mode === "commit" && decl.fork)
|
|
161
|
+
invalid("fork names where a pull request's branch goes, and mode is commit", "Drop fork, or set mode: \"pull-request\".");
|
|
162
|
+
const zed = decl.preset === "zed";
|
|
163
|
+
if (zed && (decl.template || decl.path))
|
|
164
|
+
invalid("the zed preset writes the version into extensions.toml and moves the extension's submodule, from no template", "Drop template and path.");
|
|
165
|
+
const files = [];
|
|
166
|
+
if (decl.template) {
|
|
167
|
+
const path = decl.path ?? preset?.path ?? invalid(`template needs path${decl.preset ? `, since the ${decl.preset} preset writes more than one file` : ""}`, decl.preset === "winget" ? "List the version, installer and locale manifests under files." : "Set path to where the manifest goes in the index.");
|
|
168
|
+
files.push({ path, template: decl.template });
|
|
169
|
+
}
|
|
170
|
+
for (const [path, template] of Object.entries(decl.files ?? {}))
|
|
171
|
+
files.push({ path, template });
|
|
172
|
+
if (files.length === 0 && !zed)
|
|
173
|
+
invalid("it names no template and no files", "Set template, or list the manifests under files.");
|
|
174
|
+
const tokenEnv = decl.tokenEnv ?? preset?.tokenEnv ?? INDEX_TOKEN_ENV;
|
|
175
|
+
const where = mode === "commit" ? repo : `a pull request to ${repo}`;
|
|
176
|
+
return {
|
|
177
|
+
kind: "index",
|
|
178
|
+
code: "publish-index",
|
|
179
|
+
key: publishTargetKey(decl),
|
|
180
|
+
label: `index ${decl.preset ?? "repository"} ${decl.name}: ${where}`,
|
|
181
|
+
destination: `github ${repo}${mode === "pull-request" ? " (pull request)" : ""}`,
|
|
182
|
+
name: decl.name,
|
|
183
|
+
repo,
|
|
184
|
+
mode,
|
|
185
|
+
files,
|
|
186
|
+
zed,
|
|
187
|
+
assets: decl.assets ?? [],
|
|
188
|
+
url: decl.url,
|
|
189
|
+
branch: decl.branch,
|
|
190
|
+
fork: decl.fork,
|
|
191
|
+
title: decl.title ?? preset?.title ?? "{name} {version}",
|
|
192
|
+
body: decl.body ?? "Updates {name} to {version}, released as {tag}.",
|
|
193
|
+
api: decl.api,
|
|
194
|
+
tokenEnv,
|
|
195
|
+
sshKeyEnv: decl.sshKeyEnv,
|
|
196
|
+
revealsLast: true,
|
|
197
|
+
refusalWarns: (decl.onRefusal ?? "warn") === "warn",
|
|
198
|
+
digests: "record",
|
|
199
|
+
placeholders: ["version", "label", "tag", "name", "commit"],
|
|
200
|
+
branchIs: "the branch the index is read from",
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/** Fill `{name}`, `{version}`, `{label}` and `{tag}` in a title or body. */
|
|
204
|
+
function fillText(pattern, values) {
|
|
205
|
+
return pattern.replace(/\{(name|version|label|tag)\}/g, (_, k) => values[k]);
|
|
206
|
+
}
|
|
207
|
+
/** An index target from a declaration. */
|
|
208
|
+
export function indexTarget(decl, deps) {
|
|
209
|
+
return indexTargetOf(indexSettings(decl), deps);
|
|
210
|
+
}
|
|
211
|
+
/** The target for `s`: an index declaration's, or the `homebrew` target's (./publish-homebrew.ts). */
|
|
212
|
+
export function indexTargetOf(s, deps) {
|
|
213
|
+
const fetchImpl = deps.fetch ?? ((url, init) => fetch(url, init));
|
|
214
|
+
const ssh = s.sshKeyEnv !== undefined;
|
|
215
|
+
const tokenNames = [s.sshKeyEnv ?? s.tokenEnv];
|
|
216
|
+
const code = (what) => `${s.code}-${what}`;
|
|
217
|
+
const failed = code("failed");
|
|
218
|
+
const single = s.files.length === 1 && !s.zed;
|
|
219
|
+
const first = s.files[0]?.path;
|
|
220
|
+
const setup = (ctx) => {
|
|
221
|
+
const version = releaseVersion(ctx.label);
|
|
222
|
+
if (!version || !ctx.label || !ctx.releaseTag) {
|
|
223
|
+
throw new PublishTargetError(code("no-version"), `a ${s.kind === "homebrew" ? "formula" : "manifest"}'s version is the release's label from its first digit, and release ${ctx.release.releaseDigest} has ${ctx.label ? `the label ${ctx.label}, which has no digit` : "no label"}`, "Cut the release with a label such as v1.4.0.");
|
|
224
|
+
}
|
|
225
|
+
const token = readCredential(ctx.env, tokenNames, ctx.redactor);
|
|
226
|
+
if (!token) {
|
|
227
|
+
throw new PublishTargetError("publish-credentials-missing", `the ${s.kind} target reads its ${ssh ? "SSH key" : "token"} from ${tokenNames[0]}, and it is not set`, ssh
|
|
228
|
+
? `Set ${tokenNames[0]} to a private key that may push to ${s.repo}, such as a deploy key with write access.`
|
|
229
|
+
: s.mode === "commit"
|
|
230
|
+
? `Set ${tokenNames[0]} to a token that may push to ${s.repo}.`
|
|
231
|
+
: `Set ${tokenNames[0]} to a token that may fork ${s.repo}, push to the fork and open a pull request: a classic token with public_repo.`);
|
|
232
|
+
}
|
|
233
|
+
const assets = new Map();
|
|
234
|
+
for (const p of expandArtifactAssets(ctx.release, s.assets)) {
|
|
235
|
+
let digest;
|
|
236
|
+
if (s.digests === "file") {
|
|
237
|
+
digest = bytesDigest(new Uint8Array(readFileSync(memberFile(ctx.cwd, p))));
|
|
238
|
+
checkReleaseDigest(ctx.release, "asset", ctx.cwd, p, [digest]);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
const recorded = releaseArtifactAt(ctx.release, "asset", ctx.cwd, p);
|
|
242
|
+
if (!recorded) {
|
|
243
|
+
throw new PublishTargetError(code("asset-not-recorded"), `assets names ${p}, and release ${ctx.release.releaseDigest} records no such file, so it has no SHA-256 to put in the manifest`, "Name an entry of release.artifacts with artifact:<name>, so the cut builds and records the file.");
|
|
244
|
+
}
|
|
245
|
+
digest = recorded.digest;
|
|
246
|
+
}
|
|
247
|
+
const name = basename(p);
|
|
248
|
+
if (assets.has(name))
|
|
249
|
+
throw new PublishTargetError(code("asset-name-taken"), `two assets are named ${name}, and the template names an asset by its file name`);
|
|
250
|
+
const url = fillUrl(s.url, { tag: ctx.releaseTag, label: ctx.label, version, name });
|
|
251
|
+
assets.set(name, { url, sha256: digest.slice("sha256:".length) });
|
|
252
|
+
}
|
|
253
|
+
const all = { version, label: ctx.label, tag: ctx.releaseTag, name: s.name, commit: ctx.release.commit };
|
|
254
|
+
const values = Object.fromEntries(s.placeholders.map((k) => [k, all[k]]));
|
|
255
|
+
const outputs = [];
|
|
256
|
+
const paths = new Set();
|
|
257
|
+
for (const f of s.files) {
|
|
258
|
+
const path = s.kind === "homebrew" ? f.path : fillIndexPath(f.path, { name: s.name, version, label: ctx.label }, code("path"));
|
|
259
|
+
if (paths.has(path))
|
|
260
|
+
throw new PublishTargetError(code("path"), `two manifests go to ${path}`);
|
|
261
|
+
paths.add(path);
|
|
262
|
+
const template = readFileSync(memberFile(ctx.cwd, f.template), "utf-8");
|
|
263
|
+
const text = renderManifest(template, values, assets, code("template"), s.kind === "homebrew" ? "the formula template" : `the template ${f.template}`);
|
|
264
|
+
outputs.push({ kind: "file", path, bytes: new Uint8Array(Buffer.from(text, "utf-8")) });
|
|
265
|
+
}
|
|
266
|
+
if (s.zed) {
|
|
267
|
+
outputs.push({ kind: "toml-version", path: "extensions.toml", table: s.name, version });
|
|
268
|
+
outputs.push({ kind: "gitlink", path: `extensions/${s.name}`, commit: ctx.release.commit });
|
|
269
|
+
}
|
|
270
|
+
const items = outputs.map((o) => ({ name: o.path, digest: digestOf(o) }));
|
|
271
|
+
return { version, token, assets, outputs, items, label: ctx.label, tag: ctx.releaseTag };
|
|
272
|
+
};
|
|
273
|
+
const digestOf = (o) => (o.kind === "file" ? bytesDigest(o.bytes) : o.kind === "toml-version" ? bytesDigest(new Uint8Array(Buffer.from(`[${o.table}] version = "${o.version}"`))) : undefined);
|
|
274
|
+
const staging = (version) => `chant-publish/${s.name}-${version}`;
|
|
275
|
+
const message = (version, label, tag) => fillText(s.title, { name: s.name, version, label, tag });
|
|
276
|
+
const where = (branch, path) => `${s.repo}@${branch}:${path}`;
|
|
277
|
+
const itemsAt = (items, branch, present) => items.map((i) => ({ name: i.name, destination: where(branch, i.name), ...(i.digest ? { digest: i.digest } : {}), ...(present ? { present: true } : {}) }));
|
|
278
|
+
/** What `outputs` change at `ref`: empty when the index holds them as rendered. */
|
|
279
|
+
async function changesAt(reader, ref, outputs) {
|
|
280
|
+
const out = [];
|
|
281
|
+
for (const o of outputs) {
|
|
282
|
+
if (o.kind === "gitlink") {
|
|
283
|
+
const at = await reader.gitlink(ref, o.path);
|
|
284
|
+
if (at === null) {
|
|
285
|
+
throw new PublishTargetError(code("not-listed"), `${s.repo} has no submodule ${o.path}, so ${s.name} is not listed there yet`, "Submit the extension's first version by hand, as the index asks; this target updates a listed one.");
|
|
286
|
+
}
|
|
287
|
+
if (at !== o.commit)
|
|
288
|
+
out.push({ path: o.path, gitlink: o.commit });
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
const now = await reader.file(ref, o.path);
|
|
292
|
+
if (o.kind === "file") {
|
|
293
|
+
if (!now || !now.bytes.equals(Buffer.from(o.bytes)))
|
|
294
|
+
out.push({ path: o.path, bytes: o.bytes, sha: now?.sha ?? null });
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
const set = now ? setTomlTableVersion(now.bytes.toString("utf-8"), o.table, o.version) : null;
|
|
298
|
+
if (set === null) {
|
|
299
|
+
throw new PublishTargetError(code("not-listed"), `${o.path} in ${s.repo} has no [${o.table}] table, so ${s.name} is not listed there yet`, "Submit the first version by hand, as the index asks; this target updates a listed one.");
|
|
300
|
+
}
|
|
301
|
+
if (set !== now.bytes.toString("utf-8"))
|
|
302
|
+
out.push({ path: o.path, bytes: new Uint8Array(Buffer.from(set, "utf-8")), sha: now.sha });
|
|
303
|
+
}
|
|
304
|
+
return out;
|
|
305
|
+
}
|
|
306
|
+
/** Commit `changes` onto `branch` of `repo` at `head` over the API: the contents API for one file, as the tap always has, else one commit through the git data API. Returns the commit. */
|
|
307
|
+
async function commitOnto(repo, branch, head, changes, msg, force) {
|
|
308
|
+
const only = changes[0];
|
|
309
|
+
if (changes.length === 1 && only && "bytes" in only)
|
|
310
|
+
return repo.putFile(only.path, branch, only.bytes, msg, only.sha);
|
|
311
|
+
const commit = await repo.commitTree(head, changes.map(plain), msg);
|
|
312
|
+
if (!(await repo.moveRef(`heads/${branch}`, commit, force))) {
|
|
313
|
+
throw new PublishTargetError(failed, `${branch} of ${repo.repo} moved while ${s.name} was committed onto it`, "Run the same publish again: it commits onto the branch's new head.");
|
|
314
|
+
}
|
|
315
|
+
return commit;
|
|
316
|
+
}
|
|
317
|
+
const skipNote = (ctx) => s.kind === "homebrew" ? `skipped: ${ctx.label} is a prerelease, and the formula is what \`brew upgrade\` installs` : `skipped: ${ctx.label} is a prerelease, and the index serves releases`;
|
|
318
|
+
const target = {
|
|
319
|
+
kind: s.kind,
|
|
320
|
+
name: s.label,
|
|
321
|
+
destination: s.destination,
|
|
322
|
+
credentialEnv: tokenNames,
|
|
323
|
+
key: s.key,
|
|
324
|
+
...(s.revealsLast ? { revealsLast: true } : {}),
|
|
325
|
+
...(s.refusalWarns ? { refusalWarns: true } : {}),
|
|
326
|
+
/** #5165: the package's place in the index; the files it points at are its own member's. */
|
|
327
|
+
async names() {
|
|
328
|
+
return { provides: [trainName(s.kind, `${s.repo}/${s.name}`)], needs: [] };
|
|
329
|
+
},
|
|
330
|
+
/**
|
|
331
|
+
* #5165: whether the index's branch holds each manifest with the
|
|
332
|
+
* release's version in it, read through the API. A pull request may still
|
|
333
|
+
* be open, so in that mode a manifest without it can't say; over SSH and
|
|
334
|
+
* for Zed's submodule nothing is read.
|
|
335
|
+
*/
|
|
336
|
+
async published(ctx) {
|
|
337
|
+
if (prereleaseOf(ctx.label))
|
|
338
|
+
return true;
|
|
339
|
+
const version = releaseVersion(ctx.label);
|
|
340
|
+
const token = readCredential(ctx.env, tokenNames, ctx.redactor);
|
|
341
|
+
if (!version || !ctx.label || ssh || s.zed || !token)
|
|
342
|
+
return null;
|
|
343
|
+
const upstream = new GitHubRepo(githubApi(s.api, ctx.env), s.repo, token, fetchImpl, ctx, failed);
|
|
344
|
+
const branch = s.branch ?? (await upstream.defaultBranch());
|
|
345
|
+
for (const f of s.files) {
|
|
346
|
+
const path = s.kind === "homebrew" ? f.path : fillIndexPath(f.path, { name: s.name, version, label: ctx.label }, code("path"));
|
|
347
|
+
const there = await upstream.file(path, branch);
|
|
348
|
+
if (!there || !there.bytes.toString("utf-8").includes(version))
|
|
349
|
+
return s.mode === "commit" ? false : null;
|
|
350
|
+
}
|
|
351
|
+
return true;
|
|
352
|
+
},
|
|
353
|
+
/** #5165: in `mode: "commit"`, wait until the branch serves each manifest as revealed. A pull request waits on the index's maintainers, so nothing waits for it. */
|
|
354
|
+
async visible(ctx, published) {
|
|
355
|
+
const token = readCredential(ctx.env, tokenNames, ctx.redactor);
|
|
356
|
+
const files = published.items.filter((i) => typeof i.digest === "string" && !i.refused);
|
|
357
|
+
if (s.mode !== "commit" || ssh || s.zed || !token || files.length === 0)
|
|
358
|
+
return;
|
|
359
|
+
const upstream = new GitHubRepo(githubApi(s.api, ctx.env), s.repo, token, fetchImpl, ctx, failed);
|
|
360
|
+
const branch = s.branch ?? (await upstream.defaultBranch());
|
|
361
|
+
await waitUntilServed(ctx, deps, {
|
|
362
|
+
what: `${s.repo}@${branch}`,
|
|
363
|
+
code: code("not-served"),
|
|
364
|
+
check: async () => {
|
|
365
|
+
const missing = [];
|
|
366
|
+
for (const f of files) {
|
|
367
|
+
const there = await upstream.file(f.name, branch);
|
|
368
|
+
if (!there || bytesDigest(new Uint8Array(there.bytes)) !== f.digest)
|
|
369
|
+
missing.push(f.name);
|
|
370
|
+
}
|
|
371
|
+
return missing;
|
|
372
|
+
},
|
|
373
|
+
});
|
|
374
|
+
},
|
|
375
|
+
async setStatus(ctx) {
|
|
376
|
+
const at = (path) => `${s.repo}:${path}`;
|
|
377
|
+
const noun = s.kind === "homebrew" ? "formula" : "manifest";
|
|
378
|
+
const named = ctx.revealed.length === 1 ? ctx.revealed[0].name : single && !first.includes("{") ? first : null;
|
|
379
|
+
const shown = named ? at(named) : `${s.name}'s manifests in ${s.repo}`;
|
|
380
|
+
if (ctx.status === "deprecated")
|
|
381
|
+
return [{ what: `${shown} unchanged: ${s.kind === "homebrew" ? "a formula" : "an index"} has no deprecation; yank reverts it` }];
|
|
382
|
+
if (s.mode === "pull-request") {
|
|
383
|
+
return [{
|
|
384
|
+
what: `${shown} unchanged`,
|
|
385
|
+
refused: {
|
|
386
|
+
code: "release-status-index-pull-request",
|
|
387
|
+
message: `${s.repo} takes ${s.name} by pull request, merged by its maintainers, so chant does not ${ctx.status === "yanked" ? "revert" : "put back"} the ${noun}s there`,
|
|
388
|
+
fix: `Open a pull request on ${s.repo} by hand${ctx.status === "yanked" ? " that takes the version out, as the index asks" : ""}.`,
|
|
389
|
+
},
|
|
390
|
+
}];
|
|
391
|
+
}
|
|
392
|
+
const ours = ctx.revealed.filter((i) => typeof i.digest === "string");
|
|
393
|
+
if (ours.length === 0)
|
|
394
|
+
return [{ what: `${shown} unchanged: the publish record names no ${noun} digest`, already: true }];
|
|
395
|
+
const isHead = ctx.head?.releaseDigest === ctx.release.releaseDigest;
|
|
396
|
+
const headName = ctx.head?.label ?? ctx.head?.releaseDigest;
|
|
397
|
+
const toName = ctx.status === "active" ? (ctx.label ?? ctx.release.releaseDigest) : headName;
|
|
398
|
+
const steps = [];
|
|
399
|
+
const actions = [];
|
|
400
|
+
for (const item of ours) {
|
|
401
|
+
const path = item.name;
|
|
402
|
+
const held = !isHead ? ctx.head?.items.find((h) => h.name === path && h.digest)?.digest : undefined;
|
|
403
|
+
if (ctx.status === "active") {
|
|
404
|
+
if (held)
|
|
405
|
+
actions.push({ what: `${at(path)} unchanged: a newer active release holds it`, already: true });
|
|
406
|
+
else
|
|
407
|
+
steps.push({ path, ours: item.digest, to: item.digest, what: `put back ${at(path)} as ${toName} published it` });
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (held)
|
|
411
|
+
steps.push({ path, ours: item.digest, to: held, what: `revert ${at(path)} to the ${noun} ${toName} published, if it holds this release's` });
|
|
412
|
+
else if (ctx.head && !isHead)
|
|
413
|
+
steps.push({ path, ours: item.digest, to: null, what: `remove ${at(path)}, which ${toName} did not publish, if it holds this release's` });
|
|
414
|
+
else {
|
|
415
|
+
actions.push({
|
|
416
|
+
what: `${at(path)} stays at this release's ${noun}`,
|
|
417
|
+
refused: { code: "release-status-no-previous", message: `no earlier active release published ${at(path)}, so there is no ${noun} to revert it to`, fix: `Cut and publish a release to move it to, or edit the ${noun} in ${s.repo} by hand.` },
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (!ctx.apply || steps.length === 0)
|
|
422
|
+
return [...actions, ...steps.map((x) => ({ what: x.what }))];
|
|
423
|
+
const token = readCredential(ctx.env, tokenNames, ctx.redactor);
|
|
424
|
+
if (!token)
|
|
425
|
+
throw new PublishTargetError("publish-credentials-missing", `the ${s.kind} target reads its ${ssh ? "SSH key" : "token"} from ${tokenNames[0]}, and it is not set`, `Set ${tokenNames[0]}.`);
|
|
426
|
+
const lost = (branch, path, to) => new PublishTargetError(`release-status-${s.kind === "homebrew" ? "homebrew" : "index"}-history`, `none of the last 100 commits of ${branch} in ${s.repo} that touch ${path} holds the ${noun} ${toName} published (${to})`, `Edit the ${noun} in ${s.repo} by hand.`);
|
|
427
|
+
const version = releaseVersion(toName ?? null) ?? toName ?? "";
|
|
428
|
+
const msg = fillText(s.title, { name: s.name, version, label: toName ?? "", tag: toName ?? "" });
|
|
429
|
+
/** The changes `steps` make, read through `now` and `history`: a step whose path is already where it goes, or no longer this release's on a yank, is left. */
|
|
430
|
+
const plan = async (branch, now, history) => {
|
|
431
|
+
const changes = [];
|
|
432
|
+
for (const x of steps) {
|
|
433
|
+
const there = await now(x.path);
|
|
434
|
+
const nowDigest = there ? bytesDigest(new Uint8Array(there.bytes)) : null;
|
|
435
|
+
if (nowDigest === x.to || (ctx.status === "yanked" && nowDigest !== x.ours)) {
|
|
436
|
+
actions.push({ what: `${at(x.path)} on ${branch} is not this release's ${noun}; not changed`, already: true });
|
|
437
|
+
continue;
|
|
438
|
+
}
|
|
439
|
+
if (x.to === null) {
|
|
440
|
+
changes.push({ path: x.path, remove: true });
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
const found = (await history(x.path)).find((b) => bytesDigest(new Uint8Array(b)) === x.to);
|
|
444
|
+
if (!found)
|
|
445
|
+
throw lost(branch, x.path, x.to);
|
|
446
|
+
changes.push({ path: x.path, bytes: new Uint8Array(found), sha: there?.sha ?? null });
|
|
447
|
+
}
|
|
448
|
+
actions.push({ what: x.what });
|
|
449
|
+
}
|
|
450
|
+
return changes;
|
|
451
|
+
};
|
|
452
|
+
if (ssh) {
|
|
453
|
+
return withSsh(ctx, token, async (repo) => {
|
|
454
|
+
const { defaultBranch } = await repo.heads();
|
|
455
|
+
const branch = s.branch ?? defaultBranch;
|
|
456
|
+
if (!branch)
|
|
457
|
+
throw new PublishTargetError(failed, `${repo.remote} has no default branch`, `Set branch to ${s.branchIs}.`);
|
|
458
|
+
const head = await repo.fetch(branch, 100);
|
|
459
|
+
const changes = await plan(branch, async (path) => {
|
|
460
|
+
const b = await repo.file(head, path);
|
|
461
|
+
return b ? { bytes: b, sha: null } : null;
|
|
462
|
+
}, async (path) => {
|
|
463
|
+
const out = [];
|
|
464
|
+
for (const c of await repo.history(branch, path)) {
|
|
465
|
+
const f = await repo.file(c, path);
|
|
466
|
+
if (f)
|
|
467
|
+
out.push(f);
|
|
468
|
+
}
|
|
469
|
+
return out;
|
|
470
|
+
});
|
|
471
|
+
if (changes.length === 0)
|
|
472
|
+
return actions;
|
|
473
|
+
const commit = await repo.commitFiles(head, changes.map(plain), msg);
|
|
474
|
+
if ((await repo.push(commit, branch, false)) === "rejected")
|
|
475
|
+
throw new PublishTargetError(failed, `${branch} of ${repo.remote} moved while the ${noun} was committed onto it`, "Run the same command again.");
|
|
476
|
+
return actions;
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
const upstream = new GitHubRepo(githubApi(s.api, ctx.env), s.repo, token, fetchImpl, ctx, failed);
|
|
480
|
+
const branch = s.branch ?? (await upstream.defaultBranch());
|
|
481
|
+
const changes = await plan(branch, (path) => upstream.file(path, branch), async (path) => {
|
|
482
|
+
const out = [];
|
|
483
|
+
for (const c of await upstream.commitsTouching(path, branch)) {
|
|
484
|
+
const f = await upstream.file(path, c);
|
|
485
|
+
if (f)
|
|
486
|
+
out.push(f.bytes);
|
|
487
|
+
}
|
|
488
|
+
return out;
|
|
489
|
+
});
|
|
490
|
+
if (changes.length === 0)
|
|
491
|
+
return actions;
|
|
492
|
+
const head = await upstream.branchHead(branch);
|
|
493
|
+
if (!head)
|
|
494
|
+
throw new PublishTargetError(failed, `${s.repo} has no branch ${branch}`, `Set branch to ${s.branchIs}.`);
|
|
495
|
+
await commitOnto(upstream, branch, head, changes, msg, false);
|
|
496
|
+
return actions;
|
|
497
|
+
},
|
|
498
|
+
async plan(ctx) {
|
|
499
|
+
const branch = s.branch ?? "the default branch";
|
|
500
|
+
if (prereleaseOf(ctx.label))
|
|
501
|
+
return [{ name: first ?? `extensions/${s.name}`, destination: where(branch, first ?? `extensions/${s.name}`), notes: skipNote(ctx) }];
|
|
502
|
+
const { items } = setup(ctx);
|
|
503
|
+
return itemsAt(items, branch, false);
|
|
504
|
+
},
|
|
505
|
+
async stage(ctx) {
|
|
506
|
+
if (prereleaseOf(ctx.label)) {
|
|
507
|
+
ctx.log(skipNote(ctx));
|
|
508
|
+
return { target: target.name, destination: target.destination, items: [], state: { prerelease: "true" } };
|
|
509
|
+
}
|
|
510
|
+
const r = setup(ctx);
|
|
511
|
+
ctx.log(`using the ${ssh ? "SSH key" : "token"} from ${r.token.from}`);
|
|
512
|
+
for (const [name, a] of r.assets)
|
|
513
|
+
ctx.log(`${name}: ${a.url} sha256 ${a.sha256}`);
|
|
514
|
+
if (ssh)
|
|
515
|
+
return withSsh(ctx, r.token, (repo) => stageOverSsh(ctx, repo, r));
|
|
516
|
+
const upstream = new GitHubRepo(githubApi(s.api, ctx.env), s.repo, r.token, fetchImpl, ctx, failed);
|
|
517
|
+
const branch = s.branch ?? (await upstream.defaultBranch());
|
|
518
|
+
const head = await upstream.branchHead(branch);
|
|
519
|
+
if (!head)
|
|
520
|
+
throw new PublishTargetError(failed, `${s.repo} has no branch ${branch}`, `Set branch to ${s.branchIs}.`);
|
|
521
|
+
const done = (state, present) => ({ target: target.name, destination: target.destination, items: itemsAt(r.items, branch, present), state: { branch, ...state } });
|
|
522
|
+
const what = single ? first : `${s.name}'s manifests`;
|
|
523
|
+
const changes = await changesAt(apiReader(upstream), branch, r.outputs);
|
|
524
|
+
if (changes.length === 0) {
|
|
525
|
+
ctx.log(`${branch} already has ${what} for ${r.version}`);
|
|
526
|
+
return done({ present: "true" }, true);
|
|
527
|
+
}
|
|
528
|
+
const into = s.mode === "commit" ? upstream : await forkOf(ctx, upstream, r.token);
|
|
529
|
+
const at = staging(r.version);
|
|
530
|
+
const stagingHead = await into.branchHead(at);
|
|
531
|
+
if (stagingHead) {
|
|
532
|
+
if ((await changesAt(apiReader(into), at, r.outputs)).length === 0) {
|
|
533
|
+
ctx.log(`${at} already has ${what} for ${r.version}`);
|
|
534
|
+
return done({ staging: at, commit: stagingHead, ...(into !== upstream ? { fork: into.repo } : {}) }, true);
|
|
535
|
+
}
|
|
536
|
+
await into.moveRef(`heads/${at}`, head, true);
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
await into.createBranch(at, head);
|
|
540
|
+
}
|
|
541
|
+
ctx.log(`committing ${what} for ${r.version} to ${at}${into !== upstream ? ` of ${into.repo}` : ""}, at ${branch}'s head ${head.slice(0, 12)}`);
|
|
542
|
+
const commit = await commitOnto(into, at, head, changes, message(r.version, r.label, r.tag), true);
|
|
543
|
+
return done({ staging: at, commit, ...(into !== upstream ? { fork: into.repo } : {}) }, false);
|
|
544
|
+
},
|
|
545
|
+
async reveal(ctx, staged) {
|
|
546
|
+
if (staged.state.prerelease === "true")
|
|
547
|
+
return { target: target.name, destination: target.destination, items: [] };
|
|
548
|
+
const items = staged.items.map((i) => ({ name: i.name, destination: i.destination, ...(i.digest ? { digest: i.digest } : {}) }));
|
|
549
|
+
const published = { target: target.name, destination: target.destination, items };
|
|
550
|
+
if (staged.state.present === "true")
|
|
551
|
+
return { ...published, items: items.map((i) => ({ ...i, present: true })) };
|
|
552
|
+
const r = setup(ctx);
|
|
553
|
+
const { branch, staging: at, commit } = staged.state;
|
|
554
|
+
if (s.mode === "pull-request")
|
|
555
|
+
return revealPull(ctx, new GitHubRepo(githubApi(s.api, ctx.env), s.repo, r.token, fetchImpl, ctx, failed), staged, r, published);
|
|
556
|
+
if (!branch || !at || !commit)
|
|
557
|
+
throw new PublishTargetError(failed, `the staged ${s.kind === "homebrew" ? "formula" : s.name} for ${s.repo} has no staging commit to reveal`);
|
|
558
|
+
if (ssh) {
|
|
559
|
+
await withSsh(ctx, r.token, (repo) => revealOverSsh(ctx, repo, { branch, staging: at, commit }, r));
|
|
560
|
+
return published;
|
|
561
|
+
}
|
|
562
|
+
const upstream = new GitHubRepo(githubApi(s.api, ctx.env), s.repo, r.token, fetchImpl, ctx, failed);
|
|
563
|
+
const what = single ? first : `${s.name}'s manifests`;
|
|
564
|
+
ctx.log(`fast-forwarding ${branch} to ${commit.slice(0, 12)}`);
|
|
565
|
+
if (!(await upstream.moveRef(`heads/${branch}`, commit, false))) {
|
|
566
|
+
// The branch moved since the stage: one commit onto it, unless it already holds the manifests.
|
|
567
|
+
const changes = await changesAt(apiReader(upstream), branch, r.outputs);
|
|
568
|
+
if (changes.length === 0) {
|
|
569
|
+
ctx.log(`${branch} moved since the stage and already has ${what} for ${r.version}`);
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
ctx.log(`${branch} moved since the stage; committing ${what} for ${r.version} onto it`);
|
|
573
|
+
const head = await upstream.branchHead(branch);
|
|
574
|
+
if (!head)
|
|
575
|
+
throw new PublishTargetError(failed, `${s.repo} has no branch ${branch}`, `Set branch to ${s.branchIs}.`);
|
|
576
|
+
await commitOnto(upstream, branch, head, changes, message(r.version, r.label, r.tag), false);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
await upstream.deleteRef(`heads/${at}`);
|
|
580
|
+
return published;
|
|
581
|
+
},
|
|
582
|
+
};
|
|
583
|
+
/** The repository a pull request's branch goes to: `fork`, `repo` itself, or the token's user's fork, made when there is none. */
|
|
584
|
+
async function forkOf(ctx, upstream, token) {
|
|
585
|
+
if (s.fork === s.repo)
|
|
586
|
+
return upstream;
|
|
587
|
+
const api = githubApi(s.api, ctx.env);
|
|
588
|
+
if (s.fork) {
|
|
589
|
+
const named = new GitHubRepo(api, s.fork, token, fetchImpl, ctx, failed);
|
|
590
|
+
if (!(await named.exists()))
|
|
591
|
+
throw new PublishTargetError(failed, `the token can't see the fork ${s.fork}`, `Fork ${s.repo} to ${s.fork}, or drop fork to let the target make one.`);
|
|
592
|
+
return named;
|
|
593
|
+
}
|
|
594
|
+
const name = await upstream.fork();
|
|
595
|
+
const fork = new GitHubRepo(api, name, token, fetchImpl, ctx, failed);
|
|
596
|
+
// GitHub makes a fork in the background: wait for it, up to a minute.
|
|
597
|
+
const sleep = deps.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms)));
|
|
598
|
+
const now = deps.now ?? Date.now;
|
|
599
|
+
const until = now() + 60000;
|
|
600
|
+
while (!(await fork.exists())) {
|
|
601
|
+
if (now() > until)
|
|
602
|
+
throw new PublishTargetError(failed, `GitHub did not finish forking ${s.repo} to ${name} within a minute`, "Run the same publish again: it uses the fork once it is there.");
|
|
603
|
+
await sleep(2000);
|
|
604
|
+
}
|
|
605
|
+
ctx.log(`the pull request's branch goes to ${name}`);
|
|
606
|
+
return fork;
|
|
607
|
+
}
|
|
608
|
+
async function revealPull(ctx, upstream, staged, r, published) {
|
|
609
|
+
const branch = staged.state.branch ?? s.branch ?? (await upstream.defaultBranch());
|
|
610
|
+
const at = staging(r.version);
|
|
611
|
+
const into = staged.state.fork
|
|
612
|
+
? new GitHubRepo(upstream.api, staged.state.fork, r.token, fetchImpl, ctx, failed)
|
|
613
|
+
: s.fork === s.repo
|
|
614
|
+
? upstream
|
|
615
|
+
: await forkOf(ctx, upstream, r.token);
|
|
616
|
+
const head = `${into.repo.split("/")[0]}:${at}`;
|
|
617
|
+
const as = (url, present) => ({ ...published, items: published.items.map((i) => ({ ...i, destination: url, ...(present ? { present: true } : {}) })) });
|
|
618
|
+
const found = await upstream.findPull(head);
|
|
619
|
+
if (found?.state === "open" || found?.merged) {
|
|
620
|
+
ctx.log(`${found.url} is ${found.merged ? "merged" : "open"} already; not opened again`);
|
|
621
|
+
return as(found.url, true);
|
|
622
|
+
}
|
|
623
|
+
if (found) {
|
|
624
|
+
throw new PublishTargetError(code("pr-closed"), `${s.repo} closed ${found.url} without merging it`, "Read why on the pull request. A run of the same publish opens no new one while it is closed: reopen it, or cut a new release.");
|
|
625
|
+
}
|
|
626
|
+
if ((await changesAt(apiReader(upstream), branch, r.outputs)).length === 0) {
|
|
627
|
+
ctx.log(`${branch} of ${s.repo} already has ${s.name} ${r.version}; no pull request needed`);
|
|
628
|
+
return as(`${s.repo}@${branch}`, true);
|
|
629
|
+
}
|
|
630
|
+
// The branch may be gone, or this run resumes from another: make sure it holds the manifests, then open the pull request.
|
|
631
|
+
const onto = await upstream.branchHead(branch);
|
|
632
|
+
if (!onto)
|
|
633
|
+
throw new PublishTargetError(failed, `${s.repo} has no branch ${branch}`, `Set branch to ${s.branchIs}.`);
|
|
634
|
+
const there = await into.branchHead(at);
|
|
635
|
+
if (!there || (await changesAt(apiReader(into), at, r.outputs)).length > 0) {
|
|
636
|
+
const changes = await changesAt(apiReader(upstream), branch, r.outputs);
|
|
637
|
+
if (there)
|
|
638
|
+
await into.moveRef(`heads/${at}`, onto, true);
|
|
639
|
+
else
|
|
640
|
+
await into.createBranch(at, onto);
|
|
641
|
+
await commitOnto(into, at, onto, changes, message(r.version, r.label, r.tag), true);
|
|
642
|
+
}
|
|
643
|
+
const pull = await upstream.openPull(message(r.version, r.label, r.tag), fillText(s.body, { name: s.name, version: r.version, label: r.label, tag: r.tag }), head, branch);
|
|
644
|
+
ctx.log(`opened ${pull.url}`);
|
|
645
|
+
return as(pull.url, false);
|
|
646
|
+
}
|
|
647
|
+
async function withSsh(ctx, key, step) {
|
|
648
|
+
const repo = await SshGitRepo.open({ api: githubApi(s.api, ctx.env), repo: s.repo, key, ctx, fetch: fetchImpl, code: failed, git: deps.git, ssh: deps.ssh });
|
|
649
|
+
try {
|
|
650
|
+
return await step(repo);
|
|
651
|
+
}
|
|
652
|
+
finally {
|
|
653
|
+
repo.close();
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
async function stageOverSsh(ctx, repo, r) {
|
|
657
|
+
const { defaultBranch, heads } = await repo.heads();
|
|
658
|
+
const branch = s.branch ?? defaultBranch;
|
|
659
|
+
const head = branch ? heads.get(branch) : undefined;
|
|
660
|
+
if (!branch || !head)
|
|
661
|
+
throw new PublishTargetError(failed, `${repo.remote} has no branch ${branch ?? "HEAD points at"}`, `Set branch to ${s.branchIs}.`);
|
|
662
|
+
const done = (state, present) => ({ target: target.name, destination: target.destination, items: itemsAt(r.items, branch, present), state: { branch, ...state } });
|
|
663
|
+
const what = single ? first : `${s.name}'s manifests`;
|
|
664
|
+
ctx.log(`reading ${branch} of ${repo.remote} over SSH`);
|
|
665
|
+
await repo.fetch(branch);
|
|
666
|
+
const changes = await changesAt(sshReader(repo), head, r.outputs);
|
|
667
|
+
if (changes.length === 0) {
|
|
668
|
+
ctx.log(`${branch} already has ${what} for ${r.version}`);
|
|
669
|
+
return done({ present: "true" }, true);
|
|
670
|
+
}
|
|
671
|
+
const at = staging(r.version);
|
|
672
|
+
const stagingHead = heads.get(at);
|
|
673
|
+
if (stagingHead) {
|
|
674
|
+
await repo.fetch(at);
|
|
675
|
+
if ((await changesAt(sshReader(repo), stagingHead, r.outputs)).length === 0) {
|
|
676
|
+
ctx.log(`${at} already has ${what} for ${r.version}`);
|
|
677
|
+
return done({ staging: at, commit: stagingHead }, true);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
ctx.log(`committing ${what} for ${r.version} to ${at}, at ${branch}'s head ${head.slice(0, 12)}, and pushing it over SSH`);
|
|
681
|
+
const commit = await repo.commitFiles(head, changes.map(plain), message(r.version, r.label, r.tag));
|
|
682
|
+
await repo.push(commit, at, true);
|
|
683
|
+
return done({ staging: at, commit }, false);
|
|
684
|
+
}
|
|
685
|
+
async function revealOverSsh(ctx, repo, state, r) {
|
|
686
|
+
const { branch, staging: at, commit } = state;
|
|
687
|
+
const what = single ? first : `${s.name}'s manifests`;
|
|
688
|
+
const { heads } = await repo.heads();
|
|
689
|
+
// The staged commit is on the staging branch: fetch it, since this run may be a resume on a fresh clone.
|
|
690
|
+
// Depth 2: the staged commit and the head it was made on, so git sees the push as a fast-forward.
|
|
691
|
+
const stagingHead = heads.get(at) === commit ? await repo.fetch(at, 2) : null;
|
|
692
|
+
let moved = true;
|
|
693
|
+
if (stagingHead === commit) {
|
|
694
|
+
ctx.log(`fast-forwarding ${branch} to ${commit.slice(0, 12)} over SSH`);
|
|
695
|
+
moved = (await repo.push(commit, branch, false)) === "rejected";
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
ctx.log(`${at} is not at the staged commit ${commit.slice(0, 12)} any more`);
|
|
699
|
+
}
|
|
700
|
+
if (moved) {
|
|
701
|
+
// The branch moved since the stage, or the staged commit is gone: one commit onto it, unless it already holds the manifests.
|
|
702
|
+
const head = await repo.fetch(branch);
|
|
703
|
+
const changes = await changesAt(sshReader(repo), head, r.outputs);
|
|
704
|
+
if (changes.length === 0) {
|
|
705
|
+
ctx.log(`${branch} already has ${what} for ${r.version}`);
|
|
706
|
+
}
|
|
707
|
+
else {
|
|
708
|
+
ctx.log(`committing ${what} for ${r.version} onto ${branch}'s head ${head.slice(0, 12)}`);
|
|
709
|
+
const onto = await repo.commitFiles(head, changes.map(plain), message(r.version, r.label, r.tag));
|
|
710
|
+
if ((await repo.push(onto, branch, false)) === "rejected") {
|
|
711
|
+
throw new PublishTargetError(failed, `${branch} of ${repo.remote} moved again while ${what} was committed onto it`, `Run the same publish again: it commits ${s.kind === "homebrew" ? "the formula" : "the manifests"} onto the branch's new head.`);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
await repo.deleteBranch(at);
|
|
716
|
+
}
|
|
717
|
+
return target;
|
|
718
|
+
}
|
|
719
|
+
const plain = (c) => ("bytes" in c ? { path: c.path, bytes: c.bytes } : c);
|