diff --git a/.buildkite/code-skip.pipeline.yml b/.buildkite/code-skip.pipeline.yml new file mode 100644 index 00000000000..ff08e3119db --- /dev/null +++ b/.buildkite/code-skip.pipeline.yml @@ -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 diff --git a/.buildkite/pipeline.yml b/.buildkite/code.pipeline.yml similarity index 98% rename from .buildkite/pipeline.yml rename to .buildkite/code.pipeline.yml index f9b8760bca7..6ceca2c8d57 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/code.pipeline.yml @@ -1,6 +1,10 @@ -################ -# Build pipeline -################ +## +# Code pipeline +## +# +# Main Buildkite pipeline for running code-related linters and tests. +# + docker_plugin_default_config: &docker_plugin_default_config image: "oasislabs/testing:0.3.0" always_pull: true diff --git a/.buildkite/pipeline.sh b/.buildkite/pipeline.sh new file mode 100755 index 00000000000..81844744e6c --- /dev/null +++ b/.buildkite/pipeline.sh @@ -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 diff --git a/.changelog/2702.internal.md b/.changelog/2702.internal.md new file mode 100644 index 00000000000..65de41d29a4 --- /dev/null +++ b/.changelog/2702.internal.md @@ -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.