Repository navigation
281 lines (272 loc) · 12.2 KB
/
Copy pathrust-release.yml
File metadata and controls
281 lines (272 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
name: Rust Release
# Releases the Rust client (rust/), versioned with Changesets (see
# .changeset/README.md). The zero-rust npm package (packages/zero-rust-cli),
# the codegen CLI, carries the version and the changelog, as zero-swift does
# for Swift; `pnpm --filter zero-rust sync-version` copies the version into
# rust/Cargo.toml. Swift Release's "Version Packages" PR runs it, so one PR
# versions both clients.
#
# On each push to main, when no zero-rust changeset is pending and the
# version in rust/Cargo.toml isn't released yet (0.0.0 is never released):
# that is, once the Version Packages PR merges, which is the release gate, as
# for Swift. The rust-release environment limits the jobs to main and holds
# their secrets; it has no required reviewers.
# - publishes rust/ to the mirror (wevm/zero-rust) with a subtree split, tags
# the version there, and creates a GitHub release from the version's
# section of packages/zero-rust-cli/CHANGELOG.md.
# - publishes zero-client to crates.io with trusted publishing. Trusted
# publishing needs the crate to exist, so tmm makes the first publish by
# hand, from his machine with his own `cargo login` (rust/DESIGN.md); until
# then this job is skipped with a notice. CI holds no crates.io token.
# - publishes the zero-rust CLI to npm with trusted publishing, which also
# needs the package to exist: until tmm publishes it by hand the first
# time, this job is skipped with a notice too.
# Each step is skipped when its release already exists, so a failed run can be
# rerun. The plan reads the mirror without a token, so the mirror has to be
# public, as wevm/zero-swift is.
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: rust-release
cancel-in-progress: false
jobs:
plan:
name: Plan release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.plan.outputs.version }}
mirror: ${{ steps.plan.outputs.mirror }}
release: ${{ steps.plan.outputs.release }}
crates: ${{ steps.plan.outputs.crates }}
npm: ${{ steps.plan.outputs.npm }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
sparse-checkout: |
.changeset
rust/Cargo.toml
packages/zero-rust-cli/package.json
sparse-checkout-cone-mode: false
- id: plan
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
nothing() {
for o in mirror release crates npm; do echo "$o=false" >> "$GITHUB_OUTPUT"; done
}
# The Version Packages PR releases these.
if grep -lE "^['\"]?zero-rust['\"]?: " .changeset/*.md 2>/dev/null; then
echo "::notice::zero-rust changesets are pending; nothing to release."
nothing
exit 0
fi
version="$(sed -nE '/^\[workspace\.package\]/,/^\[/ s/^version = "([^"]*)"/\1/p' rust/Cargo.toml)"
package="$(jq -r .version packages/zero-rust-cli/package.json)"
if [ "$package" != "$version" ]; then
echo "packages/zero-rust-cli is $package but rust/Cargo.toml is $version." >&2
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
if [ "$version" = "0.0.0" ]; then
echo "::notice::The Rust client is unreleased (0.0.0)."
nothing
exit 0
fi
if git ls-remote --exit-code --tags https://github.com/wevm/zero-rust.git "refs/tags/$version" >/dev/null; then
echo "mirror=false" >> "$GITHUB_OUTPUT"
else
echo "mirror=true" >> "$GITHUB_OUTPUT"
fi
# The lookups retry network errors and 408, 429, and 5xx responses,
# not a 404.
status="$(curl -sS --retry 3 --retry-all-errors -o /dev/null -w '%{http_code}' -H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/wevm/zero-rust/releases/tags/$version")"
case "$status" in
200) echo "release=false" >> "$GITHUB_OUTPUT" ;;
404) echo "release=true" >> "$GITHUB_OUTPUT" ;;
*) echo "Looking up the $version release returned HTTP $status." >&2; exit 1 ;;
esac
# Only a 404 means unpublished: a failed lookup isn't a reason to
# publish. Trusted publishing needs the package to exist, so the
# first publish is made by hand, as for crates.io.
pkg="$(curl -sS --retry 3 --retry-all-errors -o /dev/null -w '%{http_code}' https://registry.npmjs.org/zero-rust)"
case "$pkg" in
200)
npm="$(curl -sS --retry 3 --retry-all-errors -o /dev/null -w '%{http_code}' "https://registry.npmjs.org/zero-rust/$version")"
case "$npm" in
200) echo "npm=false" >> "$GITHUB_OUTPUT" ;;
404) echo "npm=true" >> "$GITHUB_OUTPUT" ;;
*) echo "Looking up zero-rust@$version on npm returned HTTP $npm." >&2; exit 1 ;;
esac
;;
404)
echo "::warning::zero-rust isn't on npm yet. Publish $version by hand (pnpm --filter zero-rust build, pnpm --filter zero-rust pack, then npm publish that tarball, at this commit; not npm publish in the package, which ships src/bin.ts as the bin), set up trusted publishing for wevm/zero's rust-release.yml, then rerun this workflow."
echo "npm=false" >> "$GITHUB_OUTPUT"
;;
*) echo "Looking up zero-rust on npm returned HTTP $pkg." >&2; exit 1 ;;
esac
# crates.io asks for a User-Agent that says who is asking.
ua='wevm/zero rust-release (https://github.com/wevm/zero)'
crate="$(curl -sS --retry 3 --retry-all-errors -o /dev/null -w '%{http_code}' -A "$ua" https://crates.io/api/v1/crates/zero-client)"
case "$crate" in
200) ;;
404)
# The first publish is made by hand (rust/DESIGN.md); trusted
# publishing takes over once the crate exists.
echo "::warning::zero-client isn't on crates.io yet. Publish $version by hand (cargo publish -p zero-client from rust/ at this commit), set up trusted publishing for wevm/zero's rust-release.yml, then rerun this workflow."
echo "crates=false" >> "$GITHUB_OUTPUT"
exit 0
;;
*) echo "Looking up zero-client on crates.io returned HTTP $crate." >&2; exit 1 ;;
esac
published="$(curl -sS --retry 3 --retry-all-errors -o /dev/null -w '%{http_code}' -A "$ua" "https://crates.io/api/v1/crates/zero-client/$version")"
case "$published" in
200) echo "crates=false" >> "$GITHUB_OUTPUT" ;;
404) echo "crates=true" >> "$GITHUB_OUTPUT" ;;
*) echo "Looking up zero-client $version on crates.io returned HTTP $published." >&2; exit 1 ;;
esac
mirror:
name: Publish mirror
runs-on: ubuntu-latest
needs: plan
if: needs.plan.outputs.mirror == 'true' || needs.plan.outputs.release == 'true'
environment: rust-release
permissions:
contents: read
id-token: write # For the github-sts token exchange.
env:
MIRROR_REPO: wevm/zero-rust
VERSION: ${{ needs.plan.outputs.version }}
steps:
# Short-lived token for the mirror, authorized by
# rust/.github/sts/mirror.sts.yaml (published to the mirror's main).
- name: Fetch mirror token
id: sts
uses: wevm/actions/.github/actions/github-sts@b518cf981b50a4c745a8b7335fc693f34b108a75 # main
with:
scope: wevm/zero-rust
policy: mirror
ttl: 5m
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
persist-credentials: false
- name: Split and push
if: needs.plan.outputs.mirror == 'true'
env:
MIRROR_TOKEN: ${{ steps.sts.outputs.token }}
run: |
set -euo pipefail
git subtree split --prefix=rust -b mirror
remote="https://x-access-token:${MIRROR_TOKEN}@github.com/${MIRROR_REPO}.git"
git push "$remote" mirror:main
git tag "$VERSION" mirror
git push "$remote" "refs/tags/$VERSION"
# The version's changelog section. Its commit hashes are wevm/zero's,
# which GitHub doesn't link from the mirror, so they become links.
- name: Create release
env:
GH_TOKEN: ${{ steps.sts.outputs.token }}
run: |
set -euo pipefail
awk -v v="## $VERSION" '$0 == v {f = 1; next} /^## / {f = 0} f' \
packages/zero-rust-cli/CHANGELOG.md |
sed -E 's|^- ([0-9a-f]{7,40}):|- [`\1`](https://github.com/wevm/zero/commit/\1):|' \
>"$RUNNER_TEMP/notes.md"
if ! grep -q '[^[:space:]]' "$RUNNER_TEMP/notes.md"; then
echo "No section for $VERSION in packages/zero-rust-cli/CHANGELOG.md." >&2
exit 1
fi
gh release create "$VERSION" -R "$MIRROR_REPO" --verify-tag \
--title "$VERSION" --notes-file "$RUNNER_TEMP/notes.md"
crates:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: plan
if: needs.plan.outputs.crates == 'true'
environment: rust-release
permissions:
contents: read
id-token: write # For crates.io trusted publishing.
defaults:
run:
working-directory: rust
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Install the toolchain
run: rustup show active-toolchain || rustup toolchain install
# Trusted publishing: a short-lived token for this workflow, which
# crates.io trusts once the crate exists and is configured for it.
- name: Authenticate
id: auth
uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6
- name: Publish
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: cargo publish -p zero-client --locked
npm-build:
name: Build npm package
runs-on: ubuntu-latest
needs: plan
if: needs.plan.outputs.npm == 'true'
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
with:
version: 11.11.0
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .nvmrc
package-manager-cache: false
- run: pnpm install --frozen-lockfile
- name: Smoke test the packed CLI
run: pnpm --filter zero-rust smoke
- name: Build and pack
run: |
pnpm --filter zero-rust build
pnpm --filter zero-rust pack --pack-destination "$GITHUB_WORKSPACE/dist/npm"
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: zero-rust-npm
path: dist/npm/*.tgz
if-no-files-found: error
npm-publish:
name: Publish npm package
runs-on: ubuntu-latest
needs: [plan, npm-build]
environment: rust-release
permissions:
contents: read
id-token: write # For npm trusted publishing.
env:
VERSION: ${{ needs.plan.outputs.version }}
steps:
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24.x
registry-url: 'https://registry.npmjs.org'
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: zero-rust-npm
path: dist/npm
# As in Swift Release: a run that plans right after the previous run's
# publish can still choose to publish. The registry's refusal settles it.
- name: Publish
run: |
set -uo pipefail
npm publish "dist/npm/zero-rust-$VERSION.tgz" --provenance --access public 2>&1 | tee publish.log && exit 0
if grep -q 'cannot publish over the previously published versions' publish.log; then
echo "::notice::zero-rust@$VERSION is already on npm."
exit 0
fi
exit 1