From 758b6100db1082585381ef059d614d7ab563f820 Mon Sep 17 00:00:00 2001 From: hellez Date: Tue, 26 Mar 2024 23:10:53 +0100 Subject: [PATCH] Determine release type from tag to also handle beta releases Signed-off-by: Tobias Giese --- docs/release/release-tasks.md | 7 +------ hack/tools/release/notes/main.go | 26 +++++++++++++++++++++++--- hack/tools/release/notes/print.go | 6 +++--- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/docs/release/release-tasks.md b/docs/release/release-tasks.md index 59c852ba60bc..fab80ac48627 100644 --- a/docs/release/release-tasks.md +++ b/docs/release/release-tasks.md @@ -364,15 +364,10 @@ The goal of this task is to keep the CAPI community updated on recent PRs that h ```bash # RELEASE_TAG should be the new desired tag (note: at this point the tag does not yet exist). + # Can be also used for pre-releases. The warning banner for RC and beta releases will be determined automatically. RELEASE_TAG=v1.6.x make release-notes ``` - If this is a beta or RC release, add the --pre-release-version flag - ```bash - make release-notes-tool - ./bin/notes --release=${RELEASE_TAG} --pre-release-version > CHANGELOG/${RELEASE_TAG}.md - ``` - 1. This will generate a new release notes file at `CHANGELOG/.md`. Finalize the release notes: - [ ] Update the `Kubernetes version support section`. If this is a patch release you can most probably copy the same values from the previous patch release notes. Except if this is the release where a new Kubernetes version support is added.
**Note**: Check our [Kubernetes support policy](https://cluster-api.sigs.k8s.io/reference/versions.html#supported-kubernetes-versions) in the CAPI book. In case of doubt, reach out to the current release lead. diff --git a/hack/tools/release/notes/main.go b/hack/tools/release/notes/main.go index 711336cbc1b5..8e0227127545 100644 --- a/hack/tools/release/notes/main.go +++ b/hack/tools/release/notes/main.go @@ -52,7 +52,6 @@ type notesCmdConfig struct { newTag string branch string prefixAreaLabel bool - preReleaseVersion bool deprecation bool addKubernetesVersionSupport bool } @@ -67,7 +66,6 @@ func readCmdConfig() *notesCmdConfig { flag.StringVar(&config.newTag, "release", "", "The tag for the new release.") flag.BoolVar(&config.prefixAreaLabel, "prefix-area-label", true, "If enabled, will prefix the area label.") - flag.BoolVar(&config.preReleaseVersion, "pre-release-version", false, "If enabled, will add a pre-release warning header. (default false)") flag.BoolVar(&config.deprecation, "deprecation", true, "If enabled, will add a templated deprecation warning header.") flag.BoolVar(&config.addKubernetesVersionSupport, "add-kubernetes-version-support", true, "If enabled, will add the Kubernetes version support header.") @@ -103,7 +101,7 @@ func (cmd *notesCmd) run() error { from, to := parseRef(cmd.config.fromRef), parseRef(cmd.config.toRef) printer := newReleaseNotesPrinter(cmd.config.repo, from.value) - printer.isPreRelease = cmd.config.preReleaseVersion + printer.releaseType = releaseTypeFromNewTag(cmd.config.newTag) printer.printDeprecation = cmd.config.deprecation printer.printKubernetesSupport = cmd.config.addKubernetesVersionSupport @@ -117,6 +115,28 @@ func (cmd *notesCmd) run() error { return generator.run() } +func releaseTypeFromNewTag(newTagConfig string) string { + // Error handling can be ignored as the version has been validated in computeConfigDefaults already. + newTag, _ := semver.ParseTolerant(newTagConfig) + + // Ensures version format includes exactly two dot-separated pre-release identifiers (e.g., v1.7.0-beta.1). + // Versions with a single pre-release identifier (e.g., v1.7.0-beta or v1.7.0-beta1) are NOT supported. + // Return early if the count of pre-release identifiers is not 2. + if len(newTag.Pre) != 2 { + return "" + } + + // Only allow RC and beta releases. More types must be defined here. + // If a new type is not defined, no warning banner will be printed. + switch newTag.Pre[0].VersionStr { + case "rc": + return "RELEASE CANDIDATE" + case "beta": + return "BETA RELEASE" + } + return "" +} + func ensureInstalledDependencies() error { if !commandExists("gh") { return errors.New("gh GitHub CLI not available. GitHub CLI is required to be present in the PATH. Refer to https://cli.github.com/ for installation") diff --git a/hack/tools/release/notes/print.go b/hack/tools/release/notes/print.go index 2c0a4affbe83..dc72d9d0c9cc 100644 --- a/hack/tools/release/notes/print.go +++ b/hack/tools/release/notes/print.go @@ -41,7 +41,7 @@ var defaultOutputOrder = []string{ // the right format for the release notes. type releaseNotesPrinter struct { outputOrder []string - isPreRelease bool + releaseType string printKubernetesSupport bool printDeprecation bool fromTag string @@ -75,8 +75,8 @@ func (p *releaseNotesPrinter) print(entries []notesEntry, commitsInRelease int, } } - if p.isPreRelease { - fmt.Printf("🚨 This is a RELEASE CANDIDATE. Use it only for testing purposes. If you find any bugs, file an [issue](https://github.com/%s/issues/new).\n", p.repo) + if p.releaseType != "" { + fmt.Printf("🚨 This is a %s. Use it only for testing purposes. If you find any bugs, file an [issue](https://github.com/%s/issues/new).\n", p.releaseType, p.repo) } if p.printKubernetesSupport {