feat: change-aware PR builds for product images#621
Open
ianpittwood wants to merge 13 commits into
Open
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements the pure classify_changes(config, changed_files) -> MatrixSelection function that maps a PR's changed file paths to image/version build selections, with fail-safe fallback to full builds for unrecognized paths.
Wire the classify_changes classifier into `bakery ci matrix`. When neither flag is set, behavior is byte-identical to before (full matrix). When --changed-files-from or --base-ref is provided, the matrix is filtered to only the images and versions touched by the PR's changed files; a repo-wide change (bakery.yaml, workflows) falls back to the full matrix automatically. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ected When matrix versions are not globally excluded, the candidate list already contains the full matrix (including latest rows). Guard the change-aware include_matrix_latest injection so it only appends the latest slice when matrix_versions == EXCLUDE, preventing duplicate entries. Also annotates the `ver` parameter of _version_selected with the correct ImageVersion type. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add three pytest-bdd scenarios covering the hermetic paths of the
--changed-files-from feature: version-dir change (filtered), Markdown-only
change (empty matrix), and bakery.yaml change (full fallback). Adds a
"with changed files in {filename}:" step that writes the list to the
context dir and injects --changed-files-from into the command args.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Bug 1: when --dev-versions include/only, BakeryConfig already called load_dev_versions() at config time; the change-aware branch was calling it again, duplicating dev entries. Guard the load with `dev_versions == EXCLUDE` to only load when the baseline didn't. Bug 2: for matrix images, the change-aware branch could overwrite the full matrix candidate list with only img.versions (losing all matrix rows). The new path always combines list(img.versions) + to_image_versions() exactly once, and _version_selected() gates which rows are actually emitted. Also adds unit tests for _version_selected and a hermetic regression test (load_dev_versions monkeypatched) for the dev-dedup bug. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
3a2ae89 to
124cd24
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #589
Summary
PR builds in product image repos currently rebuild the entire image × version × platform matrix on every PR, regardless of what changed. This adds change-aware filtering so PR builds only build/test the images and versions a PR plausibly affects.
bakery ci matrixgains--base-ref <ref>(and--changed-files-from <file|->). When given the PR base SHA, a pure classifier maps the PR's changed files to a filtered matrix:**/*.md) → ignored (build nothing).<image>/<version-subpath>/**→ build + test that release version.<image>/template/**→ build that image's dev versions (if declared); release version dirs are already-rendered snapshots, so a template edit only affects dev builds.connect-content) → latest matrix slice + dev versions if declared.bakery.yaml,.github/workflows/**, or anything unattributable → full matrix (fail-safe).Filtering is PR-only: push-to-main, scheduled, and release builds call
bakery ci matrixwithout--base-refand are byte-for-byte unchanged.Implementation
classify_changes+ git helpergit_changed_filesinposit_bakery/config/changeset.py(no filesystem/network reads — fully unit-testable).bakery ci matrixwires in--base-ref/--changed-files-from, resolving dev/matrix versions per-image only when the selection requires them. The no-flag path is preserved exactly.bakery-build-pr.yml:fetch-depth: 0, passes the PR base SHA, derives--dev-versionsper matrix entry, and adds an always-green Build/Test result gate job so docs-only PRs still satisfy branch protection.CONTRIBUTING.md.Test Plan
_version_selected, and the git merge-base helper.bakery ci matrixoutput unchanged onbasic/multiplatformsuites.--dev-versions only/include.🤖 Generated with Claude Code