Skip to content

Commit

Permalink
feat: wasm npm package (#153)
Browse files Browse the repository at this point in the history
* chore: deploy to npm

* ci: fix cross build --bin

* ci: fix window missing .exe

* ci: cache

* ci: fix sed macos

* ci: disable macos m1

* ci: fix sed

* ci: change version

* feat: clap colors

* ci: tag

* ci: cleanup dev
  • Loading branch information
ctison committed Dec 11, 2023
1 parent 5aa5478 commit 282d5de
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 211 deletions.
127 changes: 91 additions & 36 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Test
run: cargo test -F bin,wasm

- name: Lint
run: cargo clippy -F bin,wasm

Expand All @@ -35,63 +42,111 @@ jobs:
id: version
run: echo "version=${GITHUB_REF##refs/tags/v}" >> $GITHUB_OUTPUT

build:
build-wasm:
runs-on: ubuntu-latest
needs: version
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- name: Install npm packages
run: bun install --frozen-lockfile
- name: Build wasm
run: |
bun run build
cd pkg/
cp ../.npmrc .
npm version --no-git-tag-version '${{ needs.version.outputs.version }}'
- uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: base-converter-wasm
path: pkg/

- name: Override version
run: sed -i 's/^version = ".+"$/version = "${{ needs.version.outputs.version }}"/' Cargo.toml

build:
needs: version
strategy:
max-parallel: 1
matrix:
os: [ubuntu-latest,
# macos-latest-xlarge
]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross

- name: Override version
run: |
if "$(uname -s)" = "Darwin"; then
SED="sed -i ''"
else
SED="sed -i"
fi
$SED -E 's/^version = ".+"$/version = "${{ needs.version.outputs.version }}"/' Cargo.toml
- name: Build cross platforms
if: matrix.os == 'ubuntu-latest'
run: |
cross build --release --locked --target aarch64-unknown-linux-gnu
cross build --release --locked --target aarch64-unknown-linux-musl
cross build --release --locked --target x86_64-unknown-linux-gnu
cross build --release --locked --target x86_64-unknown-linux-musl
cross build --release --locked --target x86_64-pc-windows-gnu
cross build --release --locked --bin base-converter -F bin --target aarch64-unknown-linux-gnu
cross build --release --locked --bin base-converter -F bin --target aarch64-unknown-linux-musl
cross build --release --locked --bin base-converter -F bin --target x86_64-unknown-linux-gnu
cross build --release --locked --bin base-converter -F bin --target x86_64-unknown-linux-musl
cross build --release --locked --bin base-converter -F bin --target x86_64-pc-windows-gnu
mkdir tmp/
mv ./target/aarch64-unknown-linux-gnu/release/base-converter ./tmp/base-converter-aarch64-unknown-linux-gnu
mv ./target/aarch64-unknown-linux-musl/release/base-converter ./tmp/base-converter-aarch64-unknown-linux-musl
mv ./target/x86_64-unknown-linux-gnu/release/base-converter ./tmp/base-converter-x86_64-unknown-linux-gnu
mv ./target/x86_64-unknown-linux-musl/release/base-converter ./tmp/base-converter-x86_64-unknown-linux-musl
mv ./target/x86_64-pc-windows-gnu/release/base-converter ./tmp/base-converter-x86_64-pc-windows-gnu
# - name: Install wasm-pack
# run: curl -fL --tlsv1.2 --proto '=https' https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

# - name: Build wasm
# run: wasm-pack build --target web --scope ctison . -F wasm

# - name: Publish on npmjs.com
# working-directory: pkg/
# env:
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# run: npm publish
mv ./target/x86_64-pc-windows-gnu/release/base-converter.exe ./tmp/base-converter-x86_64-pc-windows-gnu.exe
- name: Build macos
if: matrix.os == 'macos-latest-xlarge'
run: |
cargo build --release --locked --bin base-converter -F bin
mkdir tmp/
mv ./target/aarch64-apple-darwin/release/base-converter ./tmp/base-converter-aarch64-apple-darwin
- uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: cli-${{ matrix.os }}
path: tmp/

release:
runs-on: ubuntu-latest
needs: [version, build-wasm, build]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
path: dist/
- name: Publish on npmjs.com
working-directory: dist/base-converter-wasm
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish
- name: Publish on crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --allow-dirty --locked

run: |
sed -i -E 's/^version = ".+"$/version = "${{ needs.version.outputs.version }}"/' Cargo.toml
cargo publish --allow-dirty --locked
- name: Github Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
fail_on_unmatched_files: true
tag_name: v${{ needs.version.outputs.version }}
files: |
./tmp/base-converter-aarch64-unknown-linux-gnu
./tmp/base-converter-aarch64-unknown-linux-musl
./tmp/base-converter-x86_64-unknown-linux-gnu
./tmp/base-converter-x86_64-unknown-linux-musl
./tmp/base-converter-x86_64-pc-windows-gnu
./dist/cli-*/*
body: |
# Rust Doc
https://docs.rs/base-converter/${{ steps.version.outputs.version }}/base_converter/
# ## NPM Package
# https://www.npmjs.com/package/base-converter/v/${{ steps.version.outputs.version }}
https://docs.rs/base-converter/${{ needs.version.outputs.version }}/base_converter/
# NPM Package
https://www.npmjs.com/package/@ctison/base-converter/v/${{ needs.version.outputs.version }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
/target/
/pkg/
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
Loading

0 comments on commit 282d5de

Please sign in to comment.