@intentius/chant 0.124.63 → 0.124.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/cli/handlers/approve.d.ts +8 -0
  2. package/dist/cli/handlers/approve.d.ts.map +1 -1
  3. package/dist/cli/handlers/approve.js +27 -4
  4. package/dist/cli/handlers/pr.d.ts.map +1 -1
  5. package/dist/cli/handlers/pr.js +2 -1
  6. package/dist/cli/handlers/release.d.ts +6 -4
  7. package/dist/cli/handlers/release.d.ts.map +1 -1
  8. package/dist/cli/handlers/release.js +83 -16
  9. package/dist/cli/main.d.ts.map +1 -1
  10. package/dist/cli/main.js +18 -6
  11. package/dist/cli/parse-args.d.ts.map +1 -1
  12. package/dist/cli/parse-args.js +12 -0
  13. package/dist/cli/registry.d.ts +5 -1
  14. package/dist/cli/registry.d.ts.map +1 -1
  15. package/dist/config.d.ts +18 -0
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/config.js +1 -0
  18. package/dist/gate-statement.schema.json +4 -2
  19. package/dist/lifecycle/gate-ledger.d.ts +11 -2
  20. package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
  21. package/dist/lifecycle/gate-ledger.js +6 -0
  22. package/dist/lifecycle/gate-seal.d.ts +20 -4
  23. package/dist/lifecycle/gate-seal.d.ts.map +1 -1
  24. package/dist/lifecycle/gate-seal.js +18 -5
  25. package/dist/lifecycle/gate-statement.d.ts +27 -2
  26. package/dist/lifecycle/gate-statement.d.ts.map +1 -1
  27. package/dist/lifecycle/gate-statement.js +37 -1
  28. package/dist/lifecycle/plan-stale.d.ts.map +1 -1
  29. package/dist/lifecycle/plan-stale.js +1 -2
  30. package/dist/lifecycle/publish-declaration.d.ts +20 -0
  31. package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
  32. package/dist/lifecycle/publish-declaration.js +24 -1
  33. package/dist/lifecycle/publish-forge.d.ts.map +1 -1
  34. package/dist/lifecycle/publish-forge.js +1 -2
  35. package/dist/lifecycle/publish-git-ssh.d.ts +82 -0
  36. package/dist/lifecycle/publish-git-ssh.d.ts.map +1 -0
  37. package/dist/lifecycle/publish-git-ssh.js +180 -0
  38. package/dist/lifecycle/publish-homebrew.d.ts +11 -0
  39. package/dist/lifecycle/publish-homebrew.d.ts.map +1 -1
  40. package/dist/lifecycle/publish-homebrew.js +96 -4
  41. package/dist/lifecycle/publish-marketplace.d.ts +36 -2
  42. package/dist/lifecycle/publish-marketplace.d.ts.map +1 -1
  43. package/dist/lifecycle/publish-marketplace.js +173 -29
  44. package/dist/lifecycle/publish-tauri.d.ts.map +1 -1
  45. package/dist/lifecycle/publish-tauri.js +1 -2
  46. package/dist/lifecycle/release-cut.d.ts +51 -5
  47. package/dist/lifecycle/release-cut.d.ts.map +1 -1
  48. package/dist/lifecycle/release-cut.js +165 -16
  49. package/dist/lifecycle/release-publish.d.ts +13 -0
  50. package/dist/lifecycle/release-publish.d.ts.map +1 -1
  51. package/dist/lifecycle/release-publish.js +5 -0
  52. package/dist/lifecycle/release-revocation.d.ts +4 -3
  53. package/dist/lifecycle/release-revocation.d.ts.map +1 -1
  54. package/dist/lifecycle/release-revocation.js +5 -4
  55. package/dist/lifecycle/release-store.d.ts +32 -0
  56. package/dist/lifecycle/release-store.d.ts.map +1 -1
  57. package/dist/lifecycle/release-store.js +11 -0
  58. package/dist/op/activities/activity-contracts.d.ts +4 -4
  59. package/dist/op/gate.d.ts +1 -1
  60. package/dist/op/gate.d.ts.map +1 -1
  61. package/dist/op/gate.js +2 -1
  62. package/dist/pr-forge.d.ts.map +1 -1
  63. package/dist/pr-forge.js +26 -6
  64. package/dist/release-floors.d.ts +1 -1
  65. package/dist/release-floors.js +1 -1
  66. package/dist/wave-runtime.mjs +284 -283
  67. package/dist/workspace/ci-green.d.ts.map +1 -1
  68. package/dist/workspace/ci-green.js +1 -2
  69. package/dist/workspace/ci-quarantine-report.d.ts.map +1 -1
  70. package/dist/workspace/ci-quarantine-report.js +1 -2
  71. package/dist/workspace/ci-quarantine.d.ts.map +1 -1
  72. package/dist/workspace/ci-quarantine.js +1 -2
  73. package/dist/workspace/intent.d.ts.map +1 -1
  74. package/dist/workspace/intent.js +1 -2
  75. package/dist/workspace/release-candidates.d.ts +9 -1
  76. package/dist/workspace/release-candidates.d.ts.map +1 -1
  77. package/dist/workspace/release-candidates.js +16 -4
  78. package/dist/workspace/release-candidates.schema.json +7 -0
  79. package/dist/workspace/releases.schema.json +47 -0
  80. package/package.json +1 -1
  81. package/src/cli/handlers/approve-external-signature.test.ts +105 -3
  82. package/src/cli/handlers/approve.ts +34 -4
  83. package/src/cli/handlers/pr.ts +2 -1
  84. package/src/cli/handlers/release.ts +75 -16
  85. package/src/cli/main.ts +18 -6
  86. package/src/cli/parse-args.ts +9 -0
  87. package/src/cli/registry.ts +5 -1
  88. package/src/config.ts +8 -0
  89. package/src/gate-statement.schema.json +4 -2
  90. package/src/lifecycle/gate-ledger.ts +17 -2
  91. package/src/lifecycle/gate-seal.ts +24 -6
  92. package/src/lifecycle/gate-statement.ts +40 -3
  93. package/src/lifecycle/plan-stale.test.ts +3 -4
  94. package/src/lifecycle/plan-stale.ts +1 -2
  95. package/src/lifecycle/publish-declaration.ts +24 -1
  96. package/src/lifecycle/publish-forge.ts +1 -2
  97. package/src/lifecycle/publish-git-ssh.ts +202 -0
  98. package/src/lifecycle/publish-homebrew.test.ts +181 -2
  99. package/src/lifecycle/publish-homebrew.ts +101 -5
  100. package/src/lifecycle/publish-marketplace.test.ts +158 -6
  101. package/src/lifecycle/publish-marketplace.ts +192 -30
  102. package/src/lifecycle/publish-resume.test.ts +40 -0
  103. package/src/lifecycle/publish-tauri.ts +1 -2
  104. package/src/lifecycle/release-cut-lane.test.ts +177 -0
  105. package/src/lifecycle/release-cut-override.test.ts +213 -0
  106. package/src/lifecycle/release-cut.ts +198 -17
  107. package/src/lifecycle/release-publish.ts +18 -0
  108. package/src/lifecycle/release-revocation.ts +5 -4
  109. package/src/lifecycle/release-store.ts +44 -0
  110. package/src/op/gate.ts +2 -1
  111. package/src/pr-forge.ts +25 -6
  112. package/src/pr-requires.test.ts +9 -0
  113. package/src/release-floors.ts +1 -1
  114. package/src/workspace/ci-green.ts +1 -2
  115. package/src/workspace/ci-quarantine-report.test.ts +2 -3
  116. package/src/workspace/ci-quarantine-report.ts +1 -2
  117. package/src/workspace/ci-quarantine.test.ts +2 -3
  118. package/src/workspace/ci-quarantine.ts +1 -2
  119. package/src/workspace/intent.ts +1 -2
  120. package/src/workspace/release-candidates.schema.json +7 -0
  121. package/src/workspace/release-candidates.ts +19 -4
  122. package/src/workspace/releases.schema.json +47 -0
  123. package/src/workspace/trust/gate-seal.test.ts +44 -0
