Skip to content

Commit

Permalink
resync.sh: update logic in case of failure
Browse files Browse the repository at this point in the history
  • Loading branch information
RisenID committed Nov 9, 2024
1 parent bcec304 commit 1537065
Showing 1 changed file with 47 additions and 9 deletions.
56 changes: 47 additions & 9 deletions resync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -euo pipefail

WORKDIR="/home/sketu/rising"
OUTPUT_FILE="/tmp/repo_sync_output.txt"
SYNC_STATUS="/tmp/sync.txt"
SYNC_STATUS_ERRORS="/tmp/sync_err.txt"
DIRTY_REPOS="/tmp/failed.txt"
DELETED_REPOS_FILE="$WORKDIR/deleted_repositories.txt"
STABLE_REPO_URL="https://github.com/RisingTechOSS/android"
STAGING_REPO_URL="https://github.com/RisingOS-staging/android"
Expand Down Expand Up @@ -38,9 +41,21 @@ init_repo() {

sync_repos() {
log "Syncing repositories..."
rm -f /tmp/sync.txt
find "$WORKDIR/.repo" -name '*.lock' -delete
repo sync -c -j"$(nproc --all)" --force-sync --no-clone-bundle --no-tags --prune
log "repo sync completed successfully"
repo sync -c -j"$(nproc --all)" --force-sync --no-clone-bundle --no-tags --prune >> "$SYNC_STATUS" && check_sync
}

check_sync() {
grep -w "error:" $SYNC_STATUS | tee $SYNC_STATUS_ERRORS
find /tmp/ -type f -empty -delete
if [ -f $SYNC_STATUS_ERRORS ]; then
((FAIL++))
log "repo sync failed $FAIL time(s)"
fix_errors
else
log "repo sync completed successfully"
fi
}

delete_failing_repos() {
Expand All @@ -58,31 +73,54 @@ delete_failing_repos() {
fi
}

perform_sync() {
if ! sync_repos; then
delete_dirty_repos() {
log "Checking for failing repositories..."
# grep -w "error: checkout" "$SYNC_STATUS"
grep -w "Cannot remove project: uncommitted changes are present." $SYNC_STATUS_ERRORS >> $DIRTY_REPOS
if [ -n "$DIRTY_REPOS" ]; then
log "Deleting dirty repositories:"
sed -i s/error\: //g "$DIRTY_REPOS"
sed -i s/\: Cannot remove project\: uncommitted changes are present\.//g "$DIRTY_REPOS"
echo "$DIRTY_REPOS" | while read -r repo; do
log "Deleting repository: $repo"
echo "$repo" >> "$DELETED_REPOS_FILE"
rm -rf "$WORKDIR/$repo" "$WORKDIR/.repo/projects/$repo.git"
done
else
log "No failing repositories found"
rm -f /tmp/failed.txt
fi
}

fix_errors() {
if [ "$FAIL" = 1 ] || [ "$FAIL" = 2 ]; then
log "Attempting to delete failing repositories"
delete_failing_repos
delete_dirty_repos
log "Re-attempting sync after deleting failing repositories"
if ! sync_repos; then
sync_repos
if [ "$FAIL" = 2 ]; then
log "Error: repo sync failed even after deleting failing repositories"
exit 1
fi
fi
}

main() {
cd "$WORKDIR" || exit 1


FAIL=0

: > "$OUTPUT_FILE"
rm -f "$DELETED_REPOS_FILE"

#update_repo_tool
init_repo
perform_sync
sync_repos

if [ -f "$DELETED_REPOS_FILE" ]; then
log "The following repositories were deleted:"
cat "$DELETED_REPOS_FILE" | tee -a "$OUTPUT_FILE"
fi
}

main "$@"
main

0 comments on commit 1537065

Please sign in to comment.