Skip to content

Commit d6e913e

Browse files
greenc-FNALgoogle-labs-jules[bot]github-actions[bot]
authored
Implement Trigger-Specific Build Matrix Defaults (#143)
* feat: implement trigger-specific build matrix defaults The `generate-build-matrix` action now uses intelligent, trigger-specific defaults for build configurations. - Workflows triggered by `push`, `pull_request`, and `pull_request_target` now default to a minimal `gcc/none` configuration. - Workflows triggered by an `issue_comment` default to `gcc/none` and `clang/none`. - Manual `workflow_dispatch` triggers default to running all available build combinations. The user input handling has also been improved to follow a clear precedence: 1. An explicit list of builds (e.g., `gcc/asan`) overrides all defaults. 2. A modified list (e.g., `+gcc/tsan`, `all -clang/none`) alters the trigger-specific default set. 3. No input uses the trigger-specific default directly. * Committing Python linting fixes * fix: address ruff and mypy issues This commit addresses the Python linting and type-checking issues reported by `ruff` and `mypy`. - Added module and function docstrings. - Corrected import order. - Removed an unnecessary `list()` call. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 3887bbb commit d6e913e

10 files changed

Lines changed: 216 additions & 166 deletions

File tree

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,85 @@
1+
"""Generates a build matrix for CI based on the trigger event and user input."""
12
import json
23
import os
34
import re
45

6+
7+
def get_default_combinations(event_name, all_combinations):
8+
"""Gets the default build combinations based on the GitHub event type."""
9+
if event_name in ("push", "pull_request", "pull_request_target"):
10+
return ["gcc/none"]
11+
elif event_name == "issue_comment":
12+
return ["gcc/none", "clang/none"]
13+
elif event_name == "workflow_dispatch":
14+
return all_combinations
15+
else:
16+
# Default to a minimal safe configuration for unknown events
17+
return ["gcc/none"]
18+
19+
520
def main():
21+
"""Generates and outputs the build matrix based on environment variables."""
622
all_combinations = [
7-
"gcc/none", "gcc/asan", "gcc/tsan", "gcc/valgrind",
8-
"clang/none", "clang/asan", "clang/tsan", "clang/valgrind"
23+
"gcc/none",
24+
"gcc/asan",
25+
"gcc/tsan",
26+
"gcc/valgrind",
27+
"clang/none",
28+
"clang/asan",
29+
"clang/tsan",
30+
"clang/valgrind",
931
]
10-
default_excluded = ["clang/none", "clang/valgrind"]
11-
1232
user_input = os.getenv("USER_INPUT", "")
1333
comment_body = os.getenv("COMMENT_BODY", "")
1434
event_name = os.getenv("GITHUB_EVENT_NAME")
1535

16-
input_str = ""
17-
if event_name == "workflow_dispatch":
18-
input_str = user_input
19-
elif event_name == "issue_comment":
36+
default_combinations = get_default_combinations(event_name, all_combinations)
37+
38+
input_str = user_input
39+
if event_name == "issue_comment":
2040
match = re.match(r"^@phlexbot build\s*(.*)", comment_body)
2141
if match:
22-
input_str = match.group(1)
42+
input_str = match.group(1).strip()
2343

2444
tokens = [token for token in re.split(r"[\s,]+", input_str) if token]
2545

2646
if not tokens:
27-
final_combinations = [combo for combo in all_combinations if combo not in default_excluded]
47+
# Case 3: No input. Use the trigger-specific default.
48+
final_combinations = default_combinations
2849
else:
29-
is_additive = any(token == "all" or token.startswith("+") or token.startswith("-") for token in tokens)
30-
31-
if is_additive:
32-
base_set = set(all_combinations if "all" in tokens else [combo for combo in all_combinations if combo not in default_excluded])
50+
# Check for explicit (non-modifier) combinations
51+
explicit_combos = {
52+
t for t in tokens if not (t.startswith("+") or t.startswith("-") or t == "all")
53+
}
3354

34-
for token in tokens:
35-
if token.startswith("+"):
36-
base_set.add(token[1:])
37-
elif token.startswith("-"):
38-
base_set.discard(token[1:])
39-
final_combinations = list(base_set)
55+
if explicit_combos:
56+
# Case 1: Explicit list. This forms the base set, ignoring defaults.
57+
base_set = explicit_combos
4058
else:
41-
final_combinations = tokens
59+
# Case 2: Only modifiers. Determine base set from 'all' or defaults.
60+
if "all" in tokens:
61+
base_set = set(all_combinations)
62+
else:
63+
base_set = set(default_combinations)
64+
65+
# Apply modifiers to the determined base set
66+
for token in tokens:
67+
if token.startswith("+"):
68+
base_set.add(token[1:])
69+
elif token.startswith("-"):
70+
base_set.discard(token[1:])
71+
72+
final_combinations = list(base_set)
4273

4374
matrix = {"include": []}
44-
for combo in sorted(list(set(final_combinations))):
75+
for combo in sorted(set(final_combinations)):
4576
compiler, sanitizer = combo.split("/")
4677
matrix["include"].append({"compiler": compiler, "sanitizer": sanitizer})
4778

4879
json_matrix = json.dumps(matrix)
4980
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
5081
print(f"matrix={json_matrix}", file=f)
5182

83+
5284
if __name__ == "__main__":
5385
main()

0 commit comments

Comments
 (0)