Skip to content

Commit 95787b7

Browse files
committed
ci: add conditional runs for non-Buildkite affecting CI checks
Adds a Buildkite entrypoint script that detects PRs which only touch docs, GitHub workflows, or root-level Markdown and skips the heavy operator test suite. A dummy pipeline is uploaded instead, which reports passing GitHub commit statuses for every required check by extracting the context list straight from `.buildkite/testsuite.yml` (scoped to `context:` keys under `github_commit_status:` so plugin contexts like junit-annotate are excluded). The dummy step pins the same agent queue as the entrypoint so it actually gets scheduled. Diff parsing is NUL-delimited and arguments are quoted to handle paths with whitespace and unusual branch names safely.
1 parent bf91db3 commit 95787b7

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

.buildkite/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ steps:
3535
(build.pull_request.id != null && !build.pull_request.repository.fork) ||
3636
((build.source == "schedule" || build.source == "ui") && build.env("K8S_NIGHTLY") == "1") ||
3737
((build.branch == "main" || build.branch =~ /^release\//) && build.source == "webhook")
38-
command: buildkite-agent pipeline upload .buildkite/testsuite.yml
38+
command: .buildkite/scripts/conditional_testsuite.sh
3939

4040
# NOTE: This build IS NOT dependent on tests passing due to their current flakey state.
4141
# It's recommended to check that tests have passed for the given commit before using it.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
testsuite=".buildkite/testsuite.yml"
5+
6+
if [[ "$BUILDKITE_SOURCE" == "webhook" && -n "$BUILDKITE_PULL_REQUEST" && "$BUILDKITE_PULL_REQUEST" != "false" ]]; then
7+
# It's a PR, let's check what changed
8+
base_branch="$BUILDKITE_PULL_REQUEST_BASE_BRANCH"
9+
if [[ -z "$base_branch" ]]; then
10+
base_branch="main"
11+
fi
12+
13+
# Fetch base branch to compare against
14+
git fetch origin -- "$base_branch"
15+
16+
# Check if any non-skippable files changed. Skippable paths are docs,
17+
# GitHub workflows, and root-level Markdown files (README, CONTRIBUTING,
18+
# etc.) — none of these affect Buildkite CI.
19+
requires_ci=false
20+
while IFS= read -r -d '' file; do
21+
if [[ "$file" =~ ^docs/ ]]; then continue; fi
22+
if [[ "$file" =~ ^\.github/ ]]; then continue; fi
23+
if [[ "$file" =~ ^[^/]+\.md$ ]]; then continue; fi
24+
requires_ci=true
25+
break
26+
done < <(git diff -z --name-only "origin/$base_branch...HEAD")
27+
28+
if [[ "$requires_ci" == "false" ]]; then
29+
echo "--- Skipping CI as only docs or GHA workflows changed"
30+
31+
# Extract commit-status contexts from the real testsuite so the dummy
32+
# pipeline reports a passing status for each one (kept in sync with
33+
# branch-protection rules automatically). Only match `context:` keys
34+
# that are children of `github_commit_status:` — other plugins (e.g.
35+
# junit-annotate) reuse the `context:` key for unrelated values.
36+
contexts=$(awk '
37+
/^[[:space:]]*-?[[:space:]]*github_commit_status:[[:space:]]*$/ { expect = 1; next }
38+
expect && match($0, /^[[:space:]]*context:[[:space:]]*/) {
39+
print substr($0, RLENGTH + 1)
40+
expect = 0
41+
}
42+
' "$testsuite" | sort -u)
43+
44+
{
45+
echo "steps:"
46+
echo " - command: echo \"Skipped CI as no source files changed\""
47+
echo " label: \":fast_forward: Skipped\""
48+
echo " agents:"
49+
echo " queue: devprod-t4gmicro"
50+
echo " notify:"
51+
while IFS= read -r ctx; do
52+
[[ -z "$ctx" ]] && continue
53+
echo " - github_commit_status:"
54+
echo " context: \"$ctx\""
55+
done <<< "$contexts"
56+
} | buildkite-agent pipeline upload
57+
exit 0
58+
fi
59+
fi
60+
61+
# Fallback to normal behavior
62+
buildkite-agent pipeline upload "$testsuite"

0 commit comments

Comments
 (0)