@@ -136,6 +136,12 @@ export const HomebrewPublishSchema = z
136
136
  api: z.string().url().optional(),
137
137
  /** The variable holding a token that may push to the tap. Default `HOMEBREW_TAP_TOKEN`. */
138
138
  tokenEnv: envName.optional(),
139
+ /**
140
+ * The variable holding an SSH private key that may push to the tap, such
141
+ * as a deploy key with write access (#4699). Set, the target pushes with
142
+ * git over SSH and reads no token; `tokenEnv` beside it is refused.
143
+ */
144
+ sshKeyEnv: envName.optional(),
139
145
  })
140
146
  .strict();
141
147
  /**
@@ -150,8 +156,25 @@ export const MarketplacePublishSchema = z
150
156
  vsix: z.string().min(1),
151
157
  /** Open VSX's root, default `https://open-vsx.org`; the VS Code Marketplace's gallery, default `https://marketplace.visualstudio.com`. */
152
158
  registry: z.string().url().optional(),
153
- /** The variable holding the token. Default `VSCE_PAT` for the VS Code Marketplace, `OVSX_PAT` for Open VSX. */
159
+ /** The variable holding the token, under `auth: "token"`. Default `VSCE_PAT` for the VS Code Marketplace, `OVSX_PAT` for Open VSX. */
154
160
  tokenEnv: envName.optional(),
161
+ /**
162
+ * How the target authenticates (#4698). `"token"` (the default) reads a
163
+ * token from `tokenEnv`. `"azure-credential"`, VS Code Marketplace only,
164
+ * runs `vsce` with `--azure-credential`, which signs in with the Microsoft
165
+ * Entra identity the job has, such as one `azure/login` set up from the
166
+ * run's OIDC token. `"trusted-publishing"`, Open VSX only, exchanges the
167
+ * run's OIDC ID token for a short-lived publishing token, as
168
+ * `ovsx publish --trusted-publishing` does.
169
+ */
170
+ auth: z.enum(["token", "azure-credential", "trusted-publishing"]).optional(),
171
+ /**
172
+ * What the reveal does when the marketplace refuses the upload (#4698).
173
+ * `"fail"` (the default) fails the publish. `"warn"` prints a warning
174
+ * and goes on to the next target, and the target is not recorded as
175
+ * published, so the same publish run again tries the upload again.
176
+ */
177
+ onRefusal: z.enum(["fail", "warn"]).optional(),
155
178
  })
156
179
  .strict();
