name: WebAssembly

permissions:
  contents: read

on:
  pull_request:
  merge_group:

jobs:
  build-and-test:
    runs-on: "${{ vars.RUNS_ON || 'ubuntu-latest' }}"
    steps:
      # Checkout should always be before setup-go to ensure caching is working
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          fetch-depth: 1
      - name: Install Go
        uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
        with:
          go-version: stable
      - name: Install pnpm
        uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
        with:
          version: 6.0.2
      - name: Build
        run: ./scripts/build-wasm.sh
      - name: Run npm package tests
        run: ./scripts/run-tests-wasm.sh
      - name: Run custom tester
        run: ./scripts/run-tests-wasm.sh
        env:
          TESTER: true
      - name: Run prettier
        working-directory: wasm
        run: pnpm lint
