name: Deploy to GitHub Pages

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: "pages"
  cancel-in-progress: false

jobs:
  build:
    name: Build comparison page
    runs-on: depot-ubuntu-24.04-16
    steps:
      - uses: actions/checkout@v5

      - name: Install toolchain
        uses: dtolnay/rust-toolchain@stable

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

      - name: Build C pikchr
        run: make -C vendor/pikchr-c pikchr

      - name: Generate comparison.html
        run: cargo xtask compare-html

      - name: Prepare site directory
        run: |
          mkdir -p _site
          cp comparison.html _site/index.html
          echo "pikru.bearcove.eu" > _site/CNAME

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3

  deploy:
    name: Deploy to GitHub Pages
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
