Skip to content

Commit 282d5de

Browse files
committed
feat: wasm npm package (#153)
* 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
1 parent 5aa5478 commit 282d5de

File tree

11 files changed

+218
-211
lines changed

11 files changed

+218
-211
lines changed

.github/workflows/ci.yaml

Lines changed: 91 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@ jobs:
1717
runs-on: ubuntu-latest
1818
steps:
1919
- uses: actions/checkout@v4
20-
20+
- uses: actions/cache@v3
21+
with:
22+
path: |
23+
~/.cargo/bin/
24+
~/.cargo/registry/index/
25+
~/.cargo/registry/cache/
26+
~/.cargo/git/db/
27+
target/
28+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
2129
- name: Test
2230
run: cargo test -F bin,wasm
23-
2431
- name: Lint
2532
run: cargo clippy -F bin,wasm
2633

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

38-
build:
45+
build-wasm:
3946
runs-on: ubuntu-latest
4047
needs: version
4148
steps:
4249
- uses: actions/checkout@v4
50+
- uses: oven-sh/setup-bun@v1
51+
- name: Install npm packages
52+
run: bun install --frozen-lockfile
53+
- name: Build wasm
54+
run: |
55+
bun run build
56+
cd pkg/
57+
cp ../.npmrc .
58+
npm version --no-git-tag-version '${{ needs.version.outputs.version }}'
59+
- uses: actions/upload-artifact@v3
60+
with:
61+
if-no-files-found: error
62+
name: base-converter-wasm
63+
path: pkg/
4364

44-
- name: Override version
45-
run: sed -i 's/^version = ".+"$/version = "${{ needs.version.outputs.version }}"/' Cargo.toml
46-
65+
build:
66+
needs: version
67+
strategy:
68+
max-parallel: 1
69+
matrix:
70+
os: [ubuntu-latest,
71+
# macos-latest-xlarge
72+
]
73+
runs-on: ${{ matrix.os }}
74+
steps:
75+
- uses: actions/checkout@v4
76+
- uses: actions/cache@v3
77+
with:
78+
path: |
79+
~/.cargo/bin/
80+
~/.cargo/registry/index/
81+
~/.cargo/registry/cache/
82+
~/.cargo/git/db/
83+
target/
84+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
4785
- name: Install cross
4886
run: cargo install cross --git https://github.com/cross-rs/cross
49-
87+
- name: Override version
88+
run: |
89+
if "$(uname -s)" = "Darwin"; then
90+
SED="sed -i ''"
91+
else
92+
SED="sed -i"
93+
fi
94+
$SED -E 's/^version = ".+"$/version = "${{ needs.version.outputs.version }}"/' Cargo.toml
5095
- name: Build cross platforms
96+
if: matrix.os == 'ubuntu-latest'
5197
run: |
52-
cross build --release --locked --target aarch64-unknown-linux-gnu
53-
cross build --release --locked --target aarch64-unknown-linux-musl
54-
cross build --release --locked --target x86_64-unknown-linux-gnu
55-
cross build --release --locked --target x86_64-unknown-linux-musl
56-
cross build --release --locked --target x86_64-pc-windows-gnu
57-
98+
cross build --release --locked --bin base-converter -F bin --target aarch64-unknown-linux-gnu
99+
cross build --release --locked --bin base-converter -F bin --target aarch64-unknown-linux-musl
100+
cross build --release --locked --bin base-converter -F bin --target x86_64-unknown-linux-gnu
101+
cross build --release --locked --bin base-converter -F bin --target x86_64-unknown-linux-musl
102+
cross build --release --locked --bin base-converter -F bin --target x86_64-pc-windows-gnu
58103
mkdir tmp/
59104
mv ./target/aarch64-unknown-linux-gnu/release/base-converter ./tmp/base-converter-aarch64-unknown-linux-gnu
60105
mv ./target/aarch64-unknown-linux-musl/release/base-converter ./tmp/base-converter-aarch64-unknown-linux-musl
61106
mv ./target/x86_64-unknown-linux-gnu/release/base-converter ./tmp/base-converter-x86_64-unknown-linux-gnu
62107
mv ./target/x86_64-unknown-linux-musl/release/base-converter ./tmp/base-converter-x86_64-unknown-linux-musl
63-
mv ./target/x86_64-pc-windows-gnu/release/base-converter ./tmp/base-converter-x86_64-pc-windows-gnu
64-
65-
# - name: Install wasm-pack
66-
# run: curl -fL --tlsv1.2 --proto '=https' https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
67-
68-
# - name: Build wasm
69-
# run: wasm-pack build --target web --scope ctison . -F wasm
70-
71-
# - name: Publish on npmjs.com
72-
# working-directory: pkg/
73-
# env:
74-
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
75-
# run: npm publish
108+
mv ./target/x86_64-pc-windows-gnu/release/base-converter.exe ./tmp/base-converter-x86_64-pc-windows-gnu.exe
109+
- name: Build macos
110+
if: matrix.os == 'macos-latest-xlarge'
111+
run: |
112+
cargo build --release --locked --bin base-converter -F bin
113+
mkdir tmp/
114+
mv ./target/aarch64-apple-darwin/release/base-converter ./tmp/base-converter-aarch64-apple-darwin
115+
- uses: actions/upload-artifact@v3
116+
with:
117+
if-no-files-found: error
118+
name: cli-${{ matrix.os }}
119+
path: tmp/
76120

121+
release:
122+
runs-on: ubuntu-latest
123+
needs: [version, build-wasm, build]
124+
steps:
125+
- uses: actions/checkout@v4
126+
- uses: actions/download-artifact@v3
127+
with:
128+
path: dist/
129+
- name: Publish on npmjs.com
130+
working-directory: dist/base-converter-wasm
131+
env:
132+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
133+
run: npm publish
77134
- name: Publish on crates.io
78135
env:
79136
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
80-
run: cargo publish --allow-dirty --locked
81-
137+
run: |
138+
sed -i -E 's/^version = ".+"$/version = "${{ needs.version.outputs.version }}"/' Cargo.toml
139+
cargo publish --allow-dirty --locked
82140
- name: Github Release
83141
uses: softprops/action-gh-release@v1
84142
with:
85143
generate_release_notes: true
86144
fail_on_unmatched_files: true
145+
tag_name: v${{ needs.version.outputs.version }}
87146
files: |
88-
./tmp/base-converter-aarch64-unknown-linux-gnu
89-
./tmp/base-converter-aarch64-unknown-linux-musl
90-
./tmp/base-converter-x86_64-unknown-linux-gnu
91-
./tmp/base-converter-x86_64-unknown-linux-musl
92-
./tmp/base-converter-x86_64-pc-windows-gnu
147+
./dist/cli-*/*
93148
body: |
94149
# Rust Doc
95-
https://docs.rs/base-converter/${{ steps.version.outputs.version }}/base_converter/
96-
# ## NPM Package
97-
# https://www.npmjs.com/package/base-converter/v/${{ steps.version.outputs.version }}
150+
https://docs.rs/base-converter/${{ needs.version.outputs.version }}/base_converter/
151+
# NPM Package
152+
https://www.npmjs.com/package/@ctison/base-converter/v/${{ needs.version.outputs.version }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
22
/target/
3+
/pkg/

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//registry.npmjs.org/:_authToken=${NPM_TOKEN}

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/*

0 commit comments

Comments
 (0)