Skip to content

Commit 16d89a5

Browse files
authored
Merge pull request #335 from carlopi/revert_script_removal
Revert "Remove old python script"
2 parents e1fff39 + 672de50 commit 16d89a5

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# This script is used by CI to modify the deployment matrix for the extension distribution
2+
3+
import argparse
4+
import json
5+
import sys
6+
import logging
7+
8+
# Define command-line arguments
9+
parser = argparse.ArgumentParser(description="Filter a JSON file based on excluded duckdb_arch values and select an OS")
10+
parser.add_argument("--input", required=True, help="Input JSON file path")
11+
parser.add_argument("--exclude", required=True, help="Semicolon-separated list of excluded duckdb_arch values")
12+
parser.add_argument("--opt_in", required=False, default="", help="Semicolon-separated list of opt-in duckdb_arch values")
13+
parser.add_argument("--output", help="Output JSON file path")
14+
parser.add_argument("--pretty", action="store_true", help="Pretty print the output JSON")
15+
parser.add_argument("--reduced_ci_mode", required=True, help="Set to default/enabled/disabled, when enabled, filters out redundant archs for testing")
16+
parser.add_argument("--select_os", help="Select an OS to include in the output JSON")
17+
parser.add_argument("--deploy_matrix", action="store_true", help="Create a merged list used in deploy step")
18+
args = parser.parse_args()
19+
20+
21+
# Parse the input file path, excluded arch values, and output file path
22+
input_json_file_path = args.input
23+
excluded_arch_values = args.exclude.split(";")
24+
opt_in_arch_values = args.opt_in.split(";")
25+
output_json_file_path = args.output
26+
select_os = args.select_os
27+
reduced_ci_mode = args.reduced_ci_mode
28+
29+
# Parse reduced CI mode
30+
if reduced_ci_mode == "auto":
31+
# Note auto is off for now TODO: change?
32+
reduced_ci_mode = False
33+
elif reduced_ci_mode == "enabled":
34+
reduced_ci_mode = True
35+
elif reduced_ci_mode == "disabled":
36+
reduced_ci_mode = False
37+
elif reduced_ci_mode is None:
38+
raise Exception("Unknown reduced_ci_mode value: None - must be auto/enabled/disabled.")
39+
else:
40+
raise Exception("Unknown reduced_ci_mode value: " + reduced_ci_mode + " - must be auto/enabled/disabled.")
41+
42+
# Read the input JSON file
43+
with open(input_json_file_path, "r") as json_file:
44+
data = json.load(json_file)
45+
46+
def should_run(config, reduced_ci_mode, excluded_arch_values, opt_in_arch_values):
47+
arch = config["duckdb_arch"]
48+
if arch in excluded_arch_values:
49+
return False
50+
if reduced_ci_mode and not config["run_in_reduced_ci_mode"]:
51+
return False
52+
if config["opt_in"] and arch not in opt_in_arch_values:
53+
return False
54+
return True
55+
56+
# Function to filter entries based on duckdb_arch values
57+
def filter_entries(data, excluded_arch_values, opt_in_arch_values):
58+
for os, config in data.items():
59+
if "include" in config:
60+
config["include"] = [entry for entry in config["include"] if should_run(entry, reduced_ci_mode, excluded_arch_values, opt_in_arch_values)]
61+
if not config["include"]:
62+
del config["include"]
63+
64+
return data
65+
66+
def sort_include_entries(value):
67+
if isinstance(value, dict):
68+
if "include" in value and isinstance(value["include"], list):
69+
value["include"] = sorted(value["include"], key=lambda item: item.get("duckdb_arch", ""))
70+
for nested in value.values():
71+
sort_include_entries(nested)
72+
elif isinstance(value, list):
73+
for nested in value:
74+
sort_include_entries(nested)
75+
76+
# Filter the JSON data
77+
filtered_data = filter_entries(data, excluded_arch_values, opt_in_arch_values)
78+
79+
# Select an OS if specified
80+
if select_os:
81+
found = False
82+
for os in filtered_data.keys():
83+
if os == select_os:
84+
filtered_data = filtered_data[os]
85+
found = True
86+
break
87+
if found == False:
88+
logging.warning('A selection OS was provided but not found')
89+
filtered_data = []
90+
91+
# When deploy_matrix is specified, we only output a single merged include list with all the duckdb_archs
92+
elif args.deploy_matrix:
93+
deploy_archs = []
94+
95+
for os, config in filtered_data.items():
96+
if "include" in config:
97+
for item in config["include"]:
98+
deploy_archs.append({"duckdb_arch": item["duckdb_arch"]})
99+
100+
filtered_data = {"include": deploy_archs}
101+
102+
# Keep matrix includes deterministic for easier diffs and comparisons.
103+
sort_include_entries(filtered_data)
104+
105+
# Determine the JSON formatting
106+
indent = 2 if args.pretty else None
107+
108+
# If no output file is provided, print to stdout
109+
if output_json_file_path:
110+
with open(output_json_file_path, "w") as output_json_file:
111+
json.dump(filtered_data, output_json_file, indent=indent)
112+
else:
113+
json.dump(filtered_data, sys.stdout, indent=indent)

0 commit comments

Comments
 (0)