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

Delta Between Two Patch Sets: releaseAutomation.py

Issue 29508667: Issue 4354, 4355 - handle dirty/outdated repos on release (Closed)
Left Patch Set: Adjusting error message, removing complexity, increasing readability Created Aug. 15, 2017, 2:38 p.m.
Right Patch Set: Created Aug. 16, 2017, 11:24 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 from __future__ import print_function 5 from __future__ import print_function
Sebastian Noack 2017/08/15 15:54:45 I would add a blank line below __future__ imports.
tlucas 2017/08/16 08:38:15 Done.
6
5 import os 7 import os
6 import re 8 import re
7 import codecs 9 import codecs
8 import subprocess 10 import subprocess
9 import tarfile 11 import tarfile
10 import json 12 import json
11 13
12 from packager import readMetadata, getDefaultFileName 14 from packager import readMetadata, getDefaultFileName
13 15
14 16
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 57
56 return False 58 return False
57 59
58 60
59 def repo_has_outgoing(): 61 def repo_has_outgoing():
60 """Checks whether there would be outgoing changesets to the given path""" 62 """Checks whether there would be outgoing changesets to the given path"""
61 try: 63 try:
62 subprocess.check_output(['hg', 'outgoing']) 64 subprocess.check_output(['hg', 'outgoing'])
63 print('Detected outgoing changesets!') 65 print('Detected outgoing changesets!')
64 return True 66 return True
65 except subprocess.CalledProcessError: 67 except subprocess.CalledProcessError as e:
66 return False 68 if e.returncode == 1:
Sebastian Noack 2017/08/15 15:54:45 What is if an unexpected exit code occurs? I think
tlucas 2017/08/16 08:38:15 Done.
69 return False
70 raise
67 71
68 72
69 def repo_has_incoming(repo_paths): 73 def repo_has_incoming(*repo_paths):
70 """Checks whether the local repositories are up-to-date""" 74 """Checks whether the local repositories are up-to-date"""
71 incoming = False 75 incoming = False
72 76
73 for repo_path in repo_paths: 77 for repo_path in repo_paths:
74 try: 78 try:
75 subprocess.check_output(['hg', 'incoming', '-R', repo_path]) 79 subprocess.check_output(['hg', 'incoming', '-R', repo_path])
76 print('Detected incoming changesets in "{}"'.format(repo_path)) 80 print('Detected incoming changesets in "{}"'.format(repo_path))
77 incoming = True 81 incoming = True
78 except subprocess.CalledProcessError: 82 except subprocess.CalledProcessError as e:
79 pass 83 if e.returncode != 1:
84 raise
80 85
81 return incoming 86 return incoming
82 87
83 88
84 def continue_with_outgoing(): 89 def continue_with_outgoing():
85 """Asks the user if he wants to continue despite facing warnings""" 90 """Asks the user if they want to continue despite facing warnings"""
86 91
87 print('If you proceed with the release, they will be included in the ' 92 print('If you proceed with the release, they will be included in the '
88 'release and pushed.') 93 'release and pushed.')
89 print('Are you sure about continuing the release-process?') 94 print('Are you sure about continuing the release process?')
90 95
91 while True: 96 while True:
92 choice = raw_input('Please choose (yes / no): ').lower() 97 choice = raw_input('Please choose (yes / no): ').lower().strip()
93 98
94 if choice == 'yes': 99 if choice == 'yes':
95 return True 100 return True
96 if choice == 'no': 101 if choice == 'no':
97 return False 102 return False
98 103
99 print('Please answer "yes" or "no"!') 104
105 def can_safely_release(*repo_paths):
106 """Run repository-checks in order to bail out early if necessary"""
107 if repo_has_uncommitted():
108 return False
109 if repo_has_incoming(*repo_paths):
110 return False
111 if repo_has_outgoing():
112 return continue_with_outgoing()
100 113
101 114
102 def run(baseDir, type, version, keyFile, downloadsRepo): 115 def run(baseDir, type, version, keyFile, downloadsRepo):
103 # run repository-checks and bail out early, in case the user does not 116 if not can_safely_release(baseDir, downloadsRepo):
104 # explicitly want to continue OR if the check would cause the process to
105 # abort anyway
106 def can_safely_release():
Sebastian Noack 2017/08/15 15:54:45 Do you really need a function here? Wouldn't this
tlucas 2017/08/16 08:38:15 I don't, but the equivalent would be: can_safely_
Sebastian Noack 2017/08/16 08:48:35 I guess, it is OK to keep the function. But then t
tlucas 2017/08/16 08:53:23 Agreed, Done.
107 if repo_has_uncommitted():
108 return False
109 if repo_has_incoming():
110 return False
111 if repo_has_outgoing():
112 return continue_with_outgoing()
113
114 if not can_safely_release():
115 print('Aborting release.') 117 print('Aborting release.')
116 return 1 118 return 1
117 119
118 if type == 'gecko': 120 if type == 'gecko':
119 import buildtools.packagerGecko as packager 121 import buildtools.packagerGecko as packager
120 elif type == 'safari': 122 elif type == 'safari':
121 import buildtools.packagerSafari as packager 123 import buildtools.packagerSafari as packager
122 elif type == 'edge': 124 elif type == 'edge':
123 import buildtools.packagerEdge as packager 125 import buildtools.packagerEdge as packager
124 elif type == 'chrome': 126 elif type == 'chrome':
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 create_sourcearchive(baseDir, archivePath) 187 create_sourcearchive(baseDir, archivePath)
186 downloads.append(archivePath) 188 downloads.append(archivePath)
187 189
188 # Now add the downloads and commit 190 # Now add the downloads and commit
189 subprocess.check_call(['hg', 'add', '-R', downloadsRepo] + downloads) 191 subprocess.check_call(['hg', 'add', '-R', downloadsRepo] + downloads)
190 subprocess.check_call(['hg', 'commit', '-R', downloadsRepo, '-m', 'Releasing %s %s' % (extensionName, version)]) 192 subprocess.check_call(['hg', 'commit', '-R', downloadsRepo, '-m', 'Releasing %s %s' % (extensionName, version)])
191 193
192 # Push all changes 194 # Push all changes
193 subprocess.check_call(['hg', 'push', '-R', baseDir]) 195 subprocess.check_call(['hg', 'push', '-R', baseDir])
194 subprocess.check_call(['hg', 'push', '-R', downloadsRepo]) 196 subprocess.check_call(['hg', 'push', '-R', downloadsRepo])
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld