✨ alpha(update): add --squash, --preserve-path, --output-branch for PR-friendly upgrades#5002
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: camilamacedo86 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
5e5b396 to
e647ab5
Compare
88cb831 to
d986484
Compare
…friendly upgrades
This change makes `kubebuilder alpha update` produce a PR-ready branch and a
single squashed commit when requested, improving automation and review UX.
Key changes
-----------
• New `--squash` flag:
- Snapshots the exact tree of the temporary merge branch into ONE commit on a
stable branch: `kubebuilder-alpha-update-to-<to-version>`.
- Intended for opening/refreshing idempotent PRs.
- Gracefully handles "no changes" (git commit exits 1 → treated as no-op).
• New `--preserve-path` (repeatable):
- When squashing, restore given paths from the base branch (e.g.
`.github/workflows`) so CI/config files are kept as-is on the PR branch.
• New `--output-branch`:
- Overrides the default PR branch name created by `--squash`.
• Commit message used by `--squash`:
- `[kubebuilder-automated-update]: update scaffold from <from> to <to>; (squashed 3-way merge)`
• Behavior/ergonomics:
- Without `--force`: stops on conflicts on the temporary merge branch.
- With `--force`: commits conflict markers on the merge branch (automation-friendly).
- After merge, still best-effort run: `make manifests generate fmt vet lint-fix`.
Defaults / Compatibility
------------------------
- `--squash` is off by default (no behavior change unless opted-in).
- `--from-branch` defaults to `main`.
- `--preserve-path` is empty by default (no restores).
- Safe to run on projects scaffolded with v4.5.0+ (uses `alpha generate`).
Motivation
----------
Make upgrades PR-centric and automation-ready by producing a deterministic,
reviewable branch and a single squashed commit that mirrors the merge result.
Assisted-by: ChatGPT (OpenAI)
Co-authored-by: Vitor Floriano <vitorfloriano@users.noreply.github.com>
d986484 to
0d40b9c
Compare
| - **With `--force`**: the merge is committed (on `tmp-merge-*`) and contains the markers. | ||
| - **With `--force`**: the merge is committed (on `tmp-merge-*`, or on the output branch if using `--squash`) and contains the markers. | ||
|
|
||
| ## Commit message used in `--squash` mode | ||
|
|
||
| > [kubebuilder-automated-update]: update scaffold from <from> to <to>; (squashed 3-way merge) | ||
|
|
||
| <aside class="note warning"> | ||
| <h1>You might need to upgrade your project first</h1> | ||
|
|
||
| This command uses `kubebuilder alpha generate` under the hood. | ||
| We support projects created with <strong>v4.5.0+</strong>. | ||
| If yours is older, first run `kubebuilder alpha generate` once to modernize the scaffold. | ||
| After that, you can use `kubebuilder alpha update` for future upgrades. | ||
|
|
||
| </aside> | ||
|
|
||
| <aside class="note"> | ||
| <h1>CLI Version Tracking</h1> | ||
|
|
||
| Projects created with **Kubebuilder v4.6.0+** include `cliVersion` in the `PROJECT` file. | ||
| We use that value to pick the correct CLI for re-scaffolding. | ||
|
|
||
| </aside> |
|
/lgtm The flags seem to incorporate the related steps in the workflow accordingly. We'll probably need to merge the changes and test it in a new workflow to be sure, though. |
|
@vitorfloriano: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
5e490bd
into
kubernetes-sigs:master
|
Thank you a lot for the review |

This change makes
kubebuilder alpha updateproduce a PR-ready branch and a single squashed commit when requested, improving automation and review UX.Key changes
• New
--squashflag:kubebuilder-alpha-update-to-<to-version>.• New
--preserve-path(repeatable):.github/workflows) so CI/config files are kept as-is on the PR branch.• New
--output-branch:--squash.• Commit message used by
--squash:[kubebuilder-automated-update]: update scaffold from <from> to <to>; (squashed 3-way merge)• Behavior/ergonomics:
--force: stops on conflicts on the temporary merge branch.--force: commits conflict markers on the merge branch (automation-friendly).make manifests generate fmt vet lint-fix.Defaults / Compatibility
--squashis off by default (no behavior change unless opted-in).--from-branchdefaults tomain.--preserve-pathis empty by default (no restores).alpha generate).Motivation
Make upgrades PR-centric and automation-ready by producing a deterministic, reviewable branch and a single squashed commit that mirrors the merge result.
Assisted-by: ChatGPT (OpenAI)