name: Documentation 

on:
  push:
    branches:
      - "main"

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

concurrency:
  group: "pages"
  cancel-in-progress: false

jobs:
  document-cvd:
    runs-on: ubuntu-22.04
    container:
      image: debian@sha256:9258a75a7e4323c9e5562b361effc84ee747920116d8adfc98a465a5cdc9150e # debian:bookworm-20250407 (amd64)
    steps:
    - name: Checkout repository
      uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8  # v6.0.1
    - name: Setup apt
      run: apt update -y && apt upgrade -y
    - name: Install dependencies
      run: apt install -y doxygen
    - name: Run doxygen
      run: cd base/cvd && doxygen
    - name: Set up docs folder
      run: |
        mv base/cvd/html docs/cvd
    - name: Fix permissions
      run: |
        chmod -c -R +rX "docs" | while read line; do
          echo "::warning title=Invalid file permissions automatically fixed::$line"
        done
    - name: Upload artifact
      uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b  # v4.0.0
      with:
        path: ./docs/

  deploy:
    runs-on: ubuntu-22.04
    container:
      image: debian@sha256:9258a75a7e4323c9e5562b361effc84ee747920116d8adfc98a465a5cdc9150e # debian:bookworm-20250407 (amd64)
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    needs: document-cvd
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # aka v4.0.5
