100 lines
2.6 KiB
Bash
Executable file
100 lines
2.6 KiB
Bash
Executable file
#!/bin/bash
|
|
# deploy_public.sh — Deploy public files from main to the Forgejo public branch
|
|
#
|
|
# Usage: ./deploy_public.sh ["optional commit message"]
|
|
#
|
|
# Checks out the public branch, updates it with public files from main,
|
|
# generates a public README (stripping private sections), commits if
|
|
# anything changed, and pushes to origin. Then switches back to main.
|
|
#
|
|
# On first run (no public branch exists), creates an orphan branch.
|
|
#
|
|
# E.M.F. February 2026
|
|
|
|
set -e
|
|
|
|
# --- Configuration ---
|
|
|
|
# Files to include on the public branch
|
|
PUBLIC_FILES=(
|
|
build_store.py
|
|
query_hybrid.py
|
|
retrieve.py
|
|
search_keywords.py
|
|
run_query.sh
|
|
clippings_search/build_clippings.py
|
|
clippings_search/retrieve_clippings.py
|
|
requirements.txt
|
|
.gitignore
|
|
LICENSE
|
|
)
|
|
|
|
REMOTE="origin"
|
|
BRANCH="public"
|
|
COMMIT_MSG="${1:-Update public branch from main}"
|
|
|
|
# --- Safety checks ---
|
|
|
|
CURRENT=$(git branch --show-current)
|
|
if [ "$CURRENT" != "main" ]; then
|
|
echo "Error: must be on main branch (currently on $CURRENT)"
|
|
exit 1
|
|
fi
|
|
|
|
if ! git diff --quiet HEAD 2>/dev/null; then
|
|
echo "Error: uncommitted changes on main. Commit or stash first."
|
|
exit 1
|
|
fi
|
|
|
|
MAIN_HEAD=$(git rev-parse --short HEAD)
|
|
|
|
# --- Build public branch ---
|
|
|
|
echo "Deploying main ($MAIN_HEAD) -> $BRANCH..."
|
|
|
|
# Check out public branch, or create orphan if it doesn't exist yet
|
|
if git show-ref --verify --quiet "refs/heads/$BRANCH"; then
|
|
git checkout "$BRANCH"
|
|
else
|
|
echo "No local $BRANCH branch — creating orphan..."
|
|
git checkout --orphan "$BRANCH"
|
|
git rm -rf . >/dev/null 2>&1 || true
|
|
fi
|
|
|
|
# Copy public files from main
|
|
for f in "${PUBLIC_FILES[@]}"; do
|
|
git checkout main -- "$f"
|
|
done
|
|
|
|
# Generate public README from main's README:
|
|
# - Strip "## Notebooks" section
|
|
# - Strip "## Development history" section
|
|
# - Remove project-tree lines referencing private files
|
|
git checkout main -- README.md
|
|
awk '
|
|
/^## Notebooks/ { skip = 1; next }
|
|
/^## Development hist/ { skip = 1; next }
|
|
/^## / { skip = 0 }
|
|
skip { next }
|
|
/archived\// { next }
|
|
/saved_output\// { next }
|
|
/devlog\.md/ { next }
|
|
/\*\.ipynb/ { next }
|
|
{ print }
|
|
' README.md > README.tmp && mv README.tmp README.md
|
|
|
|
# Stage only the public files (not untracked files on disk)
|
|
git add "${PUBLIC_FILES[@]}" README.md
|
|
|
|
# Commit only if there are changes
|
|
if git diff --cached --quiet; then
|
|
echo "No changes to deploy."
|
|
else
|
|
git commit -m "$COMMIT_MSG"
|
|
git push "$REMOTE" "$BRANCH"
|
|
echo ""
|
|
echo "Done. Deployed main ($MAIN_HEAD) -> $REMOTE/$BRANCH"
|
|
fi
|
|
|
|
# Switch back to main
|
|
git checkout main
|