Skip to content

Commit 0de0440

Browse files
fix(ci): use three-dot diff to detect only PR changes in build workflow (opendatahub-io#2876)
* fix(tests): update test_get_build_directory to expect Python 3.12 The test was checking for ubi9-python-3.11 but the actual directory uses ubi9-python-3.12. Update the assertion to match the current codebase state. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(ci): use three-dot diff to detect only PR changes in build workflow The build workflow was using a two-dot git diff which compares the complete state of two commits. When main advances with new commits after a PR branch is created, the two-dot diff shows ALL differences between the branches, including files that changed in main but not in the PR. This caused false positive build triggers. For example, PR opendatahub-io#2874 only changed scripts/README.md and scripts/sbom_analyze.py, but the CI detected 20 changed files (including all pylock.toml files that were updated in main by PR opendatahub-io#2873 after PR opendatahub-io#2874 was created), triggering unnecessary builds for all workbench images. Fix: Change from two-dot diff (A B) to three-dot diff (A...B) which shows changes from the merge-base of A and B to commit B. This correctly identifies only the changes introduced by the PR, regardless of how much main has advanced. Fixes: opendatahub-io#2875 Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent cc43ca9 commit 0de0440

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ci/cached-builds/gha_pr_changed_files.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ def get_github_token() -> str:
2222
def list_changed_files(from_ref: str, to_ref: str) -> list[str]:
2323
logging.debug("Getting list of changed files from git diff")
2424

25+
# Use three-dot diff to show changes from merge-base to to_ref
26+
# This correctly shows only changes introduced by the PR, regardless of how much from_ref has advanced
27+
# See: https://github.com/opendatahub-io/notebooks/issues/2875
2528
# https://github.com/red-hat-data-services/notebooks/pull/361: add -- in case to_ref matches a file name in the repo
2629
files = subprocess.check_output(
27-
["git", "diff", "--name-only", from_ref, to_ref, "--"], encoding="utf-8"
30+
["git", "diff", "--name-only", f"{from_ref}...{to_ref}", "--"], encoding="utf-8"
2831
).splitlines()
2932

3033
logging.debug(f"Determined {len(files)} changed files: {files[:100]} (..., printing up to 100 files)")
@@ -157,7 +160,7 @@ def test_list_changed_files(self):
157160

158161
def test_get_build_directory(self):
159162
directory = get_build_directory("rocm-jupyter-pytorch-ubi9-python-3.12")
160-
assert directory == "jupyter/rocm/pytorch/ubi9-python-3.11"
163+
assert directory == "jupyter/rocm/pytorch/ubi9-python-3.12"
161164

162165
def test_get_build_dockerfile(self):
163166
dockerfile = get_build_dockerfile("rocm-jupyter-pytorch-ubi9-python-3.12")

0 commit comments

Comments
 (0)