@intentius/chant 0.124.62 → 0.124.64
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/cli/handlers/approve.d.ts +26 -0
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +167 -18
- package/dist/cli/handlers/plan.d.ts +10 -0
- package/dist/cli/handlers/plan.d.ts.map +1 -0
- package/dist/cli/handlers/plan.js +71 -0
- package/dist/cli/handlers/pr.d.ts.map +1 -1
- package/dist/cli/handlers/pr.js +2 -1
- package/dist/cli/handlers/release.d.ts +11 -7
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +93 -20
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +48 -7
- package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
- package/dist/cli/mcp/workspace-tools.js +2 -1
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +43 -0
- package/dist/cli/registry.d.ts +18 -2
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/config.d.ts +50 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/gate-decision.d.ts +1 -1
- package/dist/gate-decision.d.ts.map +1 -1
- package/dist/gate-decision.js +4 -2
- package/dist/gate-statement.schema.json +46 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +20 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
- package/dist/lifecycle/__fixtures__/publish-fakes.js +119 -3
- package/dist/lifecycle/gate-ledger.d.ts +28 -5
- package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
- package/dist/lifecycle/gate-ledger.js +6 -0
- package/dist/lifecycle/gate-seal.d.ts +59 -7
- package/dist/lifecycle/gate-seal.d.ts.map +1 -1
- package/dist/lifecycle/gate-seal.js +68 -15
- package/dist/lifecycle/gate-statement.d.ts +95 -0
- package/dist/lifecycle/gate-statement.d.ts.map +1 -0
- package/dist/lifecycle/gate-statement.js +110 -0
- package/dist/lifecycle/gate-webauthn.d.ts +79 -0
- package/dist/lifecycle/gate-webauthn.d.ts.map +1 -0
- package/dist/lifecycle/gate-webauthn.js +105 -0
- package/dist/lifecycle/git.d.ts +1 -1
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +24 -19
- package/dist/lifecycle/ledger-remote.d.ts +37 -0
- package/dist/lifecycle/ledger-remote.d.ts.map +1 -0
- package/dist/lifecycle/ledger-remote.js +42 -0
- package/dist/lifecycle/plan-stale.d.ts +76 -0
- package/dist/lifecycle/plan-stale.d.ts.map +1 -0
- package/dist/lifecycle/plan-stale.js +120 -0
- package/dist/lifecycle/publish-credentials.d.ts +1 -1
- package/dist/lifecycle/publish-credentials.d.ts.map +1 -1
- package/dist/lifecycle/publish-credentials.js +2 -0
- package/dist/lifecycle/publish-declaration.d.ts +107 -0
- package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
- package/dist/lifecycle/publish-declaration.js +110 -1
- package/dist/lifecycle/publish-forge.d.ts +5 -1
- package/dist/lifecycle/publish-forge.d.ts.map +1 -1
- package/dist/lifecycle/publish-forge.js +13 -4
- package/dist/lifecycle/publish-git-ssh.d.ts +82 -0
- package/dist/lifecycle/publish-git-ssh.d.ts.map +1 -0
- package/dist/lifecycle/publish-git-ssh.js +180 -0
- package/dist/lifecycle/publish-github.d.ts +69 -0
- package/dist/lifecycle/publish-github.d.ts.map +1 -0
- package/dist/lifecycle/publish-github.js +153 -0
- package/dist/lifecycle/publish-homebrew.d.ts +77 -0
- package/dist/lifecycle/publish-homebrew.d.ts.map +1 -0
- package/dist/lifecycle/publish-homebrew.js +265 -0
- package/dist/lifecycle/publish-marketplace.d.ts +85 -0
- package/dist/lifecycle/publish-marketplace.d.ts.map +1 -0
- package/dist/lifecycle/publish-marketplace.js +398 -0
- package/dist/lifecycle/publish-targets.d.ts +6 -0
- package/dist/lifecycle/publish-targets.d.ts.map +1 -1
- package/dist/lifecycle/publish-targets.js +15 -0
- package/dist/lifecycle/publish-tauri.d.ts +61 -0
- package/dist/lifecycle/publish-tauri.d.ts.map +1 -0
- package/dist/lifecycle/publish-tauri.js +181 -0
- package/dist/lifecycle/release-cut.d.ts +51 -5
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +165 -16
- package/dist/lifecycle/release-publish.d.ts +18 -2
- package/dist/lifecycle/release-publish.d.ts.map +1 -1
- package/dist/lifecycle/release-publish.js +5 -0
- package/dist/lifecycle/release-revocation.d.ts +4 -3
- package/dist/lifecycle/release-revocation.d.ts.map +1 -1
- package/dist/lifecycle/release-revocation.js +5 -4
- package/dist/lifecycle/release-store.d.ts +32 -0
- package/dist/lifecycle/release-store.d.ts.map +1 -1
- package/dist/lifecycle/release-store.js +11 -0
- package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
- package/dist/lifecycle/snapshot-store.js +17 -9
- package/dist/lifecycle/test-passkey.d.ts +25 -0
- package/dist/lifecycle/test-passkey.d.ts.map +1 -0
- package/dist/lifecycle/test-passkey.js +39 -0
- package/dist/notify.d.ts +23 -3
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +8 -2
- package/dist/notify.schema.json +12 -3
- package/dist/op/gate.d.ts +1 -1
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/gate.js +2 -1
- package/dist/pr-forge.d.ts +20 -0
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +87 -8
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +333 -331
- package/dist/workspace/ci-builds.d.ts +21 -0
- package/dist/workspace/ci-builds.d.ts.map +1 -1
- package/dist/workspace/ci-builds.js +14 -0
- package/dist/workspace/ci-green.d.ts +45 -2
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +123 -5
- package/dist/workspace/ci-quarantine-report.d.ts +80 -0
- package/dist/workspace/ci-quarantine-report.d.ts.map +1 -0
- package/dist/workspace/ci-quarantine-report.js +204 -0
- package/dist/workspace/ci-quarantine.d.ts +73 -0
- package/dist/workspace/ci-quarantine.d.ts.map +1 -0
- package/dist/workspace/ci-quarantine.js +170 -0
- package/dist/workspace/ci-serve.d.ts.map +1 -1
- package/dist/workspace/ci-serve.js +7 -4
- package/dist/workspace/class-data.d.ts +3 -1
- package/dist/workspace/class-data.d.ts.map +1 -1
- package/dist/workspace/class-data.js +4 -1
- package/dist/workspace/declaration.d.ts +45 -2
- package/dist/workspace/declaration.d.ts.map +1 -1
- package/dist/workspace/declaration.js +45 -2
- package/dist/workspace/declaration.schema.json +51 -3
- package/dist/workspace/forge-work.d.ts +76 -0
- package/dist/workspace/forge-work.d.ts.map +1 -0
- package/dist/workspace/forge-work.js +160 -0
- package/dist/workspace/identity-gate-rule.d.ts +3 -2
- package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
- package/dist/workspace/identity-gate-rule.js +5 -7
- package/dist/workspace/identity.d.ts +3 -2
- package/dist/workspace/identity.d.ts.map +1 -1
- package/dist/workspace/identity.js +6 -3
- package/dist/workspace/intent-cli.d.ts +3 -2
- package/dist/workspace/intent-cli.d.ts.map +1 -1
- package/dist/workspace/intent-cli.js +26 -5
- package/dist/workspace/intent-record.d.ts +3 -0
- package/dist/workspace/intent-record.d.ts.map +1 -1
- package/dist/workspace/intent-record.schema.json +32 -0
- package/dist/workspace/intent.d.ts +9 -0
- package/dist/workspace/intent.d.ts.map +1 -1
- package/dist/workspace/intent.js +2 -0
- package/dist/workspace/intent.schema.json +32 -0
- package/dist/workspace/kind-readers.d.ts.map +1 -1
- package/dist/workspace/kind-readers.js +2 -1
- package/dist/workspace/kinds.d.ts +6 -1
- package/dist/workspace/kinds.d.ts.map +1 -1
- package/dist/workspace/kinds.js +8 -3
- package/dist/workspace/plan-stale.schema.json +286 -0
- package/dist/workspace/release-candidates.d.ts +42 -7
- package/dist/workspace/release-candidates.d.ts.map +1 -1
- package/dist/workspace/release-candidates.js +64 -23
- package/dist/workspace/release-candidates.schema.json +55 -2
- package/dist/workspace/releases.schema.json +47 -0
- package/dist/workspace/trust/policy.d.ts +10 -0
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +19 -1
- package/dist/workspace/trust/run-commits.d.ts.map +1 -1
- package/dist/workspace/trust/run-commits.js +2 -1
- package/dist/workspace/trust/seal.d.ts.map +1 -1
- package/dist/workspace/trust/seal.js +34 -3
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +6 -1
- package/package.json +2 -1
- package/src/cli/handlers/approve-external-signature.test.ts +328 -0
- package/src/cli/handlers/approve.ts +206 -18
- package/src/cli/handlers/plan.ts +74 -0
- package/src/cli/handlers/pr.ts +2 -1
- package/src/cli/handlers/release.ts +84 -20
- package/src/cli/main.ts +48 -7
- package/src/cli/mcp/workspace-tools.ts +2 -1
- package/src/cli/parse-args.ts +33 -0
- package/src/cli/registry.ts +18 -2
- package/src/config.ts +8 -0
- package/src/gate-decision-bundle.test.ts +4 -2
- package/src/gate-decision.ts +11 -2
- package/src/gate-statement.schema.json +46 -0
- package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
- package/src/lifecycle/gate-ledger.ts +34 -5
- package/src/lifecycle/gate-seal.ts +86 -15
- package/src/lifecycle/gate-statement.ts +144 -0
- package/src/lifecycle/gate-webauthn.test.ts +77 -0
- package/src/lifecycle/gate-webauthn.ts +133 -0
- package/src/lifecycle/git.ts +23 -19
- package/src/lifecycle/ledger-remote.test.ts +183 -0
- package/src/lifecycle/ledger-remote.ts +46 -0
- package/src/lifecycle/plan-stale.test.ts +149 -0
- package/src/lifecycle/plan-stale.ts +172 -0
- package/src/lifecycle/publish-credentials.ts +2 -0
- package/src/lifecycle/publish-declaration.ts +116 -1
- package/src/lifecycle/publish-forge.ts +14 -4
- package/src/lifecycle/publish-git-ssh.ts +202 -0
- package/src/lifecycle/publish-github.ts +174 -0
- package/src/lifecycle/publish-homebrew.test.ts +358 -0
- package/src/lifecycle/publish-homebrew.ts +283 -0
- package/src/lifecycle/publish-marketplace.test.ts +406 -0
- package/src/lifecycle/publish-marketplace.ts +421 -0
- package/src/lifecycle/publish-resume.test.ts +40 -0
- package/src/lifecycle/publish-target-context.test.ts +2 -2
- package/src/lifecycle/publish-targets.test.ts +23 -0
- package/src/lifecycle/publish-targets.ts +15 -0
- package/src/lifecycle/publish-tauri.test.ts +163 -0
- package/src/lifecycle/publish-tauri.ts +198 -0
- package/src/lifecycle/release-cut-lane.test.ts +177 -0
- package/src/lifecycle/release-cut-override.test.ts +213 -0
- package/src/lifecycle/release-cut.ts +198 -17
- package/src/lifecycle/release-publish.ts +23 -3
- package/src/lifecycle/release-revocation.ts +5 -4
- package/src/lifecycle/release-store.ts +44 -0
- package/src/lifecycle/snapshot-store.ts +16 -9
- package/src/lifecycle/test-passkey.ts +55 -0
- package/src/notify-bundle.test.ts +3 -1
- package/src/notify.schema.json +12 -3
- package/src/notify.ts +20 -3
- package/src/op/gate.ts +2 -1
- package/src/override-gate-bundle.test.ts +2 -0
- package/src/pr-forge-bundle.test.ts +2 -2
- package/src/pr-forge.test.ts +38 -0
- package/src/pr-forge.ts +93 -11
- package/src/pr-requires.test.ts +9 -0
- package/src/release-floors.ts +1 -1
- package/src/stage-hooks-bundle.test.ts +2 -0
- package/src/wave-runtime-bundle.test.ts +3 -2
- package/src/workspace/ci-builds.ts +27 -0
- package/src/workspace/ci-green-stale.test.ts +193 -0
- package/src/workspace/ci-green.ts +137 -6
- package/src/workspace/ci-quarantine-report.test.ts +145 -0
- package/src/workspace/ci-quarantine-report.ts +234 -0
- package/src/workspace/ci-quarantine.test.ts +160 -0
- package/src/workspace/ci-quarantine.ts +188 -0
- package/src/workspace/ci-serve.ts +7 -4
- package/src/workspace/class-data.ts +5 -1
- package/src/workspace/declaration.schema.json +51 -3
- package/src/workspace/declaration.test.ts +1 -0
- package/src/workspace/declaration.ts +88 -5
- package/src/workspace/forge-work.test.ts +143 -0
- package/src/workspace/forge-work.ts +195 -0
- package/src/workspace/identity-gate-rule.ts +6 -8
- package/src/workspace/identity.ts +6 -3
- package/src/workspace/intent-cli.ts +24 -5
- package/src/workspace/intent-record.schema.json +32 -0
- package/src/workspace/intent-record.ts +3 -0
- package/src/workspace/intent.schema.json +32 -0
- package/src/workspace/intent.ts +9 -0
- package/src/workspace/kind-readers.ts +2 -1
- package/src/workspace/kinds.test.ts +13 -0
- package/src/workspace/kinds.ts +12 -3
- package/src/workspace/plan-stale.schema.json +286 -0
- package/src/workspace/release-candidates.schema.json +55 -2
- package/src/workspace/release-candidates.test.ts +77 -4
- package/src/workspace/release-candidates.ts +80 -23
- package/src/workspace/releases.schema.json +47 -0
- package/src/workspace/trust/gate-seal.test.ts +44 -0
- package/src/workspace/trust/policy.ts +24 -1
- package/src/workspace/trust/run-commits.ts +2 -1
- package/src/workspace/trust/seal.ts +35 -3
- package/src/workspace/trust/trust-files.test.ts +5 -0
- package/src/workspace/trust/trust-files.ts +15 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The GitHub REST calls the targets that write to a repository other than the
|
|
3
|
+
* release's use (#4676): the Homebrew tap's formula, and the Tauri updater's
|
|
4
|
+
* rolling release. Requests go through the injectable `fetch`, with the token
|
|
5
|
+
* as a bearer, and every failure is redacted before it is thrown.
|
|
6
|
+
*/
|
|
7
|
+
import type { Credential } from "./publish-credentials.js";
|
|
8
|
+
import { type PublishContextBase, type PublishFetch } from "./release-publish.js";
|
|
9
|
+
/** The API root of GitHub: `api`, else `$GITHUB_API_URL`, else `https://api.github.com`. */
|
|
10
|
+
export declare function githubApi(api: string | undefined, env: NodeJS.ProcessEnv): string;
|
|
11
|
+
export interface GitHubAnswer {
|
|
12
|
+
status: number;
|
|
13
|
+
json: unknown;
|
|
14
|
+
text: string;
|
|
15
|
+
}
|
|
16
|
+
/** One repository on GitHub, reached with one token. */
|
|
17
|
+
export declare class GitHubRepo {
|
|
18
|
+
readonly api: string;
|
|
19
|
+
readonly repo: string;
|
|
20
|
+
private readonly token;
|
|
21
|
+
private readonly fetchImpl;
|
|
22
|
+
private readonly ctx;
|
|
23
|
+
/** The code a failed request throws. */
|
|
24
|
+
private readonly code;
|
|
25
|
+
constructor(api: string, repo: string, token: Credential, fetchImpl: PublishFetch, ctx: PublishContextBase,
|
|
26
|
+
/** The code a failed request throws. */
|
|
27
|
+
code: string);
|
|
28
|
+
get root(): string;
|
|
29
|
+
call(method: string, url: string, body?: Uint8Array | string, extra?: Record<string, string>): Promise<GitHubAnswer>;
|
|
30
|
+
fail(what: string, res: GitHubAnswer): never;
|
|
31
|
+
/** The repository's default branch. */
|
|
32
|
+
defaultBranch(): Promise<string>;
|
|
33
|
+
/** The commit `refs/heads/<branch>` points at, or null when there is no such branch. */
|
|
34
|
+
branchHead(branch: string): Promise<string | null>;
|
|
35
|
+
/** A file's bytes and blob sha at `ref`, or null when it has none. */
|
|
36
|
+
file(path: string, ref: string): Promise<{
|
|
37
|
+
bytes: Buffer;
|
|
38
|
+
sha: string;
|
|
39
|
+
} | null>;
|
|
40
|
+
/** Commit `bytes` as `path` on `branch`, replacing the blob `sha` when the file is there. Returns the commit. */
|
|
41
|
+
putFile(path: string, branch: string, bytes: Uint8Array, message: string, sha: string | null): Promise<string>;
|
|
42
|
+
/** Make `refs/heads/<branch>` at `sha`. */
|
|
43
|
+
createBranch(branch: string, sha: string): Promise<void>;
|
|
44
|
+
/** Move `refs/<ref>` to `sha`. Without `force`, a move that is not a fast-forward answers false. */
|
|
45
|
+
moveRef(ref: string, sha: string, force: boolean): Promise<boolean>;
|
|
46
|
+
/** The published release for `tag`, or null. A draft is not found here. */
|
|
47
|
+
publishedRelease(tag: string): Promise<GitHubRelease | null>;
|
|
48
|
+
/** The draft release for `tag` named `name`, or null. */
|
|
49
|
+
draftRelease(tag: string, name: string): Promise<GitHubRelease | null>;
|
|
50
|
+
/** A new draft release for `tag` named `name`, at `commit`. */
|
|
51
|
+
createDraft(tag: string, commit: string, name: string): Promise<GitHubRelease>;
|
|
52
|
+
/** Upload `bytes` as the asset `name` of `release`. */
|
|
53
|
+
uploadAsset(release: GitHubRelease, name: string, bytes: Uint8Array): Promise<void>;
|
|
54
|
+
/** Publish the draft `id`, with `make_latest` when it is given. */
|
|
55
|
+
publishDraft(id: string, makeLatest: string | undefined): Promise<GitHubAnswer>;
|
|
56
|
+
/** Delete the release `id`. Its tag stays. */
|
|
57
|
+
deleteRelease(id: string): Promise<void>;
|
|
58
|
+
/** Delete `refs/<ref>`. One that is not there is already gone. */
|
|
59
|
+
deleteRef(ref: string): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
/** A GitHub release as the targets read it. */
|
|
62
|
+
export interface GitHubRelease {
|
|
63
|
+
id: string;
|
|
64
|
+
draft: boolean;
|
|
65
|
+
/** Asset names, with the digest GitHub reports. */
|
|
66
|
+
assets: Map<string, string | null>;
|
|
67
|
+
uploadUrl?: string;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=publish-github.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish-github.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-github.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The GitHub REST calls the targets that write to a repository other than the
|
|
3
|
+
* release's use (#4676): the Homebrew tap's formula, and the Tauri updater's
|
|
4
|
+
* rolling release. Requests go through the injectable `fetch`, with the token
|
|
5
|
+
* as a bearer, and every failure is redacted before it is thrown.
|
|
6
|
+
*/
|
|
7
|
+
import { PublishTargetError } from "./release-publish.js";
|
|
8
|
+
/** The API root of GitHub: `api`, else `$GITHUB_API_URL`, else `https://api.github.com`. */
|
|
9
|
+
export function githubApi(api, env) {
|
|
10
|
+
return (api ?? env.GITHUB_API_URL ?? "https://api.github.com").replace(/\/+$/, "");
|
|
11
|
+
}
|
|
12
|
+
/** One repository on GitHub, reached with one token. */
|
|
13
|
+
export class GitHubRepo {
|
|
14
|
+
constructor(api, repo, token, fetchImpl, ctx,
|
|
15
|
+
/** The code a failed request throws. */
|
|
16
|
+
code) {
|
|
17
|
+
this.api = api;
|
|
18
|
+
this.repo = repo;
|
|
19
|
+
this.token = token;
|
|
20
|
+
this.fetchImpl = fetchImpl;
|
|
21
|
+
this.ctx = ctx;
|
|
22
|
+
this.code = code;
|
|
23
|
+
}
|
|
24
|
+
get root() {
|
|
25
|
+
return `${this.api}/repos/${this.repo}`;
|
|
26
|
+
}
|
|
27
|
+
async call(method, url, body, extra = {}) {
|
|
28
|
+
const headers = {
|
|
29
|
+
authorization: `Bearer ${this.token.value}`,
|
|
30
|
+
accept: "application/vnd.github+json",
|
|
31
|
+
"user-agent": "chant",
|
|
32
|
+
...(typeof body === "string" ? { "content-type": "application/json" } : {}),
|
|
33
|
+
...extra,
|
|
34
|
+
};
|
|
35
|
+
const res = await this.fetchImpl(url.startsWith("http") ? url : `${this.root}${url}`, { method, headers, ...(body !== undefined ? { body } : {}) });
|
|
36
|
+
const text = await res.text();
|
|
37
|
+
let json = null;
|
|
38
|
+
try {
|
|
39
|
+
json = text ? JSON.parse(text) : null;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
json = null;
|
|
43
|
+
}
|
|
44
|
+
return { status: res.status, json, text };
|
|
45
|
+
}
|
|
46
|
+
fail(what, res) {
|
|
47
|
+
throw new PublishTargetError(this.code, this.ctx.redactor.redact(`${what} on github ${this.repo} answered ${res.status}${res.text ? `: ${res.text.slice(0, 300)}` : ""}`));
|
|
48
|
+
}
|
|
49
|
+
/** The repository's default branch. */
|
|
50
|
+
async defaultBranch() {
|
|
51
|
+
const res = await this.call("GET", "");
|
|
52
|
+
const branch = res.json?.default_branch;
|
|
53
|
+
if (res.status !== 200 || typeof branch !== "string")
|
|
54
|
+
this.fail("reading the repository", res);
|
|
55
|
+
return branch;
|
|
56
|
+
}
|
|
57
|
+
/** The commit `refs/heads/<branch>` points at, or null when there is no such branch. */
|
|
58
|
+
async branchHead(branch) {
|
|
59
|
+
const res = await this.call("GET", `/git/ref/heads/${branch}`);
|
|
60
|
+
if (res.status === 404)
|
|
61
|
+
return null;
|
|
62
|
+
const sha = res.json?.object?.sha;
|
|
63
|
+
if (res.status !== 200 || typeof sha !== "string")
|
|
64
|
+
this.fail(`reading branch ${branch}`, res);
|
|
65
|
+
return sha;
|
|
66
|
+
}
|
|
67
|
+
/** A file's bytes and blob sha at `ref`, or null when it has none. */
|
|
68
|
+
async file(path, ref) {
|
|
69
|
+
const res = await this.call("GET", `/contents/${path.split("/").map(encodeURIComponent).join("/")}?ref=${encodeURIComponent(ref)}`);
|
|
70
|
+
if (res.status === 404)
|
|
71
|
+
return null;
|
|
72
|
+
const body = res.json;
|
|
73
|
+
if (res.status !== 200 || typeof body?.sha !== "string" || typeof body.content !== "string")
|
|
74
|
+
this.fail(`reading ${path} at ${ref}`, res);
|
|
75
|
+
return { bytes: body.encoding === "base64" ? Buffer.from(body.content, "base64") : Buffer.from(body.content), sha: body.sha };
|
|
76
|
+
}
|
|
77
|
+
/** Commit `bytes` as `path` on `branch`, replacing the blob `sha` when the file is there. Returns the commit. */
|
|
78
|
+
async putFile(path, branch, bytes, message, sha) {
|
|
79
|
+
const res = await this.call("PUT", `/contents/${path.split("/").map(encodeURIComponent).join("/")}`, JSON.stringify({ message, content: Buffer.from(bytes).toString("base64"), branch, ...(sha ? { sha } : {}) }));
|
|
80
|
+
const commit = res.json?.commit?.sha;
|
|
81
|
+
if ((res.status !== 200 && res.status !== 201) || typeof commit !== "string")
|
|
82
|
+
this.fail(`committing ${path} to ${branch}`, res);
|
|
83
|
+
return commit;
|
|
84
|
+
}
|
|
85
|
+
/** Make `refs/heads/<branch>` at `sha`. */
|
|
86
|
+
async createBranch(branch, sha) {
|
|
87
|
+
const res = await this.call("POST", "/git/refs", JSON.stringify({ ref: `refs/heads/${branch}`, sha }));
|
|
88
|
+
if (res.status !== 201)
|
|
89
|
+
this.fail(`creating branch ${branch}`, res);
|
|
90
|
+
}
|
|
91
|
+
/** Move `refs/<ref>` to `sha`. Without `force`, a move that is not a fast-forward answers false. */
|
|
92
|
+
async moveRef(ref, sha, force) {
|
|
93
|
+
const res = await this.call("PATCH", `/git/refs/${ref}`, JSON.stringify({ sha, force }));
|
|
94
|
+
if (res.status === 200)
|
|
95
|
+
return true;
|
|
96
|
+
if (res.status === 422 && !force)
|
|
97
|
+
return false;
|
|
98
|
+
this.fail(`moving ${ref} to ${sha.slice(0, 12)}`, res);
|
|
99
|
+
}
|
|
100
|
+
/** The published release for `tag`, or null. A draft is not found here. */
|
|
101
|
+
async publishedRelease(tag) {
|
|
102
|
+
const res = await this.call("GET", `/releases/tags/${encodeURIComponent(tag)}`);
|
|
103
|
+
if (res.status === 404)
|
|
104
|
+
return null;
|
|
105
|
+
if (res.status !== 200 || !res.json)
|
|
106
|
+
this.fail(`reading release ${tag}`, res);
|
|
107
|
+
return toRelease(res.json);
|
|
108
|
+
}
|
|
109
|
+
/** The draft release for `tag` named `name`, or null. */
|
|
110
|
+
async draftRelease(tag, name) {
|
|
111
|
+
const res = await this.call("GET", "/releases?per_page=100");
|
|
112
|
+
if (res.status !== 200)
|
|
113
|
+
this.fail("listing releases", res);
|
|
114
|
+
const found = (Array.isArray(res.json) ? res.json : []).find((r) => r.draft === true && r.tag_name === tag && r.name === name);
|
|
115
|
+
return found ? toRelease(found) : null;
|
|
116
|
+
}
|
|
117
|
+
/** A new draft release for `tag` named `name`, at `commit`. */
|
|
118
|
+
async createDraft(tag, commit, name) {
|
|
119
|
+
const res = await this.call("POST", "/releases", JSON.stringify({ tag_name: tag, target_commitish: commit, name, draft: true }));
|
|
120
|
+
if (res.status !== 201 || !res.json)
|
|
121
|
+
this.fail(`creating a draft release ${tag}`, res);
|
|
122
|
+
return toRelease(res.json);
|
|
123
|
+
}
|
|
124
|
+
/** Upload `bytes` as the asset `name` of `release`. */
|
|
125
|
+
async uploadAsset(release, name, bytes) {
|
|
126
|
+
const base = (release.uploadUrl ?? `${this.root}/releases/${release.id}/assets`).replace(/\{[^}]*\}$/, "");
|
|
127
|
+
const res = await this.call("POST", `${base}?name=${encodeURIComponent(name)}`, bytes, { "content-type": "application/octet-stream" });
|
|
128
|
+
if (res.status !== 201)
|
|
129
|
+
this.fail(`uploading ${name}`, res);
|
|
130
|
+
}
|
|
131
|
+
/** Publish the draft `id`, with `make_latest` when it is given. */
|
|
132
|
+
async publishDraft(id, makeLatest) {
|
|
133
|
+
return this.call("PATCH", `/releases/${id}`, JSON.stringify(makeLatest === undefined ? { draft: false } : { draft: false, make_latest: makeLatest }));
|
|
134
|
+
}
|
|
135
|
+
/** Delete the release `id`. Its tag stays. */
|
|
136
|
+
async deleteRelease(id) {
|
|
137
|
+
const res = await this.call("DELETE", `/releases/${id}`);
|
|
138
|
+
if (res.status !== 204 && res.status !== 404)
|
|
139
|
+
this.fail(`deleting release ${id}`, res);
|
|
140
|
+
}
|
|
141
|
+
/** Delete `refs/<ref>`. One that is not there is already gone. */
|
|
142
|
+
async deleteRef(ref) {
|
|
143
|
+
const res = await this.call("DELETE", `/git/refs/${ref}`);
|
|
144
|
+
if (res.status !== 204 && res.status !== 404 && res.status !== 422)
|
|
145
|
+
this.fail(`deleting ${ref}`, res);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function toRelease(body) {
|
|
149
|
+
const assets = new Map();
|
|
150
|
+
for (const a of body.assets ?? [])
|
|
151
|
+
assets.set(a.name, typeof a.digest === "string" ? a.digest : null);
|
|
152
|
+
return { id: String(body.id), draft: body.draft === true, assets, ...(typeof body.upload_url === "string" ? { uploadUrl: body.upload_url } : {}) };
|
|
153
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Homebrew tap target (#4676): a formula in a tap repository on GitHub,
|
|
3
|
+
* rendered from a template in the member with the release's version and each
|
|
4
|
+
* asset's URL and SHA-256, and committed through GitHub's REST API with the
|
|
5
|
+
* token from `tokenEnv` (default `HOMEBREW_TAP_TOKEN`).
|
|
6
|
+
*
|
|
7
|
+
* The template is the formula as the tap holds it, with placeholders where a
|
|
8
|
+
* release changes it:
|
|
9
|
+
*
|
|
10
|
+
* - `{{version}}`: the release's version, its label from the first digit on
|
|
11
|
+
* (`v1.4.0` and `app-v1.4.0` are both `1.4.0`);
|
|
12
|
+
* - `{{url:<name>}}` and `{{sha256:<name>}}`: the URL and the SHA-256 in hex
|
|
13
|
+
* of the declared asset whose file name is `<name>`;
|
|
14
|
+
* - `{{label}}` and `{{tag}}`: the release's label and the tag the cut made.
|
|
15
|
+
*
|
|
16
|
+
* A placeholder chant does not know, or an asset name no declared asset has,
|
|
17
|
+
* is refused (`publish-homebrew-template`). Everything else is copied as it
|
|
18
|
+
* is, so `on_macos`, `on_linux`, `on_arm` and `on_intel` blocks each name
|
|
19
|
+
* their own asset and the formula's Ruby stays the member's. Each SHA-256 is
|
|
20
|
+
* of the file in the checkout, which must match the digest the release
|
|
21
|
+
* records for it.
|
|
22
|
+
*
|
|
23
|
+
* A tap is a branch people install from, with no draft, so the two steps are
|
|
24
|
+
* a branch and a fast-forward (#4048):
|
|
25
|
+
*
|
|
26
|
+
* - The stage commits the rendered formula to `chant-publish/<formula>-<version>`,
|
|
27
|
+
* a branch it makes at the tap branch's head (or moves there, when an
|
|
28
|
+
* earlier stage left it elsewhere). `brew` reads only the tap branch, so
|
|
29
|
+
* nothing is visible. A tap branch that already holds the formula as
|
|
30
|
+
* rendered stages nothing, and a staging branch that already holds it is
|
|
31
|
+
* not committed to again.
|
|
32
|
+
* - The reveal fast-forwards the tap branch to the staged commit, then
|
|
33
|
+
* deletes the staging branch. When the tap branch moved since the stage,
|
|
34
|
+
* the reveal commits the formula onto it instead, one commit either way,
|
|
35
|
+
* unless it already holds the formula as rendered.
|
|
36
|
+
*
|
|
37
|
+
* With `sshKeyEnv` (#4699), the same two steps run with git over SSH and the
|
|
38
|
+
* private key in that variable, such as a deploy key limited to the tap, in
|
|
39
|
+
* place of the API and a token (./publish-git-ssh.ts). The stage fetches the
|
|
40
|
+
* tap branch, commits the formula on its head and force-pushes that commit
|
|
41
|
+
* to the staging branch. The reveal fetches the staging branch and pushes
|
|
42
|
+
* its commit to the tap branch without force, which the remote takes only
|
|
43
|
+
* as a fast-forward; when the tap branch moved, it commits the formula onto
|
|
44
|
+
* the new head instead and pushes that, then deletes the staging branch.
|
|
45
|
+
*
|
|
46
|
+
* The asset URLs are the declaration's `url` pattern, so the files must be
|
|
47
|
+
* downloadable there by the time the formula is: declare the `forge` target
|
|
48
|
+
* that attaches them before this one, and its reveal runs first.
|
|
49
|
+
*/
|
|
50
|
+
import type { HomebrewPublishDeclaration } from "./publish-declaration.js";
|
|
51
|
+
import { type PublishDeps, type PublishTarget } from "./release-publish.js";
|
|
52
|
+
/** The first chant that publishes a `homebrew` target (#4676). */
|
|
53
|
+
export declare const PUBLISH_HOMEBREW_FLOOR = "0.124.63";
|
|
54
|
+
/** The first chant that reads a homebrew target's `sshKeyEnv` (#4699). */
|
|
55
|
+
export declare const PUBLISH_HOMEBREW_SSH_KEY_FLOOR = "0.124.64";
|
|
56
|
+
/** The variable the tap token is read from when the declaration names none. */
|
|
57
|
+
export declare const HOMEBREW_TOKEN_ENV = "HOMEBREW_TAP_TOKEN";
|
|
58
|
+
/** A release's version for a package manager: its label from the first digit on, or null when the label has no digit. */
|
|
59
|
+
export declare function releaseVersion(label: string | null): string | null;
|
|
60
|
+
/** `pattern` with `{tag}`, `{label}`, `{version}` and `{name}` filled in, each URL-encoded except the tag's slashes. */
|
|
61
|
+
export declare function fillUrl(pattern: string, values: {
|
|
62
|
+
tag: string;
|
|
63
|
+
label: string;
|
|
64
|
+
version: string;
|
|
65
|
+
name: string;
|
|
66
|
+
}): string;
|
|
67
|
+
/** Render a formula template, or name what it can't fill. */
|
|
68
|
+
export declare function renderFormula(template: string, values: {
|
|
69
|
+
version: string;
|
|
70
|
+
label: string;
|
|
71
|
+
tag: string;
|
|
72
|
+
}, assets: ReadonlyMap<string, {
|
|
73
|
+
url: string;
|
|
74
|
+
sha256: string;
|
|
75
|
+
}>): string;
|
|
76
|
+
export declare function homebrewTarget(decl: HomebrewPublishDeclaration, deps: PublishDeps): PublishTarget;
|
|
77
|
+
//# sourceMappingURL=publish-homebrew.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish-homebrew.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-homebrew.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAKH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAIxE,OAAO,EAA2C,KAAK,WAAW,EAAuC,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvJ,kEAAkE;AAClE,eAAO,MAAM,sBAAsB,aAAa,CAAC;AAEjD,0EAA0E;AAC1E,eAAO,MAAM,8BAA8B,aAAe,CAAC;AAE3D,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAEvD,yHAAyH;AACzH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAGlE;AAED,wHAAwH;AACxH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAItH;AAED,6DAA6D;AAC7D,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACvD,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,GAC3D,MAAM,CAYR;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,0BAA0B,EAAE,IAAI,EAAE,WAAW,GAAG,aAAa,CAqLjG"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Homebrew tap target (#4676): a formula in a tap repository on GitHub,
|
|
3
|
+
* rendered from a template in the member with the release's version and each
|
|
4
|
+
* asset's URL and SHA-256, and committed through GitHub's REST API with the
|
|
5
|
+
* token from `tokenEnv` (default `HOMEBREW_TAP_TOKEN`).
|
|
6
|
+
*
|
|
7
|
+
* The template is the formula as the tap holds it, with placeholders where a
|
|
8
|
+
* release changes it:
|
|
9
|
+
*
|
|
10
|
+
* - `{{version}}`: the release's version, its label from the first digit on
|
|
11
|
+
* (`v1.4.0` and `app-v1.4.0` are both `1.4.0`);
|
|
12
|
+
* - `{{url:<name>}}` and `{{sha256:<name>}}`: the URL and the SHA-256 in hex
|
|
13
|
+
* of the declared asset whose file name is `<name>`;
|
|
14
|
+
* - `{{label}}` and `{{tag}}`: the release's label and the tag the cut made.
|
|
15
|
+
*
|
|
16
|
+
* A placeholder chant does not know, or an asset name no declared asset has,
|
|
17
|
+
* is refused (`publish-homebrew-template`). Everything else is copied as it
|
|
18
|
+
* is, so `on_macos`, `on_linux`, `on_arm` and `on_intel` blocks each name
|
|
19
|
+
* their own asset and the formula's Ruby stays the member's. Each SHA-256 is
|
|
20
|
+
* of the file in the checkout, which must match the digest the release
|
|
21
|
+
* records for it.
|
|
22
|
+
*
|
|
23
|
+
* A tap is a branch people install from, with no draft, so the two steps are
|
|
24
|
+
* a branch and a fast-forward (#4048):
|
|
25
|
+
*
|
|
26
|
+
* - The stage commits the rendered formula to `chant-publish/<formula>-<version>`,
|
|
27
|
+
* a branch it makes at the tap branch's head (or moves there, when an
|
|
28
|
+
* earlier stage left it elsewhere). `brew` reads only the tap branch, so
|
|
29
|
+
* nothing is visible. A tap branch that already holds the formula as
|
|
30
|
+
* rendered stages nothing, and a staging branch that already holds it is
|
|
31
|
+
* not committed to again.
|
|
32
|
+
* - The reveal fast-forwards the tap branch to the staged commit, then
|
|
33
|
+
* deletes the staging branch. When the tap branch moved since the stage,
|
|
34
|
+
* the reveal commits the formula onto it instead, one commit either way,
|
|
35
|
+
* unless it already holds the formula as rendered.
|
|
36
|
+
*
|
|
37
|
+
* With `sshKeyEnv` (#4699), the same two steps run with git over SSH and the
|
|
38
|
+
* private key in that variable, such as a deploy key limited to the tap, in
|
|
39
|
+
* place of the API and a token (./publish-git-ssh.ts). The stage fetches the
|
|
40
|
+
* tap branch, commits the formula on its head and force-pushes that commit
|
|
41
|
+
* to the staging branch. The reveal fetches the staging branch and pushes
|
|
42
|
+
* its commit to the tap branch without force, which the remote takes only
|
|
43
|
+
* as a fast-forward; when the tap branch moved, it commits the formula onto
|
|
44
|
+
* the new head instead and pushes that, then deletes the staging branch.
|
|
45
|
+
*
|
|
46
|
+
* The asset URLs are the declaration's `url` pattern, so the files must be
|
|
47
|
+
* downloadable there by the time the formula is: declare the `forge` target
|
|
48
|
+
* that attaches them before this one, and its reveal runs first.
|
|
49
|
+
*/
|
|
50
|
+
import { readFileSync } from "node:fs";
|
|
51
|
+
import { basename } from "node:path";
|
|
52
|
+
import { readCredential } from "./publish-credentials.js";
|
|
53
|
+
import { SshGitRepo } from "./publish-git-ssh.js";
|
|
54
|
+
import { GitHubRepo, githubApi } from "./publish-github.js";
|
|
55
|
+
import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets.js";
|
|
56
|
+
import { PublishTargetError } from "./release-publish.js";
|
|
57
|
+
import { NEXT_RELEASE } from "../release-floors.js";
|
|
58
|
+
/** The first chant that publishes a `homebrew` target (#4676). */
|
|
59
|
+
export const PUBLISH_HOMEBREW_FLOOR = "0.124.63";
|
|
60
|
+
/** The first chant that reads a homebrew target's `sshKeyEnv` (#4699). */
|
|
61
|
+
export const PUBLISH_HOMEBREW_SSH_KEY_FLOOR = NEXT_RELEASE;
|
|
62
|
+
/** The variable the tap token is read from when the declaration names none. */
|
|
63
|
+
export const HOMEBREW_TOKEN_ENV = "HOMEBREW_TAP_TOKEN";
|
|
64
|
+
/** A release's version for a package manager: its label from the first digit on, or null when the label has no digit. */
|
|
65
|
+
export function releaseVersion(label) {
|
|
66
|
+
const at = label?.search(/\d/) ?? -1;
|
|
67
|
+
return label && at >= 0 ? label.slice(at) : null;
|
|
68
|
+
}
|
|
69
|
+
/** `pattern` with `{tag}`, `{label}`, `{version}` and `{name}` filled in, each URL-encoded except the tag's slashes. */
|
|
70
|
+
export function fillUrl(pattern, values) {
|
|
71
|
+
return pattern.replace(/\{(tag|label|version|name)\}/g, (_, k) => k === "tag" ? values.tag.split("/").map(encodeURIComponent).join("/") : encodeURIComponent(values[k]));
|
|
72
|
+
}
|
|
73
|
+
/** Render a formula template, or name what it can't fill. */
|
|
74
|
+
export function renderFormula(template, values, assets) {
|
|
75
|
+
return template.replace(/\{\{\s*([^}]*?)\s*\}\}/g, (whole, inner) => {
|
|
76
|
+
if (inner === "version" || inner === "label" || inner === "tag")
|
|
77
|
+
return values[inner];
|
|
78
|
+
const m = /^(url|sha256):(.+)$/.exec(inner);
|
|
79
|
+
const asset = m ? assets.get(m[2].trim()) : undefined;
|
|
80
|
+
if (m && asset)
|
|
81
|
+
return m[1] === "url" ? asset.url : asset.sha256;
|
|
82
|
+
throw new PublishTargetError("publish-homebrew-template", m ? `the formula template names ${whole}, and no declared asset is named ${m[2].trim()}` : `the formula template has ${whole}, which chant does not fill`, `The placeholders are {{version}}, {{label}}, {{tag}}, and {{url:<name>}} and {{sha256:<name>}} for an asset in assets: ${[...assets.keys()].join(", ")}.`);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
export function homebrewTarget(decl, deps) {
|
|
86
|
+
const fetchImpl = deps.fetch ?? ((url, init) => fetch(url, init));
|
|
87
|
+
if (decl.sshKeyEnv && decl.tokenEnv) {
|
|
88
|
+
throw new PublishTargetError("publish-homebrew-auth-invalid", `the homebrew target for ${decl.tap} names both tokenEnv and sshKeyEnv`, "Keep one: sshKeyEnv pushes with git over SSH, tokenEnv commits through the API.");
|
|
89
|
+
}
|
|
90
|
+
const ssh = decl.sshKeyEnv !== undefined;
|
|
91
|
+
const tokenNames = [decl.sshKeyEnv ?? decl.tokenEnv ?? HOMEBREW_TOKEN_ENV];
|
|
92
|
+
const formulaName = basename(decl.formula).replace(/\.rb$/, "");
|
|
93
|
+
const setup = (ctx) => {
|
|
94
|
+
const version = releaseVersion(ctx.label);
|
|
95
|
+
if (!version || !ctx.label || !ctx.releaseTag) {
|
|
96
|
+
throw new PublishTargetError("publish-homebrew-no-version", `a formula'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.");
|
|
97
|
+
}
|
|
98
|
+
const token = readCredential(ctx.env, tokenNames, ctx.redactor);
|
|
99
|
+
if (!token) {
|
|
100
|
+
throw new PublishTargetError("publish-credentials-missing", `the homebrew target reads its ${ssh ? "SSH key" : "token"} from ${tokenNames[0]}, and it is not set`, ssh ? `Set ${tokenNames[0]} to a private key that may push to ${decl.tap}, such as a deploy key with write access.` : `Set ${tokenNames[0]} to a token that may push to ${decl.tap}.`);
|
|
101
|
+
}
|
|
102
|
+
const assets = new Map();
|
|
103
|
+
for (const p of decl.assets) {
|
|
104
|
+
const abs = memberFile(ctx.cwd, p);
|
|
105
|
+
const digest = bytesDigest(new Uint8Array(readFileSync(abs)));
|
|
106
|
+
checkReleaseDigest(ctx.release, "asset", ctx.cwd, p, [digest]);
|
|
107
|
+
const name = basename(p);
|
|
108
|
+
if (assets.has(name))
|
|
109
|
+
throw new PublishTargetError("publish-homebrew-asset-name-taken", `two assets are named ${name}, and the template names an asset by its file name`);
|
|
110
|
+
const url = fillUrl(decl.url, { tag: ctx.releaseTag, label: ctx.label, version, name });
|
|
111
|
+
assets.set(name, { url, sha256: digest.slice("sha256:".length) });
|
|
112
|
+
}
|
|
113
|
+
const template = readFileSync(memberFile(ctx.cwd, decl.template), "utf-8");
|
|
114
|
+
const bytes = new Uint8Array(Buffer.from(renderFormula(template, { version, label: ctx.label, tag: ctx.releaseTag }, assets), "utf-8"));
|
|
115
|
+
return { version, token, assets, bytes, digest: bytesDigest(bytes) };
|
|
116
|
+
};
|
|
117
|
+
const where = (branch) => `${decl.tap}@${branch}:${decl.formula}`;
|
|
118
|
+
const target = {
|
|
119
|
+
kind: "homebrew",
|
|
120
|
+
name: `homebrew formula ${formulaName} in ${decl.tap}`,
|
|
121
|
+
destination: `github ${decl.tap}`,
|
|
122
|
+
credentialEnv: tokenNames,
|
|
123
|
+
key: publishTargetKey(decl),
|
|
124
|
+
async plan(ctx) {
|
|
125
|
+
const { digest } = setup(ctx);
|
|
126
|
+
return [{ name: decl.formula, destination: where(decl.branch ?? "the default branch"), digest }];
|
|
127
|
+
},
|
|
128
|
+
async stage(ctx) {
|
|
129
|
+
const { version, token, assets, bytes, digest } = setup(ctx);
|
|
130
|
+
ctx.log(`using the ${ssh ? "SSH key" : "token"} from ${token.from}`);
|
|
131
|
+
for (const [name, a] of assets)
|
|
132
|
+
ctx.log(`${name}: ${a.url} sha256 ${a.sha256}`);
|
|
133
|
+
if (ssh)
|
|
134
|
+
return withSsh(ctx, token, (tap) => stageOverSsh(ctx, tap, version, bytes, digest));
|
|
135
|
+
const tap = new GitHubRepo(githubApi(decl.api, ctx.env), decl.tap, token, fetchImpl, ctx, "publish-homebrew-failed");
|
|
136
|
+
const branch = decl.branch ?? (await tap.defaultBranch());
|
|
137
|
+
const head = await tap.branchHead(branch);
|
|
138
|
+
if (!head)
|
|
139
|
+
throw new PublishTargetError("publish-homebrew-failed", `${decl.tap} has no branch ${branch}`, "Set branch to the branch brew installs from.");
|
|
140
|
+
const item = { name: decl.formula, destination: where(branch), digest };
|
|
141
|
+
const done = (state, present) => ({ target: target.name, destination: target.destination, items: [{ ...item, ...(present ? { present: true } : {}) }], state: { branch, ...state } });
|
|
142
|
+
const onTap = await tap.file(decl.formula, branch);
|
|
143
|
+
if (onTap && onTap.bytes.equals(Buffer.from(bytes))) {
|
|
144
|
+
ctx.log(`${branch} already has ${decl.formula} for ${version}`);
|
|
145
|
+
return done({ present: "true" }, true);
|
|
146
|
+
}
|
|
147
|
+
const staging = `chant-publish/${formulaName}-${version}`;
|
|
148
|
+
const stagingHead = await tap.branchHead(staging);
|
|
149
|
+
if (stagingHead) {
|
|
150
|
+
const onStaging = await tap.file(decl.formula, staging);
|
|
151
|
+
if (onStaging && onStaging.bytes.equals(Buffer.from(bytes))) {
|
|
152
|
+
ctx.log(`${staging} already has ${decl.formula} for ${version}`);
|
|
153
|
+
return done({ staging, commit: stagingHead }, true);
|
|
154
|
+
}
|
|
155
|
+
await tap.moveRef(`heads/${staging}`, head, true);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
await tap.createBranch(staging, head);
|
|
159
|
+
}
|
|
160
|
+
ctx.log(`committing ${decl.formula} for ${version} to ${staging}, at ${branch}'s head ${head.slice(0, 12)}`);
|
|
161
|
+
const commit = await tap.putFile(decl.formula, staging, bytes, `${formulaName} ${version}`, onTap?.sha ?? null);
|
|
162
|
+
return done({ staging, commit }, false);
|
|
163
|
+
},
|
|
164
|
+
async reveal(ctx, staged) {
|
|
165
|
+
const items = staged.items.map((i) => ({ name: i.name, destination: i.destination, ...(i.digest ? { digest: i.digest } : {}) }));
|
|
166
|
+
const published = { target: target.name, destination: target.destination, items };
|
|
167
|
+
if (staged.state.present === "true")
|
|
168
|
+
return { ...published, items: items.map((i) => ({ ...i, present: true })) };
|
|
169
|
+
const { version, token, bytes } = setup(ctx);
|
|
170
|
+
const { branch, staging, commit } = staged.state;
|
|
171
|
+
if (!branch || !staging || !commit)
|
|
172
|
+
throw new PublishTargetError("publish-homebrew-failed", `the staged formula for ${decl.tap} has no staging commit to reveal`);
|
|
173
|
+
if (ssh) {
|
|
174
|
+
await withSsh(ctx, token, (tap) => revealOverSsh(ctx, tap, { branch, staging, commit }, version, bytes));
|
|
175
|
+
return published;
|
|
176
|
+
}
|
|
177
|
+
const tap = new GitHubRepo(githubApi(decl.api, ctx.env), decl.tap, token, fetchImpl, ctx, "publish-homebrew-failed");
|
|
178
|
+
ctx.log(`fast-forwarding ${branch} to ${commit.slice(0, 12)}`);
|
|
179
|
+
if (!(await tap.moveRef(`heads/${branch}`, commit, false))) {
|
|
180
|
+
// The tap moved since the stage: one commit of the formula onto it, unless it already holds it.
|
|
181
|
+
const onTap = await tap.file(decl.formula, branch);
|
|
182
|
+
if (onTap && onTap.bytes.equals(Buffer.from(bytes))) {
|
|
183
|
+
ctx.log(`${branch} moved since the stage and already has ${decl.formula} for ${version}`);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
ctx.log(`${branch} moved since the stage; committing ${decl.formula} for ${version} onto it`);
|
|
187
|
+
await tap.putFile(decl.formula, branch, bytes, `${formulaName} ${version}`, onTap?.sha ?? null);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
await tap.deleteRef(`heads/${staging}`);
|
|
191
|
+
return published;
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
async function withSsh(ctx, key, step) {
|
|
195
|
+
const tap = await SshGitRepo.open({ api: githubApi(decl.api, ctx.env), repo: decl.tap, key, ctx, fetch: fetchImpl, code: "publish-homebrew-failed", git: deps.git, ssh: deps.ssh });
|
|
196
|
+
try {
|
|
197
|
+
return await step(tap);
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
tap.close();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
async function stageOverSsh(ctx, tap, version, bytes, digest) {
|
|
204
|
+
const { defaultBranch, heads } = await tap.heads();
|
|
205
|
+
const branch = decl.branch ?? defaultBranch;
|
|
206
|
+
const head = branch ? heads.get(branch) : undefined;
|
|
207
|
+
if (!branch || !head)
|
|
208
|
+
throw new PublishTargetError("publish-homebrew-failed", `${tap.remote} has no branch ${branch ?? "HEAD points at"}`, "Set branch to the branch brew installs from.");
|
|
209
|
+
const item = { name: decl.formula, destination: where(branch), digest };
|
|
210
|
+
const done = (state, present) => ({ target: target.name, destination: target.destination, items: [{ ...item, ...(present ? { present: true } : {}) }], state: { branch, ...state } });
|
|
211
|
+
ctx.log(`reading ${branch} of ${tap.remote} over SSH`);
|
|
212
|
+
await tap.fetch(branch);
|
|
213
|
+
const onTap = await tap.file(head, decl.formula);
|
|
214
|
+
if (onTap && onTap.equals(Buffer.from(bytes))) {
|
|
215
|
+
ctx.log(`${branch} already has ${decl.formula} for ${version}`);
|
|
216
|
+
return done({ present: "true" }, true);
|
|
217
|
+
}
|
|
218
|
+
const staging = `chant-publish/${formulaName}-${version}`;
|
|
219
|
+
const stagingHead = heads.get(staging);
|
|
220
|
+
if (stagingHead) {
|
|
221
|
+
await tap.fetch(staging);
|
|
222
|
+
const onStaging = await tap.file(stagingHead, decl.formula);
|
|
223
|
+
if (onStaging && onStaging.equals(Buffer.from(bytes))) {
|
|
224
|
+
ctx.log(`${staging} already has ${decl.formula} for ${version}`);
|
|
225
|
+
return done({ staging, commit: stagingHead }, true);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
ctx.log(`committing ${decl.formula} for ${version} to ${staging}, at ${branch}'s head ${head.slice(0, 12)}, and pushing it over SSH`);
|
|
229
|
+
const commit = await tap.commitFile(head, decl.formula, bytes, `${formulaName} ${version}`);
|
|
230
|
+
await tap.push(commit, staging, true);
|
|
231
|
+
return done({ staging, commit }, false);
|
|
232
|
+
}
|
|
233
|
+
async function revealOverSsh(ctx, tap, state, version, bytes) {
|
|
234
|
+
const { branch, staging, commit } = state;
|
|
235
|
+
const { heads } = await tap.heads();
|
|
236
|
+
// The staged commit is on the staging branch: fetch it, since this run may be a resume on a fresh clone.
|
|
237
|
+
// Depth 2: the staged commit and the head it was made on, so git sees the push as a fast-forward.
|
|
238
|
+
const stagingHead = heads.get(staging) === commit ? await tap.fetch(staging, 2) : null;
|
|
239
|
+
let moved = true;
|
|
240
|
+
if (stagingHead === commit) {
|
|
241
|
+
ctx.log(`fast-forwarding ${branch} to ${commit.slice(0, 12)} over SSH`);
|
|
242
|
+
moved = (await tap.push(commit, branch, false)) === "rejected";
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
ctx.log(`${staging} is not at the staged commit ${commit.slice(0, 12)} any more`);
|
|
246
|
+
}
|
|
247
|
+
if (moved) {
|
|
248
|
+
// The tap moved since the stage, or the staged commit is gone: one commit of the formula onto it, unless it already holds it.
|
|
249
|
+
const head = await tap.fetch(branch);
|
|
250
|
+
const onTap = await tap.file(head, decl.formula);
|
|
251
|
+
if (onTap && onTap.equals(Buffer.from(bytes))) {
|
|
252
|
+
ctx.log(`${branch} already has ${decl.formula} for ${version}`);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
ctx.log(`committing ${decl.formula} for ${version} onto ${branch}'s head ${head.slice(0, 12)}`);
|
|
256
|
+
const onto = await tap.commitFile(head, decl.formula, bytes, `${formulaName} ${version}`);
|
|
257
|
+
if ((await tap.push(onto, branch, false)) === "rejected") {
|
|
258
|
+
throw new PublishTargetError("publish-homebrew-failed", `${branch} of ${tap.remote} moved again while ${decl.formula} was committed onto it`, "Run the same publish again: it commits the formula onto the branch's new head.");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
await tap.deleteBranch(staging);
|
|
263
|
+
}
|
|
264
|
+
return target;
|
|
265
|
+
}
|