# run locally like this: # act -b -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -j publish-interpreter -s "NPM_TOKEN=uuid-uuid-uuid-uuid" name: "publish-npm-release" on: push: branches: - "master" jobs: npm-publish: name: "Publish web-runtime to NPM" runs-on: ubuntu-latest defaults: run: shell: bash steps: - name: Checkout repository uses: actions/checkout@v2 ### Prepare cargo & toolchains - uses: actions/cache@v2 with: path: | ~/.cargo/registry ~/.cargo/git ~/.cargo/bin target key: ${{ runner.os }}-cargo-v2-${{ hashFiles('**/Cargo.lock') }} - name: Install Rust toolchain with wasm32-unknown-unknown uses: actions-rs/toolchain@v1 with: toolchain: nightly-2022-01-25 target: wasm32-unknown-unknown profile: minimal override: true - uses: actions-rs/cargo@v1 with: toolchain: nightly-2022-01-25 command: update args: --aggressive ### Calculate FINAL_VERSION - name: Install jq & sponge run: sudo apt-get update && sudo apt-get --yes --force-yes install jq moreutils - name: Install cargo-show & toml-cli run: cargo install cargo-show toml-cli || true - name: Get versions from npm & crates.io, and take the highest one run: | set -x # install semver and add it to PATH yarn global add semver PATH="$(yarn global bin):$PATH" # JQ version regex pattern PAT="\\\\d+.\\\\d+.\\\\d+" MARINE_JS_CARGO_TOML="web-runtime/Cargo.toml" CARGO_TOML="web-runtime/Cargo.toml" PACKAGE_JSON="web-runtime/npm-package/package.json" # get package name from Cargo.toml RS_PKG_NAME="$(toml get "$CARGO_TOML" package.name | tr -d \")" # get package name from package.json JS_PKG_NAME="$(cat "$PACKAGE_JSON" | jq -r .name)" # get version from Cargo.toml MARINE_JS_RUST_VERSION="$(toml get "$MARINE_JS_CARGO_TOML" package.version | tr -d \")" LOCAL_RUST_VERSION="$(toml get "$CARGO_TOML" package.version | tr -d \")" # get & increment version from NPM JS_VERSIONS=$(yarn info --silent "$JS_PKG_NAME" versions | tr \' \" | jq -r ".[] | select(test(\"$PAT\"))" || true) JS_VERSION="$(semver -p $JS_VERSIONS | tail -n1)" NEXT_JS_VERSION="$(semver --increment patch "$JS_VERSION" || true)" # get & increment version from crates.io CRATE_VERSIONS=$(cargo show --json "$RS_PKG_NAME") CRATE_VERSIONS_FILTERED=$(echo $CRATE_VERSIONS | jq -r ".versions[] | .num | select(test(\"$PAT\"))") MAX_RS_VERSION="$(semver -p $CRATE_VERSIONS_FILTERED | tail -n1 || true)" NEXT_RS_VERSION="$(semver --increment patch "$MAX_RS_VERSION" || true)" # take the highest version MAX_VERSION="$(semver "$NEXT_JS_VERSION" "$NEXT_RS_VERSION" "$LOCAL_RUST_VERSION" "MARINE_JS_RUST_VERSION" | tail -n1)" echo "FINAL_VERSION=$MAX_VERSION" | tee -a $GITHUB_ENV echo "JS_PKG_NAME=$JS_PKG_NAME" | tee -a $GITHUB_ENV ### === JavaScript package release === - name: Install wasm-pack run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh continue-on-error: true - name: Build npm package working-directory: web-runtime run: | ./build.sh cd npm-package npm i npm run build ### Set version - name: Set version to ${{ env.FINAL_VERSION }} run: yarn version --new-version ${{ env.FINAL_VERSION }} --no-git-tag-version working-directory: web-runtime/npm-package ### Publish to NPM registry - uses: actions/setup-node@v1 with: node-version: "16" registry-url: "https://registry.npmjs.org" - run: npm publish --access public working-directory: web-runtime/npm-package env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}