Skip to content

Commit a9f99c6

Browse files
committed
f
1 parent a1e67da commit a9f99c6

File tree

2 files changed

+65
-32
lines changed

2 files changed

+65
-32
lines changed

.github/workflows/build_master.yml

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -60,48 +60,55 @@ jobs:
6060
# Clone the searchindex repo
6161
git clone https://x-access-token:${TOKEN}@github.com/${TARGET_REPO}.git /tmp/searchindex-repo
6262
63+
cd /tmp/searchindex-repo
64+
git config user.name "GitHub Actions"
65+
git config user.email "[email protected]"
66+
67+
# Create a fresh orphan branch (no history)
68+
git checkout --orphan new-main
69+
70+
# Remove all existing files from git index
71+
git rm -rf . 2>/dev/null || true
72+
6373
# Copy and compress the searchindex file
64-
cp "$ASSET" "/tmp/searchindex-repo/${FILENAME}"
74+
cp "$ASSET" "${FILENAME}"
6575
gzip -9 -k -f "$ASSET"
66-
cp "${ASSET}.gz" "/tmp/searchindex-repo/${FILENAME}.gz"
76+
cp "${ASSET}.gz" "${FILENAME}.gz"
6777
6878
# Show compression stats
6979
ORIGINAL_SIZE=$(wc -c < "$ASSET")
7080
COMPRESSED_SIZE=$(wc -c < "${ASSET}.gz")
7181
RATIO=$(awk "BEGIN {printf \"%.1f\", ($COMPRESSED_SIZE / $ORIGINAL_SIZE) * 100}")
7282
echo "Compression: ${ORIGINAL_SIZE} bytes -> ${COMPRESSED_SIZE} bytes (${RATIO}%)"
7383
74-
# Commit and push with retry logic
75-
cd /tmp/searchindex-repo
76-
git config user.name "GitHub Actions"
77-
git config user.email "[email protected]"
78-
git add "${FILENAME}" "${FILENAME}.gz"
84+
# Add all files from other workflows (if they exist)
85+
git checkout main -- . 2>/dev/null || true
7986
80-
if git diff --staged --quiet; then
81-
echo "No changes to commit"
82-
else
83-
git commit -m "Update ${FILENAME} from hacktricks-cloud build"
84-
85-
# Retry push up to 20 times with pull --rebase between attempts
86-
MAX_RETRIES=20
87-
RETRY_COUNT=0
88-
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
89-
if git push origin main; then
90-
echo "Successfully pushed on attempt $((RETRY_COUNT + 1))"
91-
break
92-
else
93-
RETRY_COUNT=$((RETRY_COUNT + 1))
94-
if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
95-
echo "Push failed, attempt $RETRY_COUNT/$MAX_RETRIES. Pulling and retrying..."
96-
git pull --rebase origin main
97-
sleep $((RETRY_COUNT * 2)) # Exponential backoff
98-
else
99-
echo "Failed to push after $MAX_RETRIES attempts"
100-
exit 1
101-
fi
102-
fi
103-
done
87+
# Add our new files (will overwrite if they existed)
88+
cp "$ASSET" "${FILENAME}"
89+
cp "${ASSET}.gz" "${FILENAME}.gz"
90+
91+
# Create README if it doesn't exist
92+
if [ ! -f "README.md" ]; then
93+
echo "# HackTricks Search Index Repository" > README.md
94+
echo "" >> README.md
95+
echo "This repository contains searchindex files for HackTricks and HackTricks Cloud." >> README.md
96+
echo "Files are automatically generated and updated by GitHub Actions." >> README.md
97+
echo "" >> README.md
98+
echo "⚠️ This repository is reset periodically to keep history clean." >> README.md
10499
fi
100+
101+
# Stage all files
102+
git add -A
103+
104+
# Commit with timestamp
105+
TIMESTAMP=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
106+
git commit -m "Update searchindex files - ${TIMESTAMP}"
107+
108+
# Force push to replace main branch (deletes history)
109+
git push -f origin new-main:main
110+
111+
echo "Successfully reset repository and pushed searchindex files"
105112
106113
# Login in AWs
107114
- name: Configure AWS credentials using OIDC

.github/workflows/translate_all.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,33 @@ jobs:
202202
RETRY_COUNT=$((RETRY_COUNT + 1))
203203
if [ $RETRY_COUNT -lt $MAX_RETRIES ]; then
204204
echo "Push failed, attempt $RETRY_COUNT/$MAX_RETRIES. Pulling and retrying..."
205-
git pull --rebase origin main
205+
206+
# Try normal rebase first
207+
if git pull --rebase origin main 2>&1 | tee /tmp/pull_output.txt; then
208+
echo "Rebase successful, retrying push..."
209+
else
210+
# If rebase fails due to divergent histories (orphan branch reset), re-clone
211+
if grep -q "unrelated histories\|refusing to merge\|fatal: invalid upstream" /tmp/pull_output.txt; then
212+
echo "Detected history rewrite, re-cloning repository..."
213+
cd /tmp
214+
rm -rf searchindex-repo
215+
git clone https://x-access-token:${TOKEN}@github.com/${TARGET_REPO}.git searchindex-repo
216+
cd searchindex-repo
217+
git config user.name "GitHub Actions"
218+
git config user.email "[email protected]"
219+
220+
# Re-copy and compress the searchindex file
221+
cp "$ASSET" "${FILENAME}"
222+
cp "${ASSET}.gz" "${FILENAME}.gz"
223+
224+
git add "${FILENAME}" "${FILENAME}.gz"
225+
git commit -m "Update ${FILENAME} from hacktricks-cloud build"
226+
echo "Re-cloned and re-committed, will retry push..."
227+
else
228+
echo "Rebase failed for unknown reason, retrying anyway..."
229+
fi
230+
fi
231+
206232
sleep $((RETRY_COUNT * 2)) # Exponential backoff
207233
else
208234
echo "Failed to push after $MAX_RETRIES attempts"

0 commit comments

Comments
 (0)