Skip to content

Commit

Permalink
Remove LooseVersion dependency in Py script
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Nov 29, 2022
1 parent f9fb5bc commit 8f5fbcf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions dist/firefox/publish-signed-beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import time
import zipfile

from distutils.version import LooseVersion
from string import Template

# - Download target (raw) uBlock0.firefox.xpi from GitHub
Expand Down Expand Up @@ -153,6 +152,7 @@ def input_secret(prompt, token):
#
# Convert the package to a self-hosted one: add `update_url` to the manifest
#
min_browser_version = '68';

print('Converting raw xpi package into self-hosted xpi package...')
with zipfile.ZipFile(raw_xpi_filepath, 'r') as zipin:
Expand All @@ -161,6 +161,7 @@ def input_secret(prompt, token):
data = zipin.read(item.filename)
if item.filename == 'manifest.json':
manifest = json.loads(bytes.decode(data))
min_browser_version = manifest['browser_specific_settings']['gecko']['strict_min_version']
manifest['browser_specific_settings']['gecko']['update_url'] = 'https://raw.githubusercontent.com/{0}/{1}/master/dist/firefox/updates.json'.format(github_owner, github_repo)
data = json.dumps(manifest, indent=2, separators=(',', ': '), sort_keys=True).encode()
zipout.writestr(item, data)
Expand Down Expand Up @@ -295,17 +296,23 @@ def get_jwt_auth():
r = subprocess.run(['git', 'pull', 'origin', 'master'], stdout=subprocess.PIPE)
rout = bytes.decode(r.stdout).strip()

def int_from_version(version):
parts = version.split('.')
if len(parts) == 3:
parts.append('0')
return int(parts[0])*10e9 + int(parts[1])*10e6 + int(parts[2])*10e3 + int(parts[3])

print('Update GitHub to point to newly signed self-hosted xpi package...')
updates_json_filepath = os.path.join(projdir, 'dist', 'firefox', 'updates.json')
with open(updates_json_filepath) as f:
updates_json = json.load(f)
f.close()
previous_version = updates_json['addons'][extension_id]['updates'][0]['version']
if LooseVersion(ext_version) > LooseVersion(previous_version):
if int_from_version(ext_version) > int_from_version(previous_version):
with open(os.path.join(projdir, 'dist', 'firefox', 'updates.template.json')) as f:
template_json = Template(f.read())
f.close()
updates_json = template_json.substitute(ext_version=ext_version, tag_version=tag_version)
updates_json = template_json.substitute(ext_version=ext_version, tag_version=tag_version, min_browser_version=min_browser_version)
with open(updates_json_filepath, 'w') as f:
f.write(updates_json)
f.close()
Expand Down
2 changes: 1 addition & 1 deletion dist/firefox/updates.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"updates": [
{
"version": "$ext_version",
"browser_specific_settings": { "gecko": { "strict_min_version": "60" } },
"browser_specific_settings": { "gecko": { "strict_min_version": "$min_browser_version" } },
"update_link": "https://github.com/gorhill/uBlock/releases/download/$tag_version/uBlock0_$tag_version.firefox.signed.xpi"
}
]
Expand Down

0 comments on commit 8f5fbcf

Please sign in to comment.