Skip to content

Commit 2c7d283

Browse files
chore(alpha update command): add option to use ai with gh models
Assisted-by: ChatGPT (OpenAI) Co-authored-by: Vitor Floriano <[email protected]>
1 parent 0186494 commit 2c7d283

File tree

13 files changed

+926
-125
lines changed

13 files changed

+926
-125
lines changed

docs/book/src/getting-started.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,19 @@ The [Manager][manager] in the `cmd/main.go` file is responsible for managing the
408408
```
409409
</details>
410410
411+
### Use Kubebuilder plugins to scaffold additional options
412+
413+
Now that you have a better understanding of how to create your own API and controller,
414+
let’s scaffold in this project the plugin [`autoupdate.kubebuilder.io/v1-alpha`][autoupdate-plugin]
415+
so that your project can be kept up to date with the latest Kubebuilder releases scaffolding changes
416+
and consequently adopt improvements from the ecosystem.
417+
418+
```shell
419+
kubebuilder edit --plugins="autoupdate/v1-alpha"
420+
```
421+
422+
Inspect the file `.github/workflows/auto-update.yml` to see how it works.
423+
411424
### Checking the Project running in the cluster
412425
413426
At this point you can check the steps to validate the project
@@ -444,3 +457,4 @@ implemented for your controller.
444457
[deploy-image]: ./plugins/available/deploy-image-plugin-v1-alpha.md
445458
[GOPATH-golang-docs]: https://golang.org/doc/code.html#GOPATH
446459
[go-modules-blogpost]: https://blog.golang.org/using-go-modules
460+
[autoupdate-plugin]: ./plugins/available/autoupdate-v1-alpha.md
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Auto Update
2+
3+
# The 'kubebuilder alpha update 'command requires write access to the repository to create a branch
4+
# with the update files and allow you to open a pull request using the link provided in the issue.
5+
# The branch created will be named in the format kubebuilder-update-from-<from-version>-to-<to-version> by default.
6+
# To protect your codebase, please ensure that you have branch protection rules configured for your
7+
# main branches. This will guarantee that no one can bypass a review and push directly to a branch like 'main'.
8+
permissions:
9+
contents: write
10+
issues: write
11+
models: read
12+
13+
on:
14+
workflow_dispatch:
15+
schedule:
16+
- cron: "0 0 * * 2" # Every Tuesday at 00:00 UTC
17+
18+
jobs:
19+
auto-update:
20+
runs-on: ubuntu-latest
21+
env:
22+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
24+
# Step 1: Checkout the repository.
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
with:
29+
token: ${{ secrets.GITHUB_TOKEN }}
30+
fetch-depth: 0
31+
32+
# Step 2: Configure Git to create commits with the GitHub Actions bot.
33+
- name: Configure Git
34+
run: |
35+
git config --global user.name "github-actions[bot]"
36+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
37+
38+
# Step 3: Set up Go environment.
39+
- name: Set up Go
40+
uses: actions/setup-go@v5
41+
with:
42+
go-version: stable
43+
44+
# Step 4: Install Kubebuilder.
45+
- name: Install Kubebuilder
46+
run: |
47+
curl -L -o kubebuilder "https://go.kubebuilder.io/dl/latest/$(go env GOOS)/$(go env GOARCH)"
48+
chmod +x kubebuilder
49+
sudo mv kubebuilder /usr/local/bin/
50+
kubebuilder version
51+
52+
# Step 5: Install Models extension for GitHub CLI
53+
- name: Install/upgrade gh-models extension
54+
run: |
55+
gh extension install github/gh-models --force
56+
gh models --help >/dev/null
57+
58+
# Step 6: Run the Kubebuilder alpha update command.
59+
# More info: https://kubebuilder.io/reference/commands/alpha_update
60+
- name: Run kubebuilder alpha update
61+
run: |
62+
# Executes the update command with specified flags.
63+
# --force: Completes the merge even if conflicts occur, leaving conflict markers.
64+
# --push: Automatically pushes the resulting output branch to the 'origin' remote.
65+
# --restore-path: Preserves specified paths (e.g., CI workflow files) when squashing.
66+
# --open-gh-issue: Creates a GitHub Issue with a link for opening a PR for review.
67+
# --open-gh-models: Adds an AI-generated comment to the created Issue with
68+
# a short overview of the scaffold changes and conflict-resolution guidance (If Any).
69+
kubebuilder alpha update \
70+
--force \
71+
--push \
72+
--restore-path .github/workflows \
73+
--open-gh-issue \
74+
--use-gh-models

docs/book/src/getting-started/testdata/project/PROJECT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ domain: example.com
77
layout:
88
- go.kubebuilder.io/v4
99
plugins:
10+
autoupdate.kubebuilder.io/v1-alpha: {}
1011
helm.kubebuilder.io/v1-alpha: {}
1112
projectName: project
1213
repo: example.com/memcached

docs/book/src/plugins/available/autoupdate-v1-alpha.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ refresh your project scaffold, and wraps it in a GitHub Actions workflow that op
1111

1212
- When you don’t deviate too much from the default scaffold — ensure that you see the note about customization [here](https://book.kubebuilder.io/versions_compatibility_supportability#project-customizations).
1313
- When you want to reduce the burden of keeping the project updated and well-maintained.
14+
- When you want to guidance and help from AI to know what changes are needed to keep your project up to date
15+
as to solve conflicts.
1416

1517
## How to Use It
1618

17-
0 If you want to add the `autoupdate` plugin to your project:
19+
- If you want to add the `autoupdate` plugin to your project:
1820

1921
```shell
2022
kubebuilder edit --plugins="autoupdate.kubebuilder.io/v1-alpha"
@@ -28,12 +30,21 @@ kubebuilder init --plugins=go/v4,autoupdate/v1-alpha
2830

