@intentius/chant 0.124.63 → 0.124.65
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 +101 -16
- package/dist/cli/handlers/run.d.ts +30 -1
- package/dist/cli/handlers/run.d.ts.map +1 -1
- package/dist/cli/handlers/run.js +108 -7
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +34 -7
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +19 -0
- package/dist/cli/registry.d.ts +10 -2
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/components/cli-support.d.ts +19 -1
- package/dist/components/cli-support.d.ts.map +1 -1
- package/dist/components/cli-support.js +11 -3
- package/dist/components/component.d.ts +19 -0
- package/dist/components/component.d.ts.map +1 -1
- package/dist/components/component.schema.json +17 -0
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/release-run.d.ts +48 -0
- package/dist/components/release-run.d.ts.map +1 -0
- package/dist/components/release-run.js +166 -0
- package/dist/components/starter-plugin.d.ts +1 -0
- package/dist/components/starter-plugin.d.ts.map +1 -1
- package/dist/components/starter-plugin.js +5 -1
- package/dist/components/unchanged-inputs.d.ts +81 -0
- package/dist/components/unchanged-inputs.d.ts.map +1 -0
- package/dist/components/unchanged-inputs.js +122 -0
- package/dist/components/verbs/index.d.ts +1 -0
- package/dist/components/verbs/index.d.ts.map +1 -1
- package/dist/components/verbs/index.js +1 -0
- package/dist/components/verbs/release-image.d.ts +36 -0
- package/dist/components/verbs/release-image.d.ts.map +1 -0
- package/dist/components/verbs/release-image.js +33 -0
- 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/delivery-metrics.d.ts.map +1 -1
- package/dist/lifecycle/delivery-metrics.js +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 -2
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +6 -1
- package/dist/lifecycle/ledger-read.js +1 -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 -5
- 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 -30
- package/dist/lifecycle/publish-tauri.d.ts.map +1 -1
- package/dist/lifecycle/publish-tauri.js +1 -2
- package/dist/lifecycle/query.d.ts +2 -2
- package/dist/lifecycle/query.d.ts.map +1 -1
- package/dist/lifecycle/query.js +3 -3
- package/dist/lifecycle/release-cut.d.ts +82 -6
- package/dist/lifecycle/release-cut.d.ts.map +1 -1
- package/dist/lifecycle/release-cut.js +209 -20
- package/dist/lifecycle/release-ledger.d.ts +11 -0
- package/dist/lifecycle/release-ledger.d.ts.map +1 -1
- 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 +49 -3
- package/dist/lifecycle/release-store.d.ts.map +1 -1
- package/dist/lifecycle/release-store.js +22 -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/op/op-waves-run.js +5 -3
- 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/delivery-metrics.schema.json +1 -1
- 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 -5
- package/dist/workspace/release-candidates.schema.json +7 -0
- package/dist/workspace/releases.schema.json +54 -2
- 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 +91 -16
- package/src/cli/handlers/run-unchanged.e2e.test.ts +112 -0
- package/src/cli/handlers/run.ts +117 -7
- package/src/cli/main.ts +34 -7
- package/src/cli/parse-args.ts +15 -0
- package/src/cli/registry.ts +10 -2
- package/src/components/cli-support.test.ts +53 -0
- package/src/components/cli-support.ts +26 -4
- package/src/components/component.schema.json +17 -0
- package/src/components/component.ts +20 -0
- package/src/components/index.ts +1 -0
- package/src/components/registry.test.ts +1 -1
- package/src/components/release-run.test.ts +127 -0
- package/src/components/release-run.ts +188 -0
- package/src/components/starter-plugin.ts +5 -0
- package/src/components/unchanged-inputs.test.ts +98 -0
- package/src/components/unchanged-inputs.ts +151 -0
- package/src/components/verbs/index.ts +1 -0
- package/src/components/verbs/release-image.ts +52 -0
- package/src/config.ts +8 -0
- package/src/gate-statement.schema.json +4 -2
- package/src/lifecycle/delivery-metrics.ts +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 -4
- package/src/lifecycle/git.test.ts +15 -0
- package/src/lifecycle/git.ts +5 -1
- package/src/lifecycle/ledger-read.ts +1 -1
- 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 -6
- package/src/lifecycle/publish-marketplace.test.ts +158 -6
- package/src/lifecycle/publish-marketplace.ts +192 -31
- package/src/lifecycle/publish-resume.test.ts +40 -0
- package/src/lifecycle/publish-tauri.ts +1 -2
- package/src/lifecycle/query.ts +3 -3
- package/src/lifecycle/release-cut-lane.test.ts +195 -0
- package/src/lifecycle/release-cut-override.test.ts +225 -0
- package/src/lifecycle/release-cut.test.ts +45 -0
- package/src/lifecycle/release-cut.ts +262 -21
- package/src/lifecycle/release-ledger.ts +11 -0
- package/src/lifecycle/release-publish.ts +18 -0
- package/src/lifecycle/release-revocation.ts +5 -4
- package/src/lifecycle/release-store.ts +73 -5
- package/src/op/gate.ts +2 -1
- package/src/op/op-waves-run.ts +4 -2
- 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/delivery-metrics.schema.json +1 -1
- package/src/workspace/delivery-metrics.test.ts +8 -0
- package/src/workspace/intent.ts +1 -2
- package/src/workspace/release-candidates.schema.json +7 -0
- package/src/workspace/release-candidates.ts +19 -5
- package/src/workspace/releases.schema.json +54 -2
- package/src/workspace/trust/gate-seal.test.ts +44 -0
package/src/config.ts
CHANGED
|
@@ -109,6 +109,7 @@ export const ChantConfigSchema = z.object({
|
|
|
109
109
|
release: z.object({
|
|
110
110
|
autoRecord: z.boolean().optional(),
|
|
111
111
|
publish: z.array(PublishDeclarationSchema).optional(),
|
|
112
|
+
lane: z.string().regex(/^[a-z0-9][a-z0-9-]*$/, "a ci.green lane name: lowercase letters, digits and dashes").optional(),
|
|
112
113
|
}).optional(),
|
|
113
114
|
// Strict: a misspelt key here would leave Ops on the local runtime with
|
|
114
115
|
// nothing said (#2523).
|
|
@@ -371,6 +372,13 @@ export interface ChantConfig {
|
|
|
371
372
|
* the order given. See ./lifecycle/publish-declaration.ts.
|
|
372
373
|
*/
|
|
373
374
|
publish?: PublishDeclaration[];
|
|
375
|
+
/**
|
|
376
|
+
* The green lane `chant release cut` and `chant release candidates` check
|
|
377
|
+
* when `--lane` is not given (#4692): one `ci.green.lanes` declares in
|
|
378
|
+
* chant.workspace.json. The commit must then carry `ci/green-<lane>/<sha>`
|
|
379
|
+
* rather than `ci/green/<sha>`.
|
|
380
|
+
*/
|
|
381
|
+
lane?: string;
|
|
374
382
|
};
|
|
375
383
|
|
|
376
384
|
/** Defaults for `chant run` and its subcommands (#2523). */
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
3
|
"$id": "https://intentius.io/chant/schemas/gate-statement/v1/gate-statement.schema.json",
|
|
4
4
|
"title": "chant-gate-statement/v1",
|
|
5
|
-
"description": "What `chant approve <op> <gate> --statement` prints (#4646): the exact bytes an approval of the gate signs, for a signature made outside chant. Sign `statement` (the bytes of `text`) with an ssh key in the `chant-gate` namespace, or with a passkey whose WebAuthn challenge is `challenge`, then record it with `chant approve <op> <gate> --actor <resolvedBy> --at <timestamp> --signature <file>`, passing the same `--relayed-by`, `--plan` and `--
|
|
5
|
+
"description": "What `chant approve <op> <gate> --statement` prints (#4646): the exact bytes an approval of the gate signs, for a signature made outside chant. Sign `statement` (the bytes of `text`) with an ssh key in the `chant-gate` namespace, or with a passkey whose WebAuthn challenge is `challenge`, then record it with `chant approve <op> <gate> --actor <resolvedBy> --at <timestamp> --signature <file>`, passing the same `--relayed-by`, `--plan`, `--env` and `--binding`. Written by chant 0.124.63 and newer. Readers ignore fields they do not know; a field is only ever added within a version.",
|
|
6
6
|
"type": "object",
|
|
7
7
|
"required": [
|
|
8
8
|
"schema",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"relayedBy",
|
|
16
16
|
"timestamp",
|
|
17
17
|
"checkpointDigest",
|
|
18
|
+
"binding",
|
|
18
19
|
"sealVersion",
|
|
19
20
|
"namespace",
|
|
20
21
|
"text",
|
|
@@ -33,7 +34,8 @@
|
|
|
33
34
|
"relayedBy": { "type": ["string", "null"], "description": "Who relays the approval (--relayed-by). When not null the statement has a `relayed-by <principal>` line after the time." },
|
|
34
35
|
"timestamp": { "type": "string", "description": "The approval's time, ISO 8601 UTC with milliseconds. The sixth line. Pass it as --at when recording the signature." },
|
|
35
36
|
"checkpointDigest": { "type": ["string", "null"], "description": "The checkpoint a resumed run carries its outputs from. When not null the statement ends with a `checkpoint <digest>` line." },
|
|
36
|
-
"
|
|
37
|
+
"binding": { "type": ["string", "null"], "maxLength": 512, "description": "A line the relay set with --binding (#4697) for the signature to cover as well, such as its deploy id and an expiry: one line of printable text, at most 512 UTF-8 bytes, which chant records with the approval and does not interpret. When not null the statement ends with a `binding <text>` line, after any checkpoint line." },
|
|
38
|
+
"sealVersion": { "enum": [1, 2, 3], "description": "3 when the statement signs a binding, else 2 when it signs a checkpoint digest, else 1." },
|
|
37
39
|
"namespace": { "const": "chant-gate", "description": "The ssh signature namespace (`ssh-keygen -Y sign -n chant-gate`)." },
|
|
38
40
|
"text": { "type": "string", "description": "The statement as UTF-8 text: the lines joined by LF, no final newline." },
|
|
39
41
|
"statement": { "type": "string", "contentEncoding": "base64", "description": "The same bytes, base64. These are what is signed." },
|
|
@@ -169,8 +169,10 @@ export function environmentMetrics(
|
|
|
169
169
|
window: MetricsWindow,
|
|
170
170
|
failureWindowDays: number = DEFAULT_FAILURE_WINDOW_DAYS,
|
|
171
171
|
): EnvironmentMetrics {
|
|
172
|
-
// Ledger order breaks timestamp ties, as `latestPerComponent` does.
|
|
173
|
-
|
|
172
|
+
// Ledger order breaks timestamp ties, as `latestPerComponent` does. A
|
|
173
|
+
// release that skipped a component (#4695) deployed nothing: its record is
|
|
174
|
+
// in no metric.
|
|
175
|
+
const sorted = records.filter((r) => r.unchangedSince === undefined).map((r, i) => ({ r, i })).sort((a, b) => at(a.r.timestamp) - at(b.r.timestamp) || a.i - b.i).map((x) => x.r);
|
|
174
176
|
const since = at(window.since);
|
|
175
177
|
const until = at(window.until);
|
|
176
178
|
const failureMs = failureWindowDays * DAY_MS;
|
|
@@ -161,6 +161,14 @@ export interface GateResolutionRecord {
|
|
|
161
161
|
* resumes (`resume: true`) whose run stored a checkpoint. A seal covers it.
|
|
162
162
|
*/
|
|
163
163
|
checkpointDigest?: string;
|
|
164
|
+
/**
|
|
165
|
+
* The line the relay set for the approver's signature to bind as well
|
|
166
|
+
* (#4697, `chant approve --binding`), such as a platform's deploy id and
|
|
167
|
+
* an expiry. Printable text on one line; chant reads nothing in it. Set
|
|
168
|
+
* only on an approval signed with --sign or --signature, whose seal (version
|
|
169
|
+
* 3) signs it.
|
|
170
|
+
*/
|
|
171
|
+
binding?: string;
|
|
164
172
|
/**
|
|
165
173
|
* The environment this approval is for (#2574), copied off the pending fact
|
|
166
174
|
* it answers. Set for a component gate, whose ledger is keyed by component
|
|
@@ -313,9 +321,10 @@ export interface GateApprovalSeal {
|
|
|
313
321
|
/**
|
|
314
322
|
* The seal's version (#3947). `2` on a seal over an approval that carries a
|
|
315
323
|
* `checkpointDigest`, whose payload signs the digest as one more line.
|
|
316
|
-
*
|
|
324
|
+
* `3` on a seal over an approval with a `binding` (#4697), which signs one
|
|
325
|
+
* more line after that. Absent on every other seal, which is version 1.
|
|
317
326
|
*/
|
|
318
|
-
version?: 2;
|
|
327
|
+
version?: 2 | 3;
|
|
319
328
|
}
|
|
320
329
|
|
|
321
330
|
export type GateResolutionInput = Omit<GateResolutionRecord, "version" | "kind">;
|
|
@@ -638,6 +647,12 @@ export function parseGateLedger(
|
|
|
638
647
|
malformed++;
|
|
639
648
|
continue;
|
|
640
649
|
}
|
|
650
|
+
// #4697: and for the binding a seal signs. A line break would make the statement's lines ambiguous.
|
|
651
|
+
const rawBinding: unknown = (parsed as { binding?: unknown }).binding;
|
|
652
|
+
if (rawBinding !== undefined && (typeof rawBinding !== "string" || /[\r\n\u2028\u2029]/.test(rawBinding))) {
|
|
653
|
+
malformed++;
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
641
656
|
// #4020: a commit or run id of the wrong type is dropped, so a reader can trust the type without losing the line.
|
|
642
657
|
// #4551: and so is a `changeSet` that is not a digest.
|
|
643
658
|
for (const key of ["gitSha", "runId", "changeSet"] as const) {
|
|
@@ -42,6 +42,12 @@ export interface SealedGateApproval {
|
|
|
42
42
|
timestamp: string;
|
|
43
43
|
/** The checkpoint the approval lets a run resume from (#3947), when it carries one. */
|
|
44
44
|
checkpointDigest?: string;
|
|
45
|
+
/**
|
|
46
|
+
* A line the relay set for the signature to bind as well (#4697), such as
|
|
47
|
+
* a platform's deploy id and an expiry. chant doesn't read it; the seal
|
|
48
|
+
* signs it. A carried approval keeps the original's.
|
|
49
|
+
*/
|
|
50
|
+
binding?: string;
|
|
45
51
|
/** The line a carried approval came from (#3949): the names and time its seal was made under. */
|
|
46
52
|
carriedFrom?: { op: string; gate: string; timestamp: string; checkpointDigest?: string };
|
|
47
53
|
seal?: unknown;
|
|
@@ -67,11 +73,14 @@ export function sealedFieldsOf(a: SealedGateApproval): SealedGateApproval {
|
|
|
67
73
|
}
|
|
68
74
|
|
|
69
75
|
/**
|
|
70
|
-
* The version of a seal over `a` (#3947):
|
|
71
|
-
*
|
|
72
|
-
*
|
|
76
|
+
* The version of a seal over `a` (#3947): 3 when the approval carries a
|
|
77
|
+
* relay's binding (#4697), 2 when it carries a checkpoint digest and no
|
|
78
|
+
* binding, and 1 otherwise. Each signs the lines of the one before plus its
|
|
79
|
+
* own. `chant approve --sign` and `--signature` record 2 and 3 on the seal; a
|
|
80
|
+
* seal records no version for 1.
|
|
73
81
|
*/
|
|
74
|
-
export function gateSealVersion(a: Pick<SealedGateApproval, "checkpointDigest" | "carriedFrom">): 1 | 2 {
|
|
82
|
+
export function gateSealVersion(a: Pick<SealedGateApproval, "checkpointDigest" | "carriedFrom" | "binding">): 1 | 2 | 3 {
|
|
83
|
+
if (a.binding !== undefined) return 3;
|
|
75
84
|
const checkpoint = a.carriedFrom !== undefined ? a.carriedFrom.checkpointDigest : a.checkpointDigest;
|
|
76
85
|
return checkpoint !== undefined ? 2 : 1;
|
|
77
86
|
}
|
|
@@ -91,14 +100,23 @@ export function gateSealVersion(a: Pick<SealedGateApproval, "checkpointDigest" |
|
|
|
91
100
|
* then covered by the seal too, and removing or swapping the digest stops it
|
|
92
101
|
* verifying. An approval with none signs what a version 1 seal signed.
|
|
93
102
|
*
|
|
103
|
+
* Seal version 3 (#4697) adds a binding line the relay set, `binding
|
|
104
|
+
* <text>`, after everything else, checkpoint included. A platform puts what
|
|
105
|
+
* it needs the person's signature to cover there too (a deploy id and an
|
|
106
|
+
* expiry); chant records and checks it and reads nothing in it. An approval
|
|
107
|
+
* with no binding signs what a version 1 or 2 seal signed, so those still
|
|
108
|
+
* verify, and an older chant, which leaves the line out, finds a version 3
|
|
109
|
+
* seal doesn't verify and counts nothing for it.
|
|
110
|
+
*
|
|
94
111
|
* A carried approval (#3949) signs what the line it came from signed: see
|
|
95
112
|
* {@link sealedFieldsOf}.
|
|
96
113
|
*/
|
|
97
114
|
export function gateSealPayload(approval: SealedGateApproval): Buffer {
|
|
98
115
|
const a = sealedFieldsOf(approval);
|
|
99
116
|
const relay = a.relayedBy !== undefined ? `\nrelayed-by ${a.relayedBy}` : "";
|
|
100
|
-
const checkpoint =
|
|
101
|
-
|
|
117
|
+
const checkpoint = a.checkpointDigest !== undefined ? `\ncheckpoint ${a.checkpointDigest}` : "";
|
|
118
|
+
const binding = a.binding !== undefined ? `\nbinding ${a.binding}` : "";
|
|
119
|
+
return Buffer.from(`${a.op}\n${a.gate}\n${a.environment ?? ""}\n${a.planDigest ?? ""}\n${a.resolvedBy}\n${a.timestamp}${relay}${checkpoint}${binding}`, "utf-8");
|
|
102
120
|
}
|
|
103
121
|
|
|
104
122
|
// ── SSHSIG ───────────────────────────────────────────────────────────────
|
|
@@ -10,10 +10,15 @@
|
|
|
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";
|
|
16
|
-
import { NEXT_RELEASE } from "../release-floors";
|
|
17
22
|
import { GATE_SEAL_NAMESPACE, gateSealPayload, gateSealVersion, isWebAuthnAssertion, webAuthnChallenge, type SealedGateApproval, type WebAuthnAssertion } from "./gate-seal";
|
|
18
23
|
|
|
19
24
|
/**
|
|
@@ -23,7 +28,35 @@ import { GATE_SEAL_NAMESPACE, gateSealPayload, gateSealVersion, isWebAuthnAssert
|
|
|
23
28
|
* older chant reads a trust.json with `passkeys` as invalid, which turns
|
|
24
29
|
* attestation off, and counts no passkey seal toward a gate.
|
|
25
30
|
*/
|
|
26
|
-
export const GATE_EXTERNAL_SIGNATURE_FLOOR =
|
|
31
|
+
export const GATE_EXTERNAL_SIGNATURE_FLOOR = "0.124.63";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The first chant that takes `--binding` and signs and checks a binding line
|
|
35
|
+
* (seal version 3, #4697). An older chant leaves the line out of what it
|
|
36
|
+
* checks, so it finds a version 3 seal doesn't verify and counts nothing for
|
|
37
|
+
* it, whatever the gate.
|
|
38
|
+
*/
|
|
39
|
+
export const GATE_BINDING_FLOOR = "0.124.64";
|
|
40
|
+
|
|
41
|
+
/** The longest binding `--binding` takes, in UTF-8 bytes (#4697). */
|
|
42
|
+
export const GATE_BINDING_MAX_BYTES = 512;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Why `text` can't be a gate statement's binding line (#4697), or null when
|
|
46
|
+
* it can: it must be non-empty, at most {@link GATE_BINDING_MAX_BYTES} UTF-8
|
|
47
|
+
* bytes, with no leading or trailing space, and printable on one line, so no
|
|
48
|
+
* control or format character (bidi overrides among them), line or paragraph
|
|
49
|
+
* separator, unassigned code point or lone surrogate.
|
|
50
|
+
*/
|
|
51
|
+
export function gateBindingProblem(text: string): string | null {
|
|
52
|
+
if (text === "") return "it is empty";
|
|
53
|
+
const bytes = Buffer.byteLength(text, "utf-8");
|
|
54
|
+
if (bytes > GATE_BINDING_MAX_BYTES) return `it is ${bytes} bytes, and the most is ${GATE_BINDING_MAX_BYTES}`;
|
|
55
|
+
if (text.trim() !== text) return "it starts or ends with white space";
|
|
56
|
+
const bad = /[\p{C}\p{Zl}\p{Zp}]/u.exec(text);
|
|
57
|
+
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`;
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
27
60
|
|
|
28
61
|
export const GATE_STATEMENT_SCHEMA = "chant-gate-statement/v1";
|
|
29
62
|
|
|
@@ -42,8 +75,10 @@ export interface GateStatement {
|
|
|
42
75
|
relayedBy: string | null;
|
|
43
76
|
timestamp: string;
|
|
44
77
|
checkpointDigest: string | null;
|
|
45
|
-
/**
|
|
46
|
-
|
|
78
|
+
/** The relay's binding line (#4697, `--binding`), or null. When set the statement ends with `binding <text>`. */
|
|
79
|
+
binding: string | null;
|
|
80
|
+
/** 3 when the statement signs a binding, else 2 when it signs a checkpoint digest, else 1. */
|
|
81
|
+
sealVersion: 1 | 2 | 3;
|
|
47
82
|
/** The ssh signature namespace an ssh key signs the statement in. */
|
|
48
83
|
namespace: typeof GATE_SEAL_NAMESPACE;
|
|
49
84
|
/** The statement's UTF-8 text, LF-joined with no final newline. */
|
|
@@ -70,6 +105,7 @@ export function gateStatement(a: SealedGateApproval, chantVersion: string): Gate
|
|
|
70
105
|
relayedBy: a.relayedBy ?? null,
|
|
71
106
|
timestamp: a.timestamp,
|
|
72
107
|
checkpointDigest: a.checkpointDigest ?? null,
|
|
108
|
+
binding: a.binding ?? null,
|
|
73
109
|
sealVersion: gateSealVersion(a),
|
|
74
110
|
namespace: GATE_SEAL_NAMESPACE,
|
|
75
111
|
text: bytes.toString("utf-8"),
|
|
@@ -587,6 +587,21 @@ describe("lifecycle/git", () => {
|
|
|
587
587
|
}
|
|
588
588
|
});
|
|
589
589
|
|
|
590
|
+
test("a change set the other writer stored under the same digest stays as it is there, and the rest of the commit lands", async () => {
|
|
591
|
+
const { a, b, remotePath, done } = await twoWriters();
|
|
592
|
+
try {
|
|
593
|
+
await advance(a, "_change-sets/jcs1-sha256_abc.json", '{"digest":"abc","graph":"theirs"}');
|
|
594
|
+
await writeBlobToPath("_change-sets", "jcs1-sha256_abc.json", '{"digest":"abc","graph":"ours"}', "Change set abc", { cwd: b });
|
|
595
|
+
await writeBlobToPath("prod", "release.jsonl", '{"released":1}\n', "Release record", { cwd: b });
|
|
596
|
+
|
|
597
|
+
expect(await pushLifecycleRebasing({ cwd: b })).toEqual({ pushed: true });
|
|
598
|
+
const tip = git(["rev-parse", "refs/heads/chant/lifecycle"], remotePath).stdout.trim();
|
|
599
|
+
expect(git(["show", `${tip}:prod/_change-sets/jcs1-sha256_abc.json`], remotePath).stdout).toBe('{"digest":"abc","graph":"theirs"}');
|
|
600
|
+
} finally {
|
|
601
|
+
await done();
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
|
|
590
605
|
test("a commit that changes the file the other writer changed is refused by name, and the local write is kept", async () => {
|
|
591
606
|
const { a, b, done } = await twoWriters();
|
|
592
607
|
try {
|
package/src/lifecycle/git.ts
CHANGED
|
@@ -1018,7 +1018,9 @@ async function rebaseLifecycleOnRemote(remote: string, cwd?: string): Promise<{
|
|
|
1018
1018
|
* line `onto` already holds. A run record, a release record and a gate line
|
|
1019
1019
|
* are such appends, so two writers to one environment's file no longer lose
|
|
1020
1020
|
* one of them on a replay. Any other change, or a file the commit rewrote
|
|
1021
|
-
* rather than appended to, returns why, and the replay stops as before.
|
|
1021
|
+
* rather than appended to, returns why, and the replay stops as before. A
|
|
1022
|
+
* change set the other writer already stored under the same digest stays as
|
|
1023
|
+
* it is there.
|
|
1022
1024
|
*/
|
|
1023
1025
|
async function replayAppends(parent: string, commit: string, onto: string, cwd?: string): Promise<{ tree: string } | { error: string }> {
|
|
1024
1026
|
const rt = getRuntime();
|
|
@@ -1036,6 +1038,8 @@ async function replayAppends(parent: string, commit: string, onto: string, cwd?:
|
|
|
1036
1038
|
};
|
|
1037
1039
|
const files: Array<{ path: string; content: string }> = [];
|
|
1038
1040
|
for (const { status, path } of changes) {
|
|
1041
|
+
// #4022: a stored change set is written once under its digest, so a copy already there is the same document, whatever graph it carries.
|
|
1042
|
+
if (status === "A" && /(^|\/)_change-sets\/[^/]+\.json$/.test(path) && (await blob(onto, path)) !== null) continue;
|
|
1039
1043
|
if (!path.endsWith(".jsonl") || (status !== "M" && status !== "A")) return { error: `${path} is not a ledger line file this replay appends to` };
|
|
1040
1044
|
const ours = (await blob(commit, path)) ?? "";
|
|
1041
1045
|
const base = status === "M" ? ((await blob(parent, path)) ?? "") : "";
|
|
@@ -47,7 +47,7 @@ export const LEDGER_TIME_COLUMN: Record<QueryTable, string | null> = {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
/** The columns that hold JSON, which this read prints parsed. */
|
|
50
|
-
const JSON_COLUMNS = new Set(["attributes", "labels", "outcomes", "promoted_from", "restores", "redeploys", "artifacts", "wave", "request", "detail", "components", "approvers", "settings", "estates"]);
|
|
50
|
+
const JSON_COLUMNS = new Set(["attributes", "labels", "outcomes", "promoted_from", "restores", "redeploys", "unchanged_since", "artifacts", "wave", "request", "detail", "components", "approvers", "settings", "estates"]);
|
|
51
51
|
/** The columns that hold an ISO instant. */
|
|
52
52
|
const TIME_COLUMNS = new Set(["last_updated", "observed_at", "started", "ended", "timestamp", "expires_at", "approved_at", "finished_at"]);
|
|
53
53
|
/** INTEGER columns that hold 0 or 1, which this read prints as booleans. */
|
|
@@ -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
|
+
}
|