59 lines
1.7 KiB
Bash
Executable File
59 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# daily-commit.sh
|
|
# Commits changes in the workspace and pushes to origin/main using the deploy SSH key.
|
|
# Also appends a short summary to memory/YYYY-MM-DD.md
|
|
|
|
WORKDIR="/home/alex/openclaw2"
|
|
MEMDIR="$WORKDIR/memory"
|
|
KEY="$WORKDIR/.ssh/openclaw_deploy_ed25519"
|
|
LOGTMP="/tmp/daily_commit_summary.txt"
|
|
|
|
mkdir -p "$MEMDIR"
|
|
cd "$WORKDIR"
|
|
|
|
export GIT_SSH_COMMAND="ssh -i $KEY -o StrictHostKeyChecking=accept-new"
|
|
|
|
# Ensure remote is set
|
|
git remote get-url origin >/dev/null 2>&1 || git remote add origin git@github.com:alexpolo1/openclaw2.git || true
|
|
|
|
# Fetch and rebase to avoid unrelated histories
|
|
if git rev-parse --verify origin/main >/dev/null 2>&1; then
|
|
git fetch origin main --quiet
|
|
# Try a rebase; if it fails, abort and record error
|
|
if ! git rebase origin/main --quiet; then
|
|
echo "$(date -I) - REBASE_FAILED" >> "$MEMDIR/$(date +%F).md"
|
|
git rebase --abort >/dev/null 2>&1 || true
|
|
exit 2
|
|
fi
|
|
fi
|
|
|
|
# Stage changes
|
|
git add -A
|
|
|
|
# If nothing to commit, write note and exit
|
|
if git diff --staged --quiet; then
|
|
echo "$(date -I) — nothing to commit" >> "$MEMDIR/$(date +%F).md"
|
|
exit 0
|
|
fi
|
|
|
|
# Commit and push
|
|
MSG="daily backup $(date -I)"
|
|
if git commit -m "$MSG" --quiet; then
|
|
if git push origin main --quiet; then
|
|
COMMIT_HASH=$(git rev-parse --short HEAD)
|
|
git --no-pager show --name-only --pretty=format:"%h %ad %s" --date=short "$COMMIT_HASH" > "$LOGTMP"
|
|
echo "### $MSG ($COMMIT_HASH)" >> "$MEMDIR/$(date +%F).md"
|
|
cat "$LOGTMP" >> "$MEMDIR/$(date +%F).md"
|
|
rm -f "$LOGTMP"
|
|
exit 0
|
|
else
|
|
echo "$(date -I) - PUSH_FAILED" >> "$MEMDIR/$(date +%F).md"
|
|
exit 3
|
|
fi
|
|
else
|
|
echo "$(date -I) - COMMIT_FAILED" >> "$MEMDIR/$(date +%F).md"
|
|
exit 4
|
|
fi
|