Refactoring: Shorten print_project_pipeline().
This commit moves all functionality related to validating configuration
changes into a separate function.
@@ -1672,15 +1672,21 @@ def print_project_pipeline(
)
if "validate_config" in configs:
+ pipeline_steps += create_config_validation_steps()
+
+ print(yaml.dump({"steps": pipeline_steps}))
+
+
+def get_platform_for_task(task, task_config):
+ # Most pipeline configurations have exactly one task per platform, which makes it
+ # convenient to use the platform name as task ID. Consequently, we use the
+ # task ID as platform if there is no explicit "platform" field.
+ return task_config.get("platform", task)
+
+
+def create_config_validation_steps():
output = execute_command_and_get_output(
- [
- "git",
- "diff-tree",
- "--no-commit-id",
- "--name-only",
- "-r",
- os.getenv("BUILDKITE_COMMIT"),
- ]
+ ["git", "diff-tree", "--no-commit-id", "--name-only", "-r", os.getenv("BUILDKITE_COMMIT")]
)
config_files = [
l
@@ -1688,8 +1694,7 @@ def print_project_pipeline(
if l.startswith(".bazelci/") and os.path.splitext(l)[1] in CONFIG_FILE_EXTENSIONS
]
platform = DEFAULT_PLATFORM
- for f in config_files:
- pipeline_steps.append(
+ return [
create_step(
label=":cop: Validate {}".format(f),
commands=[
@@ -1700,16 +1705,8 @@ def print_project_pipeline(
],
platform=platform,
)
- )
-
- print(yaml.dump({"steps": pipeline_steps}))
-
-
-def get_platform_for_task(task, task_config):
- # Most pipeline configurations have exactly one task per platform, which makes it
- # convenient to use the platform name as task ID. Consequently, we use the
- # task ID as platform if there is no explicit "platform" field.
- return task_config.get("platform", task)
+ for f in config_files
+ ]
def runner_step(
