Skip to content

Commit

Permalink
helpers: adds repo_sync_helper
Browse files Browse the repository at this point in the history
Add a new function wrapper to call the repo tool.

It will run with:
- maximum timeout
- retries, sleeping in the middle
- verbose mode, if fail

Signed-off-by: Jose Quaresma <[email protected]>
  • Loading branch information
quaresmajose committed Nov 21, 2024
1 parent 89af5c9 commit 50f1ffa
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ function start_ssh_agent {
fi
}

function repo_sync_helper {
_repo_retries=4
_repo_extra_args=""
for i in $(seq $_repo_retries); do
if run timeout --preserve-status 4m $@ $_repo_extra_args; then
break
fi
status "repo [$i/$_repo_retries] failed with error $?"
if [ $i -eq $_repo_retries ]; then
exit 1
fi
_sleep=$(($i*2))
status "sleeping ${_sleep}s and trying again"
sleep $_sleep
_repo_extra_args="--verbose"
done
}

function repo_sync {
status "Repo syncing sources..."

Expand All @@ -74,39 +92,10 @@ function repo_sync {
status "Adding git config extraheader for $domain/factories"
git config --global http.https://${domain}/factories.extraheader "$(cat /secrets/git.http.extraheader)"
fi
_repo_extra_args=""
for i in $(seq 4); do
if run repo init $_repo_extra_args --repo-rev=v2.35 --no-clone-bundle -u $* ${REPO_INIT_OVERRIDES}; then
break
fi
_repo_extra_args="--verbose"
status "repo init failed with error $?"
if [ $i -eq 4 ]; then
exit 1
fi
status "sleeping and trying again"
sleep $(($i*2))
done
_repo_extra_args=""
for i in $(seq 4); do
if run timeout 4m repo sync $_repo_extra_args; then
break
fi
_repo_extra_args="--verbose"
if [ $? -eq 124 ] ; then
msg="Command timed out"
if [ $i -ne 4 ] ; then
msg="${msg}, trying again"
else
status ${msg}
exit 1
fi
status ${msg}
sleep $(($i*2))
else
exit $?
fi
done

repo_sync_helper repo init --repo-rev=v2.35 --no-clone-bundle -u $* ${REPO_INIT_OVERRIDES}
repo_sync_helper repo sync

if [ -d "$archive" ] ; then
status "Generating pinned manifest"
repo manifest -r -o $archive/manifest.pinned.xml
Expand Down

0 comments on commit 50f1ffa

Please sign in to comment.