2931
## How It Works
3032

31-
This will scaffold and GitHub Actions workflow that runs the [kubebuilder alpha update][alpha-update-command] command.
32-
Then, whenever a new Kubebuilder release is available, it will open an Issue with a
33-
Pull Request compare link so you can create the PR and review it, such as:
33+
This will scaffold a GitHub Actions workflow that runs the [kubebuilder alpha update][alpha-update-command] command.
34+
Whenever a new Kubebuilder release is available, the workflow will automatically open an **Issue** with a Pull Request compare link so you can easily create the PR and review it, such as:
3435

3536
<img width="638" height="482" alt="Example Issue" src="https://github.com/user-attachments/assets/589fd16b-7709-4cd5-b169-fd53d69790d4" />
3637

38+
Moreover, AI models are used to help you understand what changes are needed to keep your project up to date,
39+
and to suggest resolutions if conflicts are encountered, as in the following example:
40+
41+
<img width="715" height="424" alt="AI Example Comment" src="https://github.com/user-attachments/assets/3f8bc35d-8ba0-4fc5-931b-56b1cb238462" />
42+
43+
You will also see a list of files changed, making it easier to review the updates.
44+
And, if conflicts arise, a summary of the conflicts will be provided to help you resolve them.
45+
46+
### Workflow details
47+
3748
The workflow will check once a week for new releases, and if there are any, it will create an Issue with a Pull Request compare link so you can create the PR and review it.
3849
The command called by the workflow is:
3950

