-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall-ci-tooling.py
More file actions
164 lines (159 loc) · 6 KB
/
install-ci-tooling.py
File metadata and controls
164 lines (159 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import argparse
import os
import platform
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
UV_VERSION = "0.10.12"
PNPM_VERSION = "10.33.0"
COPIER_VERSION = "==9.14.0"
COPIER_TEMPLATE_EXTENSIONS_VERSION = "==0.3.3"
PRE_COMMIT_VERSION = "4.5.1"
GITHUB_WINDOWS_RUNNER_BIN_PATH = r"C:\Users\runneradmin\.local\bin"
INSTALL_SSM_PLUGIN_BY_DEFAULT = False
parser = argparse.ArgumentParser(description="Install CI tooling for the repo")
_ = parser.add_argument(
"--no-python",
default=False,
action="store_true",
help="Do not process any environments using python package managers",
)
_ = parser.add_argument(
"--python-version",
default=f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
type=str,
help="What version to install.",
)
_ = parser.add_argument(
"--no-node", action="store_true", default=False, help="Do not process any environments using node package managers"
)
_ = parser.add_argument(
"--skip-installing-ssm-plugin",
action="store_true",
default=False,
help="Skip installing the SSM plugin for AWS CLI",
)
def main():
args = parser.parse_args(sys.argv[1:])
is_windows = platform.system() == "Windows"
uv_env = dict(os.environ)
uv_env.update({"UV_PYTHON": args.python_version, "UV_PYTHON_PREFERENCE": "only-system"})
uv_path = ((GITHUB_WINDOWS_RUNNER_BIN_PATH + "\\") if is_windows else "") + "uv"
if is_windows:
pwsh = shutil.which("pwsh") or shutil.which("powershell")
if not pwsh:
raise FileNotFoundError("Neither 'pwsh' nor 'powershell' found on PATH")
if not args.no_python:
if is_windows:
uv_env.update({"PATH": rf"{GITHUB_WINDOWS_RUNNER_BIN_PATH};{uv_env['PATH']}"})
# invoke installer in a pwsh process
_ = subprocess.run(
[
pwsh, # type: ignore[reportPossiblyUnboundVariable] # this matches the conditional above that defines pwsh
"-NoProfile",
"-NonInteractive",
"-Command",
f"irm https://astral.sh/uv/{UV_VERSION}/install.ps1 | iex",
],
check=True,
env=uv_env,
)
else:
_ = subprocess.run(
f"curl -fsSL --connect-timeout 20 --max-time 40 --retry 3 --retry-delay 5 --retry-connrefused --proto '=https' https://astral.sh/uv/{UV_VERSION}/install.sh | sh",
check=True,
shell=True,
env=uv_env,
)
# TODO: add uv autocompletion to the shell https://docs.astral.sh/uv/getting-started/installation/#shell-autocompletion
_ = subprocess.run(
[
uv_path,
"tool",
"install",
f"copier{COPIER_VERSION}",
"--with",
f"copier-template-extensions{COPIER_TEMPLATE_EXTENSIONS_VERSION}",
],
check=True,
env=uv_env,
)
_ = subprocess.run(
[
uv_path,
"tool",
"install",
f"pre-commit=={PRE_COMMIT_VERSION}",
],
check=True,
env=uv_env,
)
_ = subprocess.run(
[
uv_path,
"tool",
"list",
],
check=True,
env=uv_env,
)
if not args.no_node:
pnpm_install_sequence = ["npm -v", f"npm install -g pnpm@{PNPM_VERSION}", "pnpm -v"]
for cmd in pnpm_install_sequence:
cmd = (
[
pwsh, # type: ignore[reportPossiblyUnboundVariable] # this matches the conditional above that defines pwsh
"-NoProfile",
"-NonInteractive",
"-Command",
cmd,
]
if is_windows
else [cmd]
)
_ = subprocess.run(cmd, shell=True, check=True)
if INSTALL_SSM_PLUGIN_BY_DEFAULT and not args.skip_installing_ssm_plugin:
with tempfile.TemporaryDirectory() as tmp_dir:
if is_windows:
local_package_path = Path(tmp_dir) / "SessionManagerPluginSetup.exe"
# Based on https://docs.aws.amazon.com/systems-manager/latest/userguide/install-plugin-windows.html
# no specific reason for that version, just pinning it for best practice
_ = subprocess.run(
[
"curl",
"https://s3.amazonaws.com/session-manager-downloads/plugin/1.2.707.0/windows/SessionManagerPluginSetup.exe",
"-o",
f"{local_package_path}",
],
check=True,
)
_ = subprocess.run(
[str(local_package_path), "/quiet"],
check=True,
)
else:
local_package_path = Path(tmp_dir) / "session-manager-plugin.deb"
# Based on https://docs.aws.amazon.com/systems-manager/latest/userguide/install-plugin-debian-and-ubuntu.html
# no specific reason for that version, just pinning it for best practice
_ = subprocess.run(
[
"curl",
"https://s3.amazonaws.com/session-manager-downloads/plugin/1.2.707.0/ubuntu_64bit/session-manager-plugin.deb",
"-o",
f"{local_package_path}",
],
check=True,
)
_ = subprocess.run(
["sudo", "dpkg", "-i", str(local_package_path)],
check=True,
)
print("SSM Plugin Manager Version: ")
_ = subprocess.run(
["session-manager-plugin", "--version"],
check=True,
)
if __name__ == "__main__":
main()