name: documentation

on:
  push:
    branches:
    - main
  pull_request: null

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v5

    - name: Fetch release history
      uses: ./.github/actions/fetch-release-history
      with:
        github-token: "${{ github.token }}"

    - name: Load environment file
      uses: ./.github/actions/load-env

    - name: Install Python
      uses: actions/setup-python@v6
      with:
        python-version-file: pyproject.toml

    - name: Install uv
      uses: astral-sh/setup-uv@v7

    - name: Install command runner
      run: uv tool install rust-just

    - name: Install dependencies
      run: just env-sync doc

    - name: Build documentation
      run: just doc-build

    - name: Restore link check cache
      uses: actions/cache@v4
      with:
        path: .lycheecache
        key: cache-lychee-${{ github.sha }}
        restore-keys: cache-lychee-

    - name: Check links
      uses: lycheeverse/lychee-action@v2
      with:
        lycheeVersion: v0.21.0
        fail: true
        failIfEmpty: true
        token: "${{ github.token }}"
        args: >-
          --verbose
          --no-progress
          README.md
          site

    - name: Deploy
      uses: peaceiris/actions-gh-pages@v4
      if: github.ref == 'refs/heads/main'
      with:
        github_token: "${{ github.token }}"
        publish_dir: site
