build #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "NAME=$(grep '^name' Cargo.toml | sed -E 's/name = \"(.*)\"/\1/')" >> $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.NAME }}.js pkg/${{ env.NAME }}_esm.js | |
- name: Build CommonJS | |
run: | | |
npm install --global rollup | |
rollup pkg/${{ env.NAME }}_esm.js --file pkg/${{ env.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 |