@intentius/chant 0.124.63 → 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 +8 -0
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +27 -4
- 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 +6 -4
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +83 -16
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +18 -6
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +12 -0
- package/dist/cli/registry.d.ts +5 -1
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/config.d.ts +18 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/gate-statement.schema.json +4 -2
- package/dist/lifecycle/gate-ledger.d.ts +11 -2
- 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 +20 -4
- package/dist/lifecycle/gate-seal.d.ts.map +1 -1
- package/dist/lifecycle/gate-seal.js +18 -5
- package/dist/lifecycle/gate-statement.d.ts +27 -2
- package/dist/lifecycle/gate-statement.d.ts.map +1 -1
- package/dist/lifecycle/gate-statement.js +37 -1
- package/dist/lifecycle/plan-stale.d.ts.map +1 -1
- package/dist/lifecycle/plan-stale.js +1 -2
- package/dist/lifecycle/publish-declaration.d.ts +20 -0
- package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
- package/dist/lifecycle/publish-declaration.js +24 -1
- package/dist/lifecycle/publish-forge.d.ts.map +1 -1
- package/dist/lifecycle/publish-forge.js +1 -2
- 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-homebrew.d.ts +11 -0
- package/dist/lifecycle/publish-homebrew.d.ts.map +1 -1
- package/dist/lifecycle/publish-homebrew.js +96 -4
- package/dist/lifecycle/publish-marketplace.d.ts +36 -2
- package/dist/lifecycle/publish-marketplace.d.ts.map +1 -1
- package/dist/lifecycle/publish-marketplace.js +173 -29
- package/dist/lifecycle/publish-tauri.d.ts.map +1 -1
- package/dist/lifecycle/publish-tauri.js +1 -2
- 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 +13 -0
- 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/op/activities/activity-contracts.d.ts +4 -4
- 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.map +1 -1
- package/dist/pr-forge.js +26 -6
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +284 -283
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +1 -2
- package/dist/workspace/ci-quarantine-report.d.ts.map +1 -1
- package/dist/workspace/ci-quarantine-report.js +1 -2
- package/dist/workspace/ci-quarantine.d.ts.map +1 -1
- package/dist/workspace/ci-quarantine.js +1 -2
- package/dist/workspace/intent.d.ts.map +1 -1
- package/dist/workspace/intent.js +1 -2
- package/dist/workspace/release-candidates.d.ts +9 -1
- package/dist/workspace/release-candidates.d.ts.map +1 -1
- package/dist/workspace/release-candidates.js +16 -4
- package/dist/workspace/release-candidates.schema.json +7 -0
- package/dist/workspace/releases.schema.json +47 -0
- package/package.json +1 -1
- package/src/cli/handlers/approve-external-signature.test.ts +105 -3
- package/src/cli/handlers/approve.ts +34 -4
- package/src/cli/handlers/pr.ts +2 -1
- package/src/cli/handlers/release.ts +75 -16
- package/src/cli/main.ts +18 -6
- package/src/cli/parse-args.ts +9 -0
- package/src/cli/registry.ts +5 -1
- package/src/config.ts +8 -0
- package/src/gate-statement.schema.json +4 -2
- package/src/lifecycle/gate-ledger.ts +17 -2
- package/src/lifecycle/gate-seal.ts +24 -6
- package/src/lifecycle/gate-statement.ts +40 -3
- package/src/lifecycle/plan-stale.test.ts +3 -4
- package/src/lifecycle/plan-stale.ts +1 -2
- package/src/lifecycle/publish-declaration.ts +24 -1
- package/src/lifecycle/publish-forge.ts +1 -2
- package/src/lifecycle/publish-git-ssh.ts +202 -0
- package/src/lifecycle/publish-homebrew.test.ts +181 -2
- package/src/lifecycle/publish-homebrew.ts +101 -5
- package/src/lifecycle/publish-marketplace.test.ts +158 -6
- package/src/lifecycle/publish-marketplace.ts +192 -30
- package/src/lifecycle/publish-resume.test.ts +40 -0
- package/src/lifecycle/publish-tauri.ts +1 -2
- 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 +18 -0
- package/src/lifecycle/release-revocation.ts +5 -4
- package/src/lifecycle/release-store.ts +44 -0
- package/src/op/gate.ts +2 -1
- package/src/pr-forge.ts +25 -6
- package/src/pr-requires.test.ts +9 -0
- package/src/release-floors.ts +1 -1
- package/src/workspace/ci-green.ts +1 -2
- package/src/workspace/ci-quarantine-report.test.ts +2 -3
- package/src/workspace/ci-quarantine-report.ts +1 -2
- package/src/workspace/ci-quarantine.test.ts +2 -3
- package/src/workspace/ci-quarantine.ts +1 -2
- package/src/workspace/intent.ts +1 -2
- package/src/workspace/release-candidates.schema.json +7 -0
- package/src/workspace/release-candidates.ts +19 -4
- package/src/workspace/releases.schema.json +47 -0
- package/src/workspace/trust/gate-seal.test.ts +44 -0
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
* the approval that records it cover the same line. The platform has the
|
|
11
11
|
* person sign them and hands the signature to `chant approve --signature`,
|
|
12
12
|
* with the same `--actor`, `--relayed-by` and `--at`.
|
|
13
|
+
*
|
|
14
|
+
* The relay can add a line of its own for the signature to bind, `--binding
|
|
15
|
+
* <text>` on both calls (#4697): a platform's deploy id and an expiry, say.
|
|
16
|
+
* It is signed last as `binding <text>` (seal version 3) and kept on the
|
|
17
|
+
* approval, and chant checks only that it is one line of printable text no
|
|
18
|
+
* longer than {@link GATE_BINDING_MAX_BYTES}.
|
|
13
19
|
*/
|
|
14
20
|
|
|
15
21
|
import { createHash } from "node:crypto";
|
|
@@ -23,7 +29,35 @@ import { GATE_SEAL_NAMESPACE, gateSealPayload, gateSealVersion, isWebAuthnAssert
|
|
|
23
29
|
* older chant reads a trust.json with `passkeys` as invalid, which turns
|
|
24
30
|
* attestation off, and counts no passkey seal toward a gate.
|
|
25
31
|
*/
|
|
26
|
-
export const GATE_EXTERNAL_SIGNATURE_FLOOR =
|
|
32
|
+
export const GATE_EXTERNAL_SIGNATURE_FLOOR = "0.124.63";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The first chant that takes `--binding` and signs and checks a binding line
|
|
36
|
+
* (seal version 3, #4697). An older chant leaves the line out of what it
|
|
37
|
+
* checks, so it finds a version 3 seal doesn't verify and counts nothing for
|
|
38
|
+
* it, whatever the gate.
|
|
39
|
+
*/
|
|
40
|
+
export const GATE_BINDING_FLOOR = NEXT_RELEASE;
|
|
41
|
+
|
|
42
|
+
/** The longest binding `--binding` takes, in UTF-8 bytes (#4697). */
|
|
43
|
+
export const GATE_BINDING_MAX_BYTES = 512;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Why `text` can't be a gate statement's binding line (#4697), or null when
|
|
47
|
+
* it can: it must be non-empty, at most {@link GATE_BINDING_MAX_BYTES} UTF-8
|
|
48
|
+
* bytes, with no leading or trailing space, and printable on one line, so no
|
|
49
|
+
* control or format character (bidi overrides among them), line or paragraph
|
|
50
|
+
* separator, unassigned code point or lone surrogate.
|
|
51
|
+
*/
|
|
52
|
+
export function gateBindingProblem(text: string): string | null {
|
|
53
|
+
if (text === "") return "it is empty";
|
|
54
|
+
const bytes = Buffer.byteLength(text, "utf-8");
|
|
55
|
+
if (bytes > GATE_BINDING_MAX_BYTES) return `it is ${bytes} bytes, and the most is ${GATE_BINDING_MAX_BYTES}`;
|
|
56
|
+
if (text.trim() !== text) return "it starts or ends with white space";
|
|
57
|
+
const bad = /[\p{C}\p{Zl}\p{Zp}]/u.exec(text);
|
|
58
|
+
if (bad) return `it holds U+${bad[0].codePointAt(0)!.toString(16).toUpperCase().padStart(4, "0")}, and it must be printable text on one line`;
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
27
61
|
|
|
28
62
|
export const GATE_STATEMENT_SCHEMA = "chant-gate-statement/v1";
|
|
29
63
|
|
|
@@ -42,8 +76,10 @@ export interface GateStatement {
|
|
|
42
76
|
relayedBy: string | null;
|
|
43
77
|
timestamp: string;
|
|
44
78
|
checkpointDigest: string | null;
|
|
45
|
-
/**
|
|
46
|
-
|
|
79
|
+
/** The relay's binding line (#4697, `--binding`), or null. When set the statement ends with `binding <text>`. */
|
|
80
|
+
binding: string | null;
|
|
81
|
+
/** 3 when the statement signs a binding, else 2 when it signs a checkpoint digest, else 1. */
|
|
82
|
+
sealVersion: 1 | 2 | 3;
|
|
47
83
|
/** The ssh signature namespace an ssh key signs the statement in. */
|
|
48
84
|
namespace: typeof GATE_SEAL_NAMESPACE;
|
|
49
85
|
/** The statement's UTF-8 text, LF-joined with no final newline. */
|
|
@@ -70,6 +106,7 @@ export function gateStatement(a: SealedGateApproval, chantVersion: string): Gate
|
|
|
70
106
|
relayedBy: a.relayedBy ?? null,
|
|
71
107
|
timestamp: a.timestamp,
|
|
72
108
|
checkpointDigest: a.checkpointDigest ?? null,
|
|
109
|
+
binding: a.binding ?? null,
|
|
73
110
|
sealVersion: gateSealVersion(a),
|
|
74
111
|
namespace: GATE_SEAL_NAMESPACE,
|
|
75
112
|
text: bytes.toString("utf-8"),
|
|
@@ -8,7 +8,6 @@ import { writeBlobToPath } from "./git";
|
|
|
8
8
|
import { clearMemberLedgerCache } from "./member-ledger";
|
|
9
9
|
import { PLAN_STALE_FLOOR, PLAN_STALE_SCHEMA_ID, planStaleness } from "./plan-stale";
|
|
10
10
|
import { loadQueryData } from "./query";
|
|
11
|
-
import { NEXT_RELEASE } from "../release-floors";
|
|
12
11
|
import { planStaleDocument } from "../cli/handlers/plan";
|
|
13
12
|
import { loadAjv2020 } from "../workspace/ajv2020";
|
|
14
13
|
import planStaleSchema from "../workspace/plan-stale.schema.json";
|
|
@@ -95,9 +94,9 @@ describe("chant plan stale (#4648)", () => {
|
|
|
95
94
|
expect(await stale(component, P3)).toMatchObject({ plan: null, stale: null, applies: [] });
|
|
96
95
|
});
|
|
97
96
|
|
|
98
|
-
test("its floor is the
|
|
99
|
-
expect(PLAN_STALE_FLOOR).toBe(
|
|
100
|
-
expect(planStaleSchema.description).toContain(
|
|
97
|
+
test("its floor is the release it shipped in", () => {
|
|
98
|
+
expect(PLAN_STALE_FLOOR).toBe("0.124.63");
|
|
99
|
+
expect(planStaleSchema.description).toContain("written by chant 0.124.63 and newer");
|
|
101
100
|
});
|
|
102
101
|
});
|
|
103
102
|
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
*/
|
|
26
26
|
import { samePlanDigest } from "./plan-digest";
|
|
27
27
|
import type { QueryData, QueryRow } from "./query";
|
|
28
|
-
import { NEXT_RELEASE } from "../release-floors";
|
|
29
28
|
|
|
30
29
|
/** The version of the `plan-stale` document this chant writes. */
|
|
31
30
|
export const PLAN_STALE_CONTRACT_VERSION = 1;
|
|
@@ -34,7 +33,7 @@ export const PLAN_STALE_CONTRACT_VERSION = 1;
|
|
|
34
33
|
export const PLAN_STALE_SCHEMA_ID = "https://intentius.io/chant/schemas/workspace/plan-stale/v1/plan-stale.schema.json";
|
|
35
34
|
|
|
36
35
|
/** The first chant that answers `chant plan stale` (#4648). */
|
|
37
|
-
export const PLAN_STALE_FLOOR =
|
|
36
|
+
export const PLAN_STALE_FLOOR = "0.124.63";
|
|
38
37
|
|
|
39
38
|
/** Why the read stopped. Closed; each code is in `../workspace/reason-codes.ts`. */
|
|
40
39
|
export const PLAN_STALE_ERROR_CODES = ["not-a-git-repository", "ledger-unreadable"] as const;
|
|
@@ -143,6 +143,12 @@ export const HomebrewPublishSchema = z
|
|
|
143
143
|
api: z.string().url().optional(),
|
|
144
144
|
/** The variable holding a token that may push to the tap. Default `HOMEBREW_TAP_TOKEN`. */
|
|
145
145
|
tokenEnv: envName.optional(),
|
|
146
|
+
/**
|
|
147
|
+
* The variable holding an SSH private key that may push to the tap, such
|
|
148
|
+
* as a deploy key with write access (#4699). Set, the target pushes with
|
|
149
|
+
* git over SSH and reads no token; `tokenEnv` beside it is refused.
|
|
150
|
+
*/
|
|
151
|
+
sshKeyEnv: envName.optional(),
|
|
146
152
|
})
|
|
147
153
|
.strict();
|
|
148
154
|
|
|
@@ -158,8 +164,25 @@ export const MarketplacePublishSchema = z
|
|
|
158
164
|
vsix: z.string().min(1),
|
|
159
165
|
/** Open VSX's root, default `https://open-vsx.org`; the VS Code Marketplace's gallery, default `https://marketplace.visualstudio.com`. */
|
|
160
166
|
registry: z.string().url().optional(),
|
|
161
|
-
/** The variable holding the token
|
|
167
|
+
/** The variable holding the token, under `auth: "token"`. Default `VSCE_PAT` for the VS Code Marketplace, `OVSX_PAT` for Open VSX. */
|
|
162
168
|
tokenEnv: envName.optional(),
|
|
169
|
+
/**
|
|
170
|
+
* How the target authenticates (#4698). `"token"` (the default) reads a
|
|
171
|
+
* token from `tokenEnv`. `"azure-credential"`, VS Code Marketplace only,
|
|
172
|
+
* runs `vsce` with `--azure-credential`, which signs in with the Microsoft
|
|
173
|
+
* Entra identity the job has, such as one `azure/login` set up from the
|
|
174
|
+
* run's OIDC token. `"trusted-publishing"`, Open VSX only, exchanges the
|
|
175
|
+
* run's OIDC ID token for a short-lived publishing token, as
|
|
176
|
+
* `ovsx publish --trusted-publishing` does.
|
|
177
|
+
*/
|
|
178
|
+
auth: z.enum(["token", "azure-credential", "trusted-publishing"]).optional(),
|
|
179
|
+
/**
|
|
180
|
+
* What the reveal does when the marketplace refuses the upload (#4698).
|
|
181
|
+
* `"fail"` (the default) fails the publish. `"warn"` prints a warning
|
|
182
|
+
* and goes on to the next target, and the target is not recorded as
|
|
183
|
+
* published, so the same publish run again tries the upload again.
|
|
184
|
+
*/
|
|
185
|
+
onRefusal: z.enum(["fail", "warn"]).optional(),
|
|
163
186
|
})
|
|
164
187
|
.strict();
|
|
165
188
|
|
|
@@ -51,10 +51,9 @@ import { readCredential, type Credential } from "./publish-credentials";
|
|
|
51
51
|
import type { ForgePublishDeclaration } from "./publish-declaration";
|
|
52
52
|
import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets";
|
|
53
53
|
import { PublishTargetError, type PublishContext, type PublishDeps, type PublishFetch, type PublishItem, type PublishTarget, type StagedTarget } from "./release-publish";
|
|
54
|
-
import { NEXT_RELEASE } from "../release-floors";
|
|
55
54
|
|
|
56
55
|
/** The first chant that reads `latest` on a forge target and sends it as GitHub's `make_latest` (#4676). */
|
|
57
|
-
export const PUBLISH_FORGE_LATEST_FLOOR =
|
|
56
|
+
export const PUBLISH_FORGE_LATEST_FLOOR = "0.124.63";
|
|
58
57
|
|
|
59
58
|
/** The variables a forge's token is read from, in order. */
|
|
60
59
|
export function forgeTokenEnv(decl: Pick<ForgePublishDeclaration, "forge" | "tokenEnv">): string[] {
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One repository reached with git over SSH and one private key (#4699), for
|
|
3
|
+
* a target that may not use a forge's API token, such as a Homebrew tap
|
|
4
|
+
* written with a deploy key.
|
|
5
|
+
*
|
|
6
|
+
* Each {@link SshGitRepo} works in a temporary bare repository of its own.
|
|
7
|
+
* It fetches only the branches it reads, at depth 1, makes commits with git's
|
|
8
|
+
* plumbing (no checkout), and pushes. The key is written to a file only the
|
|
9
|
+
* user can read, inside that directory, and the directory is removed by
|
|
10
|
+
* {@link SshGitRepo.close}.
|
|
11
|
+
*
|
|
12
|
+
* The host's keys are pinned: ssh runs with `StrictHostKeyChecking=yes` and a
|
|
13
|
+
* known-hosts file written from the `ssh_keys` that GitHub's `GET /meta`
|
|
14
|
+
* lists, read over HTTPS from the API root. ssh reads no config file
|
|
15
|
+
* (`-F /dev/null`) and offers only the key (`IdentitiesOnly=yes`).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { execFile } from "node:child_process";
|
|
19
|
+
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
20
|
+
import { tmpdir } from "node:os";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import type { Credential } from "./publish-credentials";
|
|
23
|
+
import { PublishTargetError, type PublishContextBase, type PublishFetch } from "./release-publish";
|
|
24
|
+
|
|
25
|
+
/** The SSH host for a GitHub API root: `github.com` for `https://api.github.com`, else the API's own host (GitHub Enterprise Server). */
|
|
26
|
+
export function githubSshHost(api: string): string {
|
|
27
|
+
const host = new URL(api).hostname;
|
|
28
|
+
return host === "api.github.com" ? "github.com" : host;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The SSH URL of `owner/name` on `host`. */
|
|
32
|
+
export function sshRemote(host: string, repo: string): string {
|
|
33
|
+
return `git@${host}:${repo}.git`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A shell word for GIT_SSH_COMMAND, which git runs through the shell. */
|
|
37
|
+
function shellWord(s: string): string {
|
|
38
|
+
return /^[A-Za-z0-9_./:@=-]+$/.test(s) ? s : `'${s.replace(/'/g, `'\\''`)}'`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** What a push did: `ok`, or `rejected` when the remote refused a non-fast-forward. Any other failure throws. */
|
|
42
|
+
export type PushResult = "ok" | "rejected";
|
|
43
|
+
|
|
44
|
+
export class SshGitRepo {
|
|
45
|
+
/** The bare repository, inside {@link root}. */
|
|
46
|
+
private readonly dir: string;
|
|
47
|
+
readonly remote: string;
|
|
48
|
+
|
|
49
|
+
private constructor(
|
|
50
|
+
readonly repo: string,
|
|
51
|
+
readonly host: string,
|
|
52
|
+
private readonly ctx: PublishContextBase,
|
|
53
|
+
private readonly git: string,
|
|
54
|
+
/** The code a failure throws. */
|
|
55
|
+
private readonly code: string,
|
|
56
|
+
/** The temporary directory: the key, the known hosts, the repository. */
|
|
57
|
+
private readonly root: string,
|
|
58
|
+
private readonly env: NodeJS.ProcessEnv,
|
|
59
|
+
) {
|
|
60
|
+
this.dir = join(root, "repo.git");
|
|
61
|
+
this.remote = sshRemote(host, repo);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A repository session: reads the host's keys from `GET {api}/meta`, writes
|
|
66
|
+
* them and the key to a temporary directory, and makes an empty bare
|
|
67
|
+
* repository there. Close it with {@link close}.
|
|
68
|
+
*/
|
|
69
|
+
static async open(opts: {
|
|
70
|
+
api: string;
|
|
71
|
+
repo: string;
|
|
72
|
+
key: Credential;
|
|
73
|
+
ctx: PublishContextBase;
|
|
74
|
+
fetch: PublishFetch;
|
|
75
|
+
code: string;
|
|
76
|
+
git?: string;
|
|
77
|
+
ssh?: string;
|
|
78
|
+
}): Promise<SshGitRepo> {
|
|
79
|
+
const host = githubSshHost(opts.api);
|
|
80
|
+
const meta = await opts.fetch(`${opts.api}/meta`, { method: "GET", headers: { accept: "application/vnd.github+json", "user-agent": "chant" } });
|
|
81
|
+
const text = await meta.text().catch(() => "");
|
|
82
|
+
let keys: unknown;
|
|
83
|
+
try {
|
|
84
|
+
keys = meta.status === 200 ? (JSON.parse(text) as { ssh_keys?: unknown }).ssh_keys : undefined;
|
|
85
|
+
} catch {
|
|
86
|
+
keys = undefined;
|
|
87
|
+
}
|
|
88
|
+
if (!Array.isArray(keys) || keys.length === 0 || !keys.every((k) => typeof k === "string" && /^[a-z0-9@.-]+ [A-Za-z0-9+/=]+$/.test(k))) {
|
|
89
|
+
throw new PublishTargetError(opts.code, `${opts.api}/meta gave no SSH host keys for ${host} (it answered ${meta.status}), so ${host} can't be checked`, "Set api to the GitHub API root of the host the repository is on.");
|
|
90
|
+
}
|
|
91
|
+
const dir = mkdtempSync(join(tmpdir(), "chant-git-ssh-"));
|
|
92
|
+
try {
|
|
93
|
+
const keyFile = join(dir, "key");
|
|
94
|
+
writeFileSync(keyFile, opts.key.value.endsWith("\n") ? opts.key.value : `${opts.key.value}\n`, { mode: 0o600 });
|
|
95
|
+
chmodSync(keyFile, 0o600);
|
|
96
|
+
const knownHosts = join(dir, "known_hosts");
|
|
97
|
+
writeFileSync(knownHosts, (keys as string[]).map((k) => `${host} ${k}\n`).join(""));
|
|
98
|
+
const ssh = [opts.ssh ?? "ssh", "-F", "/dev/null", "-i", keyFile, "-o", "IdentitiesOnly=yes", "-o", "StrictHostKeyChecking=yes", "-o", `UserKnownHostsFile=${knownHosts}`, "-o", "BatchMode=yes"];
|
|
99
|
+
const env: NodeJS.ProcessEnv = { ...opts.ctx.env, GIT_SSH_COMMAND: ssh.map(shellWord).join(" "), GIT_TERMINAL_PROMPT: "0" };
|
|
100
|
+
for (const v of ["GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_OBJECT_DIRECTORY", "GIT_SSH", "GIT_SSH_VARIANT"]) delete env[v];
|
|
101
|
+
const repo = new SshGitRepo(opts.repo, host, opts.ctx, opts.git ?? "git", opts.code, dir, env);
|
|
102
|
+
await repo.run(["init", "-q", "--bare", repo.dir], dir);
|
|
103
|
+
return repo;
|
|
104
|
+
} catch (err) {
|
|
105
|
+
rmSync(dir, { recursive: true, force: true });
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Remove the temporary directory, with the key in it. */
|
|
111
|
+
close(): void {
|
|
112
|
+
rmSync(this.root, { recursive: true, force: true });
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private run(args: string[], cwd = this.dir, extraEnv: NodeJS.ProcessEnv = {}): Promise<{ code: number; stdout: string; stderr: string }> {
|
|
116
|
+
return new Promise((resolvePromise, reject) => {
|
|
117
|
+
execFile(this.git, args, { cwd, env: { ...this.env, ...extraEnv }, encoding: "utf-8", maxBuffer: 64 * 1024 * 1024 }, (err, stdout, stderr) => {
|
|
118
|
+
if (err && typeof (err as NodeJS.ErrnoException).code === "string") {
|
|
119
|
+
reject(new PublishTargetError(this.code, `git could not be run: ${err.message}`, "Install git on the job's PATH."));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
resolvePromise({ code: err ? ((err as { code?: number }).code ?? 1) : 0, stdout, stderr });
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private async must(what: string, args: string[], extraEnv: NodeJS.ProcessEnv = {}): Promise<string> {
|
|
128
|
+
const r = await this.run(args, this.dir, extraEnv);
|
|
129
|
+
if (r.code !== 0) this.fail(what, r.stderr || r.stdout);
|
|
130
|
+
return r.stdout;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private fail(what: string, output: string): never {
|
|
134
|
+
// git's advice after an ssh failure says nothing ssh didn't, and would push ssh's own line out of the last three.
|
|
135
|
+
const lines = output.split("\n").map((l) => l.trim()).filter((l) => l && !/^(Please make sure you have the correct access rights|and the repository exists\.)$/.test(l));
|
|
136
|
+
throw new PublishTargetError(this.code, this.ctx.redactor.redact(`${what} on ${this.remote} failed${lines.length ? `: ${lines.slice(-3).join(" ")}` : ""}`));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The remote's default branch and the head of each of its branches. */
|
|
140
|
+
async heads(): Promise<{ defaultBranch: string | null; heads: Map<string, string> }> {
|
|
141
|
+
const out = await this.must("listing the branches", ["ls-remote", "--symref", this.remote]);
|
|
142
|
+
const heads = new Map<string, string>();
|
|
143
|
+
let defaultBranch: string | null = null;
|
|
144
|
+
for (const line of out.split("\n")) {
|
|
145
|
+
const sym = /^ref: refs\/heads\/(\S+)\tHEAD$/.exec(line);
|
|
146
|
+
if (sym) defaultBranch = sym[1]!;
|
|
147
|
+
const ref = /^([0-9a-f]{40,64})\trefs\/heads\/(\S+)$/.exec(line);
|
|
148
|
+
if (ref) heads.set(ref[2]!, ref[1]!);
|
|
149
|
+
}
|
|
150
|
+
return { defaultBranch, heads };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Fetch `branch` and return its head. `depth` 1 is enough to read it and
|
|
155
|
+
* commit on it; 2 also brings its head's parent, so git sees that pushing
|
|
156
|
+
* the head fast-forwards a branch at that parent.
|
|
157
|
+
*/
|
|
158
|
+
async fetch(branch: string, depth = 1): Promise<string> {
|
|
159
|
+
await this.must(`fetching ${branch}`, ["fetch", "-q", "--no-tags", `--depth=${depth}`, this.remote, `+refs/heads/${branch}:refs/remotes/tap/${branch}`]);
|
|
160
|
+
return (await this.must(`reading ${branch}`, ["rev-parse", `refs/remotes/tap/${branch}`])).trim();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** The bytes of `path` at a fetched commit, or null when it holds no such file. */
|
|
164
|
+
async file(commit: string, path: string): Promise<Buffer | null> {
|
|
165
|
+
const spec = `${commit}:${path}`;
|
|
166
|
+
if ((await this.run(["cat-file", "-e", spec])).code !== 0) return null;
|
|
167
|
+
return new Promise((resolvePromise, reject) => {
|
|
168
|
+
execFile(this.git, ["cat-file", "blob", spec], { cwd: this.dir, env: this.env, encoding: "buffer", maxBuffer: 64 * 1024 * 1024 }, (err, stdout) => (err ? reject(err) : resolvePromise(stdout)));
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** A commit on `parent` that writes `bytes` to `path`, with `message`. Made here, not pushed. */
|
|
173
|
+
async commitFile(parent: string, path: string, bytes: Uint8Array, message: string): Promise<string> {
|
|
174
|
+
const blobFile = join(this.root, "blob");
|
|
175
|
+
writeFileSync(blobFile, bytes);
|
|
176
|
+
const blob = (await this.must("writing the file", ["hash-object", "-w", blobFile])).trim();
|
|
177
|
+
const index = { GIT_INDEX_FILE: join(this.root, "index") };
|
|
178
|
+
await this.must("reading the tree", ["read-tree", parent], index);
|
|
179
|
+
await this.must("staging the file", ["update-index", "--add", "--cacheinfo", `100644,${blob},${path}`], index);
|
|
180
|
+
const tree = (await this.must("writing the tree", ["write-tree"], index)).trim();
|
|
181
|
+
rmSync(index.GIT_INDEX_FILE, { force: true });
|
|
182
|
+
const who = (await this.run(["config", "user.email"])).stdout.trim() ? [] : ["-c", "user.name=chant", "-c", "user.email=chant@localhost"];
|
|
183
|
+
return (await this.must("committing", [...who, "-c", "commit.gpgsign=false", "commit-tree", tree, "-p", parent, "-m", message])).trim();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Push `commit` to `branch`. `force` moves it wherever it is; without it,
|
|
188
|
+
* a branch that does not fast-forward comes back `rejected`.
|
|
189
|
+
*/
|
|
190
|
+
async push(commit: string, branch: string, force: boolean): Promise<PushResult> {
|
|
191
|
+
const r = await this.run(["push", "--porcelain", this.remote, `${force ? "+" : ""}${commit}:refs/heads/${branch}`]);
|
|
192
|
+
if (r.code === 0) return "ok";
|
|
193
|
+
if (!force && /^!\t[^\t]*\t\[rejected\] \((non-fast-forward|fetch first)\)/m.test(r.stdout)) return "rejected";
|
|
194
|
+
this.fail(`pushing ${commit.slice(0, 12)} to ${branch}`, `${r.stdout}\n${r.stderr}`);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Delete `branch` on the remote, if it is there. */
|
|
198
|
+
async deleteBranch(branch: string): Promise<void> {
|
|
199
|
+
const r = await this.run(["push", "--porcelain", this.remote, `:refs/heads/${branch}`]);
|
|
200
|
+
if (r.code !== 0 && !/remote ref does not exist/.test(`${r.stdout}\n${r.stderr}`)) this.fail(`deleting ${branch}`, `${r.stdout}\n${r.stderr}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* #4676: the Homebrew tap target against a GitHub repository fake. The stage
|
|
3
3
|
* commits the rendered formula to a staging branch that brew does not read,
|
|
4
|
-
* and the tap branch moves only at the reveal. Nothing reaches a network
|
|
4
|
+
* and the tap branch moves only at the reveal. Nothing reaches a network:
|
|
5
|
+
* over SSH (#4699), git pushes to a bare repository through a fake ssh.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
8
|
import { afterAll, describe, expect, test } from "vitest";
|
|
8
9
|
import { createHash } from "node:crypto";
|
|
9
|
-
import {
|
|
10
|
+
import { execFileSync } from "node:child_process";
|
|
11
|
+
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
10
12
|
import { tmpdir } from "node:os";
|
|
11
13
|
import { join } from "node:path";
|
|
12
14
|
import { createRedactor } from "./publish-credentials";
|
|
13
15
|
import { PublishDeclarationSchema } from "./publish-declaration";
|
|
16
|
+
import { githubSshHost } from "./publish-git-ssh";
|
|
14
17
|
import { fillUrl, releaseVersion, renderFormula } from "./publish-homebrew";
|
|
15
18
|
import { createPublishTargets } from "./publish-targets";
|
|
16
19
|
import { PublishTargetError, type PublishContext } from "./release-publish";
|
|
@@ -177,3 +180,179 @@ describe("homebrew tap (#4676)", () => {
|
|
|
177
180
|
expect(renderFormula('version "{{ version }}" # #{bin}', { version: "1.0", label: "v1.0", tag: "t" }, new Map())).toBe('version "1.0" # #{bin}');
|
|
178
181
|
});
|
|
179
182
|
});
|
|
183
|
+
|
|
184
|
+
describe("homebrew tap over SSH with a deploy key (#4699)", () => {
|
|
185
|
+
const KEY = "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAAfakedeploykeymaterial\n-----END OPENSSH PRIVATE KEY-----\n";
|
|
186
|
+
const HOST_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl";
|
|
187
|
+
const git = (cwd: string, args: string[]) =>
|
|
188
|
+
execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@example.com", "-c", "commit.gpgsign=false", ...args], { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
189
|
+
|
|
190
|
+
/** A bare tap under `root`, as `git@github.com:<repo>.git` reaches it through the fake ssh, with one commit on main. */
|
|
191
|
+
function bareTap(files: Record<string, string>) {
|
|
192
|
+
const root = mkdtempSync(join(tmpdir(), "chant-tap-ssh-"));
|
|
193
|
+
dirs.push(root);
|
|
194
|
+
const bare = join(root, "arugula-salad", "homebrew-tap.git");
|
|
195
|
+
mkdirSync(bare, { recursive: true });
|
|
196
|
+
git(bare, ["init", "-q", "--bare", "-b", "main"]);
|
|
197
|
+
const work = join(root, "work");
|
|
198
|
+
mkdirSync(work);
|
|
199
|
+
git(work, ["init", "-q", "-b", "main"]);
|
|
200
|
+
const commit = (message: string, more: Record<string, string>) => {
|
|
201
|
+
for (const [p, text] of Object.entries(more)) {
|
|
202
|
+
mkdirSync(join(work, p, ".."), { recursive: true });
|
|
203
|
+
writeFileSync(join(work, p), text);
|
|
204
|
+
}
|
|
205
|
+
git(work, ["add", "-A"]);
|
|
206
|
+
git(work, ["commit", "-q", "-m", message]);
|
|
207
|
+
git(work, ["push", "-q", bare, "HEAD:refs/heads/main"]);
|
|
208
|
+
};
|
|
209
|
+
commit("init", files);
|
|
210
|
+
return {
|
|
211
|
+
root,
|
|
212
|
+
bare,
|
|
213
|
+
push: (more: Record<string, string>) => commit("someone else", more),
|
|
214
|
+
log: (branch: string) => git(bare, ["log", "--format=%s", branch]).split("\n").reverse(),
|
|
215
|
+
read: (branch: string, path: string) => git(bare, ["show", `${branch}:${path}`]) + "\n",
|
|
216
|
+
head: (branch: string) => git(bare, ["rev-parse", branch]),
|
|
217
|
+
branches: () => git(bare, ["for-each-ref", "--format=%(refname:short)", "refs/heads"]).split("\n").filter(Boolean),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* An ssh that serves the bare taps under `root` when it is handed `KEY`
|
|
223
|
+
* and a known-hosts file holding `HOST_KEY` for the host, and logs each
|
|
224
|
+
* call's host and options.
|
|
225
|
+
*/
|
|
226
|
+
function fakeSsh(root: string) {
|
|
227
|
+
const bin = join(root, "ssh");
|
|
228
|
+
const log = join(root, "ssh.log");
|
|
229
|
+
writeFileSync(
|
|
230
|
+
bin,
|
|
231
|
+
`#!${process.execPath}
|
|
232
|
+
const fs = require("fs");
|
|
233
|
+
const { spawnSync } = require("child_process");
|
|
234
|
+
const args = process.argv.slice(2);
|
|
235
|
+
const opts = [];
|
|
236
|
+
let key = "";
|
|
237
|
+
for (let i = 0; i < args.length - 2; i++) {
|
|
238
|
+
if (args[i] === "-o") opts.push(args[++i]);
|
|
239
|
+
else if (args[i] === "-i") key = fs.readFileSync(args[++i], "utf-8");
|
|
240
|
+
else if (args[i] === "-F") i++;
|
|
241
|
+
}
|
|
242
|
+
const host = args[args.length - 2].replace(/^git@/, "");
|
|
243
|
+
const known = opts.find((o) => o.startsWith("UserKnownHostsFile="));
|
|
244
|
+
const hosts = known ? fs.readFileSync(known.slice("UserKnownHostsFile=".length), "utf-8") : "";
|
|
245
|
+
fs.appendFileSync(${JSON.stringify(log)}, JSON.stringify({ host, opts, mode: (fs.statSync(args[args.indexOf("-i") + 1]).mode & 0o777).toString(8) }) + "\\n");
|
|
246
|
+
if (!opts.includes("StrictHostKeyChecking=yes") || !hosts.split("\\n").includes(host + " " + ${JSON.stringify(HOST_KEY)})) { console.error("Host key verification failed."); process.exit(255); }
|
|
247
|
+
if (key !== ${JSON.stringify(KEY)}) { console.error("git@" + host + ": Permission denied (publickey)."); process.exit(255); }
|
|
248
|
+
const cmd = args[args.length - 1].replace(/'([^']+\\.git)'/, (_, p) => "'" + ${JSON.stringify(root)} + "/" + p + "'");
|
|
249
|
+
const r = spawnSync("sh", ["-c", cmd], { stdio: "inherit" });
|
|
250
|
+
process.exit(r.status === null ? 1 : r.status);
|
|
251
|
+
`,
|
|
252
|
+
);
|
|
253
|
+
chmodSync(bin, 0o755);
|
|
254
|
+
const calls = () => (existsSync(log) ? readFileSync(log, "utf-8").trim().split("\n").filter(Boolean).map((l) => JSON.parse(l) as { host: string; opts: string[]; mode: string }) : []);
|
|
255
|
+
return { bin, calls };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** The API's /meta, which lists the host keys; nothing else is asked of it. */
|
|
259
|
+
function fakeMeta(keys: string[] = [HOST_KEY]) {
|
|
260
|
+
const calls: Array<{ url: string; headers: Record<string, string> }> = [];
|
|
261
|
+
const fetch = async (url: string, init: { method: string; headers: Record<string, string> }) => {
|
|
262
|
+
calls.push({ url, headers: init.headers });
|
|
263
|
+
const body = url === `${API}/meta` ? JSON.stringify({ ssh_keys: keys }) : "";
|
|
264
|
+
return { ok: body !== "", status: body ? 200 : 404, headers: { get: () => null }, text: async () => body };
|
|
265
|
+
};
|
|
266
|
+
return { fetch, calls };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const sshCtx = (dir: string, env: NodeJS.ProcessEnv = { HOMEBREW_TAP_KEY: KEY, PATH: process.env.PATH }) => context(dir, { env });
|
|
270
|
+
|
|
271
|
+
test("stages the formula on a branch over SSH, and fast-forwards the tap branch at the reveal, with no token", async () => {
|
|
272
|
+
const dir = member();
|
|
273
|
+
const tap = bareTap({ "Formula/arugula.rb": "old formula\n", "README.md": "tap\n" });
|
|
274
|
+
const ssh = fakeSsh(tap.root);
|
|
275
|
+
const meta = fakeMeta();
|
|
276
|
+
const [target] = await createPublishTargets([declaration({ sshKeyEnv: "HOMEBREW_TAP_KEY" })], { fetch: meta.fetch, ssh: ssh.bin });
|
|
277
|
+
expect(target!.credentialEnv).toEqual(["HOMEBREW_TAP_KEY"]);
|
|
278
|
+
const ctx = sshCtx(dir);
|
|
279
|
+
await target!.plan(ctx);
|
|
280
|
+
expect(ssh.calls()).toEqual([]);
|
|
281
|
+
|
|
282
|
+
const main = tap.head("main");
|
|
283
|
+
const staged = await target!.stage(ctx);
|
|
284
|
+
expect(staged.state).toMatchObject({ branch: "main", staging: "chant-publish/arugula-1.4.0" });
|
|
285
|
+
expect(staged.state.commit).toBe(tap.head("chant-publish/arugula-1.4.0"));
|
|
286
|
+
expect(tap.head("main")).toBe(main);
|
|
287
|
+
expect(tap.read("main", "Formula/arugula.rb")).toBe("old formula\n");
|
|
288
|
+
expect(tap.read("chant-publish/arugula-1.4.0", "Formula/arugula.rb")).toContain('version "1.4.0"');
|
|
289
|
+
expect(new Set(ssh.calls().map((c) => c.host))).toEqual(new Set(["api.github.test"]));
|
|
290
|
+
expect(ssh.calls()[0]!.opts).toEqual(expect.arrayContaining(["IdentitiesOnly=yes", "StrictHostKeyChecking=yes", "BatchMode=yes"]));
|
|
291
|
+
expect(ssh.calls()[0]!.mode).toBe("600");
|
|
292
|
+
// The API is asked for the host keys only, without a token.
|
|
293
|
+
expect(meta.calls.map((c) => c.url)).toEqual([`${API}/meta`]);
|
|
294
|
+
expect(meta.calls[0]!.headers.authorization).toBeUndefined();
|
|
295
|
+
|
|
296
|
+
// A stage run again finds the staging branch holding the formula and pushes nothing.
|
|
297
|
+
const again = await target!.stage(ctx);
|
|
298
|
+
expect(again.state).toEqual(staged.state);
|
|
299
|
+
expect(tap.log("chant-publish/arugula-1.4.0")).toEqual(["init", "arugula 1.4.0"]);
|
|
300
|
+
|
|
301
|
+
// The reveal is a fast-forward to the staged commit, from a session of its own, as on a fresh clone.
|
|
302
|
+
await target!.reveal(ctx, staged);
|
|
303
|
+
expect(tap.head("main")).toBe(staged.state.commit);
|
|
304
|
+
expect(tap.log("main")).toEqual(["init", "arugula 1.4.0"]);
|
|
305
|
+
expect(tap.read("main", "README.md")).toBe("tap\n");
|
|
306
|
+
expect(tap.branches()).toEqual(["main"]);
|
|
307
|
+
expect(ctx.lines.join("\n")).not.toContain("fakedeploykeymaterial");
|
|
308
|
+
|
|
309
|
+
const done = await target!.stage(ctx);
|
|
310
|
+
expect(done.state).toEqual({ branch: "main", present: "true" });
|
|
311
|
+
expect(await target!.reveal(ctx, done)).toMatchObject({ items: [{ present: true }] });
|
|
312
|
+
expect(tap.log("main")).toEqual(["init", "arugula 1.4.0"]);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test("a tap branch that moved since the stage gets the formula as one commit on top", async () => {
|
|
316
|
+
const dir = member();
|
|
317
|
+
const tap = bareTap({ "Formula/arugula.rb": "old formula\n" });
|
|
318
|
+
const [target] = await createPublishTargets([declaration({ sshKeyEnv: "HOMEBREW_TAP_KEY", branch: "main" })], { fetch: fakeMeta().fetch, ssh: fakeSsh(tap.root).bin });
|
|
319
|
+
const ctx = sshCtx(dir);
|
|
320
|
+
const staged = await target!.stage(ctx);
|
|
321
|
+
tap.push({ "Formula/other.rb": "other\n" });
|
|
322
|
+
await target!.reveal(ctx, staged);
|
|
323
|
+
expect(tap.log("main")).toEqual(["init", "someone else", "arugula 1.4.0"]);
|
|
324
|
+
expect(tap.read("main", "Formula/other.rb")).toBe("other\n");
|
|
325
|
+
expect(tap.read("main", "Formula/arugula.rb")).toContain('version "1.4.0"');
|
|
326
|
+
expect(tap.branches()).toEqual(["main"]);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
test("refuses a missing key, a key beside a token, a key the remote refuses, and a host whose key the API doesn't list", async () => {
|
|
330
|
+
const dir = member();
|
|
331
|
+
const tap = bareTap({ "Formula/arugula.rb": "old formula\n" });
|
|
332
|
+
const ssh = fakeSsh(tap.root);
|
|
333
|
+
const make = async (fetch = fakeMeta().fetch) => (await createPublishTargets([declaration({ sshKeyEnv: "HOMEBREW_TAP_KEY" })], { fetch, ssh: ssh.bin }))[0]!;
|
|
334
|
+
|
|
335
|
+
const missing = await refused((await make()).plan(sshCtx(dir, { HOMEBREW_TAP_TOKEN: "ghp_not_read" })));
|
|
336
|
+
expect(missing.code).toBe("publish-credentials-missing");
|
|
337
|
+
expect(missing.message).toContain("SSH key from HOMEBREW_TAP_KEY");
|
|
338
|
+
|
|
339
|
+
expect((await refused(createPublishTargets([declaration({ sshKeyEnv: "HOMEBREW_TAP_KEY", tokenEnv: "HOMEBREW_TAP_TOKEN" })]))).code).toBe("publish-homebrew-auth-invalid");
|
|
340
|
+
|
|
341
|
+
const wrongKey = await refused((await make()).stage(sshCtx(dir, { HOMEBREW_TAP_KEY: KEY.replace("fake", "other"), PATH: process.env.PATH })));
|
|
342
|
+
expect(wrongKey.code).toBe("publish-homebrew-failed");
|
|
343
|
+
expect(wrongKey.message).toContain("Permission denied (publickey)");
|
|
344
|
+
expect(wrongKey.message).not.toContain("otherdeploykeymaterial");
|
|
345
|
+
|
|
346
|
+
const otherHost = await refused((await make(fakeMeta(["ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIsomeoneelse"]).fetch)).stage(sshCtx(dir)));
|
|
347
|
+
expect(otherHost.message).toContain("Host key verification failed");
|
|
348
|
+
|
|
349
|
+
const noMeta = await refused((await make(fakeMeta([]).fetch)).stage(sshCtx(dir)));
|
|
350
|
+
expect(noMeta.message).toContain("gave no SSH host keys");
|
|
351
|
+
expect(tap.branches()).toEqual(["main"]);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test("the SSH host is github.com for api.github.com and the API's own host for GitHub Enterprise Server", () => {
|
|
355
|
+
expect(githubSshHost("https://api.github.com")).toBe("github.com");
|
|
356
|
+
expect(githubSshHost("https://ghe.acme.test/api/v3")).toBe("ghe.acme.test");
|
|
357
|
+
});
|
|
358
|
+
});
|