name: Build and deploy EH1 documentation

on:
  workflow_call:

defaults:
  run:
    shell: bash

permissions:
  contents: read

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

jobs:
  build:
    runs-on: ubuntu-latest
    container: ghcr.io/antmicro/cores-veer-el2:20260618

    steps:
      - name: Setup repository
        uses: actions/checkout@v4

      - name: Build documentation
        run: |
          pushd docs
            python3 -m venv venv
            source venv/bin/activate
            pip3 install -r requirements.txt
            make html
          popd
          cp .github/scripts/index.html docs/build/
          ls -lah docs/build

      - name: Configure Pages
        uses: actions/configure-pages@v5

      - name: Upload Pages artifact
        uses: actions/upload-pages-artifact@v4
        with:
          name: docs
          path: ./docs/build

  deploy:
    if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
    needs: build
    runs-on: ubuntu-latest

    permissions:
      pages: write
      id-token: write

    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}

    steps:
      - name: Deploy
        id: deployment
        uses: actions/deploy-pages@v5
        with:
          artifact_name: docs
