forked from valkey-io/valkey-glide-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_matrices.py
More file actions
executable file
·64 lines (46 loc) · 1.95 KB
/
load_matrices.py
File metadata and controls
executable file
·64 lines (46 loc) · 1.95 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
#!/usr/bin/env python3
"""
Load and filter CI test matrices based on a profile (standard, full).
Outputs JSON arrays to $GITHUB_OUTPUT for use in GitHub Actions matrix strategies.
To add a new or update a run configuration, change json_matrices with the appropriate profiles.
"""
import json
import os
import sys
from pathlib import Path
def load_json(filename: str) -> list | dict:
return json.loads(Path(filename).read_text())
PROFILES = load_json("profiles.json")
def filter_by_profile(entries: list, profile: str) -> list:
return [e for e in entries if profile in e.get("profiles", [])]
def main() -> None:
if len(sys.argv) != 2 or sys.argv[1] not in PROFILES:
print(f"Usage: {sys.argv[0]} <{'|'.join(PROFILES)}>", file=sys.stderr)
sys.exit(1)
profile = sys.argv[1]
os_matrix = filter_by_profile(load_json("os-matrix.json"), profile)
host = [h for h in os_matrix if "image" not in h]
container_host = [h for h in os_matrix if "image" in h]
server = filter_by_profile(load_json("server-matrix.json"), profile)
assert server, "Given profile resulted in empty server matrix."
dotnet_entries = filter_by_profile(load_json("version-matrix.json"), profile)
dotnet = [e["version"] for e in dotnet_entries]
assert dotnet, "Given profile resulted in empty dotnet version matrix."
configs = {
"host-matrix": json.dumps(host),
"container-host-matrix": json.dumps(container_host),
"server-matrix": json.dumps(server),
"dotnet-matrix": json.dumps(dotnet),
}
# Write to GITHUB_OUTPUT
print(f"Loaded matrices for profile '{profile}':")
github_output = os.environ.get("GITHUB_OUTPUT")
if github_output:
with open(github_output, "a") as f:
for key, value in configs.items():
print(f"{key}={value}", file=f)
else:
for key, value in configs.items():
print(f"{key}={value}")
if __name__ == "__main__":
main()