From 0e26caa4d61e836d8d0a45a0bc2723a3c2899217 Mon Sep 17 00:00:00 2001 From: Cheethas <47148561+cheethas@users.noreply.github.com> Date: Sun, 26 Feb 2023 21:53:46 +0000 Subject: [PATCH 1/2] feat: deploy_npm on release --- .github/workflows/build-wasm.yml | 38 ++++++++++++++++++++++++++++++++ .gitignore | 3 +++ huff_js/scripts/make_packages.sh | 31 ++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 .github/workflows/build-wasm.yml create mode 100755 huff_js/scripts/make_packages.sh diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml new file mode 100644 index 00000000..8701de2d --- /dev/null +++ b/.github/workflows/build-wasm.yml @@ -0,0 +1,38 @@ +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: | + pkg_version = ${GITHUB_REF#refs/*/} + echo "tag=$pkg_version" >> $GITHUB_OUTPUT + + - name: Huff js + run: cd huff_js + + - name: Build + env: + PACKAGE_VERSION: ${{ steps.vars.outputs.tag }} + run: ./scripts/make_packages.sh + + - name: Step into package + run: cd pkg + + - name: Publish to NPM + uses: JS-DevTools/npm-publish@v1 + with: + 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 From 64c46bfb396c2e0d5666e16ad70a5040f3f6eda9 Mon Sep 17 00:00:00 2001 From: Cheethas <47148561+cheethas@users.noreply.github.com> Date: Sun, 26 Feb 2023 22:25:37 +0000 Subject: [PATCH 2/2] feat: fix ci --- .github/workflows/build-wasm.yml | 42 +++++++++++++++++--------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-wasm.yml b/.github/workflows/build-wasm.yml index 8701de2d..a32f12cc 100644 --- a/.github/workflows/build-wasm.yml +++ b/.github/workflows/build-wasm.yml @@ -11,28 +11,32 @@ jobs: name: Create runs-on: ubuntu-latest - steps: - - name: "Checkout" - uses: actions/checkout@v2 + steps: + - name: Checkout + uses: actions/checkout@v2 - - name: Get version tag + - name: Get version tag id: vars run: | - pkg_version = ${GITHUB_REF#refs/*/} + export pkg_version=${GITHUB_REF#refs/*/} echo "tag=$pkg_version" >> $GITHUB_OUTPUT - - name: Huff js - run: cd huff_js - - - name: Build - env: - PACKAGE_VERSION: ${{ steps.vars.outputs.tag }} - run: ./scripts/make_packages.sh - - - name: Step into package - run: cd pkg - - - name: Publish to NPM - uses: JS-DevTools/npm-publish@v1 + - name: Install toolchain + uses: actions-rs/toolchain@v1 with: - token: ${{ secrets.NPM_TOKEN }} + 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 }}