Skip to content

Commit 8c5eaee

Browse files
chore(alpha update/AutoUpdate): Changes to ensure better usage and allow granular workflow and permissions
1 parent ee0a930 commit 8c5eaee

17 files changed

Lines changed: 756 additions & 180 deletions

File tree

docs/book/src/getting-started/testdata/project/.github/workflows/auto_update.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
auto-update:
1717
permissions:
1818
contents: write # Create and push the update branch
19-
issues: write # Create GitHub Issue with PR link
19+
pull-requests: write # Create Pull Request
2020
runs-on: ubuntu-latest
2121
env:
2222
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -57,15 +57,15 @@ jobs:
5757
# --force: Completes the merge even if conflicts occur, leaving conflict markers.
5858
# --push: Automatically pushes the resulting output branch to the 'origin' remote.
5959
# --restore-path: Preserves specified paths (e.g., CI workflow files) when squashing.
60-
# --open-gh-issue: Creates a GitHub Issue with a link for opening a PR for review.
60+
# --open-gh-pr: Creates a GitHub Pull Request directly for review.
6161
#
6262
# WARNING: This workflow does not use GitHub Models AI summary by default.
63-
# To enable AI-generated summaries in GitHub issues, you need permissions to use GitHub Models.
63+
# To enable AI-generated summaries, you need permissions to use GitHub Models.
6464
# If you have the required permissions, re-run:
6565
# kubebuilder edit --plugins="autoupdate/v1-alpha" --use-gh-models
6666
run: |
6767
kubebuilder alpha update \
6868
--force \
6969
--push \
7070
--restore-path .github/workflows \
71-
--open-gh-issue
71+
--open-gh-pr

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ With a small amount of setup, you can receive **automatic Pull Request** suggest
55
Kubebuilder release is available — keeping your project **maintained, secure, and aligned with ecosystem changes**.
66

77
This automation uses the [`kubebuilder alpha update`][alpha-update-command] command with a **3-way merge strategy** to
8-
refresh your project scaffold, and wraps it in a GitHub Actions workflow that opens an **Issue** with a **Pull Request compare link** so you can create the PR and review it.
8+
refresh your project scaffold, and wraps it in a GitHub Actions workflow that **creates Pull Requests** for review. Alternatively, you can use `--only-issue` to create Issues instead of PRs.
99

1010
<aside class="warning" role="note">
1111
<p class="note-title">Protect your branches</p>
@@ -41,12 +41,14 @@ kubebuilder init --plugins=go/v4,autoupdate/v1-alpha
4141
### Optional: GitHub Models AI Summary
4242

4343
By default, the workflow works without GitHub Models to avoid permission errors.
44-
If you want AI-generated summaries in your update issues:
44+
If you want AI-generated summaries in your update Pull Requests:
4545

4646
```shell
4747
kubebuilder edit --plugins="autoupdate/v1-alpha" --use-gh-models
4848
```
4949

50+
**Note:** AI summaries only work with Pull Requests (the default). If you use `--only-issue`, you cannot use `--use-gh-models`.
51+
5052
<aside class="note" role="note">
5153
<p class="note-title">Permissions required to use GitHub Models in GitHub Actions</p>
5254

@@ -71,13 +73,9 @@ Your organization or enterprise may have disabled it. Contact your administrator
7173
The plugin scaffolds a GitHub Actions workflow that checks for new Kubebuilder releases every week. When an update is available, it:
7274

7375
1. Creates a new branch with the merged changes
74-
2. Opens a GitHub Issue with a PR compare link
75-
76-
**Example Issue:**
76+
2. Opens a Pull Request for review (or an Issue if you use `--only-issue`)
7777

78-
<img width="638" height="482" alt="Example Issue" src="https://github.com/user-attachments/assets/589fd16b-7709-4cd5-b169-fd53d69790d4" />
79-
80-
**With GitHub Models enabled** (optional), you also get AI-generated summaries:
78+
**With GitHub Models enabled** (optional), you get AI-generated summaries in the PR description:
8179

8280
<img width="582" height="646" alt="AI Summary" src="https://github.com/user-attachments/assets/d460a5af-5ca4-4dd5-afb8-7330dd6de148" />
8381

@@ -93,8 +91,8 @@ The generated workflow uses the `kubebuilder alpha update` command with default
9391
- `--force` - Continue even if conflicts occur (automation-friendly)
9492
- `--push` - Automatically push the output branch to remote
9593
- `--restore-path .github/workflows` - Preserve CI workflows from base branch
96-
- `--open-gh-issue` - Create a GitHub Issue with PR compare link
97-
- `--use-gh-models` - (optional) Add AI summary to the issue
94+
- `--open-gh-pr` - Create a GitHub Pull Request for review
95+
- `--use-gh-models` - (optional) Add AI summary to the PR description
9896