@@ -45,12 +56,14 @@ The command called by the workflow is:
4556
# --force: Completes the merge even if conflicts occur, leaving conflict markers.
4657
# --push: Automatically pushes the resulting output branch to the 'origin' remote.
4758
# --restore-path: Preserves specified paths (e.g., CI workflow files) when squashing.
48-
# --open-gh-issue: Creates a GitHub issue with a link to the generated PR for review.
59+
# --open-gh-models: Adds an AI-generated comment to the created Issue with
60+
# a short overview of the scaffold changes and conflict-resolution guidance (If Any).
4961
kubebuilder alpha update \
5062
--force \
5163
--push \
5264
--restore-path .github/workflows \
53-
--open-gh-issue
65+
--open-gh-issue \
66+
--use-gh-models
5467
```
5568

5669
<aside class="warning">

docs/book/src/reference/commands/alpha_update.md

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ not re-applying your code.
99
By default, the final result is **squashed into a single commit** on a dedicated output branch.
1010
If you prefer to keep the full history (no squash), use `--show-commits`.
1111

12-
<aside class="note">
13-
<h1>Automate your Updates</h1>
14-
15-
You can reduce the burden of keeping your project up to date by using the
12+
> **Tip:** You can reduce the burden of keeping your project up to date by using the
1613
[`autoupdate.kubebuilder.io/v1-alpha`][autoupdate-plugin] plugin which
1714
automates the process of running `kubebuilder alpha update` on a schedule
1815
workflow when new Kubebuilder releases are available.
19-
20-
</aside>
16+
>
17+
> Moreover, you will be able to get help from AI models to understand what changes are needed to keep your project up to date
18+
and how to solve conflicts if any are faced.
2119

2220
## When to Use It
2321

@@ -27,6 +25,7 @@ Use this command when you:
2725
- Prefer automation over manual file editing
2826
- Want to review scaffold changes on a separate branch
2927
- Want to focus on resolving merge conflicts (not re-applying your custom code)
28+
- Want an **AI-generated** overview of changes and guidance for resolving conflicts
3029

3130
## How It Works
3231

@@ -64,6 +63,8 @@ The command creates three temporary branches:
6463
- `--output-branch`: pick a custom branch name.
6564
- `--push`: push the result to `origin` automatically.
6665
- `--git-config`: sets git configurations.
66+
- `--open-gh-issue`: create a GitHub issue with a checklist and compare link (requires `gh`).
67+
- `--use-gh-models`: add an AI overview **comment** to that issue using `gh models`
6768

6869
### Step 5: Cleanup
6970
- Once the output branch is ready, all the temporary working branches are deleted.
@@ -143,7 +144,48 @@ make manifests generate fmt vet lint-fix
143144
make all
144145
```
145146

146-
### Changing Extra Git configs only during the run (does not change your ~/.gitconfig)_
147+
## Using with GitHub Issues (`--open-gh-issue`) and AI (`--use-gh-models`) assistance
148+
149+
Pass `--open-gh-issue` to have the command create a GitHub **Issue** in your repository
150+
to assist with the update. Also, if you also pass `--use-gh-models`, the tool posts a follow-up comment
151+
on that Issue with an AI-generated overview of the most important changes plus brief conflict-resolution
152+
guidance.
153+
154+
### Examples
155+
156+
Create an Issue with a compare link:
157+
```shell
158+
kubebuilder alpha update --open-gh-issue
159+
```
160+
161+
Create an Issue **and** add an AI summary:
162+
```shell
163+
kubebuilder alpha update --open-gh-issue --use-gh-models
164+
```
165+
166+
### What you’ll see
167+
168+
The command opens an Issue that links to the diff so you can create the PR and review it, for example:
169+
170+
<img width="638" height="482" alt="Example Issue" src="https://github.com/user-attachments/assets/589fd16b-7709-4cd5-b169-fd53d69790d4" />
171+
172+
With `--use-gh-models`, an AI comment highlights key changes and suggests how to resolve any conflicts:
173+
174+
<img width="715" height="424" alt="AI Example Comment" src="https://github.com/user-attachments/assets/3f8bc35d-8ba0-4fc5-931b-56b1cb238462" />
175+
176+
You’ll also get a concise list of changed files to streamline the review:
177+
178+
<img width="652" height="694" alt="Files Changed" src="https://github.com/user-attachments/assets/b7b46d44-078c-4e56-8a50-bdfcfac231a7" />
179+
180+
If conflicts arise, AI-generated comments call them out and provide next steps:
181+
182+
<img width="682" height="213" alt="Conflicts" src="https://github.com/user-attachments/assets/ed8cf95d-5272-4477-8d75-4e28546dde4e" />
183+
184+
### Automation
185+
186+
This integrates cleanly with automation. The [`autoupdate.kubebuilder.io/v1-alpha`][autoupdate-plugin] plugin can scaffold a GitHub Actions workflow that runs the command on a schedule (e.g., weekly). When a new Kubebuilder release is available, it opens an Issue with a compare link so you can create the PR and review it.
187+
188+
## Changing Extra Git configs only during the run (does not change your ~/.gitconfig)_
147189

