diff --git a/hack/tools/release/internal/constants.go b/hack/tools/release/internal/constants.go new file mode 100644 index 000000000000..5f2446676d09 --- /dev/null +++ b/hack/tools/release/internal/constants.go @@ -0,0 +1,42 @@ +/* +Copyright 2021 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package release is the package for the release notes generator. +package release + +// Common tags used by PRs. +const ( + // Features is the tag used for PRs that add new features. + Features = ":sparkles: New Features" + + // Bugs is the tag used for PRs that fix bugs. + Bugs = ":bug: Bug Fixes" + + // Documentation is the tag used for PRs that update documentation. + Documentation = ":book: Documentation" + + // Proposals is the tag used for PRs that add new proposals. + Proposals = ":memo: Proposals" + + // Warning is the tag used for PRs that add breaking changes. + Warning = ":warning: Breaking Changes" + + // Other is the tag used for PRs that don't fit in any other category. + Other = ":seedling: Others" + + // Unknown is the tag used for PRs that need to be sorted by hand. + Unknown = ":question: Sort these by hand" +) diff --git a/hack/tools/release/notes/main.go b/hack/tools/release/notes/main.go index 70b2d28a770f..79f51c35128d 100644 --- a/hack/tools/release/notes/main.go +++ b/hack/tools/release/notes/main.go @@ -33,6 +33,8 @@ import ( "strings" "sync" "time" + + release "sigs.k8s.io/cluster-api/hack/tools/release/internal" ) /* @@ -42,25 +44,15 @@ This needs to be run *before* a tag is created. Use these as the base of your release notes. */ -const ( - features = ":sparkles: New Features" - bugs = ":bug: Bug Fixes" - documentation = ":book: Documentation" - proposals = ":memo: Proposals" - warning = ":warning: Breaking Changes" - other = ":seedling: Others" - unknown = ":question: Sort these by hand" -) - var ( outputOrder = []string{ - proposals, - warning, - features, - bugs, - other, - documentation, - unknown, + release.Proposals, + release.Warning, + release.Features, + release.Bugs, + release.Other, + release.Documentation, + release.Unknown, } repo = flag.String("repository", "kubernetes-sigs/cluster-api", "The repo to run the tool from.") @@ -231,12 +223,12 @@ func run() int { } merges := map[string][]string{ - features: {}, - bugs: {}, - documentation: {}, - warning: {}, - other: {}, - unknown: {}, + release.Features: {}, + release.Bugs: {}, + release.Documentation: {}, + release.Warning: {}, + release.Other: {}, + release.Unknown: {}, } out, err := cmd.CombinedOutput() if err != nil { @@ -300,7 +292,7 @@ func run() int { continue } - if result.prEntry.section == documentation { + if result.prEntry.section == release.Documentation { merges[result.prEntry.section] = append(merges[result.prEntry.section], result.prEntry.prNumber) } else { merges[result.prEntry.section] = append(merges[result.prEntry.section], result.prEntry.title) @@ -327,17 +319,17 @@ func run() int { } else if count > 1 { fmt.Printf("- %d new commits merged\n", count) } - if count := len(merges[warning]); count == 1 { + if count := len(merges[release.Warning]); count == 1 { fmt.Println("- 1 breaking change :warning:") } else if count > 1 { fmt.Printf("- %d breaking changes :warning:\n", count) } - if count := len(merges[features]); count == 1 { + if count := len(merges[release.Features]); count == 1 { fmt.Println("- 1 feature addition ✨") } else if count > 1 { fmt.Printf("- %d feature additions ✨\n", count) } - if count := len(merges[bugs]); count == 1 { + if count := len(merges[release.Bugs]); count == 1 { fmt.Println("- 1 bug fixed 🐛") } else if count > 1 { fmt.Printf("- %d bugs fixed 🐛\n", count) @@ -351,7 +343,7 @@ func run() int { } switch key { - case documentation: + case release.Documentation: sort.Strings(mergeslice) if len(mergeslice) == 1 { fmt.Printf( @@ -480,25 +472,25 @@ func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) { switch { case strings.HasPrefix(entry.title, ":sparkles:"), strings.HasPrefix(entry.title, "✨"): - entry.section = features + entry.section = release.Features entry.title = removePrefixes(entry.title, []string{":sparkles:", "✨"}) case strings.HasPrefix(entry.title, ":bug:"), strings.HasPrefix(entry.title, "🐛"): - entry.section = bugs + entry.section = release.Bugs entry.title = removePrefixes(entry.title, []string{":bug:", "🐛"}) case strings.HasPrefix(entry.title, ":book:"), strings.HasPrefix(entry.title, "📖"): - entry.section = documentation + entry.section = release.Documentation entry.title = removePrefixes(entry.title, []string{":book:", "📖"}) if strings.Contains(entry.title, "CAEP") || strings.Contains(entry.title, "proposal") { - entry.section = proposals + entry.section = release.Proposals } case strings.HasPrefix(entry.title, ":seedling:"), strings.HasPrefix(entry.title, "🌱"): - entry.section = other + entry.section = release.Other entry.title = removePrefixes(entry.title, []string{":seedling:", "🌱"}) case strings.HasPrefix(entry.title, ":warning:"), strings.HasPrefix(entry.title, "⚠️"): - entry.section = warning + entry.section = release.Warning entry.title = removePrefixes(entry.title, []string{":warning:", "⚠️"}) default: - entry.section = unknown + entry.section = release.Unknown } // If the area label indicates documentation, use documentation as the section @@ -506,7 +498,7 @@ func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) { // tends to be more accurate than the emoji (data point observed by the release team). // We handle this after the switch statement to make sure we remove all emoji prefixes. if area == documentationAreaLabel { - entry.section = documentation + entry.section = release.Documentation } entry.title = strings.TrimSpace(entry.title) diff --git a/hack/tools/release/weekly/main.go b/hack/tools/release/weekly/main.go index 6c375aa19b2b..bedbe2edc7bb 100644 --- a/hack/tools/release/weekly/main.go +++ b/hack/tools/release/weekly/main.go @@ -28,6 +28,8 @@ import ( "regexp" "strings" "time" + + release "sigs.k8s.io/cluster-api/hack/tools/release/internal" ) /* @@ -37,25 +39,15 @@ This needs to be run *before* a tag is created. Use these as the base of your release notes. */ -const ( - features = "Feature additions :sparkles:" - bugs = "Bug Fixes :bug: " - documentation = "Documentation :book: " - proposals = "Proposals :memo: " - warning = "Breaking Changes :warning: " - other = "Others :seedling: " - unknown = "Sort these by hand :question: " -) - var ( outputOrder = []string{ - proposals, - warning, - features, - bugs, - other, - documentation, - unknown, + release.Proposals, + release.Warning, + release.Features, + release.Bugs, + release.Other, + release.Documentation, + release.Unknown, } from = flag.String("from", "", "Include commits starting from and including this date. Accepts format: YYYY-MM-DD") @@ -101,12 +93,12 @@ func run() int { cmd = exec.Command("git", "rev-list", "HEAD", "--since=\""+*from+" 00:00:01\"", "--until=\""+lastDay+" 23:59:59\"", "--merges", "--pretty=format:%B") //nolint:gosec merges := map[string][]string{ - features: {}, - bugs: {}, - documentation: {}, - warning: {}, - other: {}, - unknown: {}, + release.Features: {}, + release.Bugs: {}, + release.Documentation: {}, + release.Warning: {}, + release.Other: {}, + release.Unknown: {}, } out, err := cmd.CombinedOutput() if err != nil { @@ -138,30 +130,30 @@ func run() int { var key, prNumber, fork string switch { case strings.HasPrefix(body, ":sparkles:"), strings.HasPrefix(body, "✨"): - key = features + key = release.Features body = strings.TrimPrefix(body, ":sparkles:") body = strings.TrimPrefix(body, "✨") case strings.HasPrefix(body, ":bug:"), strings.HasPrefix(body, "🐛"): - key = bugs + key = release.Bugs body = strings.TrimPrefix(body, ":bug:") body = strings.TrimPrefix(body, "🐛") case strings.HasPrefix(body, ":book:"), strings.HasPrefix(body, "📖"): - key = documentation + key = release.Documentation body = strings.TrimPrefix(body, ":book:") body = strings.TrimPrefix(body, "📖") if strings.Contains(body, "CAEP") || strings.Contains(body, "proposal") { - key = proposals + key = release.Proposals } case strings.HasPrefix(body, ":seedling:"), strings.HasPrefix(body, "🌱"): - key = other + key = release.Other body = strings.TrimPrefix(body, ":seedling:") body = strings.TrimPrefix(body, "🌱") case strings.HasPrefix(body, ":warning:"), strings.HasPrefix(body, "⚠️"): - key = warning + key = release.Warning body = strings.TrimPrefix(body, ":warning:") body = strings.TrimPrefix(body, "⚠️") default: - key = unknown + key = release.Unknown } body = strings.TrimSpace(body) @@ -170,7 +162,7 @@ func run() int { } body = fmt.Sprintf("\t - %s", body) _, _ = fmt.Sscanf(c.merge, "Merge pull request %s from %s", &prNumber, &fork) - if key == documentation { + if key == release.Documentation { merges[key] = append(merges[key], prNumber) continue } @@ -188,10 +180,10 @@ func run() int { } switch key { - case documentation: + case release.Documentation: fmt.Printf("- %d Documentation and book contributions :book: \n\n", len(mergeslice)) - case other: - fmt.Printf("- %d Other changes :seedling:\n\n", len(merges[other])) + case release.Other: + fmt.Printf("- %d Other changes :seedling:\n\n", len(merges[release.Other])) default: fmt.Printf("- %d %s\n", len(merges[key]), key) for _, merge := range mergeslice {