name: Miniexact Page
on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    container: emscripten/emsdk:3.1.44
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          persist-credentials: false
          ref: ${{ github.event.inputs.checkoutRef }}
      - name: Create Build Folder
        run: mkdir build-emscripten
      - name: Configure with CMake
        run: emcmake cmake -Bbuild-emscripten -DCMAKE_BUILD_TYPE=Release
      - name: Build
        run: make -C build-emscripten
      - name: Copy built files to web folder
        run: cp build-emscripten/miniexact.js build-emscripten/miniexact.wasm web/
      - name: Setup Pages
        if: github.ref == 'refs/heads/main'
        uses: actions/configure-pages@v5
      - name: Upload Artifact
        if: github.ref == 'refs/heads/main'
        uses: actions/upload-pages-artifact@v3
        with:
          path: "./web"
  deploy-pages:
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    needs: build

    permissions:
      pages: write
      id-token: write

    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}

    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
