Skip to content

Commit 6e57e8c

Browse files
bchaliosroypat
authored andcommitted
fix(ci): do not run optional tests for doc-only changes
We already avoid running the whole test suite when changes include only doc changes, or changes to YAML files under .github. This commit applies the same logic to the optional PR tests. Signed-off-by: Babis Chalios <[email protected]>
1 parent a7ebeaf commit 6e57e8c

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

.buildkite/common.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import argparse
99
import json
10+
import subprocess
11+
from pathlib import Path
1012

1113
DEFAULT_INSTANCES = [
1214
"m5d.metal",
@@ -86,6 +88,28 @@ def pipeline_to_json(pipeline):
8688
return json.dumps(pipeline, indent=4, sort_keys=True, ensure_ascii=False)
8789

8890

91+
def get_changed_files(branch):
92+
"""
93+
Get all files changed since `branch`
94+
"""
95+
stdout = subprocess.check_output(["git", "diff", "--name-only", branch])
96+
return [Path(line) for line in stdout.decode().splitlines()]
97+
98+
99+
def run_all_tests(changed_files):
100+
"""
101+
Check if we should run all tests, based on the files that have been changed
102+
"""
103+
104+
# run the whole test suite if either of:
105+
# - any file changed that is not documentation nor GitHub action config file
106+
# - no files changed
107+
return not changed_files or any(
108+
x.suffix != ".md" and not (x.parts[0] == ".github" and x.suffix == ".yml")
109+
for x in changed_files
110+
)
111+
112+
89113
class DictAction(argparse.Action):
90114
"""An argparse action that can receive a nested dictionary
91115

.buildkite/pipeline_pr.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,20 @@
44

55
"""Generate Buildkite pipelines dynamically"""
66

7-
import subprocess
8-
from pathlib import Path
9-
10-
from common import COMMON_PARSER, group, overlay_dict, pipeline_to_json
7+
from common import (
8+
COMMON_PARSER,
9+
get_changed_files,
10+
group,
11+
overlay_dict,
12+
pipeline_to_json,
13+
run_all_tests,
14+
)
1115

1216
# Buildkite default job priority is 0. Setting this to 1 prioritizes PRs over
1317
# scheduled jobs and other batch jobs.
1418
DEFAULT_PRIORITY = 1
1519

1620

17-
def get_changed_files(branch):
18-
"""
19-
Get all files changed since `branch`
20-
"""
21-
stdout = subprocess.check_output(["git", "diff", "--name-only", branch])
22-
return [Path(line) for line in stdout.decode().splitlines()]
23-
24-
2521
args = COMMON_PARSER.parse_args()
2622

2723
step_style = {
@@ -111,13 +107,7 @@ def get_changed_files(branch):
111107
if any(x.parts[-1] == "Dockerfile" for x in changed_files):
112108
steps += [devtool_build_grp]
113109

114-
# run the whole test suite if either of:
115-
# - any file changed that is not documentation nor GitHub action config file
116-
# - no files changed
117-
if not changed_files or any(
118-
x.suffix != ".md" and not (x.parts[0] == ".github" and x.suffix == ".yml")
119-
for x in changed_files
120-
):
110+
if run_all_tests(changed_files):
121111
steps += [
122112
kani_grp,
123113
build_grp,

.buildkite/pipeline_pr_no_block.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44

55
"""Generate Buildkite pipelines dynamically"""
66

7-
from common import COMMON_PARSER, group, overlay_dict, pipeline_to_json
7+
from common import (
8+
COMMON_PARSER,
9+
get_changed_files,
10+
group,
11+
overlay_dict,
12+
pipeline_to_json,
13+
run_all_tests,
14+
)
815

916
# Buildkite default job priority is 0. Setting this to 1 prioritizes PRs over
1017
# scheduled jobs and other batch jobs.
@@ -30,5 +37,6 @@
3037
**defaults,
3138
)
3239

33-
pipeline = {"steps": [optional_grp]}
40+
changed_files = get_changed_files("main")
41+
pipeline = {"steps": [optional_grp]} if run_all_tests(changed_files) else {"steps": []}
3442
print(pipeline_to_json(pipeline))

0 commit comments

Comments
 (0)