Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

ci: npm deploy #254

Open
wants to merge 2 commits into
base: stage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/build-wasm.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ artifacts
# Foundry cache
cache

pkg
pkg-node

31 changes: 31 additions & 0 deletions huff_js/scripts/make_packages.sh
Original file line number Diff line number Diff line change
@@ -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