name: Documentation

on:
  push:
    paths:
      - 'docs/**'
      - 'mkdocs.yml'
      - 'README.md'
      - '.github/workflows/docs.yml'
  pull_request:
    paths:
      - 'docs/**'
      - 'mkdocs.yml'
      - 'README.md'

permissions:
  contents: write
  pages: write

jobs:
  linkcheck:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Check links
        uses: lycheeverse/lychee-action@v1
        with:
          args: >-
            --verbose
            --no-progress
            --exclude-mail
            --exclude 'localhost'
            --exclude '127.0.0.1'
            --exclude 'example.com'
            'docs/**/*.md'
            'README.md'
          fail: true

  markdown-lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Lint Markdown
        uses: DavidAnson/markdownlint-cli2-action@v16
        with:
          globs: |
            docs/**/*.md
            README.md

  deploy:
    runs-on: ubuntu-latest
    needs: [linkcheck, markdown-lint]
    if: github.ref == 'refs/heads/main' && github.event_name == 'push'
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup uv
        uses: astral-sh/setup-uv@v4

      - name: Install dependencies
        run: uv sync --group docs

      - name: Build documentation
        run: uv run mkdocs build --strict

      - name: Deploy to GitHub Pages
        run: uv run mkdocs gh-deploy --force
