@@ -89,12 +89,59 @@ jobs:
8989 # Stage the updated file
9090 git add "${FILENAME}.gz"
9191
92- # Commit with timestamp if there are changes
93- TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
94- git commit -m "Update searchindex files - ${TIMESTAMP}" || echo "No changes to commit"
95-
96- # Push to master branch
97- git push origin master
92+ # Commit and push with retry logic
93+ if git diff --staged --quiet; then
94+ echo "No changes to commit"
95+ else
96+ TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
97+ git commit -m "Update searchindex files - ${TIMESTAMP}"
98+
99+ # Retry push up to 20 times with pull --rebase between attempts
100+ MAX_RETRIES=20
101+ RETRY_COUNT=0
102+ while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
103+ if git push origin master; then
104+ echo "Successfully pushed on attempt $((RETRY_COUNT + 1))"
105+ break
106+ else
107+ RETRY_COUNT=$((RETRY_COUNT + 1))
108+ if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
109+ echo "Push failed, attempt $RETRY_COUNT/$MAX_RETRIES. Pulling and retrying..."
110+
111+ # Try normal rebase first
112+ if git pull --rebase origin master 2>&1 | tee /tmp/pull_output.txt; then
113+ echo "Rebase successful, retrying push..."
114+ else
115+ # If rebase fails due to divergent histories (orphan branch reset), re-clone
116+ if grep -q "unrelated histories\|refusing to merge\|fatal: invalid upstream\|couldn't find remote ref" /tmp/pull_output.txt; then
117+ echo "Detected history rewrite, re-cloning repository..."
118+ cd /tmp
119+ rm -rf searchindex-repo
120+ git clone https://x-access-token:${TOKEN}@github.com/${TARGET_REPO}.git searchindex-repo
121+ cd searchindex-repo
122+ git config user.name "GitHub Actions"
123+ git config user.email "github-actions@github.com"
124+
125+ # Re-copy the .gz version
126+ cp "${GITHUB_WORKSPACE}/${ASSET}.gz" "${FILENAME}.gz"
127+
128+ git add "${FILENAME}.gz"
129+ TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
130+ git commit -m "Update searchindex files - ${TIMESTAMP}"
131+ echo "Re-cloned and re-committed, will retry push..."
132+ else
133+ echo "Rebase failed for unknown reason, retrying anyway..."
134+ fi
135+ fi
136+
137+ sleep 1
138+ else
139+ echo "Failed to push after $MAX_RETRIES attempts"
140+ exit 1
141+ fi
142+ fi
143+ done
144+ fi
98145
99146 echo "Successfully pushed searchindex files"
100147
0 commit comments