9997
**Additional available flags:**
10098
- `--merge-message` - Custom commit message for clean merges
@@ -118,11 +116,19 @@ Edit `.github/workflows/auto_update.yml`:
118116
--force \
119117
--push \
120118
--restore-path .github/workflows \
121-
--open-gh-issue \
119+
--open-gh-pr \
122120
--merge-message "chore: update kubebuilder scaffold" \
123121
--conflict-message "chore: update with conflicts - review needed"
124122
```
125123
124+
**Example: Create Issues instead of PRs**
125+
126+
If you prefer to receive update notifications as GitHub Issues (without AI summaries):
127+
128+
```shell
129+
kubebuilder edit --plugins="autoupdate/v1-alpha" --only-issue
130+
```
131+
126132
## Troubleshooting
127133

128134
#### If you get the 403 Forbidden Error
@@ -144,7 +150,7 @@ This regenerates the workflow without GitHub Models:
144150
```yaml
145151
permissions:
146152
contents: write
147-
issues: write
153+
pull-requests: write
148154
# No models: read permission
149155

150156
steps:
@@ -162,7 +168,7 @@ steps:
162168
--force \
163169
--push \
164170
--restore-path .github/workflows \
165-
--open-gh-issue
171+
--open-gh-pr
166172
```
167173
168174
The workflow continues to work—just without AI summaries.
@@ -182,7 +188,7 @@ This regenerates the workflow WITH GitHub Models:
182188
```yaml
183189
permissions:
184190
contents: write
185-
issues: write
191+
pull-requests: write
186192
models: read # Added for GitHub Models
187193

188194
steps:
@@ -196,14 +202,13 @@ steps:
196202
gh models --help >/dev/null
197203
198204
- name: Run kubebuilder alpha update
199-
# --use-gh-models: Adds an AI-generated comment to the Issue with
200-
# a summary of scaffold changes and conflict-resolution guidance (if any).
205+
# --use-gh-models: Adds an AI summary to the PR description.
201206
run: |
202207
kubebuilder alpha update \
203208
--force \
204209
--push \
205210
--restore-path .github/workflows \
206-
--open-gh-issue \
211+
--open-gh-pr \
207212
--use-gh-models
208213
```
209214

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

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ The command creates three temporary branches:
6868
- `--conflict-message`: customize the commit message when conflicts occur.
6969
- `--push`: push the result to `origin` automatically.
7070
- `--git-config`: sets git configurations.
71-
- `--open-gh-issue`: create a GitHub issue with a checklist and compare link (requires `gh`).
72-
- `--use-gh-models`: add an AI overview **comment** to that issue using `gh models`
71+
- `--open-gh-issue`: create a GitHub issue with instructions to run update locally (requires `gh`).
72+
- `--open-gh-pr`: create a GitHub pull request directly after the update (requires `gh`). **(requires branch name to start with `kubebuilder-update-from-`)**
73+
- `--use-gh-models`: add an AI summary to the PR description using `gh models` (only works with `--open-gh-pr`)
7374

7475
### Step 5: Cleanup
7576
- Once the output branch is ready, all the temporary working branches are deleted.
@@ -157,41 +158,61 @@ make manifests generate fmt vet lint-fix
157158
make all
158159
```
159160

160-
## Using with GitHub Issues (`--open-gh-issue`) and AI (`--use-gh-models`) assistance
161+
## Using with GitHub (`--open-gh-issue` / `--open-gh-pr`) and AI (`--use-gh-models`) assistance
161162

162-
Pass `--open-gh-issue` to have the command create a GitHub **Issue** in your repository
163-
to assist with the update. Also, if you also pass `--use-gh-models`, the tool posts a follow-up comment
164-
on that Issue with an AI-generated overview of the most important changes plus brief conflict-resolution
165-
guidance.
163+
### Creating GitHub Issues (`--open-gh-issue`)
166164

167-
### Examples
165+
Pass `--open-gh-issue` to have the command create a GitHub **Issue** in your repository with instructions
166+
to run the update locally. This requires minimal permissions (read repo, write issues).
168167

169-
Create an Issue with a compare link:
168+
**Example:**
170169
```shell
171170
kubebuilder alpha update --open-gh-issue
172171
```
173172

174-
Create an Issue **and** add an AI summary:
173+
The Issue will contain:
174+
- Upgrade description with release notes links
175+
- Instructions to run `alpha update` locally
176+
- Note about updating your GitHub Action workflow
177+
178+
### Creating Pull Requests Directly (`--open-gh-pr`)
179+
180+
Pass `--open-gh-pr` to have the command create a GitHub **Pull Request** directly after the update completes.
181+
This requires write permissions for contents and pull requests.
182+
183+
**Example:**
175184
```shell
176-
kubebuilder alpha update --open-gh-issue --use-gh-models
185+
kubebuilder alpha update --open-gh-pr
177186
```
178187

