| Index: releaseAutomation.py |
| diff --git a/releaseAutomation.py b/releaseAutomation.py |
| index 5578abf1d948fe185e046cdb70ccd4734fa876ed..0ac1345f75fd5c23a125659481767f67ea2b9848 100644 |
| --- a/releaseAutomation.py |
| +++ b/releaseAutomation.py |
| @@ -9,6 +9,8 @@ import subprocess |
| import tarfile |
| import json |
| +from itertools import groupby |
| + |
| from packager import readMetadata, getDefaultFileName |
| @@ -45,7 +47,100 @@ def create_sourcearchive(repo, output): |
| process.wait() |
| -def run(baseDir, type, version, keyFile, downloadsRepo): |
| +def repo_has_uncommitted(aborts_process=True): |
| + """Checks if the given repository is clean""" |
| + uncommitted = False |
| + status_mapping = { |
| + 'M': 'modified', |
| + 'A': 'added', |
| + 'R': 'removed', |
| + '!': 'missing', |
| + '?': 'untracked', |
| + } |
| + |
| + # Check for any uncommitted changes |
| + buff = subprocess.check_output(['hg', 'status']) |
| + if len(buff): |
| + uncommitted = True |
| + dirty_files = buff.strip().split(os.linesep) |
| + print('Dirty / uncommitted changes in repository!') |
| + grouped_dirty = groupby(dirty_files, key=lambda x: x.split(' ')[0]) |
| + for dirty_grp in grouped_dirty: |
| + print('{}:'.format(status_mapping[dirty_grp[0]])) |
| + for dirty in dirty_grp[1]: |
| + print(' {}'.format(dirty.split(' ')[1])) |
| + |
| + return uncommitted, aborts_process |
| + |
| + |
| +def repo_has_outgoing(path, aborts_process=False): |
| + """Checks whether there would be outgoing changesets to the given path""" |
| + try: |
| + buff = subprocess.check_output(['hg', 'outgoing', path]) |
| + print('Detected outgoing changesets:') |
| + print(buff) |
| + return True, aborts_process |
| + except subprocess.CalledProcessError: |
| + return False, aborts_process |
| + |
| + |
| +def repo_has_incoming(repo_paths, aborts_process=True): |
| + """Checks whether the local repositories are up-to-date""" |
| + incoming = False |
| + |
| + for repo_path in repo_paths: |
| + try: |
| + buff = subprocess.check_output(['hg', 'incoming', '-R', repo_path]) |
| + print('Detected incoming changesets:') |
| + print(buff) |
| + incoming = True |
| + except subprocess.CalledProcessError: |
| + pass |
| + |
| + return incoming, aborts_process |
| + |
| + |
| +def ask_to_continue(): |
| + """Asks the user if he wants to continue despite facing warnings""" |
| + try: |
| + input = raw_input |
| + except NameError: |
| + pass |
| + |
| + print('The above error/s has/have been detected within the repositories.') |
| + print('You might want to check whether this is ok or not.') |
| + print('Are you sure about continuing the release-process?') |
| + while True: |
| + choice = input('Please choose (yes / no): ') |
| + if choice.lower() not in ('yes', 'no'): |
| + print('Please answer "yes" or "no"!') |
| + else: |
| + break |
| + |
| + return choice.lower() == 'yes' |
| + |
| + |
| +def run(baseDir, type, version, keyFile, downloadsRepo, path='default'): |
| + # run repository-checks and bail out early, in case the user does not |
| + # explicitly want to continue OR if the check would cause the process to |
| + # abort anyway |
| + repo_checks = ( |
| + (repo_has_uncommitted, ()), |
| + (repo_has_outgoing, (path,)), |
| + (repo_has_incoming, ((baseDir, downloadsRepo),)), |
| + ) |
| + |
| + check_results = [func(*args) for func, args in repo_checks] |
| + |
| + if ( |
| + any(check and aborts for check, aborts in check_results) |
| + or ( |
| + any(check and not aborts for check, aborts in check_results) |
| + and not ask_to_continue() |
| + )): |
| + print('Aborting release.') |
| + return 1 |
| + |
| if type == 'gecko': |
| import buildtools.packagerGecko as packager |
| elif type == 'safari': |