name: Deploy to NPM

on:
  workflow_call:
    secrets:
      NPM_TOKEN:
        required: true

jobs:
  deploy:
    name: Deploy to NPM
    env:
      CARGO_INCREMENTAL: 0
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup wasm-pack
        run: cargo install wasm-pack
      - name: Cache dependencies
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.toml') }}
      - name: Package file
        run: wasm-pack build --scope nightrunner --release
      - name: Deploy to NPM
        uses: JS-DevTools/npm-publish@v3
        with:
          token: ${{ secrets.NPM_TOKEN }}
          package: ./pkg/package.json
          access: public
