From 93488b2ff815929baa84dacd237b6b4d06b7a5ce Mon Sep 17 00:00:00 2001 From: Sudan Landge Date: Fri, 9 Feb 2024 19:29:38 +0000 Subject: [PATCH] fix: use the right base branch to detect changed files Changes: Use either $BUILDKITE_PULL_REQUEST_BASE_BRANCH if available instead of main to get list of changed files. Reason: Comparing changed files with main leads to running unnecessary tests like buid_devctr even when there is no Dockerfile change in the release branch. Signed-off-by: Sudan Landge --- .buildkite/common.py | 7 +++++-- .buildkite/pipeline_pr.py | 2 +- .buildkite/pipeline_pr_no_block.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.buildkite/common.py b/.buildkite/common.py index 4a5101d8fa7..fc88145d325 100644 --- a/.buildkite/common.py +++ b/.buildkite/common.py @@ -7,6 +7,7 @@ import argparse import json +import os import subprocess from pathlib import Path @@ -88,11 +89,13 @@ def pipeline_to_json(pipeline): return json.dumps(pipeline, indent=4, sort_keys=True, ensure_ascii=False) -def get_changed_files(branch): +def get_changed_files(): """ Get all files changed since `branch` """ - stdout = subprocess.check_output(["git", "diff", "--name-only", branch]) + branch = os.environ.get("BUILDKITE_PULL_REQUEST_BASE_BRANCH", "main") + stdout = subprocess.check_output(f"git diff --name-only origin/{branch}".split(" ")) + return [Path(line) for line in stdout.decode().splitlines()] diff --git a/.buildkite/pipeline_pr.py b/.buildkite/pipeline_pr.py index 736c6c16a15..6334e2e08d3 100755 --- a/.buildkite/pipeline_pr.py +++ b/.buildkite/pipeline_pr.py @@ -108,7 +108,7 @@ step["label"] = "🔍 Kani" steps = [step_style] -changed_files = get_changed_files("main") +changed_files = get_changed_files() # run sanity build of devtool if Dockerfile is changed if any(x.name == "Dockerfile" for x in changed_files): diff --git a/.buildkite/pipeline_pr_no_block.py b/.buildkite/pipeline_pr_no_block.py index 311188098b5..2fcb9cba1bf 100755 --- a/.buildkite/pipeline_pr_no_block.py +++ b/.buildkite/pipeline_pr_no_block.py @@ -37,6 +37,6 @@ **defaults, ) -changed_files = get_changed_files("main") +changed_files = get_changed_files() pipeline = {"steps": [optional_grp]} if run_all_tests(changed_files) else {"steps": []} print(pipeline_to_json(pipeline))