Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: releaseAutomation.py

Issue 29611593: Issue 5996 - Release consistent versions across WebExtensions (Closed) Base URL: https://codereview.adblockplus.org/29609559/
Patch Set: Rebase against https://hg.adblockplus.org/buildtools/rev/f92050874f05 Created Nov. 20, 2017, 2:43 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packagerChrome.py ('k') | tox.ini » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: releaseAutomation.py
diff --git a/releaseAutomation.py b/releaseAutomation.py
index f9d6405c9605854322d35f8c0d69ffccc26ba584..3cd677e0163ee9b809f0a0d4bb57248eda2b7a40 100644
--- a/releaseAutomation.py
+++ b/releaseAutomation.py
@@ -7,11 +7,17 @@ from __future__ import print_function
import os
import re
import codecs
+import logging
import subprocess
+import sys
import tarfile
import json
-from packager import readMetadata, getDefaultFileName
+from packager import readMetadata, getDefaultFileName, get_extension
+from localeTools import read_locale_config
+
+WEBEXT_PLATFORMS = {'chrome', 'gecko'}
+WEBEXT_SOURCE_ARCHIVE = 'adblockpluswebext-{}-source.tgz'
def get_dependencies(prefix, repos):
@@ -113,68 +119,129 @@ def can_safely_release(*repo_paths):
return True
-def run(baseDir, type, version, keyFile, downloadsRepo):
- if not can_safely_release(baseDir, downloadsRepo):
- print('Aborting release.')
- return 1
+def previously_released(version, downloads_repo):
+ regex = re.compile(r'^' + WEBEXT_SOURCE_ARCHIVE.format('(.*)'),
+ re.MULTILINE)
+
+ existing = regex.findall(os.linesep.join(os.listdir(downloads_repo)))
+ return version in existing
Wladimir Palant 2017/11/20 15:33:17 I consider that quite a hack, why use regular expr
tlucas 2017/11/23 12:05:52 This is replaced completely, according to our disc
- if type == 'edge':
- import buildtools.packagerEdge as packager
- elif type == 'chrome':
- import buildtools.packagerChrome as packager
- # Replace version number in metadata file "manually", ConfigParser will mess
- # up the order of lines.
- metadata = readMetadata(baseDir, type)
- with open(metadata.option_source('general', 'version'), 'r+b') as file:
- rawMetadata = file.read()
+def update_metadata(metadata, version):
+ # Replace version number in metadata file "manually", ConfigParser will
+ # mess up the order of lines.
+ with open(metadata.option_source('general', 'version'), 'r+b') as fp:
+ rawMetadata = fp.read()
rawMetadata = re.sub(
r'^(\s*version\s*=\s*).*', r'\g<1>%s' % version,
rawMetadata, flags=re.I | re.M
)
- file.seek(0)
- file.write(rawMetadata)
- file.truncate()
+ fp.seek(0)
+ fp.write(rawMetadata)
+ fp.truncate()
+
+
+def create_build(platform, base_dir, target_path, version, key_file=None):
+ if platform in WEBEXT_PLATFORMS:
+ import buildtools.packagerChrome as packager
+ else:
+ import buildtools.packagerEdge as packager
+ metadata = readMetadata(base_dir, platform)
+ update_metadata(metadata, version)
+
+ build_path = os.path.join(
+ target_path,
+ getDefaultFileName(metadata, version,
+ get_extension(platform, key_file is not None))
Wladimir Palant 2017/11/20 15:33:16 I suggest calling these as packager.readMetadata()
tlucas 2017/11/23 12:05:51 I agree this would be cleaner, but unfortunately t
+ )
+
+ packager.createBuild(base_dir, type=platform, outFile=build_path,
+ releaseBuild=True, keyFile=key_file)
+
+ return build_path
+
- # Read extension name from locale data
- default_locale_path = os.path.join('_locales', packager.defaultLocale,
+def release_commit(base_dir, extension_name, version, platforms):
+ subprocess.check_call([
+ 'hg', 'commit', '-R', base_dir, '-m',
+ 'Releasing {} {} for {}'.format(extension_name, version,
Wladimir Palant 2017/11/20 15:33:16 Since you are touching this, how about prefixing t
tlucas 2017/11/23 12:05:51 Done.
+ ', '.join(platforms))])
Wladimir Palant 2017/11/20 15:33:16 If we want to have it extra nice, maybe map(str.ca
tlucas 2017/11/23 12:05:51 Done.
+
+
+def release_tag(base_dir, tag_name):
+ subprocess.check_call(['hg', 'tag', '-R', base_dir, '-f', tag_name])
Wladimir Palant 2017/11/20 15:33:17 Since you are touching this, how about passing '-m
tlucas 2017/11/23 12:05:52 Done.
+
+
+def run(baseDir, platforms, version, keyFile, downloads_repo):
+ if not can_safely_release(baseDir, downloads_repo):
+ print('Aborting release.')
+ return 1
+
+ if (WEBEXT_PLATFORMS.intersection(platforms) and
+ previously_released(version, downloads_repo)):
+ logging.error(('A release of version {} for WebExtension platforms '
+ 'was already done. Aborting.').format(version))
Wladimir Palant 2017/11/20 15:33:17 I wonder why we are singling out webext here. Shou
tlucas 2017/11/23 12:05:51 As discussed in IRC, this is now handled different
+ return 2
+
+ downloads = []
+ # Read extension name from first provided platform
+ locale_config = read_locale_config(baseDir, platforms[0],
+ readMetadata(baseDir, platforms[0]))
+ default_locale_path = os.path.join(locale_config['base_path'],
+ locale_config['default_locale'],
'messages.json')
with open(default_locale_path, 'r') as fp:
- extensionName = json.load(fp)['name']['message']
+ extension_name = json.load(fp)['name']['message']
+
+ webext_builds = WEBEXT_PLATFORMS.intersection(platforms)
+
+ for platform in webext_builds:
+ used_key_file = None
+ if platform == 'chrome':
+ # Currently, only chrome builds are provided by us as signed
+ # packages. Create an unsigned package in base_dir which should be
+ # uploaded to the Chrome Web Store
+ create_build(platform, baseDir, baseDir, version)
+ used_key_file = keyFile
+
+ downloads.append(
+ create_build(platform, baseDir, downloads_repo, version,
+ used_key_file)
+ )
- # Now commit the change and tag it
- subprocess.check_call(['hg', 'commit', '-R', baseDir, '-m', 'Releasing %s %s' % (extensionName, version)])
- tag_name = version
- if type == 'edge':
- tag_name = '{}-{}'.format(tag_name, type)
- subprocess.check_call(['hg', 'tag', '-R', baseDir, '-f', tag_name])
+ if webext_builds:
+ # Only create one commit, one tag and one source archive for all
+ # WebExtension platforms
+ archive_path = os.path.join(downloads_repo,
+ WEBEXT_SOURCE_ARCHIVE.format(version))
+ create_sourcearchive(baseDir, archive_path)
+ downloads.append(archive_path)
+
+ release_commit(baseDir, extension_name, version, webext_builds)
+ release_tag(baseDir, version)
+
+ for platform in set(platforms).difference(WEBEXT_PLATFORMS):
+ # Create build for platforms not yet using WebExtension
+ downloads.append(
+ create_build(platform, baseDir, downloads_repo, version,
+ keyFile)
+ )
- # Create a release build
- downloads = []
- if type == 'chrome':
- # Create both signed and unsigned Chrome builds (the latter for Chrome Web Store).
- buildPath = os.path.join(downloadsRepo, getDefaultFileName(metadata, version, 'crx'))
- packager.createBuild(baseDir, type=type, outFile=buildPath, releaseBuild=True, keyFile=keyFile)
- downloads.append(buildPath)
-
- buildPathUnsigned = os.path.join(baseDir, getDefaultFileName(metadata, version, 'zip'))
- packager.createBuild(baseDir, type=type, outFile=buildPathUnsigned, releaseBuild=True, keyFile=None)
- elif type == 'edge':
- # We only offer the Edge extension for use through the Windows Store
- buildPath = os.path.join(downloadsRepo, getDefaultFileName(metadata, version, 'appx'))
- packager.createBuild(baseDir, type=type, outFile=buildPath, releaseBuild=True)
- downloads.append(buildPath)
-
- # Create source archive
- archivePath = os.path.splitext(buildPath)[0] + '-source.tgz'
- create_sourcearchive(baseDir, archivePath)
- downloads.append(archivePath)
+ archivePath = os.path.splitext(downloads[-1])[0] + '-source.tgz'
+ create_sourcearchive(baseDir, archivePath)
+ downloads.append(archivePath)
+
+ release_commit(baseDir, extension_name, version, {platform})
+ release_tag(baseDir, '{}-{}'.format(version, platform))
Wladimir Palant 2017/11/20 15:33:17 What if we release for Firefox, Chrome and Edge at
tlucas 2017/11/23 12:05:51 As discussed in IRC, this is now handled different
# Now add the downloads and commit
- subprocess.check_call(['hg', 'add', '-R', downloadsRepo] + downloads)
- subprocess.check_call(['hg', 'commit', '-R', downloadsRepo, '-m', 'Releasing %s %s' % (extensionName, version)])
+ subprocess.check_call(['hg', 'add', '-R', downloads_repo] + downloads)
+ subprocess.check_call([
+ 'hg', 'commit', '-R', downloads_repo, '-m',
+ 'Releasing {} {} for {}'.format(extension_name, version,
+ ', '.join(platforms))])
# Push all changes
subprocess.check_call(['hg', 'push', '-R', baseDir])
- subprocess.check_call(['hg', 'push', '-R', downloadsRepo])
+ subprocess.check_call(['hg', 'push', '-R', downloads_repo])
« no previous file with comments | « packagerChrome.py ('k') | tox.ini » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld