Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 2 additions & 65 deletions .github/actions/deploy-subdir/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,55 +38,7 @@ runs:
TARGET_SUBDIR: ${{ inputs.target-subdir }}
STORAGE_BRANCH: ${{ inputs.storage-branch }}
PRESERVE: ${{ inputs.preserve }}
GH_TOKEN: ${{ inputs.github-token }}
run: |
set -euo pipefail

if [ ! -d "$SOURCE_DIR" ]; then
echo "::error::source-dir '$SOURCE_DIR' does not exist" >&2
exit 1
fi

REPO_URL="https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"

rm -rf _site _storage
mkdir -p _site

# Pull the current full site from the storage branch (if it exists).
if git ls-remote --exit-code --heads "$REPO_URL" "$STORAGE_BRANCH" >/dev/null 2>&1; then
git clone --quiet --depth 1 --branch "$STORAGE_BRANCH" "$REPO_URL" _storage
( cd _storage && tar -cf - --exclude=.git . ) | ( cd _site && tar -xf - )
rm -rf _storage
fi

# Overlay the freshly built app into its slot.
if [ -z "$TARGET_SUBDIR" ] || [ "$TARGET_SUBDIR" = "." ]; then
# Site root (shell): replace root entries but keep sibling micro apps.
keep=".git .nojekyll $PRESERVE"
shopt -s dotglob nullglob
for entry in _site/*; do
name="$(basename "$entry")"
case " $keep " in
*" $name "*) continue ;;
esac
rm -rf "$entry"
done
shopt -u dotglob nullglob
cp -R "$SOURCE_DIR"/. _site/
else
rm -rf "_site/${TARGET_SUBDIR}"
mkdir -p "_site/${TARGET_SUBDIR}"
cp -R "$SOURCE_DIR"/. "_site/${TARGET_SUBDIR}/"
fi

# SPA fallback + disable Jekyll processing.
touch _site/.nojekyll
if [ -f _site/index.html ]; then
cp _site/index.html _site/404.html
fi

echo "Assembled site tree:"
find _site -maxdepth 2 -mindepth 1 | sort
run: ${{ github.action_path }}/assemble-site.sh

- name: Upload Pages artifact 📦
uses: actions/upload-pages-artifact@v5
Expand All @@ -99,19 +51,4 @@ runs:
TARGET_SUBDIR: ${{ inputs.target-subdir }}
STORAGE_BRANCH: ${{ inputs.storage-branch }}
GH_TOKEN: ${{ inputs.github-token }}
run: |
set -euo pipefail
REPO_URL="https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
SLOT="${TARGET_SUBDIR:-/ (shell)}"

cd _site
rm -rf .git
git init -q
git add -A
git -c user.name="github-actions[bot]" \
-c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
commit -q -m "deploy: update ${SLOT} (${GITHUB_SHA})" || {
echo "Nothing to persist."; exit 0;
}
git branch -M "$STORAGE_BRANCH"
git push -f "$REPO_URL" "$STORAGE_BRANCH"
run: ${{ github.action_path }}/persist-site.sh
48 changes: 48 additions & 0 deletions .github/actions/deploy-subdir/assemble-site.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -euo pipefail

if [ ! -d "$SOURCE_DIR" ]; then
echo "::error::source-dir '$SOURCE_DIR' does not exist" >&2
exit 1
fi

REPO_URL="https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"

rm -rf _site _storage
mkdir -p _site

# Pull the current full site from the storage branch (if it exists).
if git ls-remote --exit-code --heads "$REPO_URL" "$STORAGE_BRANCH" >/dev/null 2>&1; then
git clone --quiet --depth 1 --branch "$STORAGE_BRANCH" "$REPO_URL" _storage
( cd _storage && tar -cf - --exclude=.git . ) | ( cd _site && tar -xf - )
rm -rf _storage
fi

# Overlay the freshly built app into its slot.
if [ -z "$TARGET_SUBDIR" ] || [ "$TARGET_SUBDIR" = "." ]; then
# Site root (shell): replace root entries but keep sibling micro apps.
keep=".git .nojekyll $PRESERVE"
shopt -s dotglob nullglob
for entry in _site/*; do
name="$(basename "$entry")"
case " $keep " in
*" $name "*) continue ;;
esac
rm -rf "$entry"
done
shopt -u dotglob nullglob
cp -R "$SOURCE_DIR"/. _site/
else
rm -rf "_site/${TARGET_SUBDIR}"
mkdir -p "_site/${TARGET_SUBDIR}"
cp -R "$SOURCE_DIR"/. "_site/${TARGET_SUBDIR}/"
fi

# SPA fallback + disable Jekyll processing.
touch _site/.nojekyll
if [ -f _site/index.html ]; then
cp _site/index.html _site/404.html
fi

echo "Assembled site tree:"
find _site -maxdepth 2 -mindepth 1 | sort
17 changes: 17 additions & 0 deletions .github/actions/deploy-subdir/persist-site.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail

REPO_URL="https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
SLOT="${TARGET_SUBDIR:-/ (shell)}"

cd _site
rm -rf .git
git init -q
git add -A
git -c user.name="github-actions[bot]" \
-c user.email="41898282+github-actions[bot]@users.noreply.github.com" \
commit -q -m "deploy: update ${SLOT} (${GITHUB_SHA})" || {
echo "Nothing to persist."; exit 0;
}
git branch -M "$STORAGE_BRANCH"
git push -f "$REPO_URL" "$STORAGE_BRANCH"