name: WebAssembly (GitHub Pages)

on: [push]

permissions:
  contents: write

jobs:
  deploy:
    runs-on: ubuntu-latest

    permissions:
      pages: write
      id-token: write

    steps:
      - name: Checkout 
        uses: actions/checkout@v4

      - name: Setup Emscripten SDK
        uses: mymindstorm/setup-emsdk@v11
        with:
          version: 3.1.43

      - name: Setup Rust (WASM32 Emscripten)
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: wasm32-unknown-emscripten
          override: true

      - name: Rust Cache
        uses: Swatinem/rust-cache@v2

      - name: Install pnpm
        uses: pnpm/action-setup@v3
        with:
          version: 8
          run_install: true

      - name: Build
        run: ./scripts/build.sh -er # release mode, skip emsdk

      - name: Upload Artifact
        uses: actions/upload-pages-artifact@v2
        with:
          path: './dist/'
          if-no-files-found: error
          retention-days: 7

      - name: Deploy
        uses: actions/deploy-pages@v2