Skip to content

Commit 76ee3f8

Browse files
committed
Add NPM release CI
1 parent 03a01b3 commit 76ee3f8

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

.github/workflows/npm.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: NPM Release
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
7+
jobs:
8+
npm:
9+
name: NPM Build & Publish
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Setup | Checkout
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
# Cache files between builds
18+
- name: Setup | Cache Cargo
19+
uses: actions/[email protected]
20+
with:
21+
path: |
22+
~/.cargo/registry
23+
~/.cargo/git
24+
key: npm-build-cargo-${{ hashFiles('**/Cargo.lock') }}
25+
26+
- name: Setup | Rust
27+
uses: actions-rs/[email protected]
28+
with:
29+
toolchain: nightly
30+
override: true
31+
profile: minimal
32+
target: x86_64-unknown-linux-gnu
33+
34+
- uses: actions/setup-node@v3
35+
with:
36+
node-version: "16.x"
37+
registry-url: "https://registry.npmjs.org"
38+
39+
- name: Install wasm-pack & wasm-opt
40+
run: |
41+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
42+
sudo apt-get install binaryen
43+
44+
- name: Publish NPM
45+
run: |
46+
echo $(git describe --abbrev=0 --tags | sed "s/^v//")
47+
make wasm:publish
48+
env:
49+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/release.yml

+36
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,39 @@ jobs:
143143
144144
- name: Image digest
145145
run: echo ${{ steps.docker_build.outputs.digest }}
146+
npm:
147+
runs-on: ubuntu-latest
148+
needs: github_release
149+
steps:
150+
- name: Setup | Checkout
151+
uses: actions/[email protected]
152+
153+
# Cache files between builds
154+
- name: Setup | Cache Cargo
155+
uses: actions/[email protected]
156+
with:
157+
path: |
158+
~/.cargo/registry
159+
~/.cargo/git
160+
key: npm-build-cargo-${{ hashFiles('**/Cargo.lock') }}
161+
162+
- name: Setup | Rust
163+
uses: actions-rs/[email protected]
164+
with:
165+
toolchain: stable
166+
override: true
167+
profile: minimal
168+
target: x86_64-unknown-linux-gnu
169+
170+
- uses: actions/setup-node@v3
171+
with:
172+
node-version: "16.x"
173+
registry-url: "https://registry.npmjs.org"
174+
175+
- name: Setup wasm-pack
176+
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
177+
178+
- name: Publish NPM
179+
run: make wasm:publish
180+
env:
181+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
WORKDIR=$(shell pwd)
2-
LAST_TAG_VERSION=$(shell git describe --abbrev=0 --tags | sed -e "s/v//")
2+
LAST_TAG_VERSION=$(shell git describe --abbrev=0 --tags | sed "s/^v//")
33

44
bench:
55
rustup run nightly cargo bench --features bench
@@ -19,12 +19,15 @@ test\:bench:
1919
tests/bench.sh
2020
test\:lint-json:
2121
tests/test_lint_json.sh
22+
install:
23+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
24+
brew install binaryen
2225
wasm:
2326
wasm-pack build --release --scope huacnlee -d $(WORKDIR)/pkg autocorrect
2427
wasm-opt -Os -o pkg/autocorrect_bg.wasm pkg/autocorrect_bg.wasm
2528
wasm\:publish:
2629
make wasm
2730
@echo "\n\nWill release version: $(LAST_TAG_VERSION)\n\n"
28-
cd pkg && npm version $(LAST_TAG_VERSION) && npm publish
31+
cd pkg && yarn publish --new-version $(LAST_TAG_VERSION)
2932
crate\:publish:
3033
cargo release --manifest-path autocorrect/Cargo.toml --config autocorrect/release.toml

0 commit comments

Comments
 (0)