148190
By default, `kubebuilder alpha update` applies safe Git configs:
149191
`merge.renameLimit=999999`, `diff.renameLimit=999999`, `merge.conflictStyle=merge`
@@ -170,18 +212,20 @@ kubebuilder alpha update \
170212

171213
## Flags
172214

173-
| Flag | Description |
174-
|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
175-
| `--from-version` | Kubebuilder release to update **from** (e.g., `v4.6.0`). If unset, read from the `PROJECT` file when possible. |
176-
| `--to-version` | Kubebuilder release to update **to** (e.g., `v4.7.0`). If unset, defaults to the latest available release. |
177-
| `--from-branch` | Git branch that holds your current project code. Defaults to `main`. |
178-
| `--force` | Continue even if merge conflicts happen. Conflicted files are committed with conflict markers (CI/cron friendly). |
179-
| `--show-commits` | Keep full history (do not squash). **Not compatible** with `--preserve-path`. |
180-
| `--restore-path` | Repeatable. Paths to preserve from the base branch (repeatable). Not supported with --show-commits. (e.g., `.github/workflows`). |
181-
| `--output-branch` | Name of the output branch. Default: `kubebuilder-update-from-<from-version>-to-<to-version>`. |
182-
| `--push` | Push the output branch to the `origin` remote after the update completes. |
183-
| `--git-config` | Repeatable. Pass per-invocation Git config as `-c key=value`. **Default** (if omitted): `-c merge.renameLimit=999999 -c diff.renameLimit=999999`. Your configs are applied on top. To disable defaults, include `--git-config disable` |
184-
| `-h, --help` | Show help for this command. |
215+
| Flag | Description |
216+
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
217+
| `--force` | Continue even if merge conflicts happen. Conflicted files are committed with conflict markers (CI/cron friendly). |
218+
| `--from-branch` | Git branch that holds your current project code. Defaults to `main`. |
219+
| `--from-version` | Kubebuilder release to update **from** (e.g., `v4.6.0`). If unset, read from the `PROJECT` file when possible. |
220+
| `--git-config` | Repeatable. Pass per-invocation Git config as `-c key=value`. **Default** (if omitted): `-c merge.renameLimit=999999 -c diff.renameLimit=999999`. Your configs are applied on top. To disable defaults, include `--git-config disable`. |
221+
| `--open-gh-issue` | Create a GitHub issue with a pre-filled checklist and compare link after the update completes (requires `gh`). |
222+
| `--output-branch` | Name of the output branch. Default: `kubebuilder-update-from-<from-version>-to-<to-version>`. |
223+
| `--push` | Push the output branch to the `origin` remote after the update completes. |
224+
| `--restore-path` | Repeatable. Paths to preserve from the base branch when squashing (e.g., `.github/workflows`). **Not supported** with `--show-commits`. |
225+
| `--show-commits` | Keep full history (do not squash). **Not compatible** with `--restore-path`. |
226+
| `--to-version` | Kubebuilder release to update **to** (e.g., `v4.7.0`). If unset, defaults to the latest available release. |
227+
| `--use-gh-models` | Post an AI overview as an issue comment using `gh models`. Requires `gh` + `gh-models` extension. Effective only when `--open-gh-issue` is also set. |
228+
| `-h, --help` | Show help for this command. |
185229

186230
<aside class="note warning">
187231
<h1>You might need to upgrade your project first</h1>

hack/docs/internal/getting-started/generate_getting_started.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ func (sp *Sample) GenerateSampleProject() {
219219
"--resource", "--controller",
220220
)
221221
hackutils.CheckError("Creating the API", err)
222+
223+
slog.Info("Adding AutoUpdate Plugin")
224+
err = sp.ctx.Edit(
225+
"--plugins", "autoupdate/v1-alpha",
226+
)
227+
hackutils.CheckError("Initializing the getting started project", err)
222228
}
223229

224230
// CodeGen will call targets to generate code

0 commit comments

Comments
 (0)