diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml new file mode 100644 index 00000000..a32f12cc --- /dev/null +++ b/.github/workflows/build-wasm.yml @@ -0,0 +1,42 @@ +name: Publish-wasm + +on: + push: + tags: + - "v*.*.*" + workflow_dispatch: + +jobs: + deploy: + name: Create + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Get version tag + id: vars + run: | + export pkg_version=${GITHUB_REF#refs/*/} + echo "tag=$pkg_version" >> $GITHUB_OUTPUT + + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: cargo + + - name: Install Wasm Pack + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + + - name: Build + env: + PACKAGE_VERSION: ${{ steps.vars.outputs.tag }} + working-directory: ./huff_js + run: ./scripts/make_packages.sh + + - name: Publish to NPM + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index 38a5e6ef..79feaf70 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ artifacts # Foundry cache cache +pkg +pkg-node + diff --git a/huff_js/scripts/make_packages.sh b/huff_js/scripts/make_packages.sh new file mode 100755 index 00000000..95d49842 --- /dev/null +++ b/huff_js/scripts/make_packages.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -e + +# Check if jq is installed +if ! [ -x "$(command -v jq)" ]; then + echo "jq is not installed" >& 2 + exit 1 +fi + +# Clean previous packages +if [ -d "pkg" ]; then + rm -rf pkg +fi + +if [ -d "pkg-node" ]; then + rm -rf pkg-node +fi + +# Build for both targets +wasm-pack build -t nodejs -d pkg-node +wasm-pack build -t browser -d pkg + +# Get the package name +PKG_NAME=$(jq -r .name pkg/package.json | sed 's/\-/_/g') + +# Give the pacakges a version tag +if [ -n "$VERSION_TAG" ]; then + # Overwrite the version in the package.json + jq --arg v $VERSION_TAG '.version = $v' pkg/package.json > temp.json && mv temp.json pkg/package.json + jq --arg v $VERSION_TAG '.version = $v' pkg-node/package.json > temp.json && mv temp.json pkg-node/package.json +fi \ No newline at end of file