11
11
import subprocess
12
12
import sys
13
13
14
+ v1_platforms = {
15
+ 'oculusvr3dofstore' ,
16
+ }
17
+
14
18
def main (name , argv ):
15
19
token = ''
20
+ v1_token = ''
16
21
sign_url = 'https://edge.stage.autograph.services.mozaws.net/sign'
17
22
release = False
18
- feature_name = ""
23
+ feature_name = ''
19
24
try :
20
- opts , args = getopt .getopt (argv ,"hrt:f:" )
25
+ opts , args = getopt .getopt (argv ,"hrt:c: f:" )
21
26
except getopt .GetoptError :
22
- print name + ' -t <token file name> -r -f <feature name>'
27
+ print name + ' -t <token file name> -c <v1 token file name> - r -f <feature name>'
23
28
sys .exit (2 )
24
29
for opt , arg in opts :
25
30
if opt == '-h' :
26
- print name + ' -t <token file name> -r -f <feature name>'
31
+ print name + ' -t <token file name> -c <v1 token file name> - r -f <feature name>'
27
32
sys .exit ()
33
+ elif opt in ("-c" ):
34
+ with open (arg , 'r' ) as tokenfile :
35
+ v1_token = tokenfile .read ().rstrip ()
28
36
elif opt in ("-t" ):
29
37
with open (arg , 'r' ) as tokenfile :
30
38
token = tokenfile .read ().rstrip ()
@@ -34,30 +42,56 @@ def main(name, argv):
34
42
elif opt in ('-f' ):
35
43
feature_name = arg .replace ('/' ,'-' ) + '-'
36
44
45
+ if not release and v1_token != '' :
46
+ print "Warning, v1 signing is only supported in production"
37
47
38
48
build_output_path = './app/build/outputs/apk'
49
+
39
50
# Create folder for saving build artifacts
40
51
artifacts_path = './builds'
41
52
if not os .path .exists (artifacts_path ):
42
53
os .makedirs (artifacts_path )
43
54
44
55
# Sign APKs
45
56
for apk in glob .glob (build_output_path + "/*/*/*-unsigned.apk" ):
57
+ print "=" * 80
58
+ cred = token
46
59
target = apk .replace ('-unsigned' , '-signed' )
60
+ align = False
61
+
47
62
if not release :
48
63
target = target .replace ('-release-' , '-staging-' + feature_name )
64
+ else :
65
+ for platform in v1_platforms :
66
+ if platform in target .lower ():
67
+ print "Using v1 signing on target:" , target
68
+ cred = v1_token
69
+ align = True
70
+
49
71
print "Signing" , apk
50
72
print "Target " , target
51
- print subprocess .check_output ([
52
- "curl" ,
53
- "-F" , "input=@" + apk ,
54
- "-o" , target ,
55
- "-H" , "Authorization: " + token ,
56
- sign_url ])
73
+ cmd = ["curl" , "-F" , "input=@" + apk , "-o" , target , "-H" , "Authorization: " + cred , sign_url ]
74
+
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 )
82
+
83
+ if align :
84
+ split = os .path .splitext (target )
85
+ orig = target ;
86
+ target = split [0 ] + "-aligned" + split [1 ]
87
+ print subprocess .check_output (["zipalign" , "-f" , "-v" , "-p" , "4" , orig , target ])
88
+
57
89
print "Verifying" , target
58
- print subprocess .check_output (['apksigner' , 'verify' , target ])
90
+ print subprocess .check_output (['apksigner' , 'verify' , '--verbose' , target ])
59
91
print "Archiving" , target
60
92
os .rename (target , artifacts_path + "/" + os .path .basename (target ))
93
+ print "=" * 80
94
+ print "Done Signing"
61
95
62
96
if __name__ == "__main__" :
63
97
main (sys .argv [0 ], sys .argv [1 :])
0 commit comments