@workerstack/clients 1.0.0-rc.23 → 1.0.0-rc.25
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/README.md +67 -11
- package/assets/installers/examples/github.config.ts +21 -0
- package/assets/installers/examples/goreleaser.config.ts +21 -0
- package/assets/installers/examples/raw.config.ts +17 -0
- package/assets/installers/templates/install.ps1 +426 -0
- package/assets/installers/templates/install.sh +412 -0
- package/bin/installgen.js +19 -0
- package/dist/cli.js +4 -0
- package/dist/emit/cli/install.d.ts +8 -5
- package/dist/emit/cli/install.js +14 -7
- package/dist/emit/cli/release.js +8 -7
- package/dist/emit/shared/status-keys.d.ts +2 -2
- package/dist/emit/shared/status-keys.js +2 -2
- package/dist/gen/args.js +4 -0
- package/dist/gen/formatters.d.ts +1 -1
- package/dist/gen/formatters.js +1 -1
- package/dist/gen/targets.d.ts +1 -1
- package/dist/gen/targets.js +1 -1
- package/dist/installers/cli.d.ts +21 -0
- package/dist/installers/cli.js +170 -0
- package/dist/installers/commands/build.d.ts +15 -0
- package/dist/installers/commands/build.js +34 -0
- package/dist/installers/commands/check.d.ts +10 -0
- package/dist/installers/commands/check.js +161 -0
- package/dist/installers/commands/init.d.ts +9 -0
- package/dist/installers/commands/init.js +32 -0
- package/dist/installers/config/define-config.d.ts +100 -0
- package/dist/installers/config/define-config.js +10 -0
- package/dist/installers/config/hooks/bun.d.ts +21 -0
- package/dist/installers/config/hooks/bun.js +21 -0
- package/dist/installers/config/hooks/node.d.ts +9 -0
- package/dist/installers/config/hooks/node.js +16 -0
- package/dist/installers/config/load.d.ts +35 -0
- package/dist/installers/config/load.js +97 -0
- package/dist/installers/config/resolve.d.ts +4 -0
- package/dist/installers/config/resolve.js +281 -0
- package/dist/installers/config/types.d.ts +45 -0
- package/dist/installers/config/types.js +1 -0
- package/dist/installers/errors.d.ts +5 -0
- package/dist/installers/errors.js +5 -0
- package/dist/installers/index.d.ts +11 -0
- package/dist/installers/index.js +11 -0
- package/dist/installers/render/quote.d.ts +7 -0
- package/dist/installers/render/quote.js +34 -0
- package/dist/installers/render/render.d.ts +24 -0
- package/dist/installers/render/render.js +133 -0
- package/dist/installers/ui.d.ts +15 -0
- package/dist/installers/ui.js +14 -0
- package/dist/release/bootstrap.d.ts +61 -0
- package/dist/release/bootstrap.js +191 -0
- package/dist/release/bump-args.d.ts +17 -0
- package/dist/release/bump-args.js +35 -0
- package/dist/release/bump-command.d.ts +18 -0
- package/dist/release/bump-command.js +186 -0
- package/dist/release/bump.d.ts +33 -0
- package/dist/release/bump.js +72 -0
- package/dist/release/cli.d.ts +23 -0
- package/dist/release/cli.js +85 -0
- package/dist/release/codegen.d.ts +6 -0
- package/dist/release/codegen.js +25 -0
- package/dist/release/constants.d.ts +39 -0
- package/dist/release/constants.js +35 -0
- package/dist/release/context.d.ts +33 -0
- package/dist/release/context.js +31 -0
- package/dist/release/digest.d.ts +11 -0
- package/dist/release/digest.js +59 -0
- package/dist/release/git.d.ts +10 -0
- package/dist/release/git.js +64 -0
- package/dist/release/index.d.ts +7 -0
- package/dist/release/index.js +6 -0
- package/dist/release/load.d.ts +30 -0
- package/dist/release/load.js +78 -0
- package/dist/release/manifest.d.ts +15 -0
- package/dist/release/manifest.js +164 -0
- package/dist/release/oasdiff.d.ts +20 -0
- package/dist/release/oasdiff.js +36 -0
- package/dist/release/registries.d.ts +46 -0
- package/dist/release/registries.js +243 -0
- package/dist/release/release-state.d.ts +15 -0
- package/dist/release/release-state.js +21 -0
- package/dist/release/release-workflow.d.ts +5 -0
- package/dist/release/release-workflow.js +72 -0
- package/dist/release/repo-settings.d.ts +22 -0
- package/dist/release/repo-settings.js +53 -0
- package/dist/release/spec-gate.d.ts +28 -0
- package/dist/release/spec-gate.js +107 -0
- package/dist/release/sync-command.d.ts +31 -0
- package/dist/release/sync-command.js +122 -0
- package/dist/release/sync-tree.d.ts +30 -0
- package/dist/release/sync-tree.js +123 -0
- package/dist/release/sync.d.ts +46 -0
- package/dist/release/sync.js +172 -0
- package/dist/release/types.d.ts +149 -0
- package/dist/release/types.js +1 -0
- package/dist/release/version-files.d.ts +16 -0
- package/dist/release/version-files.js +74 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.js +8 -0
- package/package.json +72 -11
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/* Actions the workflow runs, pinned to a commit. */
|
|
2
|
+
export const ACTIONS = {
|
|
3
|
+
checkout: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1",
|
|
4
|
+
cratesAuth: "rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6",
|
|
5
|
+
nugetLogin: "NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2.0",
|
|
6
|
+
pypiPublish: "pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3",
|
|
7
|
+
rustToolchain: "dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8",
|
|
8
|
+
setupDotnet: "actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0",
|
|
9
|
+
setupGradle: "gradle/actions/setup-gradle@3f5f9adaf7d9fecd50b5935e54106014257a94e6 # v6.4.0",
|
|
10
|
+
setupJava: "actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0",
|
|
11
|
+
setupNode: "actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0",
|
|
12
|
+
setupPython: "actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0",
|
|
13
|
+
};
|
|
14
|
+
/* npm publishes over OIDC from 11.5.1 on. */
|
|
15
|
+
export const TOOLS = {
|
|
16
|
+
build: "1.6.1",
|
|
17
|
+
dotnet: "10.0.403",
|
|
18
|
+
gradle: "9.8.2",
|
|
19
|
+
java: "21",
|
|
20
|
+
jsr: "0.14.3",
|
|
21
|
+
node: "24",
|
|
22
|
+
npm: "12.2.1",
|
|
23
|
+
python: "3.12",
|
|
24
|
+
rust: "1.99.0",
|
|
25
|
+
};
|
|
26
|
+
/* The record honey keeps in every package it generates: the package's name and version on each registry. */
|
|
27
|
+
const IDENTITY = ".honey-generated.json";
|
|
28
|
+
/* `field` of the package honey recorded for `registry`, or a failed step when it recorded none. */
|
|
29
|
+
const identity = (registry, field) => `jq -er '.packages[] | select(.registry == "${registry}") | .${field}' ${IDENTITY}`;
|
|
30
|
+
/* A `key = '…'` line of a Gradle build script. */
|
|
31
|
+
const gradleField = (key, file) => `sed -n "s/^${key} = '\\(.*\\)'$/\\1/p" ${file}`;
|
|
32
|
+
/* Maven Central's Portal, which takes a signed bundle and reports the deployment's state. */
|
|
33
|
+
const CENTRAL_PORTAL = "https://central.sonatype.com";
|
|
34
|
+
/* repo1 serves a deployment up to 30 minutes after the Portal reports it PUBLISHED. */
|
|
35
|
+
const MAVEN_LIVE_TRIES = 180;
|
|
36
|
+
const PORTAL_AUTH = `TOKEN="$(printf '%s:%s' "$MAVEN_CENTRAL_USERNAME" "$MAVEN_CENTRAL_PASSWORD" | base64 -w0)"`;
|
|
37
|
+
const PORTAL_SECRETS = ` MAVEN_CENTRAL_USERNAME: \${{ secrets.MAVEN_CENTRAL_USERNAME }}
|
|
38
|
+
MAVEN_CENTRAL_PASSWORD: \${{ secrets.MAVEN_CENTRAL_PASSWORD }}
|
|
39
|
+
CENTRAL_PORTAL_URL: ${CENTRAL_PORTAL}
|
|
40
|
+
`;
|
|
41
|
+
const NODE_SETUP = ` - uses: ${ACTIONS.setupNode}
|
|
42
|
+
with:
|
|
43
|
+
node-version: "${TOOLS.node}"
|
|
44
|
+
registry-url: https://registry.npmjs.org
|
|
45
|
+
`;
|
|
46
|
+
function npm() {
|
|
47
|
+
return {
|
|
48
|
+
file: IDENTITY,
|
|
49
|
+
live: `[ "$(npm view "$NAME@$VERSION" version 2>/dev/null)" = "$VERSION" ]`,
|
|
50
|
+
name: identity("npm", "name"),
|
|
51
|
+
oidc: true,
|
|
52
|
+
publish: `${NODE_SETUP} - name: npm publish
|
|
53
|
+
run: |
|
|
54
|
+
npm install --global npm@${TOOLS.npm}
|
|
55
|
+
npm publish --provenance --access public
|
|
56
|
+
`,
|
|
57
|
+
version: identity("npm", "version"),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function jsr() {
|
|
61
|
+
return {
|
|
62
|
+
file: IDENTITY,
|
|
63
|
+
live: `curl -fsS -o /dev/null "https://jsr.io/$NAME/\${VERSION}_meta.json"`,
|
|
64
|
+
name: identity("jsr", "name"),
|
|
65
|
+
oidc: true,
|
|
66
|
+
publish: `${NODE_SETUP} - name: jsr publish
|
|
67
|
+
run: npx --yes jsr@${TOOLS.jsr} publish
|
|
68
|
+
`,
|
|
69
|
+
version: identity("jsr", "version"),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function pypi() {
|
|
73
|
+
return {
|
|
74
|
+
file: IDENTITY,
|
|
75
|
+
live: `curl -fsS -o /dev/null "https://pypi.org/pypi/$NAME/$VERSION/json"`,
|
|
76
|
+
name: identity("pypi", "name"),
|
|
77
|
+
oidc: true,
|
|
78
|
+
publish: ` - uses: ${ACTIONS.setupPython}
|
|
79
|
+
with:
|
|
80
|
+
python-version: "${TOOLS.python}"
|
|
81
|
+
- name: build
|
|
82
|
+
run: |
|
|
83
|
+
python -m pip install build==${TOOLS.build}
|
|
84
|
+
python -m build
|
|
85
|
+
- uses: ${ACTIONS.pypiPublish}
|
|
86
|
+
`,
|
|
87
|
+
version: identity("pypi", "version"),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function crates() {
|
|
91
|
+
return {
|
|
92
|
+
file: IDENTITY,
|
|
93
|
+
live: `curl -fsS -o /dev/null -A "release.yml (github.com/$GITHUB_REPOSITORY)" "https://crates.io/api/v1/crates/$NAME/$VERSION"`,
|
|
94
|
+
name: identity("crates.io", "name"),
|
|
95
|
+
oidc: true,
|
|
96
|
+
publish: ` - uses: ${ACTIONS.rustToolchain}
|
|
97
|
+
with:
|
|
98
|
+
toolchain: "${TOOLS.rust}"
|
|
99
|
+
- uses: ${ACTIONS.cratesAuth}
|
|
100
|
+
id: crates-auth
|
|
101
|
+
- name: cargo publish
|
|
102
|
+
env:
|
|
103
|
+
CARGO_REGISTRY_TOKEN: \${{ steps.crates-auth.outputs.token }}
|
|
104
|
+
run: cargo publish
|
|
105
|
+
`,
|
|
106
|
+
version: identity("crates.io", "version"),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/* NuGet's trusted publishing trades the job's OIDC token for a short-lived key; the policy belongs to a
|
|
110
|
+
* nuget.org user, which the repository variable NUGET_USER names */
|
|
111
|
+
function nuget() {
|
|
112
|
+
return {
|
|
113
|
+
file: IDENTITY,
|
|
114
|
+
live: `curl -fsS -o /dev/null "https://api.nuget.org/v3-flatcontainer/$(printf '%s' "$NAME" | tr '[:upper:]' '[:lower:]')/$VERSION/$(printf '%s' "$NAME" | tr '[:upper:]' '[:lower:]').nuspec"`,
|
|
115
|
+
name: identity("nuget", "name"),
|
|
116
|
+
oidc: true,
|
|
117
|
+
publish: ` - name: NuGet names the user that owns the trusted-publishing policy
|
|
118
|
+
env:
|
|
119
|
+
NUGET_USER: \${{ vars.NUGET_USER }}
|
|
120
|
+
run: |
|
|
121
|
+
[ -n "$NUGET_USER" ] || { echo "::error::set the repository variable NUGET_USER to the nuget.org user that owns the trusted-publishing policy"; exit 1; }
|
|
122
|
+
- uses: ${ACTIONS.setupDotnet}
|
|
123
|
+
with:
|
|
124
|
+
dotnet-version: "${TOOLS.dotnet}"
|
|
125
|
+
- uses: ${ACTIONS.nugetLogin}
|
|
126
|
+
id: nuget-login
|
|
127
|
+
with:
|
|
128
|
+
user: \${{ vars.NUGET_USER }}
|
|
129
|
+
- name: dotnet nuget push
|
|
130
|
+
env:
|
|
131
|
+
NUGET_API_KEY: \${{ steps.nuget-login.outputs.NUGET_API_KEY }}
|
|
132
|
+
run: |
|
|
133
|
+
dotnet pack --configuration Release --output "$RUNNER_TEMP/nupkg"
|
|
134
|
+
dotnet nuget push "$RUNNER_TEMP/nupkg/*.nupkg" --api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json
|
|
135
|
+
`,
|
|
136
|
+
version: identity("nuget", "version"),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/* the signed bundle: the Maven layout of every file with its GPG signature, md5 and sha1 */
|
|
140
|
+
function mavenBundle() {
|
|
141
|
+
return ` - uses: ${ACTIONS.setupJava}
|
|
142
|
+
with:
|
|
143
|
+
distribution: temurin
|
|
144
|
+
java-version: "${TOOLS.java}"
|
|
145
|
+
- uses: ${ACTIONS.setupGradle}
|
|
146
|
+
with:
|
|
147
|
+
gradle-version: "${TOOLS.gradle}"
|
|
148
|
+
- name: Maven Central bundle
|
|
149
|
+
env:
|
|
150
|
+
MAVEN_GPG_PRIVATE_KEY: \${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
|
|
151
|
+
MAVEN_GPG_PASSPHRASE: \${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
|
152
|
+
run: |
|
|
153
|
+
set -euo pipefail
|
|
154
|
+
STAGE="$RUNNER_TEMP/m2"
|
|
155
|
+
gradle --no-daemon publishToMavenLocal -Dmaven.repo.local="$STAGE"
|
|
156
|
+
printf '%s' "$MAVEN_GPG_PRIVATE_KEY" | gpg --batch --import
|
|
157
|
+
GROUP="$(${gradleField("group", "build.gradle")})"
|
|
158
|
+
ARTIFACT="$(${gradleField("rootProject.name", "settings.gradle")})"
|
|
159
|
+
REL="$(printf '%s' "$GROUP" | tr . /)/$ARTIFACT/$VERSION"
|
|
160
|
+
cd "$STAGE/$REL"
|
|
161
|
+
rm -f _remote.repositories maven-metadata*
|
|
162
|
+
for FILE in *; do
|
|
163
|
+
gpg --batch --yes --pinentry-mode loopback --passphrase "$MAVEN_GPG_PASSPHRASE" --armor --detach-sign "$FILE"
|
|
164
|
+
md5sum "$FILE" | cut -d " " -f 1 > "$FILE.md5"
|
|
165
|
+
sha1sum "$FILE" | cut -d " " -f 1 > "$FILE.sha1"
|
|
166
|
+
done
|
|
167
|
+
cd "$STAGE"
|
|
168
|
+
zip -qr "$RUNNER_TEMP/bundle.zip" "$REL"
|
|
169
|
+
`;
|
|
170
|
+
}
|
|
171
|
+
/* the bundle uploaded to the Portal, then waited on until the Portal publishes it */
|
|
172
|
+
function mavenPortal() {
|
|
173
|
+
return ` - name: Maven Central upload
|
|
174
|
+
env:
|
|
175
|
+
${PORTAL_SECRETS} run: |
|
|
176
|
+
set -euo pipefail
|
|
177
|
+
${PORTAL_AUTH}
|
|
178
|
+
ID="$(curl -fsS -X POST -H "Authorization: Bearer $TOKEN" -F "bundle=@$RUNNER_TEMP/bundle.zip" "$CENTRAL_PORTAL_URL/api/v1/publisher/upload?publishingType=AUTOMATIC")"
|
|
179
|
+
echo "DEPLOYMENT_ID=$ID" >> "$GITHUB_ENV"
|
|
180
|
+
- name: Maven Central publishes the deployment
|
|
181
|
+
env:
|
|
182
|
+
${PORTAL_SECRETS} run: |
|
|
183
|
+
set -euo pipefail
|
|
184
|
+
${PORTAL_AUTH}
|
|
185
|
+
for _ in $(seq "\${PORTAL_TRIES:-60}"); do
|
|
186
|
+
BODY="$(curl -fsS -X POST -H "Authorization: Bearer $TOKEN" "$CENTRAL_PORTAL_URL/api/v1/publisher/status?id=$DEPLOYMENT_ID")"
|
|
187
|
+
STATE="$(printf '%s' "$BODY" | jq -r .deploymentState)"
|
|
188
|
+
case "$STATE" in
|
|
189
|
+
PUBLISHED) echo "Maven Central published deployment $DEPLOYMENT_ID"; exit 0 ;;
|
|
190
|
+
PENDING | VALIDATING | VALIDATED | PUBLISHING) sleep "\${PORTAL_WAIT:-10}" ;;
|
|
191
|
+
FAILED) echo "::error::Maven Central refused deployment $DEPLOYMENT_ID: $(printf '%s' "$BODY" | jq -c .errors)"; exit 1 ;;
|
|
192
|
+
*) echo "::error::Maven Central reports deployment $DEPLOYMENT_ID as $STATE"; exit 1 ;;
|
|
193
|
+
esac
|
|
194
|
+
done
|
|
195
|
+
echo "::error::Maven Central did not publish deployment $DEPLOYMENT_ID in time"
|
|
196
|
+
exit 1
|
|
197
|
+
`;
|
|
198
|
+
}
|
|
199
|
+
/* Maven Central takes no OIDC: a Portal token uploads a bundle, the Maven layout of every file with its
|
|
200
|
+
* GPG signature, md5 and sha1, and the Portal validates and publishes it */
|
|
201
|
+
function maven() {
|
|
202
|
+
return {
|
|
203
|
+
file: IDENTITY,
|
|
204
|
+
live: `curl -fsS -o /dev/null "https://repo1.maven.org/maven2/$(printf '%s' "\${NAME%%:*}" | tr . /)/\${NAME#*:}/$VERSION/\${NAME#*:}-$VERSION.pom"`,
|
|
205
|
+
name: identity("maven-central", "name"),
|
|
206
|
+
oidc: false,
|
|
207
|
+
publish: `${mavenBundle()}${mavenPortal()}`,
|
|
208
|
+
tries: MAVEN_LIVE_TRIES,
|
|
209
|
+
version: identity("maven-central", "version"),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/* the proxy fetches a module version the first time it is asked for it, so the live check publishes it */
|
|
213
|
+
function goProxy() {
|
|
214
|
+
return {
|
|
215
|
+
file: IDENTITY,
|
|
216
|
+
live: `curl -fsS -o /dev/null "https://proxy.golang.org/$NAME/@v/$TAG.info"`,
|
|
217
|
+
name: identity("go", "name"),
|
|
218
|
+
oidc: false,
|
|
219
|
+
publish: "",
|
|
220
|
+
version: identity("go", "version"),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function githubRelease(registry) {
|
|
224
|
+
const assets = registry.assets.map((asset) => JSON.stringify(asset)).join(" ");
|
|
225
|
+
return {
|
|
226
|
+
file: ".release-state.json",
|
|
227
|
+
live: `gh release view "$TAG" > /dev/null`,
|
|
228
|
+
name: 'echo "$GITHUB_REPOSITORY"',
|
|
229
|
+
oidc: false,
|
|
230
|
+
publish: ` - name: GitHub release
|
|
231
|
+
env:
|
|
232
|
+
GH_TOKEN: \${{ github.token }}
|
|
233
|
+
run: gh release create "$TAG" ${assets} --verify-tag --title "$TAG" --notes "Release $TAG."
|
|
234
|
+
`,
|
|
235
|
+
version: "jq -r .version .release-state.json",
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/* every kind but a GitHub release, which reads its assets from the registry entry */
|
|
239
|
+
const KINDS = { crates, go: goProxy, jsr, maven, npm, nuget, pypi };
|
|
240
|
+
/** The steps the release workflow runs for `registry`. */
|
|
241
|
+
export function kind(registry) {
|
|
242
|
+
return registry.kind === "github" ? githubRelease(registry) : KINDS[registry.kind]();
|
|
243
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
/** The schema of `.release-state.json`: what a package's last release was cut from. */
|
|
3
|
+
export declare function releaseStateSchema(): z.ZodObject<{
|
|
4
|
+
hand: z.ZodString;
|
|
5
|
+
output: z.ZodString;
|
|
6
|
+
publishedAt: z.ZodString;
|
|
7
|
+
spec: z.ZodObject<{
|
|
8
|
+
commit: z.ZodString;
|
|
9
|
+
path: z.ZodString;
|
|
10
|
+
sha: z.ZodString;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
version: z.ZodString;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
/** Parsed and validated release state. */
|
|
15
|
+
export type ReleaseState = z.infer<ReturnType<typeof releaseStateSchema>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
const SEMVER_REGEX = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
3
|
+
const ISO_DATETIME_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/;
|
|
4
|
+
const HEX64 = /^[a-f0-9]{64}$/;
|
|
5
|
+
/** The schema of `.release-state.json`: what a package's last release was cut from. */
|
|
6
|
+
export function releaseStateSchema() {
|
|
7
|
+
return z.object({
|
|
8
|
+
/** sha256 over the package's tracked hand files at release, version lines normalized (`digest.ts`) */
|
|
9
|
+
hand: z.string().regex(HEX64),
|
|
10
|
+
/** sha256 over the package's generated output at release, or its product's spec sha for a hand-kept package */
|
|
11
|
+
output: z.string().regex(HEX64),
|
|
12
|
+
publishedAt: z.string().regex(ISO_DATETIME_REGEX),
|
|
13
|
+
/** the committed spec the release was generated from, readable again with `git show {commit}:{path}` */
|
|
14
|
+
spec: z.object({
|
|
15
|
+
commit: z.string().regex(/^[a-f0-9]{40}$/),
|
|
16
|
+
path: z.string().min(1),
|
|
17
|
+
sha: z.string().regex(HEX64),
|
|
18
|
+
}),
|
|
19
|
+
version: z.string().regex(SEMVER_REGEX),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Registry } from "./types.ts";
|
|
2
|
+
/** Where the rendered workflow sits in a public repo. */
|
|
3
|
+
export declare const RELEASE_WORKFLOW = ".github/workflows/release.yml";
|
|
4
|
+
/** The release workflow for a package published to `registries` (at least one). */
|
|
5
|
+
export declare function releaseWorkflow(registries: readonly Registry[]): string;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ACTIONS, kind } from "./registries.js";
|
|
2
|
+
/*
|
|
3
|
+
* The `release.yml` a public repo publishes itself with, rendered from its package's `registries`. Sync writes
|
|
4
|
+
* it into the public tree and pushes `v<version>` beside it; the workflow then publishes that tag to every
|
|
5
|
+
* registry through OIDC (no token secret), fails on any rejection, and waits until each registry serves it.
|
|
6
|
+
*/
|
|
7
|
+
/** Where the rendered workflow sits in a public repo. */
|
|
8
|
+
export const RELEASE_WORKFLOW = ".github/workflows/release.yml";
|
|
9
|
+
/* Every registry is retried 10 s apart, 60 times unless its kind says more; LIVE_CHECK_TRIES lets a local run of
|
|
10
|
+
* the step give up sooner. */
|
|
11
|
+
const DEFAULT_LIVE_TRIES = 60;
|
|
12
|
+
const liveStep = (registry, k) => ` - name: ${registry.kind} serves the version
|
|
13
|
+
run: |
|
|
14
|
+
NAME="$(${k.name})"
|
|
15
|
+
for _ in $(seq "\${LIVE_CHECK_TRIES:-${k.tries ?? DEFAULT_LIVE_TRIES}}"); do
|
|
16
|
+
if ${k.live}; then echo "${registry.kind} serves $NAME $VERSION"; exit 0; fi
|
|
17
|
+
sleep 10
|
|
18
|
+
done
|
|
19
|
+
echo "::error::${registry.kind} does not serve $NAME $VERSION; the publish above did not land"
|
|
20
|
+
exit 1
|
|
21
|
+
`;
|
|
22
|
+
/** The release workflow for a package published to `registries` (at least one). */
|
|
23
|
+
export function releaseWorkflow(registries) {
|
|
24
|
+
if (registries.length === 0)
|
|
25
|
+
throw new Error("a release workflow needs at least one registry");
|
|
26
|
+
const kinds = registries.map((registry) => ({ k: kind(registry), registry }));
|
|
27
|
+
const checks = [...new Map(kinds.map(({ k }) => [k.version, k.file])).entries()]
|
|
28
|
+
.map(([version, file]) => ` FOUND="$(${version})"
|
|
29
|
+
[ "$FOUND" = "$VERSION" ] || { echo "::error::tag $TAG, but ${file} holds version $FOUND"; exit 1; }
|
|
30
|
+
`)
|
|
31
|
+
.join("");
|
|
32
|
+
const permissions = [
|
|
33
|
+
` contents: ${registries.some((r) => r.kind === "github") ? "write" : "read"}`,
|
|
34
|
+
...(kinds.some(({ k }) => k.oidc) ? [" id-token: write"] : []),
|
|
35
|
+
].join("\n");
|
|
36
|
+
return `# Generated by honey-clients release sync from release.config.ts; the next sync overwrites any edit.
|
|
37
|
+
# Publishes the tag sync pushes (or the one given to a manual run) to: ${registries.map((r) => r.kind).join(", ")}.
|
|
38
|
+
name: release
|
|
39
|
+
on:
|
|
40
|
+
push:
|
|
41
|
+
tags: ["v*"]
|
|
42
|
+
workflow_dispatch:
|
|
43
|
+
inputs:
|
|
44
|
+
tag:
|
|
45
|
+
description: Tag to publish again, as vX.Y.Z
|
|
46
|
+
required: true
|
|
47
|
+
type: string
|
|
48
|
+
permissions:
|
|
49
|
+
contents: read
|
|
50
|
+
concurrency:
|
|
51
|
+
group: release
|
|
52
|
+
cancel-in-progress: false
|
|
53
|
+
jobs:
|
|
54
|
+
publish:
|
|
55
|
+
runs-on: ubuntu-24.04
|
|
56
|
+
permissions:
|
|
57
|
+
${permissions}
|
|
58
|
+
defaults:
|
|
59
|
+
run:
|
|
60
|
+
shell: bash
|
|
61
|
+
env:
|
|
62
|
+
TAG: \${{ inputs.tag || github.ref_name }}
|
|
63
|
+
steps:
|
|
64
|
+
- uses: ${ACTIONS.checkout}
|
|
65
|
+
with:
|
|
66
|
+
ref: \${{ inputs.tag || github.ref }}
|
|
67
|
+
- name: the tag is the version the package publishes
|
|
68
|
+
run: |
|
|
69
|
+
VERSION="\${TAG#v}"
|
|
70
|
+
${checks} echo "VERSION=$VERSION" >> "$GITHUB_ENV"
|
|
71
|
+
${kinds.map(({ k, registry }) => k.publish + liveStep(registry, k)).join("")}`;
|
|
72
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PublicPackage } from "./types.ts";
|
|
2
|
+
export type RepoSetting = "description" | "homepage" | "topics";
|
|
3
|
+
export type RepoSettingsResult = {
|
|
4
|
+
changed: RepoSetting[];
|
|
5
|
+
status: "checked";
|
|
6
|
+
} | {
|
|
7
|
+
status: "unchecked: no token";
|
|
8
|
+
};
|
|
9
|
+
export type RepoSettingsSync = (pkg: PublicPackage) => Promise<RepoSettingsResult>;
|
|
10
|
+
/** The one fetch shape the step uses, so a test's fake GitHub needs no more than this. */
|
|
11
|
+
export type Fetch = (url: string, init: RequestInit) => Promise<Response>;
|
|
12
|
+
/**
|
|
13
|
+
* Reads a public repo's description, website and topics, and writes back only what differs from its package:
|
|
14
|
+
* a rerun after a crash or a hand edit converges, and one with nothing to change sends no write.
|
|
15
|
+
* A dry run reports what it would change. With no token it checks nothing, since GitHub answers its
|
|
16
|
+
* unauthenticated reads under a rate limit too low for every repo of a run.
|
|
17
|
+
*/
|
|
18
|
+
export declare function repoSettingsSyncer(io: {
|
|
19
|
+
dryRun: boolean;
|
|
20
|
+
fetch: Fetch;
|
|
21
|
+
token: string;
|
|
22
|
+
}): RepoSettingsSync;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { GITHUB_API } from "./constants.js";
|
|
3
|
+
const sameSet = (a, b) => a.length === b.length && [...a].sort().join("\n") === [...b].sort().join("\n");
|
|
4
|
+
/**
|
|
5
|
+
* Reads a public repo's description, website and topics, and writes back only what differs from its package:
|
|
6
|
+
* a rerun after a crash or a hand edit converges, and one with nothing to change sends no write.
|
|
7
|
+
* A dry run reports what it would change. With no token it checks nothing, since GitHub answers its
|
|
8
|
+
* unauthenticated reads under a rate limit too low for every repo of a run.
|
|
9
|
+
*/
|
|
10
|
+
export function repoSettingsSyncer(io) {
|
|
11
|
+
const Repo = z.object({ description: z.string().nullable(), homepage: z.string().nullable() });
|
|
12
|
+
const Topics = z.object({ names: z.array(z.string()) });
|
|
13
|
+
const GitHubError = z.object({ message: z.string() });
|
|
14
|
+
return async (pkg) => {
|
|
15
|
+
if (io.token === "")
|
|
16
|
+
return { status: "unchecked: no token" };
|
|
17
|
+
const call = async (path, method = "GET", body) => {
|
|
18
|
+
const response = await io.fetch(`${GITHUB_API}/repos/${pkg.repo}${path}`, {
|
|
19
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
20
|
+
headers: {
|
|
21
|
+
accept: "application/vnd.github+json",
|
|
22
|
+
authorization: `Bearer ${io.token}`,
|
|
23
|
+
},
|
|
24
|
+
method,
|
|
25
|
+
});
|
|
26
|
+
const json = await response.json();
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
const parsed = GitHubError.safeParse(json);
|
|
29
|
+
throw new Error(`${pkg.repo}: GitHub answered ${method} ${path || "/"} with ${response.status}: ${parsed.success ? parsed.data.message : JSON.stringify(json)}`);
|
|
30
|
+
}
|
|
31
|
+
return json;
|
|
32
|
+
};
|
|
33
|
+
const [repo, topics] = await Promise.all([
|
|
34
|
+
call("").then((json) => Repo.parse(json)),
|
|
35
|
+
call("/topics").then((json) => Topics.parse(json)),
|
|
36
|
+
]);
|
|
37
|
+
const changed = [];
|
|
38
|
+
if (repo.description !== pkg.description)
|
|
39
|
+
changed.push("description");
|
|
40
|
+
if (repo.homepage !== pkg.homepage)
|
|
41
|
+
changed.push("homepage");
|
|
42
|
+
const topicsDrifted = !sameSet(topics.names, pkg.topics);
|
|
43
|
+
if (topicsDrifted)
|
|
44
|
+
changed.push("topics");
|
|
45
|
+
if (io.dryRun)
|
|
46
|
+
return { changed, status: "checked" };
|
|
47
|
+
if (changed.includes("description") || changed.includes("homepage"))
|
|
48
|
+
await call("", "PATCH", { description: pkg.description, homepage: pkg.homepage });
|
|
49
|
+
if (topicsDrifted)
|
|
50
|
+
await call("/topics", "PUT", { names: [...pkg.topics].sort() });
|
|
51
|
+
return { changed, status: "checked" };
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { SpecSource } from "./types.ts";
|
|
2
|
+
export type SpecDrift = {
|
|
3
|
+
readonly status: "drift";
|
|
4
|
+
readonly deployedSha: string;
|
|
5
|
+
readonly committedSha: string;
|
|
6
|
+
/** `METHOD path` in the committed spec that prod does not serve. */
|
|
7
|
+
readonly missing: readonly string[];
|
|
8
|
+
/** `METHOD path` prod serves that the committed spec lacks. */
|
|
9
|
+
readonly extra: readonly string[];
|
|
10
|
+
};
|
|
11
|
+
export type SpecGate = {
|
|
12
|
+
readonly status: "match";
|
|
13
|
+
readonly sha: string;
|
|
14
|
+
} | SpecDrift;
|
|
15
|
+
/** The value with every object's keys sorted, so equal specs serialize equally. */
|
|
16
|
+
export declare function canonicalize(value: unknown): unknown;
|
|
17
|
+
/** sha256 of the spec's canonical JSON. */
|
|
18
|
+
export declare function canonicalSha(spec: unknown): string;
|
|
19
|
+
/** Fetches the deployed spec and compares it with the committed one; throws naming the URL when prod does not answer. */
|
|
20
|
+
export declare function checkDeployedSpec(source: SpecSource, fetchImpl?: typeof fetch): Promise<SpecGate>;
|
|
21
|
+
/** Why `packageName` was refused, and what unblocks it. */
|
|
22
|
+
export declare function describeDrift(packageName: string, gate: SpecDrift): string;
|
|
23
|
+
/** Honey's manifest in `dir`: each generated path, relative to `dir`, with its sha256; undefined when there is none. */
|
|
24
|
+
export declare function generatedFiles(dir: string): Readonly<Record<string, string>> | undefined;
|
|
25
|
+
/** The paths, relative to `dir`, that honey's manifest in `dir` lists as generated; empty when there is none. */
|
|
26
|
+
export declare function generatedPaths(dir: string): ReadonlySet<string>;
|
|
27
|
+
/** `checkDeployedSpec`, fetched once per deployed URL for the life of the returned function: one run, one answer. */
|
|
28
|
+
export declare function memoizedSpecGate(fetchImpl?: typeof fetch): (source: SpecSource) => Promise<SpecGate>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { MANIFEST } from "../gen/write.js";
|
|
5
|
+
/*
|
|
6
|
+
* Generated code must only describe operations prod serves. Sync, bump and release compare the deployed public
|
|
7
|
+
* spec with the committed one before they let changed generated output out.
|
|
8
|
+
*/
|
|
9
|
+
const METHODS = ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
|
|
10
|
+
const FETCH_TIMEOUT_MS = 30_000;
|
|
11
|
+
/** The value with every object's keys sorted, so equal specs serialize equally. */
|
|
12
|
+
export function canonicalize(value) {
|
|
13
|
+
if (value === null || typeof value !== "object")
|
|
14
|
+
return value;
|
|
15
|
+
if (Array.isArray(value))
|
|
16
|
+
return value.map(canonicalize);
|
|
17
|
+
const sorted = {};
|
|
18
|
+
for (const key of Object.keys(value).sort()) {
|
|
19
|
+
sorted[key] = canonicalize(value[key]);
|
|
20
|
+
}
|
|
21
|
+
return sorted;
|
|
22
|
+
}
|
|
23
|
+
/** sha256 of the spec's canonical JSON. */
|
|
24
|
+
export function canonicalSha(spec) {
|
|
25
|
+
return createHash("sha256")
|
|
26
|
+
.update(JSON.stringify(canonicalize(spec)))
|
|
27
|
+
.digest("hex");
|
|
28
|
+
}
|
|
29
|
+
function operations(spec) {
|
|
30
|
+
const paths = spec.paths ?? {};
|
|
31
|
+
const out = new Set();
|
|
32
|
+
for (const [path, item] of Object.entries(paths)) {
|
|
33
|
+
for (const method of METHODS)
|
|
34
|
+
if (item[method] !== undefined)
|
|
35
|
+
out.add(`${method.toUpperCase()} ${path}`);
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
const minus = (a, b) => [...a].filter((x) => !b.has(x)).sort();
|
|
40
|
+
/** Fetches the deployed spec and compares it with the committed one; throws naming the URL when prod does not answer. */
|
|
41
|
+
export async function checkDeployedSpec(source, fetchImpl = fetch) {
|
|
42
|
+
const committed = JSON.parse(readFileSync(source.committedPath, "utf8"));
|
|
43
|
+
let res;
|
|
44
|
+
try {
|
|
45
|
+
res = await fetchImpl(source.deployedUrl, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
const cause = error instanceof Error && error.cause instanceof Error ? `: ${error.cause.message}` : "";
|
|
49
|
+
throw new Error(`could not fetch the deployed spec from ${source.deployedUrl}: ${error instanceof Error ? error.message : String(error)}${cause}`, { cause: error });
|
|
50
|
+
}
|
|
51
|
+
if (!res.ok)
|
|
52
|
+
throw new Error(`the deployed spec at ${source.deployedUrl} answered ${res.status}`);
|
|
53
|
+
const deployed = await res.json();
|
|
54
|
+
const committedSha = canonicalSha(committed);
|
|
55
|
+
const deployedSha = canonicalSha(deployed);
|
|
56
|
+
if (committedSha === deployedSha)
|
|
57
|
+
return { sha: committedSha, status: "match" };
|
|
58
|
+
const ours = operations(committed);
|
|
59
|
+
const theirs = operations(deployed);
|
|
60
|
+
return {
|
|
61
|
+
committedSha,
|
|
62
|
+
deployedSha,
|
|
63
|
+
extra: minus(theirs, ours),
|
|
64
|
+
missing: minus(ours, theirs),
|
|
65
|
+
status: "drift",
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/* each operation on a line of its own, or a line saying there is none */
|
|
69
|
+
const list = (ops) => (ops.length === 0 ? " (none)" : ops.map((o) => ` ${o}`).join("\n"));
|
|
70
|
+
/** Why `packageName` was refused, and what unblocks it. */
|
|
71
|
+
export function describeDrift(packageName, gate) {
|
|
72
|
+
return [
|
|
73
|
+
`${packageName}: its generated output changed, but prod does not serve the committed public spec.`,
|
|
74
|
+
` committed ${gate.committedSha}`,
|
|
75
|
+
` deployed ${gate.deployedSha}`,
|
|
76
|
+
"Operations prod does not serve yet:",
|
|
77
|
+
list(gate.missing),
|
|
78
|
+
"Operations prod serves that the committed spec lacks:",
|
|
79
|
+
list(gate.extra),
|
|
80
|
+
"Deploy the API so it serves the committed spec, then re-run the bump; the next sync picks it up.",
|
|
81
|
+
].join("\n");
|
|
82
|
+
}
|
|
83
|
+
/** Honey's manifest in `dir`: each generated path, relative to `dir`, with its sha256; undefined when there is none. */
|
|
84
|
+
export function generatedFiles(dir) {
|
|
85
|
+
const file = join(dir, MANIFEST);
|
|
86
|
+
if (!existsSync(file))
|
|
87
|
+
return undefined;
|
|
88
|
+
const { files } = JSON.parse(readFileSync(file, "utf8"));
|
|
89
|
+
return files ?? {};
|
|
90
|
+
}
|
|
91
|
+
/** The paths, relative to `dir`, that honey's manifest in `dir` lists as generated; empty when there is none. */
|
|
92
|
+
export function generatedPaths(dir) {
|
|
93
|
+
return new Set(Object.keys(generatedFiles(dir) ?? {}));
|
|
94
|
+
}
|
|
95
|
+
/** `checkDeployedSpec`, fetched once per deployed URL for the life of the returned function: one run, one answer. */
|
|
96
|
+
export function memoizedSpecGate(fetchImpl = fetch) {
|
|
97
|
+
const answers = new Map();
|
|
98
|
+
return (source) => {
|
|
99
|
+
const key = `${source.deployedUrl}\0${source.committedPath}`;
|
|
100
|
+
let answer = answers.get(key);
|
|
101
|
+
if (answer === undefined) {
|
|
102
|
+
answer = checkDeployedSpec(source, fetchImpl);
|
|
103
|
+
answers.set(key, answer);
|
|
104
|
+
}
|
|
105
|
+
return answer;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ReleaseContext } from "./context.ts";
|
|
2
|
+
import { type PackageResult } from "./sync.ts";
|
|
3
|
+
/** What `release sync --help` prints. */
|
|
4
|
+
export declare const HELP = "Usage: honey-clients release sync --config <path> [options]\n\nOptions:\n --config <path> The release config (required)\n --only <names> Comma-separated package filter. Accepts short \"name\" (if unique) or \"project/name\"\n --dry-run Log push commands without executing them\n --validate-only Validate the release config and exit 0/1\n --help Show this message\n\nEnv:\n GH_TOKEN GitHub token (required unless --validate-only or --dry-run)\n";
|
|
5
|
+
/** What `release sync` was asked for. */
|
|
6
|
+
export interface CliOptions {
|
|
7
|
+
/** The release config's path; required unless `--help`. */
|
|
8
|
+
config: string | undefined;
|
|
9
|
+
/** Report what would be pushed and push nothing. */
|
|
10
|
+
dryRun: boolean;
|
|
11
|
+
/** Print the help and do nothing else. */
|
|
12
|
+
help: boolean;
|
|
13
|
+
/** The packages to sync, by `name` or `project/name`; every package when absent. */
|
|
14
|
+
only: string[] | undefined;
|
|
15
|
+
/** Only load and check the release config. */
|
|
16
|
+
validateOnly: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** A parse that succeeded with `options`, or failed with an `error` to show the caller. */
|
|
19
|
+
export type ParsedArgs = {
|
|
20
|
+
error: string;
|
|
21
|
+
ok: false;
|
|
22
|
+
} | {
|
|
23
|
+
ok: true;
|
|
24
|
+
options: CliOptions;
|
|
25
|
+
};
|
|
26
|
+
/** `release sync`'s flags; a value flag with no value is an error, any unknown argument is ignored. */
|
|
27
|
+
export declare function parseArgs(argv: readonly string[]): ParsedArgs;
|
|
28
|
+
/** The run's report: a header, a rule, and one line per package with its status and detail. */
|
|
29
|
+
export declare function formatResults(items: readonly PackageResult[]): string[];
|
|
30
|
+
/** Runs `release sync <argv>`: the exit code it ends with, 1 when any package failed. */
|
|
31
|
+
export declare function sync(argv: readonly string[], ctx: ReleaseContext): Promise<number>;
|