name: Build and deploy docs

on:
  workflow_dispatch:
  push:
    branches:
      - main
    paths:
      - "docs/**/*"
      - "modules/**/*"
      - ".github/workflows/docs.yml"
      - ".github/actions/**/*"

permissions: {}

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false

      - name: Install Lix
        uses: ./.github/actions/install-lix

      - name: Build docs
        run: nix build .#docs

      - name: Upload Pages Artifact
        uses: "actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9" # v5.0.0
        with:
          path: "result/"

  deploy:
    needs: build
    runs-on: "ubuntu-latest"

    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@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0
