Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 788d34d

Browse files
authored
Retry signing if it fails (#3558)
1 parent 50e2735 commit 788d34d

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

tools/taskcluster/sign_apk.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import os
1111
import subprocess
1212
import sys
13+
import time
1314

1415
v1_platforms = {
1516
'oculusvr3dofstore',
@@ -72,13 +73,30 @@ def main(name, argv):
7273
print "Target ", target
7374
cmd = ["curl", "-F", "input=@" + apk, "-o", target, "-H", "Authorization: " + cred, sign_url]
7475

75-
try:
76-
print subprocess.check_output(cmd)
77-
except subprocess.CalledProcessError as err:
78-
cmd = ' '.join(err.cmd).replace(cred, "XXX")
79-
print "Signing apk failed:", cmd
80-
print "Output:", err.output
81-
sys.exit(err.returncode)
76+
signTryCount = 0
77+
done = False
78+
while not done and signTryCount < 5:
79+
if signTryCount > 0:
80+
print "Waiting 5 seconds before trying to sign apk again..."
81+
time.sleep(5)
82+
signTryCount = signTryCount + 1
83+
try:
84+
print subprocess.check_output(cmd)
85+
except subprocess.CalledProcessError as err:
86+
cleanCmd = ' '.join(err.cmd).replace(cred, "XXX")
87+
print "Signing apk failed:", cleanCmd
88+
print "Output:", err.output
89+
continue
90+
fileinfo = subprocess.check_output(['file', target])
91+
if fileinfo.find("ASCII text") != -1:
92+
print 'Error returned from autograph:'
93+
print subprocess.check_output(['cat', target])
94+
else:
95+
done = True
96+
97+
if not done:
98+
print "Failed to sign apk after multiple tries"
99+
sys.exit(2)
82100

83101
if align:
84102
split = os.path.splitext(target)
@@ -91,10 +109,6 @@ def main(name, argv):
91109
print subprocess.check_output(['apksigner', 'verify', '--verbose', target])
92110
except subprocess.CalledProcessError as err:
93111
print "Verifying apk failed"
94-
fileinfo = subprocess.check_output(['file', target])
95-
if fileinfo.find("ASCII text") != -1:
96-
print 'Error returned from autograph:'
97-
print subprocess.check_output(['cat', target])
98112
sys.exit(err.returncode)
99113
print "Archiving", target
100114
os.rename(target, artifacts_path + "/" + os.path.basename(target))

0 commit comments

Comments
 (0)