Mercurial > hg
annotate contrib/automation/hgautomation/windows.py @ 47512:769037a279ec
dirstate-entry: add a `state` property (and use it)
This replace the [0] access. Ultimately is we should probably get ride of this
in its current form. However this is a good transitional solution to move away
for tuple indexing for now.
Differential Revision: https://phab.mercurial-scm.org/D10954
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sun, 04 Jul 2021 03:29:20 +0200 |
parents | 89a2afe31e82 |
children | fc1ba19ec4a0 |
rev | line source |
---|---|
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 # windows.py - Automation specific to Windows |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 # |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2019 Gregory Szorc <gregory.szorc@gmail.com> |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 # |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 # no-check-code because Python 3 native. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
10 import datetime |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 import os |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
12 import paramiko |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 import pathlib |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 import re |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 import subprocess |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
16 import tempfile |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
17 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
18 from .pypi import upload as pypi_upload |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
19 from .winrm import run_powershell |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 # PowerShell commands to activate a Visual Studio 2008 environment. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 # This is essentially a port of vcvarsall.bat to PowerShell. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 ACTIVATE_VC9_AMD64 = r''' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 Write-Output "activating Visual Studio 2008 environment for AMD64" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 $root = "$env:LOCALAPPDATA\Programs\Common\Microsoft\Visual C++ for Python\9.0" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 $Env:VCINSTALLDIR = "${root}\VC\" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 $Env:WindowsSdkDir = "${root}\WinSDK\" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 $Env:PATH = "${root}\VC\Bin\amd64;${root}\WinSDK\Bin\x64;${root}\WinSDK\Bin;$Env:PATH" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 $Env:INCLUDE = "${root}\VC\Include;${root}\WinSDK\Include;$Env:PATH" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 $Env:LIB = "${root}\VC\Lib\amd64;${root}\WinSDK\Lib\x64;$Env:LIB" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 $Env:LIBPATH = "${root}\VC\Lib\amd64;${root}\WinSDK\Lib\x64;$Env:LIBPATH" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 '''.lstrip() |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 ACTIVATE_VC9_X86 = r''' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 Write-Output "activating Visual Studio 2008 environment for x86" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 $root = "$env:LOCALAPPDATA\Programs\Common\Microsoft\Visual C++ for Python\9.0" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 $Env:VCINSTALLDIR = "${root}\VC\" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 $Env:WindowsSdkDir = "${root}\WinSDK\" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 $Env:PATH = "${root}\VC\Bin;${root}\WinSDK\Bin;$Env:PATH" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 $Env:INCLUDE = "${root}\VC\Include;${root}\WinSDK\Include;$Env:INCLUDE" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 $Env:LIB = "${root}\VC\Lib;${root}\WinSDK\Lib;$Env:LIB" |
42601
862f6bddacce
automation: correct the path separator in LIBPATH on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
42282
diff
changeset
|
43 $Env:LIBPATH = "${root}\VC\lib;${root}\WinSDK\Lib;$Env:LIBPATH" |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 '''.lstrip() |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 HG_PURGE = r''' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 $Env:PATH = "C:\hgdev\venv-bootstrap\Scripts;$Env:PATH" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 Set-Location C:\hgdev\src |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 hg.exe --config extensions.purge= purge --all |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 if ($LASTEXITCODE -ne 0) { |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 throw "process exited non-0: $LASTEXITCODE" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 } |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 Write-Output "purged Mercurial repo" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 ''' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 HG_UPDATE_CLEAN = r''' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 $Env:PATH = "C:\hgdev\venv-bootstrap\Scripts;$Env:PATH" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 Set-Location C:\hgdev\src |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 hg.exe --config extensions.purge= purge --all |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 if ($LASTEXITCODE -ne 0) {{ |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 throw "process exited non-0: $LASTEXITCODE" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 }} |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 hg.exe update -C {revision} |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 if ($LASTEXITCODE -ne 0) {{ |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 throw "process exited non-0: $LASTEXITCODE" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 }} |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 hg.exe log -r . |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 Write-Output "updated Mercurial working directory to {revision}" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 '''.lstrip() |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
71 BUILD_INNO_PYTHON3 = r''' |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
72 $Env:RUSTUP_HOME = "C:\hgdev\rustup" |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
73 $Env:CARGO_HOME = "C:\hgdev\cargo" |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
74 Set-Location C:\hgdev\src |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
75 C:\hgdev\python37-x64\python.exe contrib\packaging\packaging.py inno --pyoxidizer-target {pyoxidizer_target} --version {version} |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
76 if ($LASTEXITCODE -ne 0) {{ |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
77 throw "process exited non-0: $LASTEXITCODE" |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
78 }} |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
79 ''' |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
80 |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
81 BUILD_INNO_PYTHON2 = r''' |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 Set-Location C:\hgdev\src |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 $python = "C:\hgdev\python27-{arch}\python.exe" |
44770
47609da15379
automation: add extra arguments when building Inno
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44769
diff
changeset
|
84 C:\hgdev\python37-x64\python.exe contrib\packaging\packaging.py inno --python $python {extra_args} |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 if ($LASTEXITCODE -ne 0) {{ |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 throw "process exited non-0: $LASTEXITCODE" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 }} |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 '''.lstrip() |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 BUILD_WHEEL = r''' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
91 Set-Location C:\hgdev\src |
44768
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
92 C:\hgdev\python{python_version}-{arch}\python.exe -m pip wheel --wheel-dir dist . |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
93 if ($LASTEXITCODE -ne 0) {{ |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
94 throw "process exited non-0: $LASTEXITCODE" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 }} |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
96 ''' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
97 |
44772
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
98 BUILD_WIX_PYTHON3 = r''' |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
99 $Env:RUSTUP_HOME = "C:\hgdev\rustup" |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
100 $Env:CARGO_HOME = "C:\hgdev\cargo" |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
101 Set-Location C:\hgdev\src |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
102 C:\hgdev\python37-x64\python.exe contrib\packaging\packaging.py wix --pyoxidizer-target {pyoxidizer_target} --version {version} |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
103 if ($LASTEXITCODE -ne 0) {{ |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
104 throw "process exited non-0: $LASTEXITCODE" |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
105 }} |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
106 ''' |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
107 |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
108 BUILD_WIX_PYTHON2 = r''' |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 Set-Location C:\hgdev\src |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 $python = "C:\hgdev\python27-{arch}\python.exe" |
43513
081a77df7bc6
packaging: consolidate CLI functionality into packaging.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
111 C:\hgdev\python37-x64\python.exe contrib\packaging\packaging.py wix --python $python {extra_args} |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
112 if ($LASTEXITCODE -ne 0) {{ |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 throw "process exited non-0: $LASTEXITCODE" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
114 }} |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 ''' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
117 RUN_TESTS = r''' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 C:\hgdev\MinGW\msys\1.0\bin\sh.exe --login -c "cd /c/hgdev/src/tests && /c/hgdev/{python_path}/python.exe run-tests.py {test_flags}" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 if ($LASTEXITCODE -ne 0) {{ |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 throw "process exited non-0: $LASTEXITCODE" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 }} |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
122 ''' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
123 |
44768
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
124 WHEEL_FILENAME_PYTHON27_X86 = 'mercurial-{version}-cp27-cp27m-win32.whl' |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
125 WHEEL_FILENAME_PYTHON27_X64 = 'mercurial-{version}-cp27-cp27m-win_amd64.whl' |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
126 WHEEL_FILENAME_PYTHON37_X86 = 'mercurial-{version}-cp37-cp37m-win32.whl' |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
127 WHEEL_FILENAME_PYTHON37_X64 = 'mercurial-{version}-cp37-cp37m-win_amd64.whl' |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
128 WHEEL_FILENAME_PYTHON38_X86 = 'mercurial-{version}-cp38-cp38-win32.whl' |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
129 WHEEL_FILENAME_PYTHON38_X64 = 'mercurial-{version}-cp38-cp38-win_amd64.whl' |
45753
d1ce0ffdd3ce
automation: upload Python 3.9 Windows wheels
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44772
diff
changeset
|
130 WHEEL_FILENAME_PYTHON39_X86 = 'mercurial-{version}-cp39-cp39-win32.whl' |
d1ce0ffdd3ce
automation: upload Python 3.9 Windows wheels
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44772
diff
changeset
|
131 WHEEL_FILENAME_PYTHON39_X64 = 'mercurial-{version}-cp39-cp39-win_amd64.whl' |
44768
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
132 |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
133 EXE_FILENAME_PYTHON2_X86 = 'Mercurial-{version}-x86-python2.exe' |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
134 EXE_FILENAME_PYTHON2_X64 = 'Mercurial-{version}-x64-python2.exe' |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
135 EXE_FILENAME_PYTHON3_X86 = 'Mercurial-{version}-x86.exe' |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
136 EXE_FILENAME_PYTHON3_X64 = 'Mercurial-{version}-x64.exe' |
44772
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
137 |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
138 MSI_FILENAME_PYTHON2_X86 = 'mercurial-{version}-x86-python2.msi' |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
139 MSI_FILENAME_PYTHON2_X64 = 'mercurial-{version}-x64-python2.msi' |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
140 MSI_FILENAME_PYTHON3_X86 = 'mercurial-{version}-x86.msi' |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
141 MSI_FILENAME_PYTHON3_X64 = 'mercurial-{version}-x64.msi' |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
142 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
143 MERCURIAL_SCM_BASE_URL = 'https://mercurial-scm.org/release/windows' |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
144 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
145 X86_USER_AGENT_PATTERN = '.*Windows.*' |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
146 X64_USER_AGENT_PATTERN = '.*Windows.*(WOW|x)64.*' |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
147 |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
148 EXE_PYTHON2_X86_DESCRIPTION = ( |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
149 'Mercurial {version} Inno Setup installer - x86 Windows (Python 2) ' |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
150 '- does not require admin rights' |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
151 ) |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
152 EXE_PYTHON2_X64_DESCRIPTION = ( |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
153 'Mercurial {version} Inno Setup installer - x64 Windows (Python 2) ' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
154 '- does not require admin rights' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
155 ) |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
156 # TODO remove Python version once Python 2 is dropped. |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
157 EXE_PYTHON3_X86_DESCRIPTION = ( |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
158 'Mercurial {version} Inno Setup installer - x86 Windows (Python 3) ' |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
159 '- does not require admin rights' |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
160 ) |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
161 EXE_PYTHON3_X64_DESCRIPTION = ( |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
162 'Mercurial {version} Inno Setup installer - x64 Windows (Python 3) ' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
163 '- does not require admin rights' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
164 ) |
44772
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
165 MSI_PYTHON2_X86_DESCRIPTION = ( |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
166 'Mercurial {version} MSI installer - x86 Windows (Python 2) ' |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
167 '- requires admin rights' |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
168 ) |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
169 MSI_PYTHON2_X64_DESCRIPTION = ( |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
170 'Mercurial {version} MSI installer - x64 Windows (Python 2) ' |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
171 '- requires admin rights' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
172 ) |
44772
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
173 MSI_PYTHON3_X86_DESCRIPTION = ( |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
174 'Mercurial {version} MSI installer - x86 Windows (Python 3) ' |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
175 '- requires admin rights' |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
176 ) |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
177 MSI_PYTHON3_X64_DESCRIPTION = ( |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
178 'Mercurial {version} MSI installer - x64 Windows (Python 3) ' |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
179 '- requires admin rights' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
180 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
181 |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
182 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
183 def get_vc_prefix(arch): |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
184 if arch == 'x86': |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
185 return ACTIVATE_VC9_X86 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
186 elif arch == 'x64': |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
187 return ACTIVATE_VC9_AMD64 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
188 else: |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
189 raise ValueError('illegal arch: %s; must be x86 or x64' % arch) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
190 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
191 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
192 def fix_authorized_keys_permissions(winrm_client, path): |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
193 commands = [ |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
194 '$ErrorActionPreference = "Stop"', |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
195 'Repair-AuthorizedKeyPermission -FilePath %s -Confirm:$false' % path, |
42064
0e9066db5e44
automation: use raw strings when there are backslashes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42024
diff
changeset
|
196 r'icacls %s /remove:g "NT Service\sshd"' % path, |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
197 ] |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
198 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
199 run_powershell(winrm_client, '\n'.join(commands)) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
200 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
201 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
202 def synchronize_hg(hg_repo: pathlib.Path, revision: str, ec2_instance): |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
203 """Synchronize local Mercurial repo to remote EC2 instance.""" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
204 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
205 winrm_client = ec2_instance.winrm_client |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
206 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
207 with tempfile.TemporaryDirectory() as temp_dir: |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
208 temp_dir = pathlib.Path(temp_dir) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
209 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
210 ssh_dir = temp_dir / '.ssh' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
211 ssh_dir.mkdir() |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
212 ssh_dir.chmod(0o0700) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
213 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
214 # Generate SSH key to use for communication. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
215 subprocess.run( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
216 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
217 'ssh-keygen', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
218 '-t', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
219 'rsa', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
220 '-b', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
221 '4096', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
222 '-N', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
223 '', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
224 '-f', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
225 str(ssh_dir / 'id_rsa'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
226 ], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
227 check=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
228 capture_output=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
229 ) |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
230 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
231 # Add it to ~/.ssh/authorized_keys on remote. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
232 # This assumes the file doesn't already exist. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
233 authorized_keys = r'c:\Users\Administrator\.ssh\authorized_keys' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
234 winrm_client.execute_cmd(r'mkdir c:\Users\Administrator\.ssh') |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
235 winrm_client.copy(str(ssh_dir / 'id_rsa.pub'), authorized_keys) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
236 fix_authorized_keys_permissions(winrm_client, authorized_keys) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
237 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
238 public_ip = ec2_instance.public_ip_address |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
239 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
240 ssh_config = temp_dir / '.ssh' / 'config' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
241 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
242 with open(ssh_config, 'w', encoding='utf-8') as fh: |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
243 fh.write('Host %s\n' % public_ip) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
244 fh.write(' User Administrator\n') |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
245 fh.write(' StrictHostKeyChecking no\n') |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
246 fh.write(' UserKnownHostsFile %s\n' % (ssh_dir / 'known_hosts')) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
247 fh.write(' IdentityFile %s\n' % (ssh_dir / 'id_rsa')) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
248 |
42281
4274b1369b75
automation: add check that hg source directory is a repo
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42064
diff
changeset
|
249 if not (hg_repo / '.hg').is_dir(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
250 raise Exception( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
251 '%s is not a Mercurial repository; ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
252 'synchronization not yet supported' % hg_repo |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
253 ) |
42281
4274b1369b75
automation: add check that hg source directory is a repo
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42064
diff
changeset
|
254 |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
255 env = dict(os.environ) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
256 env['HGPLAIN'] = '1' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
257 env['HGENCODING'] = 'utf-8' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
258 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
259 hg_bin = hg_repo / 'hg' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
260 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
261 res = subprocess.run( |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
262 ['python2.7', str(hg_bin), 'log', '-r', revision, '-T', '{node}'], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
263 cwd=str(hg_repo), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
264 env=env, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
265 check=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
266 capture_output=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
267 ) |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
268 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
269 full_revision = res.stdout.decode('ascii') |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
270 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
271 args = [ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
272 'python2.7', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
273 hg_bin, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
274 '--config', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
275 'ui.ssh=ssh -F %s' % ssh_config, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
276 '--config', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
277 'ui.remotecmd=c:/hgdev/venv-bootstrap/Scripts/hg.exe', |
42684
9e0f1c80cddb
automation: push changes affecting .hgtags
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42660
diff
changeset
|
278 # Also ensure .hgtags changes are present so auto version |
9e0f1c80cddb
automation: push changes affecting .hgtags
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42660
diff
changeset
|
279 # calculation works. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
280 'push', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
281 '-f', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
282 '-r', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
283 full_revision, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
284 '-r', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
285 'file(.hgtags)', |
42282
5c242c427897
automation: do a force push to synchronize
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42281
diff
changeset
|
286 'ssh://%s/c:/hgdev/src' % public_ip, |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
287 ] |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
288 |
42660
24cd5b0ba5b3
automation: allow exit code of 1 for `hg push`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42601
diff
changeset
|
289 res = subprocess.run(args, cwd=str(hg_repo), env=env) |
24cd5b0ba5b3
automation: allow exit code of 1 for `hg push`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42601
diff
changeset
|
290 |
24cd5b0ba5b3
automation: allow exit code of 1 for `hg push`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42601
diff
changeset
|
291 # Allow 1 (no-op) to not trigger error. |
24cd5b0ba5b3
automation: allow exit code of 1 for `hg push`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42601
diff
changeset
|
292 if res.returncode not in (0, 1): |
24cd5b0ba5b3
automation: allow exit code of 1 for `hg push`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42601
diff
changeset
|
293 res.check_returncode() |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
294 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
295 run_powershell( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
296 winrm_client, HG_UPDATE_CLEAN.format(revision=full_revision) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
297 ) |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
298 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
299 # TODO detect dirty local working directory and synchronize accordingly. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
300 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
301 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
302 def purge_hg(winrm_client): |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
303 """Purge the Mercurial source repository on an EC2 instance.""" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
304 run_powershell(winrm_client, HG_PURGE) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
305 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
306 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
307 def find_latest_dist(winrm_client, pattern): |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
308 """Find path to newest file in dist/ directory matching a pattern.""" |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
309 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
310 res = winrm_client.execute_ps( |
42064
0e9066db5e44
automation: use raw strings when there are backslashes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42024
diff
changeset
|
311 r'$v = Get-ChildItem -Path C:\hgdev\src\dist -Filter "%s" ' |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
312 '| Sort-Object LastWriteTime -Descending ' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
313 '| Select-Object -First 1\n' |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
314 '$v.name' % pattern |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
315 ) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
316 return res[0] |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
317 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
318 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
319 def copy_latest_dist(winrm_client, pattern, dest_path): |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
320 """Copy latest file matching pattern in dist/ directory. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
321 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
322 Given a WinRM client and a file pattern, find the latest file on the remote |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
323 matching that pattern and copy it to the ``dest_path`` directory on the |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
324 local machine. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
325 """ |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
326 latest = find_latest_dist(winrm_client, pattern) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
327 source = r'C:\hgdev\src\dist\%s' % latest |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
328 dest = dest_path / latest |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
329 print('copying %s to %s' % (source, dest)) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
330 winrm_client.fetch(source, str(dest)) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
331 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
332 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
333 def build_inno_installer( |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
334 winrm_client, |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
335 python_version: int, |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
336 arch: str, |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
337 dest_path: pathlib.Path, |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
338 version=None, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
339 ): |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
340 """Build the Inno Setup installer on a remote machine. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
341 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
342 Using a WinRM client, remote commands are executed to build |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
343 a Mercurial Inno Setup installer. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
344 """ |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
345 print( |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
346 'building Inno Setup installer for Python %d %s' |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
347 % (python_version, arch) |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
348 ) |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
349 |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
350 if python_version == 3: |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
351 # TODO fix this limitation in packaging code |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
352 if not version: |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
353 raise Exception( |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
354 "version string is required when building for Python 3" |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
355 ) |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
356 |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
357 if arch == "x86": |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
358 target_triple = "i686-pc-windows-msvc" |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
359 elif arch == "x64": |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
360 target_triple = "x86_64-pc-windows-msvc" |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
361 else: |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
362 raise Exception("unhandled arch: %s" % arch) |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
363 |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
364 ps = BUILD_INNO_PYTHON3.format( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45753
diff
changeset
|
365 pyoxidizer_target=target_triple, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45753
diff
changeset
|
366 version=version, |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
367 ) |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
368 else: |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
369 extra_args = [] |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
370 if version: |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
371 extra_args.extend(['--version', version]) |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
372 |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
373 ps = get_vc_prefix(arch) + BUILD_INNO_PYTHON2.format( |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
374 arch=arch, extra_args=' '.join(extra_args) |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
375 ) |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
376 |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
377 run_powershell(winrm_client, ps) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
378 copy_latest_dist(winrm_client, '*.exe', dest_path) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
379 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
380 |
44768
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
381 def build_wheel( |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
382 winrm_client, python_version: str, arch: str, dest_path: pathlib.Path |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
383 ): |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
384 """Build Python wheels on a remote machine. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
385 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
386 Using a WinRM client, remote commands are executed to build a Python wheel |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
387 for Mercurial. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
388 """ |
44768
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
389 print('Building Windows wheel for Python %s %s' % (python_version, arch)) |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
390 |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
391 ps = BUILD_WHEEL.format( |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
392 python_version=python_version.replace(".", ""), arch=arch |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
393 ) |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
394 |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
395 # Python 2.7 requires an activated environment. |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
396 if python_version == "2.7": |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
397 ps = get_vc_prefix(arch) + ps |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
398 |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
399 run_powershell(winrm_client, ps) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
400 copy_latest_dist(winrm_client, '*.whl', dest_path) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
401 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
402 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
403 def build_wix_installer( |
44772
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
404 winrm_client, |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
405 python_version: int, |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
406 arch: str, |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
407 dest_path: pathlib.Path, |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
408 version=None, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
409 ): |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
410 """Build the WiX installer on a remote machine. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
411 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
412 Using a WinRM client, remote commands are executed to build a WiX installer. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
413 """ |
44772
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
414 print('Building WiX installer for Python %d %s' % (python_version, arch)) |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
415 |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
416 if python_version == 3: |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
417 # TODO fix this limitation in packaging code |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
418 if not version: |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
419 raise Exception( |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
420 "version string is required when building for Python 3" |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
421 ) |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
422 |
44772
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
423 if arch == "x86": |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
424 target_triple = "i686-pc-windows-msvc" |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
425 elif arch == "x64": |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
426 target_triple = "x86_64-pc-windows-msvc" |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
427 else: |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
428 raise Exception("unhandled arch: %s" % arch) |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
429 |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
430 ps = BUILD_WIX_PYTHON3.format( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45753
diff
changeset
|
431 pyoxidizer_target=target_triple, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45753
diff
changeset
|
432 version=version, |
44772
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
433 ) |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
434 else: |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
435 extra_args = [] |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
436 if version: |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
437 extra_args.extend(['--version', version]) |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
438 |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
439 ps = get_vc_prefix(arch) + BUILD_WIX_PYTHON2.format( |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
440 arch=arch, extra_args=' '.join(extra_args) |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
441 ) |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
442 |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
443 run_powershell(winrm_client, ps) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
444 copy_latest_dist(winrm_client, '*.msi', dest_path) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
445 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
446 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
447 def run_tests(winrm_client, python_version, arch, test_flags=''): |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
448 """Run tests on a remote Windows machine. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
449 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
450 ``python_version`` is a ``X.Y`` string like ``2.7`` or ``3.7``. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
451 ``arch`` is ``x86`` or ``x64``. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
452 ``test_flags`` is a str representing extra arguments to pass to |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
453 ``run-tests.py``. |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
454 """ |
42064
0e9066db5e44
automation: use raw strings when there are backslashes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42024
diff
changeset
|
455 if not re.match(r'\d\.\d', python_version): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
456 raise ValueError( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
457 r'python_version must be \d.\d; got %s' % python_version |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
458 ) |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
459 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
460 if arch not in ('x86', 'x64'): |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
461 raise ValueError('arch must be x86 or x64; got %s' % arch) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
462 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
463 python_path = 'python%s-%s' % (python_version.replace('.', ''), arch) |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
464 |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45753
diff
changeset
|
465 ps = RUN_TESTS.format( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45753
diff
changeset
|
466 python_path=python_path, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45753
diff
changeset
|
467 test_flags=test_flags or '', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45753
diff
changeset
|
468 ) |
42024
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
469 |
b05a3e28cf24
automation: perform tasks on remote machines
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
470 run_powershell(winrm_client, ps) |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
471 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
472 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
473 def resolve_wheel_artifacts(dist_path: pathlib.Path, version: str): |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
474 return ( |
44768
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
475 dist_path / WHEEL_FILENAME_PYTHON27_X86.format(version=version), |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
476 dist_path / WHEEL_FILENAME_PYTHON27_X64.format(version=version), |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
477 dist_path / WHEEL_FILENAME_PYTHON37_X86.format(version=version), |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
478 dist_path / WHEEL_FILENAME_PYTHON37_X64.format(version=version), |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
479 dist_path / WHEEL_FILENAME_PYTHON38_X86.format(version=version), |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
480 dist_path / WHEEL_FILENAME_PYTHON38_X64.format(version=version), |
45753
d1ce0ffdd3ce
automation: upload Python 3.9 Windows wheels
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44772
diff
changeset
|
481 dist_path / WHEEL_FILENAME_PYTHON39_X86.format(version=version), |
d1ce0ffdd3ce
automation: upload Python 3.9 Windows wheels
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44772
diff
changeset
|
482 dist_path / WHEEL_FILENAME_PYTHON39_X64.format(version=version), |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
483 ) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
484 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
485 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
486 def resolve_all_artifacts(dist_path: pathlib.Path, version: str): |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
487 return ( |
44768
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
488 dist_path / WHEEL_FILENAME_PYTHON27_X86.format(version=version), |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
489 dist_path / WHEEL_FILENAME_PYTHON27_X64.format(version=version), |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
490 dist_path / WHEEL_FILENAME_PYTHON37_X86.format(version=version), |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
491 dist_path / WHEEL_FILENAME_PYTHON37_X64.format(version=version), |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
492 dist_path / WHEEL_FILENAME_PYTHON38_X86.format(version=version), |
9d441f820c8b
automation: support building Windows wheels for Python 3.7 and 3.8
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43513
diff
changeset
|
493 dist_path / WHEEL_FILENAME_PYTHON38_X64.format(version=version), |
45753
d1ce0ffdd3ce
automation: upload Python 3.9 Windows wheels
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44772
diff
changeset
|
494 dist_path / WHEEL_FILENAME_PYTHON39_X86.format(version=version), |
d1ce0ffdd3ce
automation: upload Python 3.9 Windows wheels
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44772
diff
changeset
|
495 dist_path / WHEEL_FILENAME_PYTHON39_X64.format(version=version), |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
496 dist_path / EXE_FILENAME_PYTHON2_X86.format(version=version), |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
497 dist_path / EXE_FILENAME_PYTHON2_X64.format(version=version), |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
498 dist_path / EXE_FILENAME_PYTHON3_X86.format(version=version), |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
499 dist_path / EXE_FILENAME_PYTHON3_X64.format(version=version), |
44772
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
500 dist_path / MSI_FILENAME_PYTHON2_X86.format(version=version), |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
501 dist_path / MSI_FILENAME_PYTHON2_X64.format(version=version), |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
502 dist_path / MSI_FILENAME_PYTHON3_X86.format(version=version), |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
503 dist_path / MSI_FILENAME_PYTHON3_X64.format(version=version), |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
504 ) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
505 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
506 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
507 def generate_latest_dat(version: str): |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
508 python2_x86_exe_filename = EXE_FILENAME_PYTHON2_X86.format(version=version) |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
509 python2_x64_exe_filename = EXE_FILENAME_PYTHON2_X64.format(version=version) |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
510 python3_x86_exe_filename = EXE_FILENAME_PYTHON3_X86.format(version=version) |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
511 python3_x64_exe_filename = EXE_FILENAME_PYTHON3_X64.format(version=version) |
44772
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
512 python2_x86_msi_filename = MSI_FILENAME_PYTHON2_X86.format(version=version) |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
513 python2_x64_msi_filename = MSI_FILENAME_PYTHON2_X64.format(version=version) |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
514 python3_x86_msi_filename = MSI_FILENAME_PYTHON3_X86.format(version=version) |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
515 python3_x64_msi_filename = MSI_FILENAME_PYTHON3_X64.format(version=version) |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
516 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
517 entries = ( |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
518 ( |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
519 '10', |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
520 version, |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
521 X86_USER_AGENT_PATTERN, |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
522 '%s/%s' % (MERCURIAL_SCM_BASE_URL, python3_x86_exe_filename), |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
523 EXE_PYTHON3_X86_DESCRIPTION.format(version=version), |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
524 ), |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
525 ( |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
526 '10', |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
527 version, |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
528 X64_USER_AGENT_PATTERN, |
44771
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
529 '%s/%s' % (MERCURIAL_SCM_BASE_URL, python3_x64_exe_filename), |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
530 EXE_PYTHON3_X64_DESCRIPTION.format(version=version), |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
531 ), |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
532 ( |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
533 '9', |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
534 version, |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
535 X86_USER_AGENT_PATTERN, |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
536 '%s/%s' % (MERCURIAL_SCM_BASE_URL, python2_x86_exe_filename), |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
537 EXE_PYTHON2_X86_DESCRIPTION.format(version=version), |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
538 ), |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
539 ( |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
540 '9', |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
541 version, |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
542 X64_USER_AGENT_PATTERN, |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
543 '%s/%s' % (MERCURIAL_SCM_BASE_URL, python2_x64_exe_filename), |
802ee93c205d
automation: support building Python 3 Inno installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44770
diff
changeset
|
544 EXE_PYTHON2_X64_DESCRIPTION.format(version=version), |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
545 ), |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
546 ( |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
547 '10', |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
548 version, |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
549 X86_USER_AGENT_PATTERN, |
44772
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
550 '%s/%s' % (MERCURIAL_SCM_BASE_URL, python3_x86_msi_filename), |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
551 MSI_PYTHON3_X86_DESCRIPTION.format(version=version), |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
552 ), |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
553 ( |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
554 '10', |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
555 version, |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
556 X64_USER_AGENT_PATTERN, |
44772
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
557 '%s/%s' % (MERCURIAL_SCM_BASE_URL, python3_x64_msi_filename), |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
558 MSI_PYTHON3_X64_DESCRIPTION.format(version=version), |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
559 ), |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
560 ( |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
561 '9', |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
562 version, |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
563 X86_USER_AGENT_PATTERN, |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
564 '%s/%s' % (MERCURIAL_SCM_BASE_URL, python2_x86_msi_filename), |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
565 MSI_PYTHON2_X86_DESCRIPTION.format(version=version), |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
566 ), |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
567 ( |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
568 '9', |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
569 version, |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
570 X64_USER_AGENT_PATTERN, |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
571 '%s/%s' % (MERCURIAL_SCM_BASE_URL, python2_x64_msi_filename), |
5e788dc7fb5d
automation: support building Python 3 MSI installers
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44771
diff
changeset
|
572 MSI_PYTHON2_X64_DESCRIPTION.format(version=version), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
573 ), |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
574 ) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
575 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
576 lines = ['\t'.join(e) for e in entries] |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
577 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
578 return '\n'.join(lines) + '\n' |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
579 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
580 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
581 def publish_artifacts_pypi(dist_path: pathlib.Path, version: str): |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
582 """Publish Windows release artifacts to PyPI.""" |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
583 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
584 wheel_paths = resolve_wheel_artifacts(dist_path, version) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
585 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
586 for p in wheel_paths: |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
587 if not p.exists(): |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
588 raise Exception('%s not found' % p) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
589 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
590 print('uploading wheels to PyPI (you may be prompted for credentials)') |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
591 pypi_upload(wheel_paths) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
592 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
593 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
594 def publish_artifacts_mercurial_scm_org( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
595 dist_path: pathlib.Path, version: str, ssh_username=None |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
596 ): |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
597 """Publish Windows release artifacts to mercurial-scm.org.""" |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
598 all_paths = resolve_all_artifacts(dist_path, version) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
599 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
600 for p in all_paths: |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
601 if not p.exists(): |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
602 raise Exception('%s not found' % p) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
603 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
604 client = paramiko.SSHClient() |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
605 client.load_system_host_keys() |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
606 # We assume the system SSH configuration knows how to connect. |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
607 print('connecting to mercurial-scm.org via ssh...') |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
608 try: |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
609 client.connect('mercurial-scm.org', username=ssh_username) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
610 except paramiko.AuthenticationException: |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
611 print('error authenticating; is an SSH key available in an SSH agent?') |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
612 raise |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
613 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
614 print('SSH connection established') |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
615 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
616 print('opening SFTP client...') |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
617 sftp = client.open_sftp() |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
618 print('SFTP client obtained') |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
619 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
620 for p in all_paths: |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
621 dest_path = '/var/www/release/windows/%s' % p.name |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
622 print('uploading %s to %s' % (p, dest_path)) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
623 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
624 with p.open('rb') as fh: |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
625 data = fh.read() |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
626 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
627 with sftp.open(dest_path, 'wb') as fh: |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
628 fh.write(data) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
629 fh.chmod(0o0664) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
630 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
631 latest_dat_path = '/var/www/release/windows/latest.dat' |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
632 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
633 now = datetime.datetime.utcnow() |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
634 backup_path = dist_path / ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
635 'latest-windows-%s.dat' % now.strftime('%Y%m%dT%H%M%S') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
636 ) |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
637 print('backing up %s to %s' % (latest_dat_path, backup_path)) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
638 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
639 with sftp.open(latest_dat_path, 'rb') as fh: |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
640 latest_dat_old = fh.read() |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
641 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
642 with backup_path.open('wb') as fh: |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
643 fh.write(latest_dat_old) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
644 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
645 print('writing %s with content:' % latest_dat_path) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
646 latest_dat_content = generate_latest_dat(version) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
647 print(latest_dat_content) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
648 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
649 with sftp.open(latest_dat_path, 'wb') as fh: |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
650 fh.write(latest_dat_content.encode('ascii')) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
651 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
652 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
653 def publish_artifacts( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
654 dist_path: pathlib.Path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
655 version: str, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
656 pypi=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
657 mercurial_scm_org=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
658 ssh_username=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
659 ): |
42907
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
660 """Publish Windows release artifacts. |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
661 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
662 Files are found in `dist_path`. We will look for files with version string |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
663 `version`. |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
664 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
665 `pypi` controls whether we upload to PyPI. |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
666 `mercurial_scm_org` controls whether we upload to mercurial-scm.org. |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
667 """ |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
668 if pypi: |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
669 publish_artifacts_pypi(dist_path, version) |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
670 |
92593d72e10b
automation: implement "publish-windows-artifacts" command
Gregory Szorc <gregory.szorc@gmail.com>
parents:
42684
diff
changeset
|
671 if mercurial_scm_org: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
672 publish_artifacts_mercurial_scm_org( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
673 dist_path, version, ssh_username=ssh_username |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42907
diff
changeset
|
674 ) |