Skip to content

Commit

Permalink
Implement validation of configuration changes. (#628)
Browse files Browse the repository at this point in the history
If the "validate_config" option is set in the pipeline configuration, all changes to pipeline configuration files in the .bazelci folder will be validated. Currently this means that CI tries to print a project pipeline using that configuration.

Examples:

- https://buildkite.com/bazel/fwe-test/builds/35: No validation step since no configs were modified.
- https://buildkite.com/bazel/fwe-test/builds/36: Successful validation of a commit that changed two configuration files correctly.
- https://buildkite.com/bazel/fwe-test/builds/38: Validation failed due to bug in the configuration.
  • Loading branch information
fweikert committed Apr 25, 2019
1 parent f5a2feb commit 778251c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
16 changes: 16 additions & 0 deletions buildkite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,19 @@ tasks:
test_targets:
- //...
```

### Validating changes to pipeline configuration files

You can set the top-level `validate_config` option to ensure that changes to pipeline configuration files in the `.bazelci` directory will be validated.
With this option, every build for a commit that touches a configuration file will contain an additional validation step for each modified configuration file.

Example usage:

```yaml
---
validate_config: 1
tasks:
macos:
build_targets:
- "..."
```
33 changes: 33 additions & 0 deletions buildkite/bazelci.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@

SKIP_TASKS_ENV_VAR = "CI_SKIP_TASKS"

CONFIG_FILE_EXTENSIONS = set([".yml", ".yaml"])


class BuildkiteException(Exception):
"""
Expand Down Expand Up @@ -1559,6 +1561,37 @@ def SetEnvVar(config_key, env_var_name):
)
)

if "validate_config" in configs:
output = execute_command_and_get_output(
[
"git",
"diff-tree",
"--no-commit-id",
"--name-only",
"-r",
os.getenv("BUILDKITE_COMMIT"),
]
)
config_files = [
l
for l in output.split("\n")
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(
create_step(
label=":cop: Validate {}".format(f),
commands=[
fetch_bazelcipy_command(),
"{} bazelci.py project_pipeline --file_config={}".format(
python_binary(platform), f
),
],
platform=platform,
)
)

print(yaml.dump({"steps": pipeline_steps}))


Expand Down

0 comments on commit 778251c

Please sign in to comment.