diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index c77e2e1..c8805b4 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -20,6 +20,7 @@ jobs: environment: name: github-pages url: ${{ steps.deploy.outputs.page_url }} + steps: - name: Checkout (shallow) uses: actions/checkout@v4 @@ -29,42 +30,152 @@ jobs: - name: Configure Pages uses: actions/configure-pages@v5 - - name: Aggregate files from all branches into ./public + - name: Aggregate and build recursive directory pages shell: bash run: | set -euo pipefail + + # jq for JSON escaping (present on runners, but ensure) + if ! command -v jq >/dev/null 2>&1; then + sudo apt-get update -y + sudo apt-get install -y jq + fi + + REPO="${GITHUB_REPOSITORY#*/}" + SITE_ROOT="/${REPO}/" + mkdir -p public + : > public/.nojekyll - # List remote branches (exclude HEAD pointer) - mapfile -t BRANCHES < <(git ls-remote --heads origin \ - | awk '{print $2}' | sed 's@refs/heads/@@') + # Tiny favicon assets to avoid 404s + printf "%s" \ + "" \ + > public/favicon.svg - # Minimal index page + # List remote branches + mapfile -t BRANCHES < <( + git ls-remote --heads origin | awk '{print $2}' \ + | sed 's@refs/heads/@@' + ) + + # Landing page (no globals except window.__branches) cat > public/index.html <<'HTML' - -
| Name | Size | Modified |
|---|---|---|
| 📁 %s/ | — | — |
| 📄 %s | %s | %s |
Generated $(date -u '+%Y-%m-%d %H:%M UTC')
" + } > "$DIR/index.html" + } + + # Build per-branch trees and indexes for BR in "${BRANCHES[@]}"; do - SAFE=$(echo "$BR" | tr '/:@ ' '----' | sed 's/[^A-Za-z0-9._-]/-/g') + SAFE="$(echo "$BR" | tr '/:@ ' '----' | sed 's/[^A-Za-z0-9._-]/-/g')" mkdir -p "public/$SAFE" - # Fetch that branch tip and export without checkout git fetch --depth=1 origin "$BR" git archive --format=tar FETCH_HEAD | tar -x -C "public/$SAFE" - # Keep only static assets; drop heavy/unneeded dirs - rm -rf "public/$SAFE/.git" "public/$SAFE/.github" "public/$SAFE/node_modules" + # Keep only static assets; prune empty dirs + rm -rf "public/$SAFE/.git" "public/$SAFE/.github" \ + "public/$SAFE/node_modules" find "public/$SAFE" -type f ! \ - \( -name '*.html' -o -name '*.js' -o -name '*.css' -o -name '*.json' -o \ - -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.gif' -o -name '*.svg' \) \ + \( -name '*.html' -o -name '*.js' -o -name '*.css' -o \ + -name '*.json' -o -name '*.png' -o -name '*.jpg' -o \ + -name '*.jpeg' -o -name '*.gif' -o -name '*.svg' \) \ -delete find "public/$SAFE" -type d -empty -delete - echo "