From e141e994840309879e5ad658711dec4c6a721cde Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Wed, 6 Nov 2024 15:03:16 +0200 Subject: [PATCH] fix(kbuild): Implement command retry to firmware clone As often firmware git clone fails - implement retry, so build wont fail. Signed-off-by: Denys Fedoryshchenko --- kernelci/kbuild.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/kernelci/kbuild.py b/kernelci/kbuild.py index e429a7f083..9d26b23fb2 100644 --- a/kernelci/kbuild.py +++ b/kernelci/kbuild.py @@ -381,6 +381,22 @@ def startjob(self, jobname): cmd = f'echo jobsts:{jobname}=$(date +%s) >> {self._af_dir}/state.txt' self._steps.append(cmd) + def addcmdretry(self, cmd, retries=10): + ''' + Retry command if it fails up to retries times + ''' + self.addcomment(f"Retry command {cmd} {retries} times") + self.addcmd("for i in $(seq 1 " + str(retries) + "); do") + self.addcmd(" echo \"Attempt $i\"") + self.addcmd(" sleep 1") + self.addcmd(" " + cmd + " && break") + self.addcmd("done") + self.addcmd("if [ $? -ne 0 ]; then") + self.addcmd(" echo \"Failed to run " + cmd + "\"") + self.addcmd(" exit 1") + self.addcmd("fi") + + def addcmd(self, cmd, critical=True): ''' critical - if True, check return code and exit, as command is critical @@ -397,7 +413,8 @@ def _fetch_firmware(self): TODO: Implement firmware commit id meta/settings ''' self.startjob("fetch_firmware") - self.addcmd(f"git clone {FW_GIT} --depth 1", False) + #self.addcmd(f"git clone {FW_GIT} --depth 1", False) + self.addcmdretry(f"git clone {FW_GIT} --depth 1", 10) self.addcmd("cd linux-firmware") self.addcmd("./copy-firmware.sh " + self._firmware_dir) self.addcmd("cd ..")