157
180
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"publish-forge.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-forge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAMH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAA2C,KAAK,WAAW,EAAuC,KAAK,aAAa,EAAqB,MAAM,mBAAmB,CAAC;AAG1K,4GAA4G;AAC5G,eAAO,MAAM,0BAA0B,aAAe,CAAC;AAEvD,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,uBAAuB,EAAE,OAAO,GAAG,UAAU,CAAC,GAAG,MAAM,EAAE,CAKjG;AAED,0CAA0C;AAC1C,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,uBAAuB,EAAE,OAAO,GAAG,KAAK,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,GAAG,IAAI,CAGpH;AAuID,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,uBAAuB,EAAE,IAAI,EAAE,WAAW,GAAG,aAAa,CA6H3F"}
1
+ {"version":3,"file":"publish-forge.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-forge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAMH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAA2C,KAAK,WAAW,EAAuC,KAAK,aAAa,EAAqB,MAAM,mBAAmB,CAAC;AAE1K,4GAA4G;AAC5G,eAAO,MAAM,0BAA0B,aAAa,CAAC;AAErD,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,uBAAuB,EAAE,OAAO,GAAG,UAAU,CAAC,GAAG,MAAM,EAAE,CAKjG;AAED,0CAA0C;AAC1C,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,uBAAuB,EAAE,OAAO,GAAG,KAAK,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,GAAG,IAAI,CAGpH;AAuID,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,uBAAuB,EAAE,IAAI,EAAE,WAAW,GAAG,aAAa,CA6H3F"}
@@ -49,9 +49,8 @@ import { memberSbom, releaseProvenance } from "./publish-attachments.js";
49
49
  import { readCredential } from "./publish-credentials.js";
50
50
  import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets.js";
51
51
  import { PublishTargetError } from "./release-publish.js";
52
- import { NEXT_RELEASE } from "../release-floors.js";
53
52
  /** The first chant that reads `latest` on a forge target and sends it as GitHub's `make_latest` (#4676). */
54
- export const PUBLISH_FORGE_LATEST_FLOOR = NEXT_RELEASE;
53
+ export const PUBLISH_FORGE_LATEST_FLOOR = "0.124.63";
55
54
  /** The variables a forge's token is read from, in order. */
