name: Documentation

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

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

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

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - uses: prefix-dev/setup-pixi@v0.9.4
        with:
          cache: true
          cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
          environments: docs

      - name: Add cargo bin to PATH
        run: echo "${{ runner.temp }}/.cargo/bin" >> "$GITHUB_PATH"

      - name: Build documentation
        run: pixi r -e docs docbld
        env:
          CARGO_HOME: ${{ runner.temp }}/.cargo

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v4
        with:
          path: docs/build

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