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

Side by Side Diff: releaseAutomation.py

Issue 29508667: Issue 4354, 4355 - handle dirty/outdated repos on release (Closed)
Patch Set: Created Aug. 16, 2017, 10:22 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 23 matching lines...) Expand all
38 if os.path.basename(fileinfo.name) in ('.hgtags', '.hgig nore'): 40 if os.path.basename(fileinfo.name) in ('.hgtags', '.hgig nore'):
39 continue 41 continue
40 filedata = repoarchive.extractfile(fileinfo) 42 filedata = repoarchive.extractfile(fileinfo)
41 fileinfo.name = re.sub(r'^[^/]+/', prefix, fileinfo.name ) 43 fileinfo.name = re.sub(r'^[^/]+/', prefix, fileinfo.name )
42 archive.addfile(fileinfo, filedata) 44 archive.addfile(fileinfo, filedata)
43 finally: 45 finally:
44 process.stdout.close() 46 process.stdout.close()
45 process.wait() 47 process.wait()
46 48
47 49
50 def repo_has_uncommitted():
51 """Checks if the given repository is clean"""
52 buff = subprocess.check_output(['hg', 'status'])
53
54 if len(buff):
55 print('Dirty / uncommitted changes in repository!')
56 return True
57
58 return False
59
60
61 def repo_has_outgoing():
62 """Checks whether there would be outgoing changesets to the given path"""
63 try:
64 subprocess.check_output(['hg', 'outgoing'])
65 print('Detected outgoing changesets!')
66 return True
67 except subprocess.CalledProcessError as e:
68 if e.returncode == 1:
69 return False
70 raise
71
72
73 def repo_has_incoming(repo_paths):
74 """Checks whether the local repositories are up-to-date"""
75 incoming = False
76
77 for repo_path in repo_paths:
78 try:
79 subprocess.check_output(['hg', 'incoming', '-R', repo_path])
80 print('Detected incoming changesets in "{}"'.format(repo_path))
81 incoming = True
Wladimir Palant 2017/08/16 10:46:09 This seems inconsistent compared to repo_has_outgo
tlucas 2017/08/16 11:05:19 If i returned immediately on the first occurrence
Wladimir Palant 2017/08/16 11:11:46 I see, I overlooked that difference between the tw
tlucas 2017/08/16 11:27:54 You are right, re-added the correct parameters to
82 except subprocess.CalledProcessError as e:
83 if e.returncode != 1:
84 raise
85
86 return incoming
87
88
89 def continue_with_outgoing():
90 """Asks the user if he wants to continue despite facing warnings"""
Wladimir Palant 2017/08/16 10:46:09 Please formulate this in a gender-neutral way, "th
tlucas 2017/08/16 11:05:18 Alright - i didn't want to leave anyone out :)
tlucas 2017/08/16 11:27:54 Done.
91
92 print('If you proceed with the release, they will be included in the '
93 'release and pushed.')
94 print('Are you sure about continuing the release-process?')
Wladimir Palant 2017/08/16 10:46:08 Nit: it's "release process"
tlucas 2017/08/16 11:05:18 Acknowledged.
tlucas 2017/08/16 11:27:54 Done.
95
96 while True:
97 choice = raw_input('Please choose (yes / no): ').lower()
Wladimir Palant 2017/08/16 10:46:08 Maybe strip whitespace as well?
tlucas 2017/08/16 11:05:18 Acknowledged.
tlucas 2017/08/16 11:27:54 Done.
98
99 if choice == 'yes':
100 return True
101 if choice == 'no':
102 return False
103
104 print('Please answer "yes" or "no"!')
Sebastian Noack 2017/08/16 10:33:29 This message seems redundant. If we don't return a
tlucas 2017/08/16 10:40:29 Right, missed that. Done.
105
106
107 def can_safely_release():
108 """Run repository-checks in order to bail out early if necessary"""
109 if repo_has_uncommitted():
110 return False
111 if repo_has_incoming():
112 return False
113 if repo_has_outgoing():
114 return continue_with_outgoing()
115
116
48 def run(baseDir, type, version, keyFile, downloadsRepo): 117 def run(baseDir, type, version, keyFile, downloadsRepo):
118 if not can_safely_release():
119 print('Aborting release.')
120 return 1
121
49 if type == 'gecko': 122 if type == 'gecko':
50 import buildtools.packagerGecko as packager 123 import buildtools.packagerGecko as packager
51 elif type == 'safari': 124 elif type == 'safari':
52 import buildtools.packagerSafari as packager 125 import buildtools.packagerSafari as packager
53 elif type == 'edge': 126 elif type == 'edge':
54 import buildtools.packagerEdge as packager 127 import buildtools.packagerEdge as packager
55 elif type == 'chrome': 128 elif type == 'chrome':
56 import buildtools.packagerChrome as packager 129 import buildtools.packagerChrome as packager
57 130
58 # Replace version number in metadata file "manually", ConfigParser will mess 131 # Replace version number in metadata file "manually", ConfigParser will mess
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 create_sourcearchive(baseDir, archivePath) 189 create_sourcearchive(baseDir, archivePath)
117 downloads.append(archivePath) 190 downloads.append(archivePath)
118 191
119 # Now add the downloads and commit 192 # Now add the downloads and commit
120 subprocess.check_call(['hg', 'add', '-R', downloadsRepo] + downloads) 193 subprocess.check_call(['hg', 'add', '-R', downloadsRepo] + downloads)
121 subprocess.check_call(['hg', 'commit', '-R', downloadsRepo, '-m', 'Releasing %s %s' % (extensionName, version)]) 194 subprocess.check_call(['hg', 'commit', '-R', downloadsRepo, '-m', 'Releasing %s %s' % (extensionName, version)])
122 195
123 # Push all changes 196 # Push all changes
124 subprocess.check_call(['hg', 'push', '-R', baseDir]) 197 subprocess.check_call(['hg', 'push', '-R', baseDir])
125 subprocess.check_call(['hg', 'push', '-R', downloadsRepo]) 198 subprocess.check_call(['hg', 'push', '-R', downloadsRepo])
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld