name: Publish air-interpreter-wasm snapshot

on:
  workflow_call:
    inputs:
      ref:
        description: "git ref to checkout to"
        type: string
        default: "master"
      cargo-dependencies:
        description: "Cargo dependencies map"
        type: string
        default: "null"

jobs:
  wasm:
    name: "Build air-interpreter-wasm"
    runs-on: builder
    timeout-minutes: 60

    env:
      RUSTFLAGS: "-D warnings"
      RUSTC_WRAPPER: "sccache"

    steps:
      - name: Checkout AquaVM
        uses: actions/checkout@v4
        with:
          repository: fluencelabs/aquavm
          ref: ${{ inputs.ref }}

      - name: Setup Rust toolchain
        uses: dsherret/rust-toolchain-file@v1

      - name: Setup cache
        uses: Swatinem/rust-cache@v2
        with:
          cache-directories: ~/.cache/sccache
          shared-key: aquavm
          save-if: false

      - name: Setup sccache
        uses: mozilla-actions/sccache-action@v0.0.3

      - name: Setup marine
        uses: fluencelabs/setup-marine@v1
        with:
          artifact-name: marine

      - name: Set dependencies
        if: inputs.cargo-dependencies != 'null'
        uses: fluencelabs/github-actions/cargo-set-dependency@main
        with:
          dependencies: ${{ inputs.cargo-dependencies }}

      - name: Build air-interpreter-wasm binary
        run: marine build --release --features marine
        working-directory: air-interpreter

      - name: Upload air-interpreter-wasm binary
        uses: actions/upload-artifact@v3
        with:
          name: air-interpreter-wasm
          path: target/wasm32-wasi/release/air_interpreter_server.wasm
