-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathresynchronize-upstream-changes.py
More file actions
executable file
·115 lines (105 loc) · 4.68 KB
/
Copy pathresynchronize-upstream-changes.py
File metadata and controls
executable file
·115 lines (105 loc) · 4.68 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
#!/usr/bin/env python3
import argparse
import os
import subprocess
import sys
from pathlib import Path
path_to_synchronization_script = {
"applications/dashboard/upstream": "scripts/synchronize-dashboard-manifests.sh",
"applications/dashboard/overlays/istio": "scripts/synchronize-dashboard-manifests.sh",
"applications/dashboard/helm/Chart.yaml": "scripts/synchronize-dashboard-manifests.sh",
"applications/dashboard/helm/kustomize": "scripts/synchronize-dashboard-manifests.sh",
"applications/dashboard/helm/manifests": "scripts/synchronize-dashboard-manifests.sh",
"applications/hub/upstream": "scripts/synchronize-hub-manifests.sh",
"applications/katib/upstream": "scripts/synchronize-katib-manifests.sh",
"applications/kserve/kserve/upstream": "scripts/synchronize-kserve-kserve-manifests.sh",
"applications/kserve/kserve-ui/upstream": "scripts/synchronize-kserve-ui-manifests.sh",
"applications/notebooks-v1/upstream": "scripts/synchronize-notebooks-v1-manifests.sh",
"applications/notebooks-v1/helm/Chart.yaml": "scripts/synchronize-notebooks-v1-manifests.sh",
"applications/notebooks-v1/helm/kustomize": "scripts/synchronize-notebooks-v1-manifests.sh",
"applications/notebooks-v1/helm/manifests": "scripts/synchronize-notebooks-v1-manifests.sh",
"scripts/generate-notebooks-v1-helm-manifests.py": "scripts/synchronize-notebooks-v1-manifests.sh",
"applications/pipeline/upstream": "scripts/synchronize-pipelines-manifests.sh",
"applications/spark/spark-operator": "scripts/synchronize-spark-operator-manifests.sh",
"applications/trainer/upstream": "scripts/synchronize-trainer-manifests.sh",
"applications/workspaces/upstream": "scripts/synchronize-kubeflow-workspaces-manifests.sh",
"common/cert-manager": "scripts/synchronize-cert-manager-manifests.sh",
"common/dex": "scripts/synchronize-dex-manifests.sh",
"common/istio": "scripts/synchronize-istio-manifests.sh",
"common/knative": "scripts/synchronize-knative-manifests.sh",
"common/oauth2-proxy": "scripts/synchronize-oauth2-proxy-manifests.sh",
"scripts/generate-dashboard-helm-manifests.py": "scripts/synchronize-dashboard-manifests.sh",
# The shared generator belongs to every component that renders through it,
# so a change to it must resynchronize all of them.
"scripts/helm_manifest_generator.py": (
"scripts/synchronize-dashboard-manifests.sh",
"scripts/synchronize-notebooks-v1-manifests.sh",
),
}
# convert the strings above into actual path objects for easier handling later
path_to_synchronization_script = {
Path(key): tuple(
Path(script) for script in ((value,) if isinstance(value, str) else value)
)
for key, value in path_to_synchronization_script.items()
}
def find_upstream_scripts(changed_files: list[Path]) -> set[Path]:
upstream_scripts = set()
for changed in changed_files:
for upstream_path, scripts in path_to_synchronization_script.items():
if (
changed in scripts
or upstream_path in changed.parents
or changed == upstream_path
):
upstream_scripts.update(scripts)
return upstream_scripts
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Find synchronization scripts for changed upstream files."
)
parser.add_argument(
"files",
nargs="*",
type=Path,
metavar="FILE",
help="Changed file paths to check against tracked upstream directories.",
)
parser.add_argument(
"--dry-run",
action="store_true",
help="Print the scripts that would run without executing them.",
)
parser.add_argument(
"--all",
action="store_true",
help="Run all synchronization scripts regardless of changed files.",
)
args = parser.parse_args()
if args.all:
upstream_scripts = {
script
for scripts in path_to_synchronization_script.values()
for script in scripts
}
else:
upstream_scripts = find_upstream_scripts(args.files)
failed = False
for script in sorted(upstream_scripts):
print(f"Running {script}...")
if args.dry_run:
print(f"Skipping {script} due to '--dry-run'")
continue
process = subprocess.Popen(
[script],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env={**os.environ, "KUBEFLOW_SYNCHRONIZE_NO_COMMIT": "true"},
text=True,
)
output, _ = process.communicate()
if process.returncode != 0:
print(output, end="")
failed = True
if failed:
sys.exit(1)