37 lines
797 B
Bash
Executable File
37 lines
797 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
: "${FILE:?FILE is required}"
|
|
: "${COMMIT_MESSAGE:?COMMIT_MESSAGE is required}"
|
|
|
|
git config user.name "gitea actions"
|
|
git config user.email "actions@localhost"
|
|
|
|
# schedule runs can checkout a detached HEAD, so create a throwaway branch
|
|
branch="automation/update-$(date +%s)"
|
|
git switch -C "$branch"
|
|
|
|
git add "$FILE"
|
|
|
|
if git diff --cached --quiet; then
|
|
echo "No staged changes for ${FILE}; skipping commit"
|
|
exit 0
|
|
fi
|
|
|
|
git commit -m "$COMMIT_MESSAGE"
|
|
|
|
for attempt in 1 2 3 4 5; do
|
|
if git push origin HEAD:main; then
|
|
echo "Pushed to main"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Push failed (attempt ${attempt}); rebasing on origin/main and retrying"
|
|
git fetch origin main
|
|
git rebase origin/main
|
|
sleep 2
|
|
done
|
|
|
|
echo "Failed to push update after retries"
|
|
exit 1
|