@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
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
* { type: "npm", packages: ["packages/core", "packages/cli"] },
|
|
11
11
|
* { type: "oci", image: "dist/api.oci.tar", repository: "ghcr.io/acme/api", tags: ["{label}"], usernameEnv: "GITHUB_ACTOR", passwordEnv: "GITHUB_TOKEN" },
|
|
12
12
|
* { type: "forge", forge: "github", repo: "acme/api", assets: ["dist/api-linux-amd64.tar.gz"] },
|
|
13
|
+
* { type: "marketplace", marketplace: "openvsx", vsix: "dist/acme.vsix" },
|
|
14
|
+
* { type: "tauri-updater", repo: "acme/app", tag: "app-latest", platforms: { "darwin-aarch64": "dist/Acme_aarch64.app.tar.gz" } },
|
|
15
|
+
* { type: "homebrew", tap: "acme/homebrew-tap", formula: "Formula/api.rb", template: "packaging/api.rb", assets: ["dist/api-linux-amd64.tar.gz"], url: "https://github.com/acme/api/releases/download/{tag}/{name}" },
|
|
13
16
|
* ],
|
|
14
17
|
* },
|
|
15
18
|
* };
|
|
@@ -106,12 +109,124 @@ export const ForgePublishSchema = z
|
|
|
106
109
|
tokenEnv: envName.optional(),
|
|
107
110
|
/** The SBOM attached to the release (#4049), relative to the member. Default: one written from the member's lockfile. `false` publishes without one. */
|
|
108
111
|
sbom: sbomField.optional(),
|
|
112
|
+
/**
|
|
113
|
+
* GitHub only (#4676): whether the release becomes the repository's
|
|
114
|
+
* latest when the reveal publishes it, sent as GitHub's `make_latest`.
|
|
115
|
+
* `"legacy"` lets GitHub pick by creation date and semantic version.
|
|
116
|
+
* Unset, nothing is sent and GitHub makes it latest.
|
|
117
|
+
*/
|
|
118
|
+
latest: z.union([z.boolean(), z.literal("legacy")]).optional(),
|
|
119
|
+
})
|
|
120
|
+
.strict();
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A Homebrew formula in a tap repository on GitHub (#4676), rendered from a
|
|
124
|
+
* template in the member with the release's version and each asset's URL and
|
|
125
|
+
* SHA-256 (./publish-homebrew.ts).
|
|
126
|
+
*/
|
|
127
|
+
export const HomebrewPublishSchema = z
|
|
128
|
+
.object({
|
|
129
|
+
type: z.literal("homebrew"),
|
|
130
|
+
/** The tap's repository, `owner/name`, such as `acme/homebrew-tap`. */
|
|
131
|
+
tap: z.string().regex(/^[^/\s]+\/[^/\s]+$/, "owner/name"),
|
|
132
|
+
/** The formula's path in the tap, such as `Formula/api.rb`. */
|
|
133
|
+
formula: z.string().min(1),
|
|
134
|
+
/** The formula with placeholders, relative to the member: `{{version}}`, `{{label}}`, `{{tag}}`, `{{url:<asset name>}}`, `{{sha256:<asset name>}}`. */
|
|
135
|
+
template: z.string().min(1),
|
|
136
|
+
/** The files the formula downloads, relative to the member. Each is named in the template by its file name. */
|
|
137
|
+
assets: z.array(z.string().min(1)).min(1),
|
|
138
|
+
/** Where each asset is downloaded from: `{tag}`, `{label}`, `{version}` and `{name}` (its file name) are filled in. */
|
|
139
|
+
url: z.string().min(1),
|
|
140
|
+
/** The tap's branch that brew installs from. Default: the repository's default branch. */
|
|
141
|
+
branch: z.string().min(1).optional(),
|
|
142
|
+
/** The GitHub API root. Default `$GITHUB_API_URL`, else `https://api.github.com`. */
|
|
143
|
+
api: z.string().url().optional(),
|
|
144
|
+
/** The variable holding a token that may push to the tap. Default `HOMEBREW_TAP_TOKEN`. */
|
|
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(),
|
|
152
|
+
})
|
|
153
|
+
.strict();
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* A packaged `.vsix` on the VS Code Marketplace or Open VSX (#4676), uploaded
|
|
157
|
+
* at the reveal, since a marketplace has no draft (./publish-marketplace.ts).
|
|
158
|
+
*/
|
|
159
|
+
export const MarketplacePublishSchema = z
|
|
160
|
+
.object({
|
|
161
|
+
type: z.literal("marketplace"),
|
|
162
|
+
marketplace: z.enum(["vscode", "openvsx"]),
|
|
163
|
+
/** The `.vsix` that `vsce package` wrote, relative to the member. Its publisher, name and version are read from it. */
|
|
164
|
+
vsix: z.string().min(1),
|
|
165
|
+
/** Open VSX's root, default `https://open-vsx.org`; the VS Code Marketplace's gallery, default `https://marketplace.visualstudio.com`. */
|
|
166
|
+
registry: z.string().url().optional(),
|
|
167
|
+
/** The variable holding the token, under `auth: "token"`. Default `VSCE_PAT` for the VS Code Marketplace, `OVSX_PAT` for Open VSX. */
|
|
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(),
|
|
186
|
+
})
|
|
187
|
+
.strict();
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* A Tauri v2 updater manifest and the rolling GitHub release that holds it
|
|
191
|
+
* with the app's bundles (#4676), replaced on each publish
|
|
192
|
+
* (./publish-tauri.ts).
|
|
193
|
+
*/
|
|
194
|
+
export const TauriUpdaterPublishSchema = z
|
|
195
|
+
.object({
|
|
196
|
+
type: z.literal("tauri-updater"),
|
|
197
|
+
/** The GitHub repository, `owner/name`. */
|
|
198
|
+
repo: z.string().regex(/^[^/\s]+\/[^/\s]+$/, "owner/name"),
|
|
199
|
+
/** The rolling release's tag, such as `app-latest`. */
|
|
200
|
+
tag: z.string().min(1),
|
|
201
|
+
/**
|
|
202
|
+
* Each updater platform, such as `darwin-aarch64`, `linux-x86_64` or
|
|
203
|
+
* `windows-x86_64-nsis`, and its updater bundle, relative to the member.
|
|
204
|
+
* Its signature is the `.sig` file beside it that the Tauri build wrote.
|
|
205
|
+
*/
|
|
206
|
+
platforms: z.record(z.string().regex(/^(darwin|linux|windows)-[a-z0-9_]+(-[a-z0-9]+)?$/, "<os>-<arch> or <os>-<arch>-<installer>"), z.string().min(1)).refine((p) => Object.keys(p).length > 0, "at least one platform"),
|
|
207
|
+
/** More files the rolling release holds, such as installers for the site's download links, relative to the member. */
|
|
208
|
+
assets: z.array(z.string().min(1)).optional(),
|
|
209
|
+
/** A file whose text is the manifest's `notes`, relative to the member. */
|
|
210
|
+
notes: z.string().min(1).optional(),
|
|
211
|
+
/** Each platform's URL in the manifest: `{tag}` (the rolling tag), `{label}`, `{version}` and `{name}` are filled in. Default: the bundle's download URL on the rolling release on github.com. */
|
|
212
|
+
url: z.string().min(1).optional(),
|
|
213
|
+
/** The manifest's asset name. Default `latest.json`. */
|
|
214
|
+
manifest: z.string().regex(/^[^/\\]+$/, "a file name").optional(),
|
|
215
|
+
/** GitHub's `make_latest` for the rolling release. Default `false`. */
|
|
216
|
+
latest: z.union([z.boolean(), z.literal("legacy")]).optional(),
|
|
217
|
+
/** The GitHub API root. Default `$GITHUB_API_URL`, else `https://api.github.com`. */
|
|
218
|
+
api: z.string().url().optional(),
|
|
219
|
+
/** The variable holding the token. Default `GITHUB_TOKEN`. */
|
|
220
|
+
tokenEnv: envName.optional(),
|
|
109
221
|
})
|
|
110
222
|
.strict();
|
|
111
223
|
|
|
112
|
-
export const PublishDeclarationSchema = z.discriminatedUnion("type", [NpmPublishSchema, OciPublishSchema, ForgePublishSchema]);
|
|
224
|
+
export const PublishDeclarationSchema = z.discriminatedUnion("type", [NpmPublishSchema, OciPublishSchema, ForgePublishSchema, HomebrewPublishSchema, MarketplacePublishSchema, TauriUpdaterPublishSchema]);
|
|
113
225
|
|
|
114
226
|
export type NpmPublishDeclaration = z.infer<typeof NpmPublishSchema>;
|
|
115
227
|
export type OciPublishDeclaration = z.infer<typeof OciPublishSchema>;
|
|
116
228
|
export type ForgePublishDeclaration = z.infer<typeof ForgePublishSchema>;
|
|
229
|
+
export type HomebrewPublishDeclaration = z.infer<typeof HomebrewPublishSchema>;
|
|
230
|
+
export type MarketplacePublishDeclaration = z.infer<typeof MarketplacePublishSchema>;
|
|
231
|
+
export type TauriUpdaterPublishDeclaration = z.infer<typeof TauriUpdaterPublishSchema>;
|
|
117
232
|
export type PublishDeclaration = z.infer<typeof PublishDeclarationSchema>;
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
* GitHub uploads each asset to the draft's `upload_url`, Forgejo with a
|
|
17
17
|
* multipart `POST /repos/{repo}/releases/{id}/assets`. The reveal publishes
|
|
18
18
|
* the draft, `PATCH /repos/{repo}/releases/{id}` with `draft: false`, and
|
|
19
|
-
* the forge creates the tag then if it was not pushed.
|
|
19
|
+
* the forge creates the tag then if it was not pushed. On GitHub, a
|
|
20
|
+
* declared `latest` goes in the same request as `make_latest` (#4676), so
|
|
21
|
+
* the release becomes the repository's latest, or doesn't, as it appears.
|
|
20
22
|
* - GitLab has no draft release, so its stage puts each asset in the
|
|
21
23
|
* project's generic package registry (package `release`, version the
|
|
22
24
|
* label) and makes no release. The reveal creates the release at the
|
|
@@ -50,6 +52,9 @@ import type { ForgePublishDeclaration } from "./publish-declaration";
|
|
|
50
52
|
import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets";
|
|
51
53
|
import { PublishTargetError, type PublishContext, type PublishDeps, type PublishFetch, type PublishItem, type PublishTarget, type StagedTarget } from "./release-publish";
|
|
52
54
|
|
|
55
|
+
/** The first chant that reads `latest` on a forge target and sends it as GitHub's `make_latest` (#4676). */
|
|
56
|
+
export const PUBLISH_FORGE_LATEST_FLOOR = "0.124.63";
|
|
57
|
+
|
|
53
58
|
/** The variables a forge's token is read from, in order. */
|
|
54
59
|
export function forgeTokenEnv(decl: Pick<ForgePublishDeclaration, "forge" | "tokenEnv">): string[] {
|
|
55
60
|
if (decl.tokenEnv) return [decl.tokenEnv];
|
|
@@ -155,9 +160,11 @@ class ForgeClient {
|
|
|
155
160
|
return this.toRelease(create.json as Record<string, unknown>, tag);
|
|
156
161
|
}
|
|
157
162
|
|
|
158
|
-
/** GitHub and Forgejo: publish the draft `id
|
|
163
|
+
/** GitHub and Forgejo: publish the draft `id`, with GitHub's `make_latest` when `latest` is declared. */
|
|
159
164
|
async publishDraft(id: string, tag: string): Promise<void> {
|
|
160
|
-
const
|
|
165
|
+
const latest = this.decl.latest;
|
|
166
|
+
const body = latest === undefined ? { draft: false } : { draft: false, make_latest: String(latest) };
|
|
167
|
+
const res = await this.call("PATCH", `${this.repoPath}/releases/${id}`, JSON.stringify(body));
|
|
161
168
|
if (res.status !== 200) this.fail(`publishing the draft release ${tag}`, res.status, res.text);
|
|
162
169
|
}
|
|
163
170
|
|
|
@@ -208,6 +215,9 @@ export function forgeTarget(decl: ForgePublishDeclaration, deps: PublishDeps): P
|
|
|
208
215
|
if (!tag) {
|
|
209
216
|
throw new PublishTargetError("publish-forge-no-tag", `a ${decl.forge} release is named by a tag, and release ${ctx.release.releaseDigest} has no label`, "Cut the release with a label, or set tag in the declaration.");
|
|
210
217
|
}
|
|
218
|
+
if (decl.latest !== undefined && decl.forge !== "github") {
|
|
219
|
+
throw new PublishTargetError("publish-forge-latest-unsupported", `latest is GitHub's make_latest, and ${decl.forge} has no setting for which release is latest`, "Remove latest from the declaration.");
|
|
220
|
+
}
|
|
211
221
|
const api = forgeApi(decl, ctx.env);
|
|
212
222
|
if (!api) throw new PublishTargetError("publish-forge-no-api", "a Forgejo target needs its API root, and neither api nor GITHUB_API_URL is set", "Set api, such as https://forgejo.example/api/v1.");
|
|
213
223
|
const token = readCredential(ctx.env, tokenNames, ctx.redactor);
|
|
@@ -316,7 +326,7 @@ export function forgeTarget(decl: ForgePublishDeclaration, deps: PublishDeps): P
|
|
|
316
326
|
} else {
|
|
317
327
|
const id = staged.state.releaseId;
|
|
318
328
|
if (!id) throw new PublishTargetError("publish-forge-failed", `the staged ${decl.forge} release for ${tag} has no draft id to publish`);
|
|
319
|
-
ctx.log(`publishing the draft ${decl.forge} release ${tag}`);
|
|
329
|
+
ctx.log(`publishing the draft ${decl.forge} release ${tag}${decl.latest === undefined ? "" : ` with make_latest ${String(decl.latest)}`}`);
|
|
320
330
|
await client.publishDraft(id, tag);
|
|
321
331
|
}
|
|
322
332
|
return { target: this.name, destination: this.destination, items };
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
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
|
+
|
|
8
|
+
import type { Credential } from "./publish-credentials";
|
|
9
|
+
import { PublishTargetError, type PublishContextBase, type PublishFetch } from "./release-publish";
|
|
10
|
+
|
|
11
|
+
/** The API root of GitHub: `api`, else `$GITHUB_API_URL`, else `https://api.github.com`. */
|
|
12
|
+
export function githubApi(api: string | undefined, env: NodeJS.ProcessEnv): string {
|
|
13
|
+
return (api ?? env.GITHUB_API_URL ?? "https://api.github.com").replace(/\/+$/, "");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface GitHubAnswer {
|
|
17
|
+
status: number;
|
|
18
|
+
json: unknown;
|
|
19
|
+
text: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** One repository on GitHub, reached with one token. */
|
|
23
|
+
export class GitHubRepo {
|
|
24
|
+
constructor(
|
|
25
|
+
readonly api: string,
|
|
26
|
+
readonly repo: string,
|
|
27
|
+
private readonly token: Credential,
|
|
28
|
+
private readonly fetchImpl: PublishFetch,
|
|
29
|
+
private readonly ctx: PublishContextBase,
|
|
30
|
+
/** The code a failed request throws. */
|
|
31
|
+
private readonly code: string,
|
|
32
|
+
) {}
|
|
33
|
+
|
|
34
|
+
get root(): string {
|
|
35
|
+
return `${this.api}/repos/${this.repo}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async call(method: string, url: string, body?: Uint8Array | string, extra: Record<string, string> = {}): Promise<GitHubAnswer> {
|
|
39
|
+
const headers = {
|
|
40
|
+
authorization: `Bearer ${this.token.value}`,
|
|
41
|
+
accept: "application/vnd.github+json",
|
|
42
|
+
"user-agent": "chant",
|
|
43
|
+
...(typeof body === "string" ? { "content-type": "application/json" } : {}),
|
|
44
|
+
...extra,
|
|
45
|
+
};
|
|
46
|
+
const res = await this.fetchImpl(url.startsWith("http") ? url : `${this.root}${url}`, { method, headers, ...(body !== undefined ? { body } : {}) });
|
|
47
|
+
const text = await res.text();
|
|
48
|
+
let json: unknown = null;
|
|
49
|
+
try {
|
|
50
|
+
json = text ? JSON.parse(text) : null;
|
|
51
|
+
} catch {
|
|
52
|
+
json = null;
|
|
53
|
+
}
|
|
54
|
+
return { status: res.status, json, text };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fail(what: string, res: GitHubAnswer): never {
|
|
58
|
+
throw new PublishTargetError(this.code, this.ctx.redactor.redact(`${what} on github ${this.repo} answered ${res.status}${res.text ? `: ${res.text.slice(0, 300)}` : ""}`));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The repository's default branch. */
|
|
62
|
+
async defaultBranch(): Promise<string> {
|
|
63
|
+
const res = await this.call("GET", "");
|
|
64
|
+
const branch = (res.json as { default_branch?: unknown } | null)?.default_branch;
|
|
65
|
+
if (res.status !== 200 || typeof branch !== "string") this.fail("reading the repository", res);
|
|
66
|
+
return branch;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The commit `refs/heads/<branch>` points at, or null when there is no such branch. */
|
|
70
|
+
async branchHead(branch: string): Promise<string | null> {
|
|
71
|
+
const res = await this.call("GET", `/git/ref/heads/${branch}`);
|
|
72
|
+
if (res.status === 404) return null;
|
|
73
|
+
const sha = (res.json as { object?: { sha?: unknown } } | null)?.object?.sha;
|
|
74
|
+
if (res.status !== 200 || typeof sha !== "string") this.fail(`reading branch ${branch}`, res);
|
|
75
|
+
return sha;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A file's bytes and blob sha at `ref`, or null when it has none. */
|
|
79
|
+
async file(path: string, ref: string): Promise<{ bytes: Buffer; sha: string } | null> {
|
|
80
|
+
const res = await this.call("GET", `/contents/${path.split("/").map(encodeURIComponent).join("/")}?ref=${encodeURIComponent(ref)}`);
|
|
81
|
+
if (res.status === 404) return null;
|
|
82
|
+
const body = res.json as { content?: unknown; sha?: unknown; encoding?: unknown } | null;
|
|
83
|
+
if (res.status !== 200 || typeof body?.sha !== "string" || typeof body.content !== "string") this.fail(`reading ${path} at ${ref}`, res);
|
|
84
|
+
return { bytes: body.encoding === "base64" ? Buffer.from(body.content, "base64") : Buffer.from(body.content), sha: body.sha };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Commit `bytes` as `path` on `branch`, replacing the blob `sha` when the file is there. Returns the commit. */
|
|
88
|
+
async putFile(path: string, branch: string, bytes: Uint8Array, message: string, sha: string | null): Promise<string> {
|
|
89
|
+
const res = await this.call(
|
|
90
|
+
"PUT",
|
|
91
|
+
`/contents/${path.split("/").map(encodeURIComponent).join("/")}`,
|
|
92
|
+
JSON.stringify({ message, content: Buffer.from(bytes).toString("base64"), branch, ...(sha ? { sha } : {}) }),
|
|
93
|
+
);
|
|
94
|
+
const commit = (res.json as { commit?: { sha?: unknown } } | null)?.commit?.sha;
|
|
95
|
+
if ((res.status !== 200 && res.status !== 201) || typeof commit !== "string") this.fail(`committing ${path} to ${branch}`, res);
|
|
96
|
+
return commit;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Make `refs/heads/<branch>` at `sha`. */
|
|
100
|
+
async createBranch(branch: string, sha: string): Promise<void> {
|
|
101
|
+
const res = await this.call("POST", "/git/refs", JSON.stringify({ ref: `refs/heads/${branch}`, sha }));
|
|
102
|
+
if (res.status !== 201) this.fail(`creating branch ${branch}`, res);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Move `refs/<ref>` to `sha`. Without `force`, a move that is not a fast-forward answers false. */
|
|
106
|
+
async moveRef(ref: string, sha: string, force: boolean): Promise<boolean> {
|
|
107
|
+
const res = await this.call("PATCH", `/git/refs/${ref}`, JSON.stringify({ sha, force }));
|
|
108
|
+
if (res.status === 200) return true;
|
|
109
|
+
if (res.status === 422 && !force) return false;
|
|
110
|
+
this.fail(`moving ${ref} to ${sha.slice(0, 12)}`, res);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The published release for `tag`, or null. A draft is not found here. */
|
|
114
|
+
async publishedRelease(tag: string): Promise<GitHubRelease | null> {
|
|
115
|
+
const res = await this.call("GET", `/releases/tags/${encodeURIComponent(tag)}`);
|
|
116
|
+
if (res.status === 404) return null;
|
|
117
|
+
if (res.status !== 200 || !res.json) this.fail(`reading release ${tag}`, res);
|
|
118
|
+
return toRelease(res.json as Record<string, unknown>);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** The draft release for `tag` named `name`, or null. */
|
|
122
|
+
async draftRelease(tag: string, name: string): Promise<GitHubRelease | null> {
|
|
123
|
+
const res = await this.call("GET", "/releases?per_page=100");
|
|
124
|
+
if (res.status !== 200) this.fail("listing releases", res);
|
|
125
|
+
const found = (Array.isArray(res.json) ? (res.json as Array<Record<string, unknown>>) : []).find((r) => r.draft === true && r.tag_name === tag && r.name === name);
|
|
126
|
+
return found ? toRelease(found) : null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A new draft release for `tag` named `name`, at `commit`. */
|
|
130
|
+
async createDraft(tag: string, commit: string, name: string): Promise<GitHubRelease> {
|
|
131
|
+
const res = await this.call("POST", "/releases", JSON.stringify({ tag_name: tag, target_commitish: commit, name, draft: true }));
|
|
132
|
+
if (res.status !== 201 || !res.json) this.fail(`creating a draft release ${tag}`, res);
|
|
133
|
+
return toRelease(res.json as Record<string, unknown>);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Upload `bytes` as the asset `name` of `release`. */
|
|
137
|
+
async uploadAsset(release: GitHubRelease, name: string, bytes: Uint8Array): Promise<void> {
|
|
138
|
+
const base = (release.uploadUrl ?? `${this.root}/releases/${release.id}/assets`).replace(/\{[^}]*\}$/, "");
|
|
139
|
+
const res = await this.call("POST", `${base}?name=${encodeURIComponent(name)}`, bytes, { "content-type": "application/octet-stream" });
|
|
140
|
+
if (res.status !== 201) this.fail(`uploading ${name}`, res);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Publish the draft `id`, with `make_latest` when it is given. */
|
|
144
|
+
async publishDraft(id: string, makeLatest: string | undefined): Promise<GitHubAnswer> {
|
|
145
|
+
return this.call("PATCH", `/releases/${id}`, JSON.stringify(makeLatest === undefined ? { draft: false } : { draft: false, make_latest: makeLatest }));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Delete the release `id`. Its tag stays. */
|
|
149
|
+
async deleteRelease(id: string): Promise<void> {
|
|
150
|
+
const res = await this.call("DELETE", `/releases/${id}`);
|
|
151
|
+
if (res.status !== 204 && res.status !== 404) this.fail(`deleting release ${id}`, res);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Delete `refs/<ref>`. One that is not there is already gone. */
|
|
155
|
+
async deleteRef(ref: string): Promise<void> {
|
|
156
|
+
const res = await this.call("DELETE", `/git/refs/${ref}`);
|
|
157
|
+
if (res.status !== 204 && res.status !== 404 && res.status !== 422) this.fail(`deleting ${ref}`, res);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** A GitHub release as the targets read it. */
|
|
162
|
+
export interface GitHubRelease {
|
|
163
|
+
id: string;
|
|
164
|
+
draft: boolean;
|
|
165
|
+
/** Asset names, with the digest GitHub reports. */
|
|
166
|
+
assets: Map<string, string | null>;
|
|
167
|
+
uploadUrl?: string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function toRelease(body: Record<string, unknown>): GitHubRelease {
|
|
171
|
+
const assets = new Map<string, string | null>();
|
|
172
|
+
for (const a of (body.assets as Array<{ name: string; digest?: string | null }> | undefined) ?? []) assets.set(a.name, typeof a.digest === "string" ? a.digest : null);
|
|
173
|
+
return { id: String(body.id), draft: body.draft === true, assets, ...(typeof body.upload_url === "string" ? { uploadUrl: body.upload_url } : {}) };
|
|
174
|
+
}
|