name: Documentation-Action

on:
  push:
    branches:
    - main
  pull_request:
    branches:
    - '*'

jobs:
  doc-build:
    name: Build
    runs-on: ubuntu-latest
    steps:
    - run: sudo apt install pandoc -y
    - uses: actions/checkout@v3
    - name: Setup Python
      uses: actions/setup-python@v4
      with:
        python-version: 3.11
    - name: Install and configure Poetry
      uses: snok/install-poetry@v1
      with:
        version: 1.4.2
        virtualenvs-create: false
    - run: poetry install --only doc,root,develop
    - name: Doc-Build
      run: |
        cd documentations
        sphinx-apidoc -o . ../src/aki_prj23_transparenzregister -feP
        make html
    - name: Package artifact
      uses: actions/upload-pages-artifact@v1
      with:
        path: documentations/_build/html/

  doc-deploy:
    name: Deployment
    runs-on: ubuntu-latest
    needs: doc-build
    permissions:
      pages: write
      id-token: write
    concurrency:
      group: pages
      cancel-in-progress: false
    if: github.ref == 'refs/heads/main'
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
    - run: echo "Deployment URL = ${{ steps.deployment.outputs.page_url }}"
    - uses: actions/download-artifact@v3
      with:
        name: github-pages
    - name: Deploy to GitHub Pages
      id: deployment
      uses: actions/deploy-pages@v2
      with:
        artifact_name: github-pages