179-
### What you’ll see
188+
With `--use-gh-models`, the AI summary is added to the PR description:
189+
```shell
190+
kubebuilder alpha update --open-gh-pr --use-gh-models
191+
```
180192

181-
The command opens an Issue that links to the diff so you can create the PR and review it, for example:
193+
The PR will include:
194+
- Upgrade description with release notes links
195+
- Conflict warnings if any were detected
196+
- AI-generated summary of changes (if `--use-gh-models` is used)
182197

183-
<img width="638" height="482" alt="Example Issue" src="https://github.com/user-attachments/assets/589fd16b-7709-4cd5-b169-fd53d69790d4" />
198+
<aside class="warning" role="note">
199+
<p class="note-title">Security: Branch Name Validation</p>
200+
201+
For security reasons, `--open-gh-pr` can only be used with branches that start with `kubebuilder-update-from-`.
202+
This prevents accidentally creating PRs from arbitrary branches. The default output branch already follows this pattern.
184203

185-
With `--use-gh-models`, an AI comment highlights key changes and suggests how to resolve any conflicts:
204+
</aside>
186205

187-
<img width="740" height="425" alt="Comment" src="https://github.com/user-attachments/assets/fb5f214e-be0e-43b8-a3fb-b5744ac8f66e" />
206+
**Important:** `--open-gh-issue` and `--open-gh-pr` are mutually exclusive. Choose one based on your workflow and permissions.
207+
208+
### What you’ll see
188209

189-
Moreover, AI models are used to help you understand what changes are needed to keep your project up to date,
190-
and to suggest resolutions if conflicts are encountered, as in the following example:
210+
With `--use-gh-models`, AI models help you understand what changes are needed to keep your project up to date,
211+
and suggest resolutions if conflicts are encountered.
191212

192213
### Automation
193214

194-
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.
215+
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). By default, it creates Pull Requests directly, but you can use `--only-issue` to create Issues instead.
195216

196217
## Changing Extra Git configs only during the run (does not change your ~/.gitconfig)_
197218

@@ -241,13 +262,14 @@ We use that value to pick the correct CLI for re-scaffolding.
241262
| `--from-version` | Kubebuilder release to update **from** (e.g., `v4.6.0`). If unset, read from the `PROJECT` file when possible. |
242263
| `--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`. |
243264
| `--merge-message` | Custom commit message for successful merges (no conflicts). Defaults to `chore(kubebuilder): update scaffold <from> -> <to>`. |
244-
| `--open-gh-issue` | Create a GitHub issue with a pre-filled checklist and compare link after the update completes (requires `gh`). |
265+
| `--open-gh-issue` | Create a GitHub issue with instructions to run update locally (requires `gh`). Mutually exclusive with `--open-gh-pr`. |
266+
| `--open-gh-pr` | Create a GitHub pull request directly after the update completes (requires `gh`). Mutually exclusive with `--open-gh-issue`. **Security:** Branch name must start with `kubebuilder-update-from-`. |
245267
| `--output-branch` | Name of the output branch. Default: `kubebuilder-update-from-<from-version>-to-<to-version>`. |
246268
| `--push` | Push the output branch to the `origin` remote after the update completes. |
247269
| `--restore-path` | Repeatable. Paths to preserve from the base branch when squashing (e.g., `.github/workflows`). **Not supported** with `--show-commits`. |
248270
| `--show-commits` | Keep full history (do not squash). **Not compatible** with `--restore-path`. |
249271
| `--to-version` | Kubebuilder release to update **to** (e.g., `v4.7.0`). If unset, defaults to the latest available release. |
250-
| `--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. |
272+
| `--use-gh-models` | Generate an AI summary using `gh models` and add it to the PR description. Requires `gh` + `gh-models` extension. Only works with `--open-gh-pr`. |
251273
| `-h, --help` | Show help for this command. |
252274

253275
## Demonstration

internal/cli/alpha/internal/generate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ func migrateAutoUpdatePlugin(s store.Store) error {
328328
if autoUpdatePlugin.UseGHModels {
329329
args = append(args, "--use-gh-models")
330330
}
331+
if autoUpdatePlugin.OnlyIssue {
332+
args = append(args, "--only-issue")
333+
}
331334
if err = util.RunCmd("kubebuilder edit", "kubebuilder", args...); err != nil {
332335
return fmt.Errorf("failed to run edit subcommand for Auto plugin: %w", err)
333336
}

internal/cli/alpha/internal/update/helpers/open_gh_issue.go

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -36,73 +36,34 @@ const (
3636
// IssueTitleTmpl is the title template for the GitHub issue.
3737
const IssueTitleTmpl = "[Action Required] Upgrade the Scaffold: %[2]s -> %[1]s"
3838

39-
// IssueBodyTmpl is used when no conflicts are detected during the merge.
39+
// CommonDescriptionTmpl is the base description used for both issues and PRs.
40+
// Parameters: [1]=toVersion, [2]=fromVersion
4041
//
4142
//nolint:lll
42-
const IssueBodyTmpl = `## Description
43+
const CommonDescriptionTmpl = `## Description
4344
44-
Upgrade your project to use the latest scaffold changes introduced in Kubebuilder [%[1]s](https://github.com/kubernetes-sigs/kubebuilder/releases/tag/%[1]s).
45+
Upgrade project to use the scaffold changes introduced in Kubebuilder [%[1]s](https://github.com/kubernetes-sigs/kubebuilder/releases/tag/%[1]s).
4546
46-
See the release notes from [%[3]s](https://github.com/kubernetes-sigs/kubebuilder/releases/tag/%[3]s) to [%[1]s](https://github.com/kubernetes-sigs/kubebuilder/releases/tag/%[1]s) for details about the changes included in this upgrade.
47-
48-
## What to do
49-
50-
A scheduled workflow already attempted this upgrade and created the branch %[4]s to help you in this process.
51-
52-
Create a Pull Request using the URL below to review the changes:
53-
%[2]s
54-
55-
## Next steps
56-
57-
**Verify the changes**
58-
- Build the project
59-
- Run tests
60-
- Confirm everything still works
61-
62-
:book: **More info:** https://kubebuilder.io/reference/commands/alpha_update
47+
See the release notes from [%[2]s](https://github.com/kubernetes-sigs/kubebuilder/releases/tag/%[2]s) to [%[1]s](https://github.com/kubernetes-sigs/kubebuilder/releases/tag/%[1]s) for details about the changes included in this upgrade.
6348
`
6449

