4242 print ('Version file not found.' )
4343 exit (1 )
4444
45+ # We need a version string to work with
46+ if len (sys .argv ) >= 2 and sys .argv [1 ]:
47+ tag_version = sys .argv [1 ]
48+ else :
49+ tag_version = input ('Github release version: ' )
50+ tag_version .strip ()
51+ match = re .search ('^(\d+\.\d+\.\d+)(?:(b|rc)(\d+))?$' , tag_version )
52+ if not match :
53+ print ('Error: Invalid version string.' )
54+ exit (1 )
55+ ext_version = match .group (1 );
56+ if match .group (2 ):
57+ revision = int (match .group (3 ))
58+ if match .group (2 ) == 'rc' :
59+ revision += 100 ;
60+ ext_version += '.' + str (revision )
61+
4562extension_id = '[email protected] ' 4663tmpdir = tempfile .TemporaryDirectory ()
4764raw_xpi_filename = 'uMatrix.firefox.xpi'
5269github_owner = 'gorhill'
5370github_repo = 'uMatrix'
5471
55- # We need a version string to work with
56- if len (sys .argv ) >= 2 and sys .argv [1 ]:
57- version = sys .argv [1 ]
58- else :
59- version = input ('Github release version: ' )
60- version .strip ()
61- if not re .search ('^\d+\.\d+\.\d+(b|rc)\d+$' , version ):
62- print ('Error: Invalid version string.' )
63- exit (1 )
64-
6572# Load/save auth secrets
6673# The build directory is excluded from git
6774ubo_secrets = dict ()
@@ -99,7 +106,7 @@ def input_secret(prompt, token):
99106
100107# https://developer.github.com/v3/repos/releases/#get-a-single-release
101108print ('Downloading release info from GitHub...' )
102- release_info_url = 'https://api.github.com/repos/{0}/{1}/releases/tags/{2}' .format (github_owner , github_repo , version )
109+ release_info_url = 'https://api.github.com/repos/{0}/{1}/releases/tags/{2}' .format (github_owner , github_repo , tag_version )
103110headers = { 'Authorization' : github_auth , }
104111response = requests .get (release_info_url , headers = headers )
105112if response .status_code != 200 :
@@ -154,7 +161,7 @@ def input_secret(prompt, token):
154161 data = zipin .read (item .filename )
155162 if item .filename == 'manifest.json' :
156163 manifest = json .loads (bytes .decode (data ))
157- manifest ['applications ' ]['gecko' ]['update_url' ] = 'https://raw.githubusercontent.com/{0}/{1}/master/dist/firefox/updates.json' .format (github_owner , github_repo )
164+ manifest ['browser_specific_settings ' ]['gecko' ]['update_url' ] = 'https://raw.githubusercontent.com/{0}/{1}/master/dist/firefox/updates.json' .format (github_owner , github_repo )
158165 data = json .dumps (manifest , indent = 2 , separators = (',' , ': ' ), sort_keys = True ).encode ()
159166 zipout .writestr (item , data )
160167
@@ -181,7 +188,7 @@ def input_secret(prompt, token):
181188 headers = { 'Authorization' : jwt_auth , }
182189 data = { 'channel' : 'unlisted' }
183190 files = { 'upload' : f , }
184- signing_url = 'https://addons.mozilla.org/api/v3/addons/{0}/versions/{1}/' .format (extension_id , version )
191+ signing_url = 'https://addons.mozilla.org/api/v3/addons/{0}/versions/{1}/' .format (extension_id , ext_version )
185192 print ('Submitting package to be signed...' )
186193 response = requests .put (signing_url , headers = headers , data = data , files = files )
187194 if response .status_code != 202 :
@@ -278,11 +285,11 @@ def input_secret(prompt, token):
278285 updates_json = json .load (f )
279286 f .close ()
280287 previous_version = updates_json ['addons' ][extension_id ]['updates' ][0 ]['version' ]
281- if LooseVersion (version ) > LooseVersion (previous_version ):
288+ if LooseVersion (ext_version ) > LooseVersion (previous_version ):
282289 with open (os .path .join (projdir , 'dist' , 'firefox' , 'updates.template.json' )) as f :
283290 template_json = Template (f .read ())
284291 f .close ()
285- updates_json = template_json .substitute (version = version )
292+ updates_json = template_json .substitute (ext_version = ext_version , tag_version = tag_version )
286293 with open (updates_json_filepath , 'w' ) as f :
287294 f .write (updates_json )
288295 f .close ()
@@ -296,7 +303,7 @@ def input_secret(prompt, token):
296303 r = subprocess .run (['git' , 'status' , '-s' , updates_json_filepath ], stdout = subprocess .PIPE )
297304 rout = bytes .decode (r .stdout ).strip ()
298305 if len (rout ) >= 2 and rout [0 ] == 'M' :
299- subprocess .run (['git' , 'commit' , '-m' , 'make Firefox dev build auto-update' , updates_json_filepath ])
300- subprocess .run (['git' , 'push' , 'origin' , 'master ' ])
306+ subprocess .run (['git' , 'commit' , '-m' , 'Make Firefox dev build auto-update' , updates_json_filepath ])
307+ subprocess .run (['git' , 'push' , 'origin' , 'HEAD ' ])
301308
302309print ('All done.' )
0 commit comments