feat(release): add create-release-branch target#4587
feat(release): add create-release-branch target#4587radTuti wants to merge 1 commit intotigera:masterfrom
Conversation
6009212 to
bcd4ff3
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds a new release branch subcommand (and make create-release-branch target) to automate release-branch creation, while refactoring release prep to reuse the shared branch/config/commit logic.
Changes:
- Add
release branchcommand to create a release branch, update version configs, commit, tag, and optionally push. - Refactor
release prepto share common branch creation + config update logic via shared helpers. - Add new flags (
--stream,--calico-ref,--enterprise-ref) and update release documentation.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
hack/release/branch.go |
New command + shared helpers for branching/config updates/commit/tag/push. |
hack/release/prep.go |
Refactors prep to reuse shared branch/config/commit logic and uses shared cleanup. |
hack/release/main.go |
Registers the new branch command with the CLI. |
hack/release/flags.go |
Adds new flags for stream and component refs/prefix. |
hack/release/checks.go |
Adds shared validation helpers for prep/branch. |
hack/release/README.md |
Documents the new release branch command and Makefile target. |
RELEASING.md |
Updates the release-branch preparation process docs to point at the new automation. |
Makefile |
Adds create-release-branch target. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - Creates a `release-vX.Y` branch from master | ||
| - Updates `config/calico_versions.yml` and `config/enterprise_versions.yml` to point at the given refs |
There was a problem hiding this comment.
Docs say this target "Creates a release-vX.Y branch from master", but the command currently creates the branch from whatever commit you’re on when you run it (git switch -C <branch>). Either document that you must run it from master (or fetch/checkout first), or update the command to explicitly base off master/origin/master.
| @REPO=$(REPO) hack/bin/release prep | ||
|
|
||
| create-release-branch: hack/bin/release var-require-all-STREAM | ||
| RELEASE_STREAM=$(STREAM) hack/bin/release branch |
There was a problem hiding this comment.
This target only sets RELEASE_STREAM in the command environment. CALICO_REF / ENTERPRISE_REF are not passed through, so make create-release-branch STREAM=... CALICO_REF=... ENTERPRISE_REF=... (as documented) won’t actually provide those values to hack/bin/release branch unless the user separately exports them in their shell. Update the recipe to pass them (or pass --calico-ref/--enterprise-ref flags).
| RELEASE_STREAM=$(STREAM) hack/bin/release branch | |
| RELEASE_STREAM=$(STREAM) CALICO_REF=$(CALICO_REF) ENTERPRISE_REF=$(ENTERPRISE_REF) hack/bin/release branch |
| } | ||
|
|
||
| // branchBeforeCommon handles shared Before logic for both branch and prep | ||
| func branchBeforeCommon(ctx context.Context, c *cli.Command, scopeContextFn func(context.Context, *cli.Command) (context.Context, error), validateFn func(context.Context, *cli.Command) (context.Context, error)) (context.Context, error) { |
There was a problem hiding this comment.
branchCleanupFns is package-level state but isn’t cleared at the start of a command run. For consistency with buildCleanupFns (cleared in buildBefore), clear branchCleanupFns in branchBeforeCommon so stale cleanup functions can’t leak across multiple executions in the same process (e.g., tests).
| func branchBeforeCommon(ctx context.Context, c *cli.Command, scopeContextFn func(context.Context, *cli.Command) (context.Context, error), validateFn func(context.Context, *cli.Command) (context.Context, error)) (context.Context, error) { | |
| func branchBeforeCommon(ctx context.Context, c *cli.Command, scopeContextFn func(context.Context, *cli.Command) (context.Context, error), validateFn func(context.Context, *cli.Command) (context.Context, error)) (context.Context, error) { | |
| branchCleanupFns = nil |
| - Updates `config/calico_versions.yml` and `config/enterprise_versions.yml` to point at the given refs | ||
| - Runs `make fix gen-versions-calico gen-versions-enterprise` to regenerate files | ||
| - Commits the changes to the release branch | ||
| - Switches back to master, creates an empty commit, and tags it `vX.Y.0-0.dev` |
There was a problem hiding this comment.
RELEASING.md describes the dev tag format as vX.Y.0-0.dev, but the CLI default dev-tag suffix is 0-dev, which would produce vX.Y.0-0-dev. Update the documented tag format (or the default suffix) so users can follow RELEASING.md without extra flags/env vars.
| - Switches back to master, creates an empty commit, and tags it `vX.Y.0-0.dev` | |
| - Switches back to master, creates an empty commit, and tags it `vX.Y.0-0-dev` |
|
|
||
| For a major or minor release, you will need to create: | ||
| For a major or minor release, you will need to create a new `release-vX.Y` branch, a dev tag on master, | ||
| and a GitHub milestone for the next release. The `create-release-branch` Makefile target automates this: |
There was a problem hiding this comment.
This paragraph says create-release-branch automates creating a dev tag on master and the next GitHub milestone. The implementation (new release branch command) creates a tag on the new release branch and does not manage milestones. Please adjust the docs to reflect actual behavior, or update the command to do what’s described.
| and a GitHub milestone for the next release. The `create-release-branch` Makefile target automates this: | |
| and a GitHub milestone for the next release. The `create-release-branch` Makefile target automates creating | |
| the branch and dev tag; you will create the milestone manually in a later step: |
| return checkVersionMatchesGitVersion(ctx, c) | ||
| } | ||
|
|
||
| // check that at least one of the given flags is explicitly set and non-empty. |
There was a problem hiding this comment.
checkAtLeastOneOfFlags comment says it checks flags are "explicitly set", but the implementation only checks for a non-empty string value. Either update the comment to match behavior, or use the CLI API (e.g., an IsSet-style check) so defaults/non-empty values don’t count as "explicit".
| // check that at least one of the given flags is explicitly set and non-empty. | |
| // check that at least one of the given flags is set to a non-empty value. |
| // We are now on the release branch with config changes committed. | ||
|
|
||
| // Switch back to master to create the dev tag. | ||
| // The dev tag goes on an empty commit on master so that git describe --tags | ||
| // produces sensible versions for subsequent master commits. |
There was a problem hiding this comment.
devTag is constructed using --dev-tag-suffix (default currently 0-dev), but the updated release docs describe tags like vX.Y.0-0.dev. As-is, the default tag created by this command will be vX.Y.0-0-dev, which won’t match the documented format. Align the default suffix and/or update the docs so the generated tag format is consistent.
| release-prep: hack/bin/release hack/bin/gh var-require-all-VERSION var-require-one-of-CALICO_VERSION-ENTERPRISE_VERSION | ||
| @REPO=$(REPO) hack/bin/release prep | ||
|
|
||
| create-release-branch: hack/bin/release var-require-all-STREAM |
There was a problem hiding this comment.
The new create-release-branch target only requires STREAM, but release branch errors unless both CALICO_REF and ENTERPRISE_REF are set (unless validations are skipped). Consider adding var-require-all-CALICO_REF-ENTERPRISE_REF (or similar) to fail fast with a Make-level error, consistent with release-prep.
| create-release-branch: hack/bin/release var-require-all-STREAM | |
| create-release-branch: hack/bin/release var-require-all-STREAM var-require-all-CALICO_REF-ENTERPRISE_REF |
| first release version for the new minor version. | ||
| | Env var | Flag | Description | | ||
| | --------------------------- | ------------------------- | ----------------------------------------------------------------- | | ||
| | `STREAM` (required) | `--stream` | Release stream, e.g., `v1.43` | |
There was a problem hiding this comment.
The env var for --stream is RELEASE_STREAM (per the flag definition), but this table lists STREAM. STREAM is a Makefile variable, not an env var consumed by the CLI. Please change the table entry to RELEASE_STREAM to avoid confusion when calling the CLI directly.
| | `STREAM` (required) | `--stream` | Release stream, e.g., `v1.43` | | |
| | `RELEASE_STREAM` (required) | `--stream` | Release stream, e.g., `v1.43` | |
| var branchAction = cli.ActionFunc(func(ctx context.Context, c *cli.Command) error { | ||
| stream := c.String(streamFlag.Name) | ||
| branchName := ctx.Value(branchNameCtxKey).(string) | ||
| remote := c.String(gitRemoteFlag.Name) | ||
|
|
||
| if _, err := branchActionCommon(ctx, c, fmt.Sprintf("build: update config for %s", stream)); err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
New release branch command adds non-trivial git/tag/push behavior, but there are no unit tests covering the new validation/context wiring (e.g., validateBranchRefs, branch name derivation from --stream/--release-branch-prefix, and behavior when --local is set). Since hack/release already has UTs, please add focused tests (mocking git helpers where needed) to prevent regressions.
Summary
release branchCLI command for automated release branch creationcreate-release-branchMakefile targetprepcommand to share branch creation logic withbranchviabranchBeforeCommonandbranchActionCommonUsage
Or directly:
Use
--localto skip pushing to remote.