| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 # This Source Code Form is subject to the terms of the Mozilla Public | 1 # This Source Code Form is subject to the terms of the Mozilla Public |
| 2 # License, v. 2.0. If a copy of the MPL was not distributed with this | 2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. | 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | 4 |
| 5 from __future__ import print_function | 5 from __future__ import print_function |
| 6 | 6 |
| 7 import os | 7 import os |
| 8 import operator | 8 import operator |
| 9 import re | 9 import re |
| 10 import codecs | 10 import codecs |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 return continue_with_outgoing() | 118 return continue_with_outgoing() |
| 119 return True | 119 return True |
| 120 | 120 |
| 121 | 121 |
| 122 def compare_versions(a, b): | 122 def compare_versions(a, b): |
| 123 """Compare two version numbers.""" | 123 """Compare two version numbers.""" |
| 124 a_digits = [int(v) for v in a.split('.')] | 124 a_digits = [int(v) for v in a.split('.')] |
| 125 b_digits = [int(v) for v in b.split('.')] | 125 b_digits = [int(v) for v in b.split('.')] |
| 126 | 126 |
| 127 def safe_get(items, index): | 127 def safe_get(items, index): |
| 128 return int(items[index]) if index < len(items) else 0 | 128 return items[index] if index < len(items) else 0 |
|
Wladimir Palant
2017/11/28 14:04:41
You don't need to call int() here, you converted t
tlucas
2017/11/28 14:21:15
Done.
| |
| 129 | 129 |
| 130 for i in range(len(a_digits)): | 130 for i in range(max(len(a_digits), len(b_digits))): |
|
Wladimir Palant
2017/11/28 14:04:41
This needs to be max(len(a_digits), len(b_digits))
tlucas
2017/11/28 14:21:15
Done.
| |
| 131 result = safe_get(a_digits, i) - safe_get(b_digits, i) | 131 result = safe_get(a_digits, i) - safe_get(b_digits, i) |
| 132 if result != 0: | 132 if result != 0: |
| 133 return result | 133 return result |
| 134 return 0 | 134 return 0 |
| 135 | 135 |
| 136 | 136 |
| 137 def release_combination_is_possible(version, platforms, base_dir): | 137 def release_combination_is_possible(version, platforms, base_dir): |
| 138 """Determine whether a release for the given parameters is possible. | 138 """Determine whether a release for the given parameters is possible. |
| 139 | 139 |
| 140 Examine existing tags in order to find either higher or matching versions. | 140 Examine existing tags in order to find either higher or matching versions. |
| 141 The release is impossible if a) a higher version for a requested platform | 141 The release is impossible if a) a higher version for a requested platform |
| 142 exists, or if b) a matching version exists and the requested set of | 142 exists, or if b) a matching version exists and the requested set of |
| 143 platforms differs from what was already released. | 143 platforms differs from what was already released. |
| 144 """ | 144 """ |
| 145 def higher_tag_version(tag, version, platforms): | 145 def higher_tag_version(tag, version, platforms): |
| 146 return (compare_versions(tag[0], version) > 0 and | 146 return (compare_versions(tag[0], version) > 0 and |
| 147 set(tag[1:]).intersection(platforms)) | 147 set(tag[1:]).intersection(platforms)) |
| 148 | 148 |
| 149 def incomplete_platforms_for_version(tag, version, platforms): | 149 def incomplete_platforms_for_version(tag, version, platforms): |
| 150 intersection = set(tag[1:]).intersection(platforms) | 150 intersection = set(tag[1:]).intersection(platforms) |
| 151 return (compare_versions(tag[0], version) == 0 and | 151 return (compare_versions(tag[0], version) == 0 and |
| 152 intersection and set(platforms) != set(tag[1:])) | 152 intersection and set(platforms) != set(tag[1:])) |
| 153 | 153 |
| 154 # only consider tags of the form "1.2[.x ...]-platform[-platform ...] | 154 # only consider tags of the form "1.2[.x ...]-platform[-platform ...] |
| 155 platform_tags = re.compile(r'^(\d+(?:(?:\.\d+)+)(?:-\w+)+)$', re.MULTILINE) | 155 platform_tags = re.compile(r'^(\d+(?:(?:\.\d+)*)(?:-\w+)+)$', re.MULTILINE) |
|
Wladimir Palant
2017/11/28 14:04:41
Technically speaking, "1" is a valid version numbe
tlucas
2017/11/28 14:21:15
Good point, Done.
| |
| 156 tags = [ | 156 tags = [ |
| 157 c for c in [ | 157 c for c in [ |
| 158 t.split('-') for t in | 158 t.split('-') for t in |
| 159 platform_tags.findall(subprocess.check_output( | 159 platform_tags.findall(subprocess.check_output( |
| 160 ['hg', 'tags', '-R', base_dir, '-q'])) | 160 ['hg', 'tags', '-R', base_dir, '-q'])) |
| 161 ] if compare_versions(c[0], version) >= 0 | 161 ] if compare_versions(c[0], version) >= 0 |
| 162 ] | 162 ] |
| 163 | 163 |
| 164 for tag in tags: | 164 for tag in tags: |
| 165 if higher_tag_version(tag, version, platforms): | 165 if higher_tag_version(tag, version, platforms): |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 ) | 210 ) |
| 211 | 211 |
| 212 packager.createBuild(base_dir, type=platform, outFile=build_path, | 212 packager.createBuild(base_dir, type=platform, outFile=build_path, |
| 213 releaseBuild=True, keyFile=key_file) | 213 releaseBuild=True, keyFile=key_file) |
| 214 | 214 |
| 215 return build_path | 215 return build_path |
| 216 | 216 |
| 217 | 217 |
| 218 def release_commit(base_dir, extension_name, version, platforms): | 218 def release_commit(base_dir, extension_name, version, platforms): |
| 219 """Create a release commit with a representative message.""" | 219 """Create a release commit with a representative message.""" |
| 220 subprocess.check_call([ | 220 subprocess.check_output([ |
| 221 'hg', 'commit', '-R', base_dir, '-m', | 221 'hg', 'commit', '-R', base_dir, '-m', |
| 222 'Noissue - Releasing {} {} for {}'.format( | 222 'Noissue - Releasing {} {} for {}'.format( |
| 223 extension_name, version, | 223 extension_name, version, |
| 224 ', '.join([p.capitalize() for p in platforms]))]) | 224 ', '.join([p.capitalize() for p in platforms]))], |
| 225 stderr=subprocess.STDOUT) | |
| 225 | 226 |
| 226 | 227 |
| 227 def release_tag(base_dir, tag_name, extension_name): | 228 def release_tag(base_dir, tag_name, extension_name): |
| 228 """Create a tag, along with a commit message for that tag.""" | 229 """Create a tag, along with a commit message for that tag.""" |
| 229 subprocess.check_call([ | 230 subprocess.check_call([ |
| 230 'hg', 'tag', '-R', base_dir, '-f', tag_name, | 231 'hg', 'tag', '-R', base_dir, '-f', tag_name, |
| 231 '-m', 'Noissue - Adding release tag for {} {}'.format( | 232 '-m', 'Noissue - Adding release tag for {} {}'.format( |
| 232 extension_name, tag_name)]) | 233 extension_name, tag_name)]) |
| 233 | 234 |
| 234 | 235 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 ) | 274 ) |
| 274 | 275 |
| 275 # Only create one commit, one tag and one source archive for all | 276 # Only create one commit, one tag and one source archive for all |
| 276 # platforms | 277 # platforms |
| 277 archive_path = os.path.join( | 278 archive_path = os.path.join( |
| 278 downloads_repo, | 279 downloads_repo, |
| 279 'adblockplus-{}-source.tgz'.format(release_identifier), | 280 'adblockplus-{}-source.tgz'.format(release_identifier), |
| 280 ) | 281 ) |
| 281 create_sourcearchive(baseDir, archive_path) | 282 create_sourcearchive(baseDir, archive_path) |
| 282 downloads.append(archive_path) | 283 downloads.append(archive_path) |
| 283 if not re_release: | 284 try: |
|
Wladimir Palant
2017/11/28 14:04:41
This might not be a good measure. What if the rele
tlucas
2017/11/28 14:21:15
Done. Replaced it with a try-except block, re-rais
| |
| 284 release_commit(baseDir, extension_name, version, target_platforms) | 285 release_commit(baseDir, extension_name, version, target_platforms) |
| 286 except subprocess.CalledProcessError as e: | |
| 287 if not (re_release and 'nothing changed' in e.output): | |
| 288 raise | |
| 285 | 289 |
| 286 release_tag(baseDir, release_identifier, extension_name) | 290 release_tag(baseDir, release_identifier, extension_name) |
| 287 | 291 |
| 288 # Now add the downloads and commit | 292 # Now add the downloads and commit |
| 289 subprocess.check_call(['hg', 'add', '-R', downloads_repo] + downloads) | 293 subprocess.check_call(['hg', 'add', '-R', downloads_repo] + downloads) |
| 290 release_commit(downloads_repo, extension_name, version, target_platforms) | 294 release_commit(downloads_repo, extension_name, version, target_platforms) |
| 291 | 295 |
| 292 # Push all changes | 296 # Push all changes |
| 293 subprocess.check_call(['hg', 'push', '-R', baseDir]) | 297 subprocess.check_call(['hg', 'push', '-R', baseDir]) |
| 294 subprocess.check_call(['hg', 'push', '-R', downloads_repo]) | 298 subprocess.check_call(['hg', 'push', '-R', downloads_repo]) |
| LEFT | RIGHT |