65-
// IssueBodyTmplWithConflicts is used when conflicts are detected during the merge.
50+
// IssueBodyTmpl is the complete issue body template.
51+
// Parameters: [1]=toVersion, [2]=fromVersion
6652
//
6753
//nolint:lll
68-
const IssueBodyTmplWithConflicts = `## Description
69-
70-
Upgrade your project to use the latest scaffold changes introduced in Kubebuilder [%[1]s](https://github.com/kubernetes-sigs/kubebuilder/releases/tag/%[1]s).
71-
72-
See the release notes from [%[3]s](https://github.com/kubernetes-sigs/kubebuilder/releases/tag/%[3]s) to [%[1]s](https://github.com/kubernetes-sigs/kubebuilder/releases/tag/%[1]s) for details about the changes included in this upgrade.
73-
54+
const IssueBodyTmpl = CommonDescriptionTmpl + `
7455
## What to do
7556
76-
A scheduled workflow already attempted this upgrade and created the branch (%[4]s) to help you in this process.
77-
78-
:warning: **Conflicts were detected during the merge.**
79-
80-
Create a Pull Request using the URL below to review the changes and resolve conflicts manually:
81-
%[2]s
57+
Run the command ` + "`alpha update`" + ` locally. This upgrades your scaffold and preserves your changes using a 3-way merge.
8258
83-
## Next steps
59+
More info: https://kubebuilder.io/reference/commands/alpha_update
8460
85-
### 1. Resolve conflicts
86-
After fixing conflicts, run:
87-
~~~bash
88-
make manifests generate fmt vet lint-fix
89-
~~~
90-
91-
### 2. Optional: work on a new branch
92-
To apply the update in a clean branch, run:
93-
~~~bash
94-
kubebuilder alpha update --output-branch my-fix-branch
95-
~~~
96-
97-
This will create a new branch (my-fix-branch) with the update applied.
98-
Resolve conflicts there, complete the merge locally, and push the branch.
61+
> Note: If you want to automate PR creation, use the latest Kubebuilder release and run: ` + "`kubebuilder edit --plugins=\"autoupdate/v1-alpha\" --force`" + `
62+
`
9963

100-
### 3. Verify the changes
101-
- Build the project
102-
- Run tests
103-
- Confirm everything still works
64+
// ConflictWarningForIssue is prepended to "What to do" section when conflicts exist.
65+
const ConflictWarningForIssue = `:warning: **Conflicts were detected during the merge.**
10466
105-
:book: **More info:** https://kubebuilder.io/reference/commands/alpha_update
10667
`
10768

10869
// AiPRPrompt is the prompt to `gh models run`.

0 commit comments

Comments
 (0)