26 lines
755 B
Bash
26 lines
755 B
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# This script is invoked by adnanh/webhook when a matching hook is triggered.
|
|
# It updates the git checkout in /app/site to origin/$GIT_BRANCH.
|
|
# Hugo server runs separately and watches the files, so no explicit hugo build is required.
|
|
|
|
REPO_DIR="/app/site"
|
|
GIT_BRANCH="${GIT_BRANCH:-main}"
|
|
|
|
if [ ! -d "$REPO_DIR/.git" ]; then
|
|
echo "Repository not found at $REPO_DIR; nothing to update."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Updating repository in $REPO_DIR to origin/$GIT_BRANCH"
|
|
cd "$REPO_DIR"
|
|
|
|
# Fetch and reset
|
|
git fetch origin "$GIT_BRANCH" --depth=1 || true
|
|
git reset --hard "origin/$GIT_BRANCH"
|
|
|
|
# Optionally, you can clear caches or perform other tasks here.
|
|
echo "Update completed at $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
exit 0
|