build_package.sh: Retry SPM submodule operations
These fail frequently for LTS builds.
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
Change-Id: I4accef70afc8fb90c7cf0d04e8e8208e572662bf
(cherry picked from commit be6510c3a1fbb6a1e494490218c5df3ed37965a7)
diff --git a/script/build_package.sh b/script/build_package.sh
index 7291f35..fe602fe 100755
--- a/script/build_package.sh
+++ b/script/build_package.sh
@@ -98,6 +98,18 @@
fi
}
+# Retry a command a number of times if it fails. Intended for I/O commands
+# in a CI environment which may be flaky.
+function retry() {
+ for i in $(seq 1 3); do
+ if "$@"; then
+ return 0
+ fi
+ sleep $(( i * 5 ))
+ done
+ return 1
+}
+
# Call hook $1 in all chosen fragments if it's defined. Hooks are invoked from
# within a subshell, so any variables set within a hook are lost. Should a
# variable needs to be set from within a hook, the function 'set_hook_var'
@@ -1242,7 +1254,7 @@
pushd "$spm_root"
# Check if submodules need initialising
if git submodule status | grep '^-'; then
- git submodule update --init
+ retry git submodule update --init
fi
popd