|
57 | 57 | exit 1 |
58 | 58 | fi |
59 | 59 |
|
60 | | - # Clone the searchindex repo |
61 | | - git clone https://x-access-token:${TOKEN}@github.com/${TARGET_REPO}.git /tmp/searchindex-repo |
62 | | - |
63 | | - cd /tmp/searchindex-repo |
64 | | - git config user.name "GitHub Actions" |
65 | | - git config user.email "github-actions@github.com" |
66 | | - |
67 | | - # Save all current files from main branch to temp directory |
68 | | - mkdir -p /tmp/searchindex-backup |
69 | | - cp -r * /tmp/searchindex-backup/ 2>/dev/null || true |
70 | | - |
71 | | - # Create a fresh orphan branch (no history) |
72 | | - git checkout --orphan new-main |
73 | | - |
74 | | - # Remove all files from git index (but keep working directory) |
75 | | - git rm -rf . 2>/dev/null || true |
76 | | - |
77 | | - # Restore all the files from backup (keeps all language files) |
78 | | - cp -r /tmp/searchindex-backup/* . 2>/dev/null || true |
79 | | - |
80 | | - # Now update/add our English searchindex file |
81 | 60 | # First, compress the original file (in the build directory) |
82 | 61 | cd "${GITHUB_WORKSPACE}" |
83 | 62 | gzip -9 -k -f "$ASSET" |
@@ -107,21 +86,57 @@ jobs: |
107 | 86 | EOF |
108 | 87 | python3 /tmp/xor_encrypt.py "$KEY" "${ASSET}.gz" "${ASSET}.gz.enc" |
109 | 88 | |
110 | | - # Copy ONLY the encrypted .gz version to the searchindex repo (no uncompressed .js) |
111 | | - cd /tmp/searchindex-repo |
112 | | - cp "${GITHUB_WORKSPACE}/${ASSET}.gz.enc" "${FILENAME}.gz" |
113 | | - |
114 | | - # Stage all files |
115 | | - git add -A |
116 | | - |
117 | | - # Commit with timestamp |
118 | | - TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC") |
119 | | - git commit -m "Update searchindex files - ${TIMESTAMP}" --allow-empty |
120 | | - |
121 | | - # Force push to replace master branch (deletes history, keeps all files) |
122 | | - git push -f origin new-main:master |
123 | | - |
124 | | - echo "Successfully reset repository history and pushed all searchindex files" |
| 89 | + # Rebuild and force-push with retries to handle concurrent updates. |
| 90 | + MAX_RETRIES=20 |
| 91 | + RETRY_COUNT=0 |
| 92 | + while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do |
| 93 | + RETRY_COUNT=$((RETRY_COUNT + 1)) |
| 94 | + echo "Push attempt ${RETRY_COUNT}/${MAX_RETRIES}" |
| 95 | +
|
| 96 | + rm -rf /tmp/searchindex-repo /tmp/searchindex-backup |
| 97 | + git clone https://x-access-token:${TOKEN}@github.com/${TARGET_REPO}.git /tmp/searchindex-repo |
| 98 | +
|
| 99 | + cd /tmp/searchindex-repo |
| 100 | + git config user.name "GitHub Actions" |
| 101 | + git config user.email "github-actions@github.com" |
| 102 | +
|
| 103 | + # Save all current files from master branch to temp directory. |
| 104 | + mkdir -p /tmp/searchindex-backup |
| 105 | + cp -r * /tmp/searchindex-backup/ 2>/dev/null || true |
| 106 | +
|
| 107 | + # Create a fresh orphan branch (no history). |
| 108 | + git checkout --orphan new-main |
| 109 | +
|
| 110 | + # Remove all files from git index (but keep working directory). |
| 111 | + git rm -rf . 2>/dev/null || true |
| 112 | +
|
| 113 | + # Restore all files from backup (keeps all language files). |
| 114 | + cp -r /tmp/searchindex-backup/* . 2>/dev/null || true |
| 115 | +
|
| 116 | + # Update English searchindex artifact. |
| 117 | + cp "${GITHUB_WORKSPACE}/${ASSET}.gz.enc" "${FILENAME}.gz" |
| 118 | +
|
| 119 | + git add -A |
| 120 | + TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC") |
| 121 | + git commit -m "Update searchindex files - ${TIMESTAMP}" --allow-empty |
| 122 | +
|
| 123 | + if git push -f origin new-main:master 2>&1 | tee /tmp/push_output.txt; then |
| 124 | + echo "Successfully reset repository history and pushed all searchindex files" |
| 125 | + break |
| 126 | + fi |
| 127 | +
|
| 128 | + if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then |
| 129 | + if grep -q "cannot lock ref 'refs/heads/master'" /tmp/push_output.txt; then |
| 130 | + echo "Concurrent update detected on remote master. Retrying..." |
| 131 | + else |
| 132 | + echo "Force push failed. Retrying..." |
| 133 | + fi |
| 134 | + sleep 1 |
| 135 | + else |
| 136 | + echo "Failed to push after ${MAX_RETRIES} attempts" |
| 137 | + exit 1 |
| 138 | + fi |
| 139 | + done |
125 | 140 |
|
126 | 141 | # Login in AWs |
127 | 142 | - name: Configure AWS credentials using OIDC |
|
0 commit comments