name: Deploy Docs

on:
  push:
    branches:
      - main
  workflow_dispatch:

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

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

jobs:
  build:
    if: github.repository == 'datagallery-lab/datafoundry'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v5

      - name: Setup Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.12"
          cache: pip

      - name: Install dependencies
        run: python -m pip install -r requirements-docs.txt

      - name: Build docs
        run: python -m mkdocs build --strict

      - name: Configure Pages
        uses: actions/configure-pages@v6
        with:
          enablement: true

      - name: Upload Pages artifact
        uses: actions/upload-pages-artifact@v5
        with:
          path: site

  deploy:
    if: github.repository == 'datagallery-lab/datafoundry'
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v5
        with:
          timeout: 1200000