Skip to content

Commit

Permalink
Add NPM release CI
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Apr 11, 2022
1 parent 03a01b3 commit 76ee3f8
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: NPM Release
on:
push:
tags:
- "v*"

jobs:
npm:
name: NPM Build & Publish
runs-on: ubuntu-latest
steps:
- name: Setup | Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

# Cache files between builds
- name: Setup | Cache Cargo
uses: actions/[email protected]
with:
path: |
~/.cargo/registry
~/.cargo/git
key: npm-build-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Setup | Rust
uses: actions-rs/[email protected]
with:
toolchain: nightly
override: true
profile: minimal
target: x86_64-unknown-linux-gnu

- uses: actions/setup-node@v3
with:
node-version: "16.x"
registry-url: "https://registry.npmjs.org"

- name: Install wasm-pack & wasm-opt
run: |
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
sudo apt-get install binaryen
- name: Publish NPM
run: |
echo $(git describe --abbrev=0 --tags | sed "s/^v//")
make wasm:publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,39 @@ jobs:
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
npm:
runs-on: ubuntu-latest
needs: github_release
steps:
- name: Setup | Checkout
uses: actions/[email protected]

# Cache files between builds
- name: Setup | Cache Cargo
uses: actions/[email protected]
with:
path: |
~/.cargo/registry
~/.cargo/git
key: npm-build-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Setup | Rust
uses: actions-rs/[email protected]
with:
toolchain: stable
override: true
profile: minimal
target: x86_64-unknown-linux-gnu

- uses: actions/setup-node@v3
with:
node-version: "16.x"
registry-url: "https://registry.npmjs.org"

- name: Setup wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Publish NPM
run: make wasm:publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
WORKDIR=$(shell pwd)
LAST_TAG_VERSION=$(shell git describe --abbrev=0 --tags | sed -e "s/v//")
LAST_TAG_VERSION=$(shell git describe --abbrev=0 --tags | sed "s/^v//")

bench:
rustup run nightly cargo bench --features bench
Expand All @@ -19,12 +19,15 @@ test\:bench:
tests/bench.sh
test\:lint-json:
tests/test_lint_json.sh
install:
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
brew install binaryen
wasm:
wasm-pack build --release --scope huacnlee -d $(WORKDIR)/pkg autocorrect
wasm-opt -Os -o pkg/autocorrect_bg.wasm pkg/autocorrect_bg.wasm
wasm\:publish:
make wasm
@echo "\n\nWill release version: $(LAST_TAG_VERSION)\n\n"
cd pkg && npm version $(LAST_TAG_VERSION) && npm publish
cd pkg && yarn publish --new-version $(LAST_TAG_VERSION)
crate\:publish:
cargo release --manifest-path autocorrect/Cargo.toml --config autocorrect/release.toml

0 comments on commit 76ee3f8

Please sign in to comment.