Skip to content

Commit 50f1ffa

Browse files
committed
helpers: adds repo_sync_helper
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 <jose.quaresma@foundries.io>
1 parent 89af5c9 commit 50f1ffa

File tree

1 file changed

+22
-33
lines changed

1 file changed

+22
-33
lines changed

helpers.sh

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ function start_ssh_agent {
6666
fi
6767
}
6868

69+
function repo_sync_helper {
70+
_repo_retries=4
71+
_repo_extra_args=""
72+
for i in $(seq $_repo_retries); do
73+
if run timeout --preserve-status 4m $@ $_repo_extra_args; then
74+
break
75+
fi
76+
status "repo [$i/$_repo_retries] failed with error $?"
77+
if [ $i -eq $_repo_retries ]; then
78+
exit 1
79+
fi
80+
_sleep=$(($i*2))
81+
status "sleeping ${_sleep}s and trying again"
82+
sleep $_sleep
83+
_repo_extra_args="--verbose"
84+
done
85+
}
86+
6987
function repo_sync {
7088
status "Repo syncing sources..."
7189

@@ -74,39 +92,10 @@ function repo_sync {
7492
status "Adding git config extraheader for $domain/factories"
7593
git config --global http.https://${domain}/factories.extraheader "$(cat /secrets/git.http.extraheader)"
7694
fi
77-
_repo_extra_args=""
78-
for i in $(seq 4); do
79-
if run repo init $_repo_extra_args --repo-rev=v2.35 --no-clone-bundle -u $* ${REPO_INIT_OVERRIDES}; then
80-
break
81-
fi
82-
_repo_extra_args="--verbose"
83-
status "repo init failed with error $?"
84-
if [ $i -eq 4 ]; then
85-
exit 1
86-
fi
87-
status "sleeping and trying again"
88-
sleep $(($i*2))
89-
done
90-
_repo_extra_args=""
91-
for i in $(seq 4); do
92-
if run timeout 4m repo sync $_repo_extra_args; then
93-
break
94-
fi
95-
_repo_extra_args="--verbose"
96-
if [ $? -eq 124 ] ; then
97-
msg="Command timed out"
98-
if [ $i -ne 4 ] ; then
99-
msg="${msg}, trying again"
100-
else
101-
status ${msg}
102-
exit 1
103-
fi
104-
status ${msg}
105-
sleep $(($i*2))
106-
else
107-
exit $?
108-
fi
109-
done
95+
96+
repo_sync_helper repo init --repo-rev=v2.35 --no-clone-bundle -u $* ${REPO_INIT_OVERRIDES}
97+
repo_sync_helper repo sync
98+
11099
if [ -d "$archive" ] ; then
111100
status "Generating pinned manifest"
112101
repo manifest -r -o $archive/manifest.pinned.xml

0 commit comments

Comments
 (0)