name: Deploy Docs

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

permissions:
  contents: write

concurrency:
  group: docs-deploy
  cancel-in-progress: false

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # mike needs full history

      - uses: astral-sh/setup-uv@v5
        with:
          enable-cache: true

      - name: Build Kelora (for executable examples)
        run: |
          cargo build --release

      - name: Configure Git
        run: |
          git config user.name github-actions
          git config user.email github-actions@github.com

      - name: Deploy dev version
        if: github.ref == 'refs/heads/main'
        run: |
          PATH="${GITHUB_WORKSPACE}/target/release:${PATH}" uvx --with mkdocs-material --with mike --with markdown-exec[ansi] mike deploy --push dev

      - name: Deploy release version
        if: startsWith(github.ref, 'refs/tags/v')
        run: |
          VERSION=${GITHUB_REF#refs/tags/}
          PATH="${GITHUB_WORKSPACE}/target/release:${PATH}" uvx --with mkdocs-material --with mike --with markdown-exec[ansi] mike deploy --push --update-aliases $VERSION latest
          PATH="${GITHUB_WORKSPACE}/target/release:${PATH}" uvx --with mkdocs-material --with mike --with markdown-exec[ansi] mike set-default --push latest
