-
Notifications
You must be signed in to change notification settings - Fork 0
49 lines (40 loc) · 1.73 KB
/
build.yml
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
name: "build"
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Install Wasm-pack
run: |
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Install node
uses: actions/setup-node@v3
with:
node-version: "18.18.x"
- name: Get package name and version
run: |
echo "CARGO_NAME=$(grep '^name' Cargo.toml | sed -E 's/name = \"(.*)\"/\1/')" >> $GITHUB_ENV
echo "NPM_NAME=$(echo "${{ env.CARGO_NAME }}" | sed 's/_/-/g')" >> $GITHUB_ENV
echo "VERSION=$(grep '^version' Cargo.toml | sed -E 's/version = \"(.*)\"/\1/')" >> $GITHUB_ENV
- name: Build ESM
run: |
wasm-pack build --release --target web -d pkg
mv "pkg/${{ env.CARGO_NAME }}.js" "pkg/${{ env.NPM_NAME }}-esm.js"
mv "pkg/${{ env.CARGO_NAME }}.d.ts" "pkg/${{ env.NPM_NAME }}.d.ts"
mv "pkg/${{ env.CARGO_NAME }}_bg.wasm" "pkg/${{ env.NPM_NAME }}-bg.wasm"
sed -i "s/${{ env.CARGO_NAME }}_bg.wasm/${{ env.NPM_NAME }}-bg.wasm/g" "pkg/${{ env.NPM_NAME }}-esm.js"
- name: Build CommonJS
run: |
npm install --global rollup
rollup "pkg/${{ env.NPM_NAME }}-esm.js" --file "pkg/${{ env.NPM_NAME }}-cjs.js" --format cjs
- name: Create package.json
run: |
cp -f package.json pkg/package.json
sed -i "s/\"version\": \".*\"/\"version\": \"${{ env.VERSION }}\"/" "pkg/package.json"
- name: Publish to npm
run: |
npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_ACCESS_TOKEN }}
npm publish pkg/ --access public