Add polling deployment scripts

This commit is contained in:
shkim
2026-05-10 20:10:46 +09:00
parent 94ff09dc98
commit 1fe15ea3ea
4 changed files with 66 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
#!/bin/sh
set -eu
APP_DIR="$(cd "$(dirname "$0")" && pwd)"
STATE_FILE="$APP_DIR/data/deployed-rev"
LOG_FILE="$APP_DIR/data/deploy.log"
mkdir -p "$APP_DIR/data"
cd "$APP_DIR"
remote_rev="$(git ls-remote origin refs/heads/main | awk '{print $1}')"
if [ -z "$remote_rev" ]; then
echo "$(date '+%Y-%m-%d %H:%M:%S') no remote revision found" >> "$LOG_FILE"
exit 1
fi
current_rev=""
[ -f "$STATE_FILE" ] && current_rev="$(cat "$STATE_FILE")"
if [ "$remote_rev" = "$current_rev" ]; then
exit 0
fi
echo "$(date '+%Y-%m-%d %H:%M:%S') change detected $current_rev -> $remote_rev" >> "$LOG_FILE"
"$APP_DIR/deploy.sh"
printf '%s\n' "$remote_rev" > "$STATE_FILE"