-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargocd-diff
executable file
·77 lines (67 loc) · 2.14 KB
/
argocd-diff
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
#!/usr/bin/env python3
import argparse
import json
import os
import re
import subprocess
import time
import yaml
def main() -> None:
"""
Display application diff for GitHub.
"""
parser = argparse.ArgumentParser(description="Display application diff for GitHub.")
parser.add_argument("--revision", help="Diff on the revision")
args = parser.parse_args()
app_list = json.loads(
subprocess.run(
["argocd", "app", "list", "--output=json"], stdout=subprocess.PIPE, check=True
).stdout.decode("utf-8")
)
apps = {
app["metadata"]["name"]
for app in app_list
if app["spec"]["source"]["repoURL"] == f"[email protected]:{os.environ['GITHUB_REPOSITORY']}.git"
}
with open("data/argocd.yaml", encoding="utf-8") as no_sync_file:
apps_re = [
re.compile(pattern) for pattern in yaml.load(no_sync_file, Loader=yaml.SafeLoader)["apps_re"]
]
for app in apps:
accept = False
for app_re in apps_re:
if app_re.match(app):
accept = True
break
if not accept:
continue
start = time.perf_counter()
app_diff_proc = subprocess.run( # pylint: disable=subprocess-run-check
[
"argocd",
"app",
"diff",
"--exit-code=false",
app,
"--loglevel=warn",
f"--revision={args.revision}",
],
stdout=subprocess.PIPE,
encoding="utf-8",
)
end = time.perf_counter()
if app_diff_proc.returncode == 0:
app_diff = app_diff_proc.stdout
if app_diff:
print(f"::group::Diff on application {app}")
print(app_diff)
print("::endgroup::")
else:
print(f"No diff on application {app}")
else:
print(f"Error on application {app}")
print(app_diff_proc.stderr)
print(app_diff_proc.stdout)
print(f"Time to diff application {app}: {end - start:.2f}s")
if __name__ == "__main__":
main()