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
name: release
# Publishes on a version tag, e.g. `git tag v0.1.0 && git push origin v0.1.0`.
# Both jobs guard that the tag matches the manifest version before publishing.
on:
push:
tags:
- "v*"
permissions:
contents: read
jobs:
crates-io:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Tag matches Cargo.toml version
run: |
tag="${GITHUB_REF_NAME#v}"
ver="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')"
echo "tag=$tag manifest=$ver"
[ "$tag" = "$ver" ] || { echo "::error::tag $tag != Cargo.toml version $ver"; exit 1; }
- run: cargo publish --locked
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
npm:
name: Publish to npm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@v2
with:
tool: wasm-bindgen-cli@0.2.126
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
- name: Tag matches package.json version
run: |
tag="${GITHUB_REF_NAME#v}"
ver="$(node -p "require('./package.json').version")"
echo "tag=$tag manifest=$ver"
[ "$tag" = "$ver" ] || { echo "::error::tag $tag != package.json version $ver"; exit 1; }
# Build the wasm artifact into pkg/, then publish it. --ignore-scripts so
# the `prepare` lifecycle doesn't rebuild during publish.
- run: npm run build
- run: npm publish --access public --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}