# Copyright (C) 2025 Siemens
#
# SPDX-License-Identifier: MIT

name: Docs

on:
  push:
    branches:
    - main
  pull_request:

jobs:
  docs:
    name: Build Docs
    runs-on: ubuntu-24.04
    steps:
      - name: Check out the repo
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: 3.13

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install .[dev]

      - name: Build HTML docs
        run: |
          cd docs
          make html

      # build-test only to catch doc building issues
      - name: Build manpages
        run: |
          cd docs
          make man

      - name: Upload HTML docs
        if: github.ref == 'refs/heads/main'
        uses: actions/upload-artifact@v4
        with:
          name: docs-html
          path: docs/build/html

  publish:
    name: Publish Docs
    runs-on: ubuntu-24.04
    if: github.ref == 'refs/heads/main'
    needs:
      - docs
    permissions:
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Download HTML docs
        uses: actions/download-artifact@v4
        with:
          name: docs-html
          path: docs-html

      - name: Upload pages artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: docs-html

      - name: Deploy to GitHub Pages
        uses: actions/deploy-pages@v4
