name: Verify

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: checkout
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          submodules: true
          persist-credentials: false

      - name: setup deno
        uses: denoland/setup-deno@22d081ff2d3a40755e97629de92e3bcbfa7cf2ed # v2.0.5
        with:
          # Pinned to v2.8.3 to avoid https://github.com/denoland/deno/issues/35529
          # (v2.9.0 rejects JSR files without a manifest checksum on warm cache).
          # Restore to v2.x once v2.9.1 ships.
          deno-version: v2.8.3

      - name: format
        run: deno task fmt:check

      - name: lint
        run: deno lint

      - name: build wasm
        run: make

      - name: upload wasm artifact
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: clayterm-wasm
          path: |
            clayterm.wasm
            wasm.ts

  test-alt-os:
    needs: test
    strategy:
      matrix:
        os:
          - name: macos
            value: macos-latest
          - name: windows
            value: windows-latest
      fail-fast: false
    runs-on: ${{ matrix.os.value }}
    name: test ${{ matrix.os.name }}

    steps:
      - name: checkout
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          submodules: true
          persist-credentials: false

      - name: setup deno
        uses: denoland/setup-deno@22d081ff2d3a40755e97629de92e3bcbfa7cf2ed # v2.0.5
        with:
          # Pinned to v2.8.3 to avoid https://github.com/denoland/deno/issues/35529
          # (v2.9.0 rejects JSR files without a manifest checksum on warm cache).
          # Restore to v2.x once v2.9.1 ships.
          deno-version: v2.8.3

      - name: download wasm artifact
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: clayterm-wasm
          path: .

      - name: test
        run: deno task test

  npm:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          submodules: true
          persist-credentials: false

      - name: setup deno
        uses: denoland/setup-deno@22d081ff2d3a40755e97629de92e3bcbfa7cf2ed # v2.0.5
        with:
          # Pinned to v2.8.3 to avoid https://github.com/denoland/deno/issues/35529
          # (v2.9.0 rejects JSR files without a manifest checksum on warm cache).
          # Restore to v2.x once v2.9.1 ships.
          deno-version: v2.8.3

      - name: Setup Node
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version: 24

      - name: build wasm
        run: make

      - name: Build
        run: deno task build:npm 0.0.0-verify.0

      - name: dry run publish
        run: npm publish --dry-run --tag=verify
        working-directory: ./build/npm
