From a5e82fe408931a7dfbc36c5ac2c5c3f7f2209d78 Mon Sep 17 00:00:00 2001
From: Staninna <26458805+Staninna@users.noreply.github.com>
Date: Wed, 27 Aug 2025 16:37:45 +0200
Subject: [PATCH 1/3] update cd.yml to be better??? test run
---
.github/workflows/cd.yml | 122 ++++++++++++++++++++++++++++++++++-----
1 file changed, 106 insertions(+), 16 deletions(-)
diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml
index c77e2e1..ebc3c81 100644
--- a/.github/workflows/cd.yml
+++ b/.github/workflows/cd.yml
@@ -29,42 +29,132 @@ 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
+
+ OWNER="${GITHUB_REPOSITORY%/*}"
+ 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/@@')
+ # List remote branches
+ mapfile -t BRANCHES < <(
+ git ls-remote --heads origin | awk '{print $2}' \
+ | sed 's@refs/heads/@@'
+ )
- # Minimal index page
+ # Top-level landing page
cat > public/index.html <<'HTML'
-
-
BranchesBranches
" >> public/index.html
- echo "Built public/ for ${#BRANCHES[@]} branches."
+
+ # Finish landing page with JS to render branch cards
+ cat >> public/index.html <<'HTML'
+
+ HTML
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v4
@@ -73,4 +163,4 @@ jobs:
- name: Deploy to GitHub Pages
id: deploy
- uses: actions/deploy-pages@v4
+ uses: actions/deploy-pages@v4
\ No newline at end of file
From e20d2818bed3a5b81c02a601abc648d808f6e25b Mon Sep 17 00:00:00 2001
From: Staninna <26458805+Staninna@users.noreply.github.com>
Date: Wed, 27 Aug 2025 16:55:03 +0200
Subject: [PATCH 2/3] update cd.yml to be better??? test run
---
.github/workflows/cd.yml | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml
index ebc3c81..1c26237 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
@@ -34,6 +35,12 @@ jobs:
run: |
set -euo pipefail
+ # Ensure jq is available (usually preinstalled)
+ if ! command -v jq >/dev/null 2>&1; then
+ sudo apt-get update -y
+ sudo apt-get install -y jq
+ fi
+
OWNER="${GITHUB_REPOSITORY%/*}"
REPO="${GITHUB_REPOSITORY#*/}"
SITE_ROOT="/${REPO}/"
@@ -41,13 +48,14 @@ jobs:
mkdir -p public
: > public/.nojekyll
- # List remote branches
+ # List remote branches (exclude symbolic HEAD)
mapfile -t BRANCHES < <(
- git ls-remote --heads origin | awk '{print $2}' \
+ git ls-remote --heads origin \
+ | awk '{print $2}' \
| sed 's@refs/heads/@@'
)
- # Top-level landing page
+ # Landing page shell
cat > public/index.html <<'HTML'
@@ -66,17 +74,16 @@ jobs:
HTML
- # Helper to create an index.html for every directory
+ # Function to emit an index.html for a directory
gen_index_dir() {
local DIR="$1" ROOT="$2" BR="$3" SAFE="$4"
local rel="${DIR#$ROOT}" # "" or "/sub/dir"
local title="Branch: ${BR}${rel:-/}"
- # Collect entries
mapfile -t SUBDIRS < <(find "$DIR" -mindepth 1 -maxdepth 1 -type d \
-printf '%f\n' | sort)
mapfile -t FILES < <(find "$DIR" -mindepth 1 -maxdepth 1 -type f \
@@ -108,16 +115,16 @@ jobs:
} > "$DIR/index.html"
}
- # Process each branch
+ # Build trees and index entries per branch
for BR in "${BRANCHES[@]}"; do
SAFE="$(echo "$BR" | tr '/:@ ' '----' | sed 's/[^A-Za-z0-9._-]/-/g')"
mkdir -p "public/$SAFE"
- # Fetch and extract content without checkout
+ # Export branch contents without checkout
git fetch --depth=1 origin "$BR"
git archive --format=tar FETCH_HEAD | tar -x -C "public/$SAFE"
- # Keep only static assets, then remove empty dirs
+ # Keep only static assets, then prune empties
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 \
@@ -125,17 +132,20 @@ jobs:
-name '*.svg' \) -delete
find "public/$SAFE" -type d -empty -delete
- # Generate index.html for every directory (recursive)
+ # Generate index.html for every directory in this branch
ROOT_DIR="public/$SAFE"
while IFS= read -r -d '' d; do
gen_index_dir "$d" "$ROOT_DIR" "$BR" "$SAFE"
done < <(find "$ROOT_DIR" -type d -print0)
- # Add branch to landing page list
- echo "" >> public/index.html
+ # Append to landing page using JSON-escaped values
+ SAFE_JSON=$(printf '%s' "$SAFE" | jq -Rr @json)
+ BR_JSON=$(printf '%s' "$BR" | jq -Rr @json)
+ echo "" \
+ >> public/index.html
done
- # Finish landing page with JS to render branch cards
+ # Finish landing page
cat >> public/index.html <<'HTML'
+
HTML
- # Function to emit an index.html for a directory
+ # Emit index.html for a directory
gen_index_dir() {
- local DIR="$1" ROOT="$2" BR="$3" SAFE="$4"
- local rel="${DIR#$ROOT}" # "" or "/sub/dir"
+ local DIR="$1" ROOT="$2" BR="$3"
+ local rel="${DIR#$ROOT}"
local title="Branch: ${BR}${rel:-/}"
- mapfile -t SUBDIRS < <(find "$DIR" -mindepth 1 -maxdepth 1 -type d \
- -printf '%f\n' | sort)
- mapfile -t FILES < <(find "$DIR" -mindepth 1 -maxdepth 1 -type f \
- ! -name 'index.html' -printf '%f\n' | sort)
-
{
echo ""
echo ""
+ echo ""
echo "${title}"
echo ""
echo "${title}
"
@@ -101,68 +98,82 @@ jobs:
echo "All branches
"
fi
echo "| Name | Size | Modified |
"
- for d in "${SUBDIRS[@]}"; do
- echo "| 📁 $d/ | — | — |
"
- done
- for f in "${FILES[@]}"; do
- local size=$(stat -c %s "$DIR/$f" 2>/dev/null || echo 0)
- local size_h=$(numfmt --to=iec --suffix=B "$size" 2>/dev/null || echo "$size")
- local mod=$(date -r "$DIR/$f" "+%Y-%m-%d %H:%M" 2>/dev/null || echo "")
- echo "| 📄 $f | $size_h | $mod |
"
- done
+
+ # Subdirectories
+ while IFS= read -r d; do
+ [[ -n "$d" ]] || continue
+ printf "| 📁 %s/ | — | — |
\n" "$d" "$d"
+ done < <(find "$DIR" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | sort)
+
+ # Files
+ while IFS= read -r f; do
+ [[ -n "$f" ]] || continue
+ size=$(stat -c %s "$DIR/$f" 2>/dev/null || echo 0)
+ size_h=$(numfmt --to=iec --suffix=B "$size" 2>/dev/null || echo "$size")
+ mod=$(date -r "$DIR/$f" "+%Y-%m-%d %H:%M" 2>/dev/null || echo "")
+ printf "| 📄 %s | %s | %s |
\n" "$f" "$f" "$size_h" "$mod"
+ done < <(find "$DIR" -mindepth 1 -maxdepth 1 -type f ! -name 'index.html' -printf '%f\n' | sort)
+
echo "
"
echo "Generated $(date -u '+%Y-%m-%d %H:%M UTC')
"
} > "$DIR/index.html"
}
- # Build trees and index entries per branch
+ # Build per-branch trees and indexes
for BR in "${BRANCHES[@]}"; do
SAFE="$(echo "$BR" | tr '/:@ ' '----' | sed 's/[^A-Za-z0-9._-]/-/g')"
mkdir -p "public/$SAFE"
- # Export branch contents without checkout
git fetch --depth=1 origin "$BR"
git archive --format=tar FETCH_HEAD | tar -x -C "public/$SAFE"
- # Keep only static assets, then prune empties
- 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' \) -delete
+ \( -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
- # Generate index.html for every directory in this branch
ROOT_DIR="public/$SAFE"
while IFS= read -r -d '' d; do
- gen_index_dir "$d" "$ROOT_DIR" "$BR" "$SAFE"
+ gen_index_dir "$d" "$ROOT_DIR" "$BR"
done < <(find "$ROOT_DIR" -type d -print0)
- # Append to landing page using JSON-escaped values
+ # Append to landing page (JSON-escaped)
SAFE_JSON=$(printf '%s' "$SAFE" | jq -Rr @json)
BR_JSON=$(printf '%s' "$BR" | jq -Rr @json)
- echo "" \
+ echo "" \
>> public/index.html
done
# Finish landing page
cat >> public/index.html <<'HTML'
HTML