Show More
@@ -1,460 +1,460 b'' | |||||
1 | # cli.py - Command line interface for automation |
|
1 | # cli.py - Command line interface for automation | |
2 | # |
|
2 | # | |
3 | # Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com> |
|
3 | # Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | # no-check-code because Python 3 native. |
|
8 | # no-check-code because Python 3 native. | |
9 |
|
9 | |||
10 | import argparse |
|
10 | import argparse | |
11 | import concurrent.futures as futures |
|
11 | import concurrent.futures as futures | |
12 | import os |
|
12 | import os | |
13 | import pathlib |
|
13 | import pathlib | |
14 | import time |
|
14 | import time | |
15 |
|
15 | |||
16 | from . import ( |
|
16 | from . import ( | |
17 | aws, |
|
17 | aws, | |
18 | HGAutomation, |
|
18 | HGAutomation, | |
19 | linux, |
|
19 | linux, | |
20 | windows, |
|
20 | windows, | |
21 | ) |
|
21 | ) | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | SOURCE_ROOT = pathlib.Path(os.path.abspath(__file__)).parent.parent.parent.parent |
|
24 | SOURCE_ROOT = pathlib.Path(os.path.abspath(__file__)).parent.parent.parent.parent | |
25 | DIST_PATH = SOURCE_ROOT / 'dist' |
|
25 | DIST_PATH = SOURCE_ROOT / 'dist' | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | def bootstrap_linux_dev(hga: HGAutomation, aws_region, distros=None, |
|
28 | def bootstrap_linux_dev(hga: HGAutomation, aws_region, distros=None, | |
29 | parallel=False): |
|
29 | parallel=False): | |
30 | c = hga.aws_connection(aws_region) |
|
30 | c = hga.aws_connection(aws_region) | |
31 |
|
31 | |||
32 | if distros: |
|
32 | if distros: | |
33 | distros = distros.split(',') |
|
33 | distros = distros.split(',') | |
34 | else: |
|
34 | else: | |
35 | distros = sorted(linux.DISTROS) |
|
35 | distros = sorted(linux.DISTROS) | |
36 |
|
36 | |||
37 | # TODO There is a wonky interaction involving KeyboardInterrupt whereby |
|
37 | # TODO There is a wonky interaction involving KeyboardInterrupt whereby | |
38 | # the context manager that is supposed to terminate the temporary EC2 |
|
38 | # the context manager that is supposed to terminate the temporary EC2 | |
39 | # instance doesn't run. Until we fix this, make parallel building opt-in |
|
39 | # instance doesn't run. Until we fix this, make parallel building opt-in | |
40 | # so we don't orphan instances. |
|
40 | # so we don't orphan instances. | |
41 | if parallel: |
|
41 | if parallel: | |
42 | fs = [] |
|
42 | fs = [] | |
43 |
|
43 | |||
44 | with futures.ThreadPoolExecutor(len(distros)) as e: |
|
44 | with futures.ThreadPoolExecutor(len(distros)) as e: | |
45 | for distro in distros: |
|
45 | for distro in distros: | |
46 | fs.append(e.submit(aws.ensure_linux_dev_ami, c, distro=distro)) |
|
46 | fs.append(e.submit(aws.ensure_linux_dev_ami, c, distro=distro)) | |
47 |
|
47 | |||
48 | for f in fs: |
|
48 | for f in fs: | |
49 | f.result() |
|
49 | f.result() | |
50 | else: |
|
50 | else: | |
51 | for distro in distros: |
|
51 | for distro in distros: | |
52 | aws.ensure_linux_dev_ami(c, distro=distro) |
|
52 | aws.ensure_linux_dev_ami(c, distro=distro) | |
53 |
|
53 | |||
54 |
|
54 | |||
55 | def bootstrap_windows_dev(hga: HGAutomation, aws_region, base_image_name): |
|
55 | def bootstrap_windows_dev(hga: HGAutomation, aws_region, base_image_name): | |
56 | c = hga.aws_connection(aws_region) |
|
56 | c = hga.aws_connection(aws_region) | |
57 | image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name) |
|
57 | image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name) | |
58 | print('Windows development AMI available as %s' % image.id) |
|
58 | print('Windows development AMI available as %s' % image.id) | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | def build_inno(hga: HGAutomation, aws_region, arch, revision, version, |
|
61 | def build_inno(hga: HGAutomation, aws_region, arch, revision, version, | |
62 | base_image_name): |
|
62 | base_image_name): | |
63 | c = hga.aws_connection(aws_region) |
|
63 | c = hga.aws_connection(aws_region) | |
64 | image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name) |
|
64 | image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name) | |
65 | DIST_PATH.mkdir(exist_ok=True) |
|
65 | DIST_PATH.mkdir(exist_ok=True) | |
66 |
|
66 | |||
67 | with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts: |
|
67 | with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts: | |
68 | instance = insts[0] |
|
68 | instance = insts[0] | |
69 |
|
69 | |||
70 | windows.synchronize_hg(SOURCE_ROOT, revision, instance) |
|
70 | windows.synchronize_hg(SOURCE_ROOT, revision, instance) | |
71 |
|
71 | |||
72 | for a in arch: |
|
72 | for a in arch: | |
73 | windows.build_inno_installer(instance.winrm_client, a, |
|
73 | windows.build_inno_installer(instance.winrm_client, a, | |
74 | DIST_PATH, |
|
74 | DIST_PATH, | |
75 | version=version) |
|
75 | version=version) | |
76 |
|
76 | |||
77 |
|
77 | |||
78 | def build_wix(hga: HGAutomation, aws_region, arch, revision, version, |
|
78 | def build_wix(hga: HGAutomation, aws_region, arch, revision, version, | |
79 | base_image_name): |
|
79 | base_image_name): | |
80 | c = hga.aws_connection(aws_region) |
|
80 | c = hga.aws_connection(aws_region) | |
81 | image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name) |
|
81 | image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name) | |
82 | DIST_PATH.mkdir(exist_ok=True) |
|
82 | DIST_PATH.mkdir(exist_ok=True) | |
83 |
|
83 | |||
84 | with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts: |
|
84 | with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts: | |
85 | instance = insts[0] |
|
85 | instance = insts[0] | |
86 |
|
86 | |||
87 | windows.synchronize_hg(SOURCE_ROOT, revision, instance) |
|
87 | windows.synchronize_hg(SOURCE_ROOT, revision, instance) | |
88 |
|
88 | |||
89 | for a in arch: |
|
89 | for a in arch: | |
90 | windows.build_wix_installer(instance.winrm_client, a, |
|
90 | windows.build_wix_installer(instance.winrm_client, a, | |
91 | DIST_PATH, version=version) |
|
91 | DIST_PATH, version=version) | |
92 |
|
92 | |||
93 |
|
93 | |||
94 | def build_windows_wheel(hga: HGAutomation, aws_region, arch, revision, |
|
94 | def build_windows_wheel(hga: HGAutomation, aws_region, arch, revision, | |
95 | base_image_name): |
|
95 | base_image_name): | |
96 | c = hga.aws_connection(aws_region) |
|
96 | c = hga.aws_connection(aws_region) | |
97 | image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name) |
|
97 | image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name) | |
98 | DIST_PATH.mkdir(exist_ok=True) |
|
98 | DIST_PATH.mkdir(exist_ok=True) | |
99 |
|
99 | |||
100 | with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts: |
|
100 | with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts: | |
101 | instance = insts[0] |
|
101 | instance = insts[0] | |
102 |
|
102 | |||
103 | windows.synchronize_hg(SOURCE_ROOT, revision, instance) |
|
103 | windows.synchronize_hg(SOURCE_ROOT, revision, instance) | |
104 |
|
104 | |||
105 | for a in arch: |
|
105 | for a in arch: | |
106 | windows.build_wheel(instance.winrm_client, a, DIST_PATH) |
|
106 | windows.build_wheel(instance.winrm_client, a, DIST_PATH) | |
107 |
|
107 | |||
108 |
|
108 | |||
109 | def build_all_windows_packages(hga: HGAutomation, aws_region, revision, |
|
109 | def build_all_windows_packages(hga: HGAutomation, aws_region, revision, | |
110 | version, base_image_name): |
|
110 | version, base_image_name): | |
111 | c = hga.aws_connection(aws_region) |
|
111 | c = hga.aws_connection(aws_region) | |
112 | image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name) |
|
112 | image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name) | |
113 | DIST_PATH.mkdir(exist_ok=True) |
|
113 | DIST_PATH.mkdir(exist_ok=True) | |
114 |
|
114 | |||
115 | with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts: |
|
115 | with aws.temporary_windows_dev_instances(c, image, 't3.medium') as insts: | |
116 | instance = insts[0] |
|
116 | instance = insts[0] | |
117 |
|
117 | |||
118 | winrm_client = instance.winrm_client |
|
118 | winrm_client = instance.winrm_client | |
119 |
|
119 | |||
120 | windows.synchronize_hg(SOURCE_ROOT, revision, instance) |
|
120 | windows.synchronize_hg(SOURCE_ROOT, revision, instance) | |
121 |
|
121 | |||
122 | for arch in ('x86', 'x64'): |
|
122 | for arch in ('x86', 'x64'): | |
123 | windows.purge_hg(winrm_client) |
|
123 | windows.purge_hg(winrm_client) | |
124 | windows.build_wheel(winrm_client, arch, DIST_PATH) |
|
124 | windows.build_wheel(winrm_client, arch, DIST_PATH) | |
125 | windows.purge_hg(winrm_client) |
|
125 | windows.purge_hg(winrm_client) | |
126 | windows.build_inno_installer(winrm_client, arch, DIST_PATH, |
|
126 | windows.build_inno_installer(winrm_client, arch, DIST_PATH, | |
127 | version=version) |
|
127 | version=version) | |
128 | windows.purge_hg(winrm_client) |
|
128 | windows.purge_hg(winrm_client) | |
129 | windows.build_wix_installer(winrm_client, arch, DIST_PATH, |
|
129 | windows.build_wix_installer(winrm_client, arch, DIST_PATH, | |
130 | version=version) |
|
130 | version=version) | |
131 |
|
131 | |||
132 |
|
132 | |||
133 | def terminate_ec2_instances(hga: HGAutomation, aws_region): |
|
133 | def terminate_ec2_instances(hga: HGAutomation, aws_region): | |
134 | c = hga.aws_connection(aws_region, ensure_ec2_state=False) |
|
134 | c = hga.aws_connection(aws_region, ensure_ec2_state=False) | |
135 | aws.terminate_ec2_instances(c.ec2resource) |
|
135 | aws.terminate_ec2_instances(c.ec2resource) | |
136 |
|
136 | |||
137 |
|
137 | |||
138 | def purge_ec2_resources(hga: HGAutomation, aws_region): |
|
138 | def purge_ec2_resources(hga: HGAutomation, aws_region): | |
139 | c = hga.aws_connection(aws_region, ensure_ec2_state=False) |
|
139 | c = hga.aws_connection(aws_region, ensure_ec2_state=False) | |
140 | aws.remove_resources(c) |
|
140 | aws.remove_resources(c) | |
141 |
|
141 | |||
142 |
|
142 | |||
143 | def run_tests_linux(hga: HGAutomation, aws_region, instance_type, |
|
143 | def run_tests_linux(hga: HGAutomation, aws_region, instance_type, | |
144 | python_version, test_flags, distro, filesystem): |
|
144 | python_version, test_flags, distro, filesystem): | |
145 | c = hga.aws_connection(aws_region) |
|
145 | c = hga.aws_connection(aws_region) | |
146 | image = aws.ensure_linux_dev_ami(c, distro=distro) |
|
146 | image = aws.ensure_linux_dev_ami(c, distro=distro) | |
147 |
|
147 | |||
148 | t_start = time.time() |
|
148 | t_start = time.time() | |
149 |
|
149 | |||
150 | ensure_extra_volume = filesystem not in ('default', 'tmpfs') |
|
150 | ensure_extra_volume = filesystem not in ('default', 'tmpfs') | |
151 |
|
151 | |||
152 | with aws.temporary_linux_dev_instances( |
|
152 | with aws.temporary_linux_dev_instances( | |
153 | c, image, instance_type, |
|
153 | c, image, instance_type, | |
154 | ensure_extra_volume=ensure_extra_volume) as insts: |
|
154 | ensure_extra_volume=ensure_extra_volume) as insts: | |
155 |
|
155 | |||
156 | instance = insts[0] |
|
156 | instance = insts[0] | |
157 |
|
157 | |||
158 | linux.prepare_exec_environment(instance.ssh_client, |
|
158 | linux.prepare_exec_environment(instance.ssh_client, | |
159 | filesystem=filesystem) |
|
159 | filesystem=filesystem) | |
160 | linux.synchronize_hg(SOURCE_ROOT, instance, '.') |
|
160 | linux.synchronize_hg(SOURCE_ROOT, instance, '.') | |
161 | t_prepared = time.time() |
|
161 | t_prepared = time.time() | |
162 | linux.run_tests(instance.ssh_client, python_version, |
|
162 | linux.run_tests(instance.ssh_client, python_version, | |
163 | test_flags) |
|
163 | test_flags) | |
164 | t_done = time.time() |
|
164 | t_done = time.time() | |
165 |
|
165 | |||
166 | t_setup = t_prepared - t_start |
|
166 | t_setup = t_prepared - t_start | |
167 | t_all = t_done - t_start |
|
167 | t_all = t_done - t_start | |
168 |
|
168 | |||
169 | print( |
|
169 | print( | |
170 | 'total time: %.1fs; setup: %.1fs; tests: %.1fs; setup overhead: %.1f%%' |
|
170 | 'total time: %.1fs; setup: %.1fs; tests: %.1fs; setup overhead: %.1f%%' | |
171 | % (t_all, t_setup, t_done - t_prepared, t_setup / t_all * 100.0)) |
|
171 | % (t_all, t_setup, t_done - t_prepared, t_setup / t_all * 100.0)) | |
172 |
|
172 | |||
173 |
|
173 | |||
174 | def run_tests_windows(hga: HGAutomation, aws_region, instance_type, |
|
174 | def run_tests_windows(hga: HGAutomation, aws_region, instance_type, | |
175 | python_version, arch, test_flags, base_image_name): |
|
175 | python_version, arch, test_flags, base_image_name): | |
176 | c = hga.aws_connection(aws_region) |
|
176 | c = hga.aws_connection(aws_region) | |
177 | image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name) |
|
177 | image = aws.ensure_windows_dev_ami(c, base_image_name=base_image_name) | |
178 |
|
178 | |||
179 | with aws.temporary_windows_dev_instances(c, image, instance_type, |
|
179 | with aws.temporary_windows_dev_instances(c, image, instance_type, | |
180 | disable_antivirus=True) as insts: |
|
180 | disable_antivirus=True) as insts: | |
181 | instance = insts[0] |
|
181 | instance = insts[0] | |
182 |
|
182 | |||
183 | windows.synchronize_hg(SOURCE_ROOT, '.', instance) |
|
183 | windows.synchronize_hg(SOURCE_ROOT, '.', instance) | |
184 | windows.run_tests(instance.winrm_client, python_version, arch, |
|
184 | windows.run_tests(instance.winrm_client, python_version, arch, | |
185 | test_flags) |
|
185 | test_flags) | |
186 |
|
186 | |||
187 |
|
187 | |||
188 | def publish_windows_artifacts(hg: HGAutomation, aws_region, version: str, |
|
188 | def publish_windows_artifacts(hg: HGAutomation, aws_region, version: str, | |
189 | pypi: bool, mercurial_scm_org: bool, |
|
189 | pypi: bool, mercurial_scm_org: bool, | |
190 | ssh_username: str): |
|
190 | ssh_username: str): | |
191 | windows.publish_artifacts(DIST_PATH, version, |
|
191 | windows.publish_artifacts(DIST_PATH, version, | |
192 | pypi=pypi, mercurial_scm_org=mercurial_scm_org, |
|
192 | pypi=pypi, mercurial_scm_org=mercurial_scm_org, | |
193 | ssh_username=ssh_username) |
|
193 | ssh_username=ssh_username) | |
194 |
|
194 | |||
195 |
|
195 | |||
196 | def get_parser(): |
|
196 | def get_parser(): | |
197 | parser = argparse.ArgumentParser() |
|
197 | parser = argparse.ArgumentParser() | |
198 |
|
198 | |||
199 | parser.add_argument( |
|
199 | parser.add_argument( | |
200 | '--state-path', |
|
200 | '--state-path', | |
201 | default='~/.hgautomation', |
|
201 | default='~/.hgautomation', | |
202 | help='Path for local state files', |
|
202 | help='Path for local state files', | |
203 | ) |
|
203 | ) | |
204 | parser.add_argument( |
|
204 | parser.add_argument( | |
205 | '--aws-region', |
|
205 | '--aws-region', | |
206 | help='AWS region to use', |
|
206 | help='AWS region to use', | |
207 |
default='us-west- |
|
207 | default='us-west-2', | |
208 | ) |
|
208 | ) | |
209 |
|
209 | |||
210 | subparsers = parser.add_subparsers() |
|
210 | subparsers = parser.add_subparsers() | |
211 |
|
211 | |||
212 | sp = subparsers.add_parser( |
|
212 | sp = subparsers.add_parser( | |
213 | 'bootstrap-linux-dev', |
|
213 | 'bootstrap-linux-dev', | |
214 | help='Bootstrap Linux development environments', |
|
214 | help='Bootstrap Linux development environments', | |
215 | ) |
|
215 | ) | |
216 | sp.add_argument( |
|
216 | sp.add_argument( | |
217 | '--distros', |
|
217 | '--distros', | |
218 | help='Comma delimited list of distros to bootstrap', |
|
218 | help='Comma delimited list of distros to bootstrap', | |
219 | ) |
|
219 | ) | |
220 | sp.add_argument( |
|
220 | sp.add_argument( | |
221 | '--parallel', |
|
221 | '--parallel', | |
222 | action='store_true', |
|
222 | action='store_true', | |
223 | help='Generate AMIs in parallel (not CTRL-c safe)' |
|
223 | help='Generate AMIs in parallel (not CTRL-c safe)' | |
224 | ) |
|
224 | ) | |
225 | sp.set_defaults(func=bootstrap_linux_dev) |
|
225 | sp.set_defaults(func=bootstrap_linux_dev) | |
226 |
|
226 | |||
227 | sp = subparsers.add_parser( |
|
227 | sp = subparsers.add_parser( | |
228 | 'bootstrap-windows-dev', |
|
228 | 'bootstrap-windows-dev', | |
229 | help='Bootstrap the Windows development environment', |
|
229 | help='Bootstrap the Windows development environment', | |
230 | ) |
|
230 | ) | |
231 | sp.add_argument( |
|
231 | sp.add_argument( | |
232 | '--base-image-name', |
|
232 | '--base-image-name', | |
233 | help='AMI name of base image', |
|
233 | help='AMI name of base image', | |
234 | default=aws.WINDOWS_BASE_IMAGE_NAME, |
|
234 | default=aws.WINDOWS_BASE_IMAGE_NAME, | |
235 | ) |
|
235 | ) | |
236 | sp.set_defaults(func=bootstrap_windows_dev) |
|
236 | sp.set_defaults(func=bootstrap_windows_dev) | |
237 |
|
237 | |||
238 | sp = subparsers.add_parser( |
|
238 | sp = subparsers.add_parser( | |
239 | 'build-all-windows-packages', |
|
239 | 'build-all-windows-packages', | |
240 | help='Build all Windows packages', |
|
240 | help='Build all Windows packages', | |
241 | ) |
|
241 | ) | |
242 | sp.add_argument( |
|
242 | sp.add_argument( | |
243 | '--revision', |
|
243 | '--revision', | |
244 | help='Mercurial revision to build', |
|
244 | help='Mercurial revision to build', | |
245 | default='.', |
|
245 | default='.', | |
246 | ) |
|
246 | ) | |
247 | sp.add_argument( |
|
247 | sp.add_argument( | |
248 | '--version', |
|
248 | '--version', | |
249 | help='Mercurial version string to use', |
|
249 | help='Mercurial version string to use', | |
250 | ) |
|
250 | ) | |
251 | sp.add_argument( |
|
251 | sp.add_argument( | |
252 | '--base-image-name', |
|
252 | '--base-image-name', | |
253 | help='AMI name of base image', |
|
253 | help='AMI name of base image', | |
254 | default=aws.WINDOWS_BASE_IMAGE_NAME, |
|
254 | default=aws.WINDOWS_BASE_IMAGE_NAME, | |
255 | ) |
|
255 | ) | |
256 | sp.set_defaults(func=build_all_windows_packages) |
|
256 | sp.set_defaults(func=build_all_windows_packages) | |
257 |
|
257 | |||
258 | sp = subparsers.add_parser( |
|
258 | sp = subparsers.add_parser( | |
259 | 'build-inno', |
|
259 | 'build-inno', | |
260 | help='Build Inno Setup installer(s)', |
|
260 | help='Build Inno Setup installer(s)', | |
261 | ) |
|
261 | ) | |
262 | sp.add_argument( |
|
262 | sp.add_argument( | |
263 | '--arch', |
|
263 | '--arch', | |
264 | help='Architecture to build for', |
|
264 | help='Architecture to build for', | |
265 | choices={'x86', 'x64'}, |
|
265 | choices={'x86', 'x64'}, | |
266 | nargs='*', |
|
266 | nargs='*', | |
267 | default=['x64'], |
|
267 | default=['x64'], | |
268 | ) |
|
268 | ) | |
269 | sp.add_argument( |
|
269 | sp.add_argument( | |
270 | '--revision', |
|
270 | '--revision', | |
271 | help='Mercurial revision to build', |
|
271 | help='Mercurial revision to build', | |
272 | default='.', |
|
272 | default='.', | |
273 | ) |
|
273 | ) | |
274 | sp.add_argument( |
|
274 | sp.add_argument( | |
275 | '--version', |
|
275 | '--version', | |
276 | help='Mercurial version string to use in installer', |
|
276 | help='Mercurial version string to use in installer', | |
277 | ) |
|
277 | ) | |
278 | sp.add_argument( |
|
278 | sp.add_argument( | |
279 | '--base-image-name', |
|
279 | '--base-image-name', | |
280 | help='AMI name of base image', |
|
280 | help='AMI name of base image', | |
281 | default=aws.WINDOWS_BASE_IMAGE_NAME, |
|
281 | default=aws.WINDOWS_BASE_IMAGE_NAME, | |
282 | ) |
|
282 | ) | |
283 | sp.set_defaults(func=build_inno) |
|
283 | sp.set_defaults(func=build_inno) | |
284 |
|
284 | |||
285 | sp = subparsers.add_parser( |
|
285 | sp = subparsers.add_parser( | |
286 | 'build-windows-wheel', |
|
286 | 'build-windows-wheel', | |
287 | help='Build Windows wheel(s)', |
|
287 | help='Build Windows wheel(s)', | |
288 | ) |
|
288 | ) | |
289 | sp.add_argument( |
|
289 | sp.add_argument( | |
290 | '--arch', |
|
290 | '--arch', | |
291 | help='Architecture to build for', |
|
291 | help='Architecture to build for', | |
292 | choices={'x86', 'x64'}, |
|
292 | choices={'x86', 'x64'}, | |
293 | nargs='*', |
|
293 | nargs='*', | |
294 | default=['x64'], |
|
294 | default=['x64'], | |
295 | ) |
|
295 | ) | |
296 | sp.add_argument( |
|
296 | sp.add_argument( | |
297 | '--revision', |
|
297 | '--revision', | |
298 | help='Mercurial revision to build', |
|
298 | help='Mercurial revision to build', | |
299 | default='.', |
|
299 | default='.', | |
300 | ) |
|
300 | ) | |
301 | sp.add_argument( |
|
301 | sp.add_argument( | |
302 | '--base-image-name', |
|
302 | '--base-image-name', | |
303 | help='AMI name of base image', |
|
303 | help='AMI name of base image', | |
304 | default=aws.WINDOWS_BASE_IMAGE_NAME, |
|
304 | default=aws.WINDOWS_BASE_IMAGE_NAME, | |
305 | ) |
|
305 | ) | |
306 | sp.set_defaults(func=build_windows_wheel) |
|
306 | sp.set_defaults(func=build_windows_wheel) | |
307 |
|
307 | |||
308 | sp = subparsers.add_parser( |
|
308 | sp = subparsers.add_parser( | |
309 | 'build-wix', |
|
309 | 'build-wix', | |
310 | help='Build WiX installer(s)' |
|
310 | help='Build WiX installer(s)' | |
311 | ) |
|
311 | ) | |
312 | sp.add_argument( |
|
312 | sp.add_argument( | |
313 | '--arch', |
|
313 | '--arch', | |
314 | help='Architecture to build for', |
|
314 | help='Architecture to build for', | |
315 | choices={'x86', 'x64'}, |
|
315 | choices={'x86', 'x64'}, | |
316 | nargs='*', |
|
316 | nargs='*', | |
317 | default=['x64'], |
|
317 | default=['x64'], | |
318 | ) |
|
318 | ) | |
319 | sp.add_argument( |
|
319 | sp.add_argument( | |
320 | '--revision', |
|
320 | '--revision', | |
321 | help='Mercurial revision to build', |
|
321 | help='Mercurial revision to build', | |
322 | default='.', |
|
322 | default='.', | |
323 | ) |
|
323 | ) | |
324 | sp.add_argument( |
|
324 | sp.add_argument( | |
325 | '--version', |
|
325 | '--version', | |
326 | help='Mercurial version string to use in installer', |
|
326 | help='Mercurial version string to use in installer', | |
327 | ) |
|
327 | ) | |
328 | sp.add_argument( |
|
328 | sp.add_argument( | |
329 | '--base-image-name', |
|
329 | '--base-image-name', | |
330 | help='AMI name of base image', |
|
330 | help='AMI name of base image', | |
331 | default=aws.WINDOWS_BASE_IMAGE_NAME, |
|
331 | default=aws.WINDOWS_BASE_IMAGE_NAME, | |
332 | ) |
|
332 | ) | |
333 | sp.set_defaults(func=build_wix) |
|
333 | sp.set_defaults(func=build_wix) | |
334 |
|
334 | |||
335 | sp = subparsers.add_parser( |
|
335 | sp = subparsers.add_parser( | |
336 | 'terminate-ec2-instances', |
|
336 | 'terminate-ec2-instances', | |
337 | help='Terminate all active EC2 instances managed by us', |
|
337 | help='Terminate all active EC2 instances managed by us', | |
338 | ) |
|
338 | ) | |
339 | sp.set_defaults(func=terminate_ec2_instances) |
|
339 | sp.set_defaults(func=terminate_ec2_instances) | |
340 |
|
340 | |||
341 | sp = subparsers.add_parser( |
|
341 | sp = subparsers.add_parser( | |
342 | 'purge-ec2-resources', |
|
342 | 'purge-ec2-resources', | |
343 | help='Purge all EC2 resources managed by us', |
|
343 | help='Purge all EC2 resources managed by us', | |
344 | ) |
|
344 | ) | |
345 | sp.set_defaults(func=purge_ec2_resources) |
|
345 | sp.set_defaults(func=purge_ec2_resources) | |
346 |
|
346 | |||
347 | sp = subparsers.add_parser( |
|
347 | sp = subparsers.add_parser( | |
348 | 'run-tests-linux', |
|
348 | 'run-tests-linux', | |
349 | help='Run tests on Linux', |
|
349 | help='Run tests on Linux', | |
350 | ) |
|
350 | ) | |
351 | sp.add_argument( |
|
351 | sp.add_argument( | |
352 | '--distro', |
|
352 | '--distro', | |
353 | help='Linux distribution to run tests on', |
|
353 | help='Linux distribution to run tests on', | |
354 | choices=linux.DISTROS, |
|
354 | choices=linux.DISTROS, | |
355 | default='debian10', |
|
355 | default='debian10', | |
356 | ) |
|
356 | ) | |
357 | sp.add_argument( |
|
357 | sp.add_argument( | |
358 | '--filesystem', |
|
358 | '--filesystem', | |
359 | help='Filesystem type to use', |
|
359 | help='Filesystem type to use', | |
360 | choices={'btrfs', 'default', 'ext3', 'ext4', 'jfs', 'tmpfs', 'xfs'}, |
|
360 | choices={'btrfs', 'default', 'ext3', 'ext4', 'jfs', 'tmpfs', 'xfs'}, | |
361 | default='default', |
|
361 | default='default', | |
362 | ) |
|
362 | ) | |
363 | sp.add_argument( |
|
363 | sp.add_argument( | |
364 | '--instance-type', |
|
364 | '--instance-type', | |
365 | help='EC2 instance type to use', |
|
365 | help='EC2 instance type to use', | |
366 | default='c5.9xlarge', |
|
366 | default='c5.9xlarge', | |
367 | ) |
|
367 | ) | |
368 | sp.add_argument( |
|
368 | sp.add_argument( | |
369 | '--python-version', |
|
369 | '--python-version', | |
370 | help='Python version to use', |
|
370 | help='Python version to use', | |
371 | choices={'system2', 'system3', '2.7', '3.5', '3.6', '3.7', '3.8', |
|
371 | choices={'system2', 'system3', '2.7', '3.5', '3.6', '3.7', '3.8', | |
372 | 'pypy', 'pypy3.5', 'pypy3.6'}, |
|
372 | 'pypy', 'pypy3.5', 'pypy3.6'}, | |
373 | default='system2', |
|
373 | default='system2', | |
374 | ) |
|
374 | ) | |
375 | sp.add_argument( |
|
375 | sp.add_argument( | |
376 | 'test_flags', |
|
376 | 'test_flags', | |
377 | help='Extra command line flags to pass to run-tests.py', |
|
377 | help='Extra command line flags to pass to run-tests.py', | |
378 | nargs='*', |
|
378 | nargs='*', | |
379 | ) |
|
379 | ) | |
380 | sp.set_defaults(func=run_tests_linux) |
|
380 | sp.set_defaults(func=run_tests_linux) | |
381 |
|
381 | |||
382 | sp = subparsers.add_parser( |
|
382 | sp = subparsers.add_parser( | |
383 | 'run-tests-windows', |
|
383 | 'run-tests-windows', | |
384 | help='Run tests on Windows', |
|
384 | help='Run tests on Windows', | |
385 | ) |
|
385 | ) | |
386 | sp.add_argument( |
|
386 | sp.add_argument( | |
387 | '--instance-type', |
|
387 | '--instance-type', | |
388 | help='EC2 instance type to use', |
|
388 | help='EC2 instance type to use', | |
389 | default='t3.medium', |
|
389 | default='t3.medium', | |
390 | ) |
|
390 | ) | |
391 | sp.add_argument( |
|
391 | sp.add_argument( | |
392 | '--python-version', |
|
392 | '--python-version', | |
393 | help='Python version to use', |
|
393 | help='Python version to use', | |
394 | choices={'2.7', '3.5', '3.6', '3.7', '3.8'}, |
|
394 | choices={'2.7', '3.5', '3.6', '3.7', '3.8'}, | |
395 | default='2.7', |
|
395 | default='2.7', | |
396 | ) |
|
396 | ) | |
397 | sp.add_argument( |
|
397 | sp.add_argument( | |
398 | '--arch', |
|
398 | '--arch', | |
399 | help='Architecture to test', |
|
399 | help='Architecture to test', | |
400 | choices={'x86', 'x64'}, |
|
400 | choices={'x86', 'x64'}, | |
401 | default='x64', |
|
401 | default='x64', | |
402 | ) |
|
402 | ) | |
403 | sp.add_argument( |
|
403 | sp.add_argument( | |
404 | '--test-flags', |
|
404 | '--test-flags', | |
405 | help='Extra command line flags to pass to run-tests.py', |
|
405 | help='Extra command line flags to pass to run-tests.py', | |
406 | ) |
|
406 | ) | |
407 | sp.add_argument( |
|
407 | sp.add_argument( | |
408 | '--base-image-name', |
|
408 | '--base-image-name', | |
409 | help='AMI name of base image', |
|
409 | help='AMI name of base image', | |
410 | default=aws.WINDOWS_BASE_IMAGE_NAME, |
|
410 | default=aws.WINDOWS_BASE_IMAGE_NAME, | |
411 | ) |
|
411 | ) | |
412 | sp.set_defaults(func=run_tests_windows) |
|
412 | sp.set_defaults(func=run_tests_windows) | |
413 |
|
413 | |||
414 | sp = subparsers.add_parser( |
|
414 | sp = subparsers.add_parser( | |
415 | 'publish-windows-artifacts', |
|
415 | 'publish-windows-artifacts', | |
416 | help='Publish built Windows artifacts (wheels, installers, etc)' |
|
416 | help='Publish built Windows artifacts (wheels, installers, etc)' | |
417 | ) |
|
417 | ) | |
418 | sp.add_argument( |
|
418 | sp.add_argument( | |
419 | '--no-pypi', |
|
419 | '--no-pypi', | |
420 | dest='pypi', |
|
420 | dest='pypi', | |
421 | action='store_false', |
|
421 | action='store_false', | |
422 | default=True, |
|
422 | default=True, | |
423 | help='Skip uploading to PyPI', |
|
423 | help='Skip uploading to PyPI', | |
424 | ) |
|
424 | ) | |
425 | sp.add_argument( |
|
425 | sp.add_argument( | |
426 | '--no-mercurial-scm-org', |
|
426 | '--no-mercurial-scm-org', | |
427 | dest='mercurial_scm_org', |
|
427 | dest='mercurial_scm_org', | |
428 | action='store_false', |
|
428 | action='store_false', | |
429 | default=True, |
|
429 | default=True, | |
430 | help='Skip uploading to www.mercurial-scm.org', |
|
430 | help='Skip uploading to www.mercurial-scm.org', | |
431 | ) |
|
431 | ) | |
432 | sp.add_argument( |
|
432 | sp.add_argument( | |
433 | '--ssh-username', |
|
433 | '--ssh-username', | |
434 | help='SSH username for mercurial-scm.org', |
|
434 | help='SSH username for mercurial-scm.org', | |
435 | ) |
|
435 | ) | |
436 | sp.add_argument( |
|
436 | sp.add_argument( | |
437 | 'version', |
|
437 | 'version', | |
438 | help='Mercurial version string to locate local packages', |
|
438 | help='Mercurial version string to locate local packages', | |
439 | ) |
|
439 | ) | |
440 | sp.set_defaults(func=publish_windows_artifacts) |
|
440 | sp.set_defaults(func=publish_windows_artifacts) | |
441 |
|
441 | |||
442 | return parser |
|
442 | return parser | |
443 |
|
443 | |||
444 |
|
444 | |||
445 | def main(): |
|
445 | def main(): | |
446 | parser = get_parser() |
|
446 | parser = get_parser() | |
447 | args = parser.parse_args() |
|
447 | args = parser.parse_args() | |
448 |
|
448 | |||
449 | local_state_path = pathlib.Path(os.path.expanduser(args.state_path)) |
|
449 | local_state_path = pathlib.Path(os.path.expanduser(args.state_path)) | |
450 | automation = HGAutomation(local_state_path) |
|
450 | automation = HGAutomation(local_state_path) | |
451 |
|
451 | |||
452 | if not hasattr(args, 'func'): |
|
452 | if not hasattr(args, 'func'): | |
453 | parser.print_help() |
|
453 | parser.print_help() | |
454 | return |
|
454 | return | |
455 |
|
455 | |||
456 | kwargs = dict(vars(args)) |
|
456 | kwargs = dict(vars(args)) | |
457 | del kwargs['func'] |
|
457 | del kwargs['func'] | |
458 | del kwargs['state_path'] |
|
458 | del kwargs['state_path'] | |
459 |
|
459 | |||
460 | args.func(automation, **kwargs) |
|
460 | args.func(automation, **kwargs) |
General Comments 0
You need to be logged in to leave comments.
Login now