56
55
  export function forgeTokenEnv(decl) {
57
56
  if (decl.tokenEnv)
@@ -0,0 +1,82 @@
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
+ import type { Credential } from "./publish-credentials.js";
18
+ import { type PublishContextBase, type PublishFetch } from "./release-publish.js";
19
+ /** The SSH host for a GitHub API root: `github.com` for `https://api.github.com`, else the API's own host (GitHub Enterprise Server). */
20
+ export declare function githubSshHost(api: string): string;
21
+ /** The SSH URL of `owner/name` on `host`. */
22
+ export declare function sshRemote(host: string, repo: string): string;
23
+ /** What a push did: `ok`, or `rejected` when the remote refused a non-fast-forward. Any other failure throws. */
24
+ export type PushResult = "ok" | "rejected";
25
+ export declare class SshGitRepo {
26
+ readonly repo: string;
27
+ readonly host: string;
28
+ private readonly ctx;
29
+ private readonly git;
30
+ /** The code a failure throws. */
31
+ private readonly code;
32
+ /** The temporary directory: the key, the known hosts, the repository. */
33
+ private readonly root;
34
+ private readonly env;
35
+ /** The bare repository, inside {@link root}. */
36
+ private readonly dir;
37
+ readonly remote: string;
38
+ private constructor();
39
+ /**
40
+ * A repository session: reads the host's keys from `GET {api}/meta`, writes
41
+ * them and the key to a temporary directory, and makes an empty bare
42
+ * repository there. Close it with {@link close}.
43
+ */
44
+ static open(opts: {
45
+ api: string;
46
+ repo: string;
47
+ key: Credential;
48
+ ctx: PublishContextBase;
49
+ fetch: PublishFetch;
50
+ code: string;
51
+ git?: string;
52
+ ssh?: string;
53
+ }): Promise<SshGitRepo>;
54
+ /** Remove the temporary directory, with the key in it. */
55
+ close(): void;
56
+ private run;
57
+ private must;
58
+ private fail;
59
+ /** The remote's default branch and the head of each of its branches. */
60
+ heads(): Promise<{
61
+ defaultBranch: string | null;
62
+ heads: Map<string, string>;
63
+ }>;
64
+ /**
65
+ * Fetch `branch` and return its head. `depth` 1 is enough to read it and
66
+ * commit on it; 2 also brings its head's parent, so git sees that pushing
67
+ * the head fast-forwards a branch at that parent.
68
+ */
69
+ fetch(branch: string, depth?: number): Promise<string>;
70
+ /** The bytes of `path` at a fetched commit, or null when it holds no such file. */
71
+ file(commit: string, path: string): Promise<Buffer | null>;
72
+ /** A commit on `parent` that writes `bytes` to `path`, with `message`. Made here, not pushed. */
73
+ commitFile(parent: string, path: string, bytes: Uint8Array, message: string): Promise<string>;
74
+ /**
75
+ * Push `commit` to `branch`. `force` moves it wherever it is; without it,
76
+ * a branch that does not fast-forward comes back `rejected`.
77
+ */
78
+ push(commit: string, branch: string, force: boolean): Promise<PushResult>;
79
+ /** Delete `branch` on the remote, if it is there. */
80
+ deleteBranch(branch: string): Promise<void>;
81
+ }
82
+ //# sourceMappingURL=publish-git-ssh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish-git-ssh.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-git-ssh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAsB,KAAK,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEnG,yIAAyI;AACzI,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGjD;AAED,6CAA6C;AAC7C,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5D;AA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F;IAC7E,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAM/D;IAED,iGAAiG;IAC3F,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAWlG;IAED;;;OAGG;IACG,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAK9E;IAED,qDAAqD;IAC/C,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGhD;CACF"}
@@ -0,0 +1,180 @@
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
+ import { execFile } from "node:child_process";
18
+ import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
19
+ import { tmpdir } from "node:os";
20
+ import { join } from "node:path";
21
+ import { PublishTargetError } from "./release-publish.js";
22
+ /** The SSH host for a GitHub API root: `github.com` for `https://api.github.com`, else the API's own host (GitHub Enterprise Server). */
23
+ export function githubSshHost(api) {
24
+ const host = new URL(api).hostname;
25
+ return host === "api.github.com" ? "github.com" : host;
26
+ }
27
+ /** The SSH URL of `owner/name` on `host`. */
28
+ export function sshRemote(host, repo) {
29
+ return `git@${host}:${repo}.git`;
30
+ }
31
+ /** A shell word for GIT_SSH_COMMAND, which git runs through the shell. */
32
+ function shellWord(s) {
33
+ return /^[A-Za-z0-9_./:@=-]+$/.test(s) ? s : `'${s.replace(/'/g, `'\\''`)}'`;
34
+ }
35
+ export class SshGitRepo {
36
+ constructor(repo, host, ctx, git,
37
+ /** The code a failure throws. */
38
+ code,
39
+ /** The temporary directory: the key, the known hosts, the repository. */
40
+ root, env) {
41
+ this.repo = repo;
42
+ this.host = host;
43
+ this.ctx = ctx;
44
+ this.git = git;
45
+ this.code = code;
46
+ this.root = root;
47
+ this.env = env;
48
+ this.dir = join(root, "repo.git");
49
+ this.remote = sshRemote(host, repo);
50
+ }
51
+ /**
52
+ * A repository session: reads the host's keys from `GET {api}/meta`, writes
53
+ * them and the key to a temporary directory, and makes an empty bare
54
+ * repository there. Close it with {@link close}.
55
+ */
56
+ static async open(opts) {
57
+ const host = githubSshHost(opts.api);
58
+ const meta = await opts.fetch(`${opts.api}/meta`, { method: "GET", headers: { accept: "application/vnd.github+json", "user-agent": "chant" } });
59
+ const text = await meta.text().catch(() => "");
60
+ let keys;
61
+ try {
62
+ keys = meta.status === 200 ? JSON.parse(text).ssh_keys : undefined;
63
+ }
64
+ catch {
65
+ keys = undefined;
66
+ }
67
+ if (!Array.isArray(keys) || keys.length === 0 || !keys.every((k) => typeof k === "string" && /^[a-z0-9@.-]+ [A-Za-z0-9+/=]+$/.test(k))) {
68
+ 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.");
69
+ }
70
+ const dir = mkdtempSync(join(tmpdir(), "chant-git-ssh-"));
71
+ try {
72
+ const keyFile = join(dir, "key");
73
+ writeFileSync(keyFile, opts.key.value.endsWith("\n") ? opts.key.value : `${opts.key.value}\n`, { mode: 0o600 });
74
+ chmodSync(keyFile, 0o600);
75
+ const knownHosts = join(dir, "known_hosts");
76
+ writeFileSync(knownHosts, keys.map((k) => `${host} ${k}\n`).join(""));
77
+ const ssh = [opts.ssh ?? "ssh", "-F", "/dev/null", "-i", keyFile, "-o", "IdentitiesOnly=yes", "-o", "StrictHostKeyChecking=yes", "-o", `UserKnownHostsFile=${knownHosts}`, "-o", "BatchMode=yes"];
78
+ const env = { ...opts.ctx.env, GIT_SSH_COMMAND: ssh.map(shellWord).join(" "), GIT_TERMINAL_PROMPT: "0" };
79
+ for (const v of ["GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_OBJECT_DIRECTORY", "GIT_SSH", "GIT_SSH_VARIANT"])
80
+ delete env[v];
81
+ const repo = new SshGitRepo(opts.repo, host, opts.ctx, opts.git ?? "git", opts.code, dir, env);
82
+ await repo.run(["init", "-q", "--bare", repo.dir], dir);
83
+ return repo;
84
+ }
85
+ catch (err) {
86
+ rmSync(dir, { recursive: true, force: true });
87
+ throw err;
88
+ }
89
+ }
90
+ /** Remove the temporary directory, with the key in it. */
91
+ close() {
92
+ rmSync(this.root, { recursive: true, force: true });
93
+ }
94
+ run(args, cwd = this.dir, extraEnv = {}) {
95
+ return new Promise((resolvePromise, reject) => {
96
+ execFile(this.git, args, { cwd, env: { ...this.env, ...extraEnv }, encoding: "utf-8", maxBuffer: 64 * 1024 * 1024 }, (err, stdout, stderr) => {
97
+ if (err && typeof err.code === "string") {
98
+ reject(new PublishTargetError(this.code, `git could not be run: ${err.message}`, "Install git on the job's PATH."));
99
+ return;
100
+ }
101
+ resolvePromise({ code: err ? (err.code ?? 1) : 0, stdout, stderr });
102
+ });
103
+ });
104
+ }
105
+ async must(what, args, extraEnv = {}) {
106
+ const r = await this.run(args, this.dir, extraEnv);
107
+ if (r.code !== 0)
108
+ this.fail(what, r.stderr || r.stdout);
109
+ return r.stdout;
110
+ }
111
+ fail(what, output) {
112
+ // git's advice after an ssh failure says nothing ssh didn't, and would push ssh's own line out of the last three.
113
+ 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));
114
+ throw new PublishTargetError(this.code, this.ctx.redactor.redact(`${what} on ${this.remote} failed${lines.length ? `: ${lines.slice(-3).join(" ")}` : ""}`));
115
+ }
116
+ /** The remote's default branch and the head of each of its branches. */
117
+ async heads() {
118
+ const out = await this.must("listing the branches", ["ls-remote", "--symref", this.remote]);
119
+ const heads = new Map();
120
+ let defaultBranch = null;
121
+ for (const line of out.split("\n")) {
122
+ const sym = /^ref: refs\/heads\/(\S+)\tHEAD$/.exec(line);
123
+ if (sym)
124
+ defaultBranch = sym[1];
125
+ const ref = /^([0-9a-f]{40,64})\trefs\/heads\/(\S+)$/.exec(line);
126
+ if (ref)
127
+ heads.set(ref[2], ref[1]);
128
+ }
129
+ return { defaultBranch, heads };
130
+ }
131
+ /**
132
+ * Fetch `branch` and return its head. `depth` 1 is enough to read it and
133
+ * commit on it; 2 also brings its head's parent, so git sees that pushing
134
+ * the head fast-forwards a branch at that parent.
135
+ */
136
+ async fetch(branch, depth = 1) {
137
+ await this.must(`fetching ${branch}`, ["fetch", "-q", "--no-tags", `--depth=${depth}`, this.remote, `+refs/heads/${branch}:refs/remotes/tap/${branch}`]);
138
+ return (await this.must(`reading ${branch}`, ["rev-parse", `refs/remotes/tap/${branch}`])).trim();
139
+ }
140
+ /** The bytes of `path` at a fetched commit, or null when it holds no such file. */
141
+ async file(commit, path) {
142
+ const spec = `${commit}:${path}`;
143
+ if ((await this.run(["cat-file", "-e", spec])).code !== 0)
144
+ return null;
145
+ return new Promise((resolvePromise, reject) => {
146
+ 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)));
147
+ });
148
+ }
149
+ /** A commit on `parent` that writes `bytes` to `path`, with `message`. Made here, not pushed. */
150
+ async commitFile(parent, path, bytes, message) {
151
+ const blobFile = join(this.root, "blob");
152
+ writeFileSync(blobFile, bytes);
153
+ const blob = (await this.must("writing the file", ["hash-object", "-w", blobFile])).trim();
154
+ const index = { GIT_INDEX_FILE: join(this.root, "index") };
155
+ await this.must("reading the tree", ["read-tree", parent], index);
156
+ await this.must("staging the file", ["update-index", "--add", "--cacheinfo", `100644,${blob},${path}`], index);
157
+ const tree = (await this.must("writing the tree", ["write-tree"], index)).trim();
158
+ rmSync(index.GIT_INDEX_FILE, { force: true });
159
+ const who = (await this.run(["config", "user.email"])).stdout.trim() ? [] : ["-c", "user.name=chant", "-c", "user.email=chant@localhost"];
160
+ return (await this.must("committing", [...who, "-c", "commit.gpgsign=false", "commit-tree", tree, "-p", parent, "-m", message])).trim();
161
+ }
162
+ /**
163
+ * Push `commit` to `branch`. `force` moves it wherever it is; without it,
164
+ * a branch that does not fast-forward comes back `rejected`.
165
+ */
166
+ async push(commit, branch, force) {
167
+ const r = await this.run(["push", "--porcelain", this.remote, `${force ? "+" : ""}${commit}:refs/heads/${branch}`]);
168
+ if (r.code === 0)
169
+ return "ok";
170
+ if (!force && /^!\t[^\t]*\t\[rejected\] \((non-fast-forward|fetch first)\)/m.test(r.stdout))
171
+ return "rejected";
172
+ this.fail(`pushing ${commit.slice(0, 12)} to ${branch}`, `${r.stdout}\n${r.stderr}`);
173
+ }
174
+ /** Delete `branch` on the remote, if it is there. */
175
+ async deleteBranch(branch) {
176
+ const r = await this.run(["push", "--porcelain", this.remote, `:refs/heads/${branch}`]);
177
+ if (r.code !== 0 && !/remote ref does not exist/.test(`${r.stdout}\n${r.stderr}`))
178
+ this.fail(`deleting ${branch}`, `${r.stdout}\n${r.stderr}`);
179
+ }
180
+ }
@@ -34,6 +34,15 @@
34
34
  * the reveal commits the formula onto it instead, one commit either way,
35
35
  * unless it already holds the formula as rendered.
36
36
  *
37
+ * With `sshKeyEnv` (#4699), the same two steps run with git over SSH and the
38
+ * private key in that variable, such as a deploy key limited to the tap, in
39
+ * place of the API and a token (./publish-git-ssh.ts). The stage fetches the
40
+ * tap branch, commits the formula on its head and force-pushes that commit
41
+ * to the staging branch. The reveal fetches the staging branch and pushes
42
+ * its commit to the tap branch without force, which the remote takes only
43
+ * as a fast-forward; when the tap branch moved, it commits the formula onto
44
+ * the new head instead and pushes that, then deletes the staging branch.
45
+ *
37
46
  * The asset URLs are the declaration's `url` pattern, so the files must be
38
47
  * downloadable there by the time the formula is: declare the `forge` target
39
48
  * that attaches them before this one, and its reveal runs first.
@@ -42,6 +51,8 @@ import type { HomebrewPublishDeclaration } from "./publish-declaration.js";
42
51
  import { type PublishDeps, type PublishTarget } from "./release-publish.js";
43
52
  /** The first chant that publishes a `homebrew` target (#4676). */
44
53
  export declare const PUBLISH_HOMEBREW_FLOOR = "0.124.63";
54
+ /** The first chant that reads a homebrew target's `sshKeyEnv` (#4699). */
55
+ export declare const PUBLISH_HOMEBREW_SSH_KEY_FLOOR = "0.124.64";
45
56
  /** The variable the tap token is read from when the declaration names none. */
46
57
  export declare const HOMEBREW_TOKEN_ENV = "HOMEBREW_TAP_TOKEN";
47
58
  /** A release's version for a package manager: its label from the first digit on, or null when the label has no digit. */
@@ -1 +1 @@
1
- {"version":3,"file":"publish-homebrew.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-homebrew.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAKH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAGxE,OAAO,EAA2C,KAAK,WAAW,EAAuC,KAAK,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvJ,kEAAkE;AAClE,eAAO,MAAM,sBAAsB,aAAe,CAAC;AAEnD,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAEvD,yHAAyH;AACzH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,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AAED,wHAAwH;AACxH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAItH;AAED,6DAA6D;AAC7D,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACvD,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,GAC3D,MAAM,CAYR;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,0BAA0B,EAAE,IAAI,EAAE,WAAW,GAAG,aAAa,CAqLjG"}
@@ -34,6 +34,15 @@
34
34
  * the reveal commits the formula onto it instead, one commit either way,
35
35
  * unless it already holds the formula as rendered.
36
36
  *
37
+ * With `sshKeyEnv` (#4699), the same two steps run with git over SSH and the
38
+ * private key in that variable, such as a deploy key limited to the tap, in
39
+ * place of the API and a token (./publish-git-ssh.ts). The stage fetches the
40
+ * tap branch, commits the formula on its head and force-pushes that commit
41
+ * to the staging branch. The reveal fetches the staging branch and pushes
42
+ * its commit to the tap branch without force, which the remote takes only
43
+ * as a fast-forward; when the tap branch moved, it commits the formula onto
44
+ * the new head instead and pushes that, then deletes the staging branch.
45
+ *
37
46
  * The asset URLs are the declaration's `url` pattern, so the files must be
38
47
  * downloadable there by the time the formula is: declare the `forge` target
39
48
  * that attaches them before this one, and its reveal runs first.
@@ -41,12 +50,15 @@
41
50
  import { readFileSync } from "node:fs";
42
51
  import { basename } from "node:path";
43
52
  import { readCredential } from "./publish-credentials.js";
53
+ import { SshGitRepo } from "./publish-git-ssh.js";
44
54
  import { GitHubRepo, githubApi } from "./publish-github.js";
45
55
  import { bytesDigest, checkReleaseDigest, memberFile, publishTargetKey } from "./publish-targets.js";
46
56
  import { PublishTargetError } from "./release-publish.js";
47
57
  import { NEXT_RELEASE } from "../release-floors.js";
48
58
  /** The first chant that publishes a `homebrew` target (#4676). */
49
- export const PUBLISH_HOMEBREW_FLOOR = NEXT_RELEASE;
59
+ export const PUBLISH_HOMEBREW_FLOOR = "0.124.63";
60
+ /** The first chant that reads a homebrew target's `sshKeyEnv` (#4699). */
61
+ export const PUBLISH_HOMEBREW_SSH_KEY_FLOOR = NEXT_RELEASE;
50
62
  /** The variable the tap token is read from when the declaration names none. */
51
63
  export const HOMEBREW_TOKEN_ENV = "HOMEBREW_TAP_TOKEN";
52
64
  /** A release's version for a package manager: its label from the first digit on, or null when the label has no digit. */
@@ -72,7 +84,11 @@ export function renderFormula(template, values, assets) {
72
84
  }
73
85
  export function homebrewTarget(decl, deps) {
74
86
  const fetchImpl = deps.fetch ?? ((url, init) => fetch(url, init));
75
- const tokenNames = [decl.tokenEnv ?? HOMEBREW_TOKEN_ENV];
87
+ if (decl.sshKeyEnv && decl.tokenEnv) {
88
+ throw new PublishTargetError("publish-homebrew-auth-invalid", `the homebrew target for ${decl.tap} names both tokenEnv and sshKeyEnv`, "Keep one: sshKeyEnv pushes with git over SSH, tokenEnv commits through the API.");
89
+ }
90
+ const ssh = decl.sshKeyEnv !== undefined;
91
+ const tokenNames = [decl.sshKeyEnv ?? decl.tokenEnv ?? HOMEBREW_TOKEN_ENV];
76
92
  const formulaName = basename(decl.formula).replace(/\.rb$/, "");
77
93
  const setup = (ctx) => {
78
94
  const version = releaseVersion(ctx.label);
@@ -81,7 +97,7 @@ export function homebrewTarget(decl, deps) {
81
97
  }
82
98
  const token = readCredential(ctx.env, tokenNames, ctx.redactor);
83
99
  if (!token) {
84
- throw new PublishTargetError("publish-credentials-missing", `the homebrew target reads its token from ${tokenNames[0]}, and it is not set`, `Set ${tokenNames[0]} to a token that may push to ${decl.tap}.`);
100
+ throw new PublishTargetError("publish-credentials-missing", `the homebrew target reads its ${ssh ? "SSH key" : "token"} from ${tokenNames[0]}, and it is not set`, ssh ? `Set ${tokenNames[0]} to a private key that may push to ${decl.tap}, such as a deploy key with write access.` : `Set ${tokenNames[0]} to a token that may push to ${decl.tap}.`);
85
101
  }
86
102
  const assets = new Map();
87
103
  for (const p of decl.assets) {
@@ -111,9 +127,11 @@ export function homebrewTarget(decl, deps) {
111
127
  },
112
128
  async stage(ctx) {
113
129
  const { version, token, assets, bytes, digest } = setup(ctx);
114
- ctx.log(`using the token from ${token.from}`);
130
+ ctx.log(`using the ${ssh ? "SSH key" : "token"} from ${token.from}`);
115
131
  for (const [name, a] of assets)
116
132
  ctx.log(`${name}: ${a.url} sha256 ${a.sha256}`);
133
+ if (ssh)
134
+ return withSsh(ctx, token, (tap) => stageOverSsh(ctx, tap, version, bytes, digest));
117
135
  const tap = new GitHubRepo(githubApi(decl.api, ctx.env), decl.tap, token, fetchImpl, ctx, "publish-homebrew-failed");
118
136
  const branch = decl.branch ?? (await tap.defaultBranch());
119
137
  const head = await tap.branchHead(branch);
@@ -152,6 +170,10 @@ export function homebrewTarget(decl, deps) {
152
170
  const { branch, staging, commit } = staged.state;
153
171
  if (!branch || !staging || !commit)
154
172
  throw new PublishTargetError("publish-homebrew-failed", `the staged formula for ${decl.tap} has no staging commit to reveal`);
173
+ if (ssh) {
174
+ await withSsh(ctx, token, (tap) => revealOverSsh(ctx, tap, { branch, staging, commit }, version, bytes));
175
+ return published;
176
+ }
155
177
  const tap = new GitHubRepo(githubApi(decl.api, ctx.env), decl.tap, token, fetchImpl, ctx, "publish-homebrew-failed");
156
178
  ctx.log(`fast-forwarding ${branch} to ${commit.slice(0, 12)}`);
157
179
  if (!(await tap.moveRef(`heads/${branch}`, commit, false))) {
@@ -169,5 +191,75 @@ export function homebrewTarget(decl, deps) {
169
191
  return published;
170
192
  },
171
193
  };
194
+ async function withSsh(ctx, key, step) {
195
+ const tap = await SshGitRepo.open({ api: githubApi(decl.api, ctx.env), repo: decl.tap, key, ctx, fetch: fetchImpl, code: "publish-homebrew-failed", git: deps.git, ssh: deps.ssh });
196
+ try {
197
+ return await step(tap);
198
+ }
199
+ finally {
200
+ tap.close();
201
+ }
202
+ }
203
+ async function stageOverSsh(ctx, tap, version, bytes, digest) {
204
+ const { defaultBranch, heads } = await tap.heads();
205
+ const branch = decl.branch ?? defaultBranch;
206
+ const head = branch ? heads.get(branch) : undefined;
207
+ if (!branch || !head)
208
+ throw new PublishTargetError("publish-homebrew-failed", `${tap.remote} has no branch ${branch ?? "HEAD points at"}`, "Set branch to the branch brew installs from.");
209
+ const item = { name: decl.formula, destination: where(branch), digest };
210
+ const done = (state, present) => ({ target: target.name, destination: target.destination, items: [{ ...item, ...(present ? { present: true } : {}) }], state: { branch, ...state } });
211
+ ctx.log(`reading ${branch} of ${tap.remote} over SSH`);
212
+ await tap.fetch(branch);
213
+ const onTap = await tap.file(head, decl.formula);
214
+ if (onTap && onTap.equals(Buffer.from(bytes))) {
215
+ ctx.log(`${branch} already has ${decl.formula} for ${version}`);
216
+ return done({ present: "true" }, true);
217
+ }
218
+ const staging = `chant-publish/${formulaName}-${version}`;
219
+ const stagingHead = heads.get(staging);
220
+ if (stagingHead) {
221
+ await tap.fetch(staging);
222
+ const onStaging = await tap.file(stagingHead, decl.formula);
223
+ if (onStaging && onStaging.equals(Buffer.from(bytes))) {
224
+ ctx.log(`${staging} already has ${decl.formula} for ${version}`);
225
+ return done({ staging, commit: stagingHead }, true);
226
+ }
227
+ }
228
+ ctx.log(`committing ${decl.formula} for ${version} to ${staging}, at ${branch}'s head ${head.slice(0, 12)}, and pushing it over SSH`);
229
+ const commit = await tap.commitFile(head, decl.formula, bytes, `${formulaName} ${version}`);
230
+ await tap.push(commit, staging, true);
231
+ return done({ staging, commit }, false);
232
+ }
233
+ async function revealOverSsh(ctx, tap, state, version, bytes) {
234
+ const { branch, staging, commit } = state;
235
+ const { heads } = await tap.heads();
236
+ // The staged commit is on the staging branch: fetch it, since this run may be a resume on a fresh clone.
237
+ // Depth 2: the staged commit and the head it was made on, so git sees the push as a fast-forward.
238
+ const stagingHead = heads.get(staging) === commit ? await tap.fetch(staging, 2) : null;
239
+ let moved = true;
240
+ if (stagingHead === commit) {
241
+ ctx.log(`fast-forwarding ${branch} to ${commit.slice(0, 12)} over SSH`);
242
+ moved = (await tap.push(commit, branch, false)) === "rejected";
243
+ }
244
+ else {
245
+ ctx.log(`${staging} is not at the staged commit ${commit.slice(0, 12)} any more`);
246
+ }
247
+ if (moved) {
248
+ // The tap moved since the stage, or the staged commit is gone: one commit of the formula onto it, unless it already holds it.
249
+ const head = await tap.fetch(branch);
250
+ const onTap = await tap.file(head, decl.formula);
251
+ if (onTap && onTap.equals(Buffer.from(bytes))) {
252
+ ctx.log(`${branch} already has ${decl.formula} for ${version}`);
253
+ }
254
+ else {
255
+ ctx.log(`committing ${decl.formula} for ${version} onto ${branch}'s head ${head.slice(0, 12)}`);
256
+ const onto = await tap.commitFile(head, decl.formula, bytes, `${formulaName} ${version}`);
257
+ if ((await tap.push(onto, branch, false)) === "rejected") {
258
+ throw new PublishTargetError("publish-homebrew-failed", `${branch} of ${tap.remote} moved again while ${decl.formula} was committed onto it`, "Run the same publish again: it commits the formula onto the branch's new head.");
259
+ }
260
+ }
261
+ }
262
+ await tap.deleteBranch(staging);
263
+ }
172
264
  return target;
173
265
  }
