name: Deploy MkDocs to Test Environment

on:
  push:
    branches:
      - test
  workflow_dispatch:  # Allows manual triggering

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

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

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.10'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install mkdocs-material
          pip install mkdocs-minify-plugin
          pip install mkdocs-git-revision-date-localized-plugin
          pip install mkdocs-blog-plugin
          pip install pymdown-extensions
          pip install mkdocs-macros-plugin
          pip install mkdocs-glightbox
          pip install mkdocs-include-markdown-plugin
          pip install mkdocs-video
          pip install mkdocs-rss-plugin
          pip install mkdocs-snippets
          pip install mkdocs-exclude
          pip install mkdocs-git-revision-date-localized-plugin
          pip install mkdocs-redirects
          pip install mkdocs-literate-nav
          pip install "mkdocs-material[imaging]"
          pip install libsass
      - name: Verify CNAME
        run: |
          mkdir -p docs
          if [ ! -f docs/CNAME ]; then
            echo "test.satware.ai" > docs/CNAME
          fi
      - name: Build css
        run: python compile_scss.py
      - name: Build site
        run: mkdocs build

      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./site
          destination_dir: .
          cname: test.satware.ai
          force_orphan: true
