name: Docs

on:
  push:
    tags: ["v*.*.*"]
    branches: ["main"]
  pull_request:
  merge_group:
  workflow_dispatch:

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

jobs:
  pre-commit:
    name: Linting Checks
    runs-on: ubuntu-22.04
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6
      - name: Install python
        uses: actions/setup-python@v6
        with:
          python-version: 3.x
      - name: Check files
        uses: pre-commit/action@v3.0.1

  test:
    name: Test Build Docs
    if: github.repository == 'gethomepage/homepage' && github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    needs:
      - pre-commit
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-python@v6
        with:
          python-version-file: ".python-version"
      - name: Install uv
        uses: astral-sh/setup-uv@v7
      - run: sudo apt-get install pngquant
      - name: Test Docs Build
        run: uv run --frozen zensical build --clean
  deploy:
    name: Build & Deploy Docs
    if: github.repository == 'gethomepage/homepage' && github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    needs:
      - pre-commit
    steps:
      - uses: actions/configure-pages@v5
      - uses: actions/checkout@v6
      - uses: actions/setup-python@v6
        with:
          python-version-file: ".python-version"
      - name: Install uv
        uses: astral-sh/setup-uv@v7
      - run: sudo apt-get install pngquant
      - name: Build Docs
        run: uv run --frozen zensical build --clean
      - uses: actions/upload-pages-artifact@v4
        with:
          path: site
      - uses: actions/deploy-pages@v4
        id: deployment