@@ -30,15 +30,49 @@
30
30
  *
31
31
  * The token is read from `tokenEnv`, else `VSCE_PAT` or `OVSX_PAT`, the
32
32
  * variables `vsce` and `ovsx` read, and is masked in all output.
33
+ *
34
+ * Or the target authenticates with the run's identity, with no stored
35
+ * token (#4698):
36
+ *
37
+ * - `auth: "azure-credential"` (VS Code Marketplace): `vsce` runs with
38
+ * `--azure-credential`, which gets a Microsoft Entra token from the job's
39
+ * Azure sign-in, such as the one `azure/login` makes from the run's OIDC
40
+ * token. `VSCE_PAT` is taken out of vsce's environment, since vsce prefers
41
+ * a PAT it finds there. The stage runs
42
+ * `vsce verify-pat --azure-credential <publisher>`, which signs in and asks
43
+ * the marketplace for the identity's role on the publisher, and changes
44
+ * nothing.
45
+ * - `auth: "trusted-publishing"` (Open VSX): the run's OIDC ID token, from
46
+ * GitHub Actions (a job with `id-token: write`) or from `OVSX_ID_TOKEN`, is
47
+ * exchanged at `POST {registry}/api/-/trusted-publishing/token` for a
48
+ * publishing token that lasts minutes, as `ovsx publish --trusted-publishing`
49
+ * does. The stage makes the exchange to check that Open VSX takes this
50
+ * workflow as a trusted publisher of the extension, and drops the token;
51
+ * the reveal exchanges again for the upload.
52
+ *
53
+ * With `onRefusal: "warn"`, a marketplace that refuses the reveal's upload,
54
+ * or a request around it, is a warning: the reveal returns the target with
55
+ * its items `refused` and a `warning`, and the publish goes on. Every check
56
+ * the stage makes still refuses, and so does a digest that differs after an
57
+ * upload.
33
58
  */
34
59
  import type { MarketplacePublishDeclaration } from "./publish-declaration.js";
35
60
  import { type PublishDeps, type PublishTarget } from "./release-publish.js";
36
61
  /** The first chant that publishes a `marketplace` target (#4676). */
37
62
  export declare const PUBLISH_MARKETPLACE_FLOOR = "0.124.63";
63
+ /** The first chant that reads a marketplace target's `auth` (#4698). */
64
+ export declare const PUBLISH_MARKETPLACE_AUTH_FLOOR = "0.124.64";
65
+ /** The first chant that reads a marketplace target's `onRefusal` (#4698). */
66
+ export declare const PUBLISH_MARKETPLACE_ON_REFUSAL_FLOOR = "0.124.64";
38
67
  export declare const OPEN_VSX_REGISTRY = "https://open-vsx.org";
39
68
  export declare const VSCODE_GALLERY = "https://marketplace.visualstudio.com";
40
- /** The variables a marketplace's token is read from. */
41
- export declare function marketplaceTokenEnv(decl: Pick<MarketplacePublishDeclaration, "marketplace" | "tokenEnv">): string[];
69
+ /** The variable an OIDC ID token for Open VSX is read from outside GitHub Actions, as `ovsx` reads it. */
70
+ export declare const OVSX_ID_TOKEN_ENV = "OVSX_ID_TOKEN";
71
+ export type MarketplaceAuth = NonNullable<MarketplacePublishDeclaration["auth"]>;
72
+ /** The declaration's `auth`, refused when the marketplace does not take it or when `tokenEnv` is set with another. */
73
+ export declare function marketplaceAuth(decl: Pick<MarketplacePublishDeclaration, "marketplace" | "auth" | "tokenEnv">): MarketplaceAuth;
74
+ /** The variables a marketplace's credential is read from, whose values are masked. */
75
+ export declare function marketplaceTokenEnv(decl: Pick<MarketplacePublishDeclaration, "marketplace" | "tokenEnv" | "auth">): string[];
42
76
  /** One file of a zip archive, or null when it holds none by that name. Reads stored and deflated entries; refuses a zip64 archive. */
43
77
  export declare function readZipEntry(zip: Buffer, name: string): Buffer | null;
44
78
  /** The publisher, name and version a `.vsix` declares. */
@@ -1 +1 @@
1
- {"version":3,"file":"publish-marketplace.d.ts","sourceRoot":"","sources":["../../src/lifecycle/publish-marketplace.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAMH,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAE3E,OAAO,EAA2C,KAAK,WAAW,EAAuC,KAAK,aAAa,EAAqB,MAAM,mBAAmB,CAAC;AAG1K,qEAAqE;AACrE,eAAO,MAAM,yBAAyB,aAAe,CAAC;AAEtD,eAAO,MAAM,iBAAiB,yBAAyB,CAAC;AACxD,eAAO,MAAM,cAAc,yCAAyC,CAAC;AAErE,wDAAwD;AACxD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,6BAA6B,EAAE,aAAa,GAAG,UAAU,CAAC,GAAG,MAAM,EAAE,CAEnH;AAED,sIAAsI;AACtI,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA6BrE;AAED,0DAA0D;AAC1D,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IA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