aquavm/.github/workflows/publish_interpreter.yml
2021-10-05 20:08:10 +03:00

178 lines
6.2 KiB
YAML

# 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-interpreter"
on:
push:
branches:
- "master"
jobs:
npm-publish:
name: "Publish AIR to NPM & crates.io"
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-2021-07-13
target: wasm32-unknown-unknown
profile: minimal
override: true
- name: Install wasm32-wasi
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2021-07-13
target: wasm32-wasi
profile: minimal
- uses: actions-rs/cargo@v1
with:
toolchain: nightly-2021-07-13
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+"
INTERPRETER_CARGO_TOML="air-interpreter/Cargo.toml"
CARGO_TOML="crates/interpreter-wasm/Cargo.toml"
PACKAGE_JSON="avm/client/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
INTERPRETER_RUST_VERSION="$(toml get "$INTERPRETER_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" "$INTERPRETER_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: avm/client
run: |
./build_wasm.sh
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: avm/client
### Publish to NPM registry
- uses: actions/setup-node@v1
with:
node-version: "14"
registry-url: "https://registry.npmjs.org"
- run: npm publish --access public
working-directory: avm/client
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
### === Rust package release ===
- name: Install marine
run: cargo install marine || true
- name: Set interpreter version to ${{ env.FINAL_VERSION }} before the build
run: |
PATH="~/.cargo/bin:$PATH"
(
cd air-interpreter
toml set Cargo.toml package.version "${{ env.FINAL_VERSION }}" | sponge Cargo.toml
)
(
cd air
toml set Cargo.toml package.version "${{ env.FINAL_VERSION }}" | sponge Cargo.toml
)
- name: Build air_interpreter_server.wasm for node
run: marine build --release -p air-interpreter --features marine
working-directory: air-interpreter
- name: Copy air_interpreter_server.wasm to interpreter-wasm
run: cp target/wasm32-wasi/release/air_interpreter_server.wasm crates/interpreter-wasm/air_interpreter_server.wasm
- name: Set project version to ${{ env.FINAL_VERSION }}
run: |
PATH="~/.cargo/bin:$PATH"
toml set Cargo.toml package.version "${{ env.FINAL_VERSION }}" | sponge Cargo.toml
working-directory: crates/interpreter-wasm
- name: Login to crates.io
run: cargo login ${{ secrets.CRATES_IO_TOKEN }}
- name: Publish to crates.io
run: cargo publish --allow-dirty
working-directory: crates/interpreter-wasm
### Create a pre-release
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.FINAL_VERSION }}
release_name: AIR interpreter ${{ env.FINAL_VERSION }}
body: |
- [${{ env.FINAL_VERSION }} @ NPM registry](https://www.npmjs.com/package/${{ env.JS_PKG_NAME }}/v/${{ env.FINAL_VERSION }})
- [${{ env.FINAL_VERSION }} @ crates.io](https://crates.io/crates/${{ env.PKG_NAME }}/${{ env.FINAL_VERSION }})
draft: false
prerelease: false