name: Deploy static site to pages

on:
  push:
    branches: ["main"]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Deploy to shared pages volume (tar stream, no bind mounts)
        shell: bash
        run: |
          set -euo pipefail

          OWNER="$(echo "${GITHUB_REPOSITORY}" | cut -d/ -f1)"
          REPO="$(echo "${GITHUB_REPOSITORY}" | cut -d/ -f2)"
          TARGET="/target/${OWNER}/${REPO}"

          echo "Deploying ${GITHUB_REPOSITORY} -> ${TARGET}"
          echo "Files in repo root:"
          ls -la

          # Create a tar stream of the repo content (excluding VCS + workflow folder)
          # and extract it directly into the docker volume via stdin.
          tar -czf - \
            --exclude=".git" \
            --exclude=".gitea" \
            . \
          | docker run --rm -i \
              -v gitea_pages_root:/target \
              alpine:3.20 sh -lc '
                set -e
                mkdir -p "'"$TARGET"'"
                rm -rf "'"$TARGET"'/"* "'"$TARGET"'/"..* 2>/dev/null || true
                tar -xzf - -C "'"$TARGET"'"
              '

          echo "Deployed. Listing target:"
          docker run --rm \
            -v gitea_pages_root:/target \
            alpine:3.20 sh -lc 'ls -la "'"$TARGET"'" | sed -n "1,50p"'
