-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buildkite: Add dynamic pipeline generator for conditional skipping
Use Buildkite's dynamic pipelines feature to dynamically choose between Code/Code-skip pipelines depending on whether the build was triggered for a pull request and the list of changes files.
- Loading branch information
Showing
4 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## | ||
# Code-skip pipeline | ||
## | ||
# | ||
# Buildkite pipeline for skipping running code-related linters and tests. | ||
# | ||
|
||
steps: | ||
- label: No code-related changes detected, skipping Code pipeline | ||
command: exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
## | ||
# Dynamic Buildkite pipeline generator. | ||
## | ||
# | ||
# It outputs valid Buildkite pipeline in YAML format. | ||
# | ||
# To use it, define the following Steps under your Buildkite's Pipeline Settings: | ||
# | ||
# steps: | ||
# - command: .buildkite/pipeline.sh | buildkite-agent pipeline upload | ||
# label: ":pipeline: Upload" | ||
# | ||
# For more details, see: | ||
# https://buildkite.com/docs/pipelines/defining-steps#dynamic-pipelines. | ||
# | ||
|
||
set -eux | ||
|
||
# Helper that ensures the build is triggered for a pull request and that there | ||
# are no code-related changes compared to the pull request's base branch. | ||
pr_and_no_code_related_changes() { | ||
# Check if the build was triggered for a pull request. | ||
if [[ -z $BUILDKITE_PULL_REQUEST_BASE_BRANCH ]]; then | ||
return 1 | ||
fi | ||
# Get the list of changes files, excluding changes unrelated to code. | ||
# NOTE: The exclude patterns below use git's pathspec syntax: | ||
# https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec. | ||
git diff --name-only --exit-code "refs/remotes/origin/$BUILDKITE_PULL_REQUEST_BASE_BRANCH.." 1>&2 -- \ | ||
':(exclude)*.md' \ | ||
':(exclude).changelog/' \ | ||
':(exclude).github/' \ | ||
':(exclude).gitlint' \ | ||
':(exclude).markdownlint.yml' \ | ||
':(exclude).punch_config.py' \ | ||
':(exclude)docs/' \ | ||
':(exclude)towncrier.toml' | ||
} | ||
|
||
if pr_and_no_code_related_changes; then | ||
cat .buildkite/code-skip.pipeline.yml | ||
else | ||
cat .buildkite/code.pipeline.yml | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ci: Skip some steps for non-code changes | ||
|
||
When one makes a pull request that e.g. only adds documentation or | ||
assembles the Change Log from fragments, all the *heavy* Buildkite | ||
pipeline steps (e.g. Go/Rust building, Go tests, E2E tests) should be | ||
skipped. |