Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 4339be1

Browse files
committed
Add missing release targets and tools
Signed-off-by: Roman Hros <[email protected]>
1 parent e180c9e commit 4339be1

File tree

2 files changed

+218
-2
lines changed

2 files changed

+218
-2
lines changed

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ clean-bin: ## Remove all generated helper binaries
206206
rm -rf $(BIN_DIR)
207207
rm -rf $(TOOLS_BIN_DIR)
208208

209+
.PHONY: clean-release
210+
clean-release: ## Remove the release folder
211+
rm -rf $(RELEASE_DIR)
212+
213+
.PHONY: clean-release-git
214+
clean-release-git: ## Restores the git files usually modified during a release
215+
git restore ./*manager_config_patch.yaml ./*manager_pull_policy.yaml
216+
209217
##@ Build
210218

211219
.PHONY: build
@@ -443,8 +451,7 @@ release: clean-release ## Builds and push container images using the latest git
443451
@if ! [ -z "$$(git status --porcelain)" ]; then echo "Your local git repository contains uncommitted changes, use git clean before proceeding."; exit 1; fi
444452
git checkout "${RELEASE_TAG}"
445453
# Set the manifest image to the production bucket.
446-
$(MAKE) set-manifest-image MANIFEST_IMG=$(IMAGE_PREFIX)/cso MANIFEST_TAG=$(RELEASE_TAG) TARGET_RESOURCE="./config/default/manager_config_patch.yaml"
447-
$(MAKE) set-manifest-image MANIFEST_IMG=$(IMAGE_PREFIX)/cspo MANIFEST_TAG=$(RELEASE_TAG)
454+
$(MAKE) set-manifest-image MANIFEST_IMG=$(IMAGE_PREFIX)/cspo MANIFEST_TAG=$(RELEASE_TAG) TARGET_RESOURCE="./config/default/manager_config_patch.yaml"
448455
$(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./config/default/manager_pull_policy.yaml"
449456
## Build the manifests
450457
$(MAKE) release-manifests clean-release-git

hack/tools/release/notes.go

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
// +build tools
2+
3+
/*
4+
Copyright 2022 The Kubernetes Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
//go:build tools
20+
package main
21+
22+
import (
23+
"bytes"
24+
"flag"
25+
"fmt"
26+
"os"
27+
"os/exec"
28+
"strings"
29+
)
30+
31+
/*
32+
This tool prints all the titles of all PRs from previous release to HEAD.
33+
This needs to be run *before* a tag is created.
34+
35+
Use these as the base of your release notes.
36+
*/
37+
38+
const (
39+
features = ":sparkles: New Features"
40+
bugs = ":bug: Bug Fixes"
41+
documentation = ":book: Documentation"
42+
proposals = ":memo: Proposals"
43+
warning = ":warning: Breaking Changes"
44+
other = ":seedling: Others"
45+
unknown = ":question: Sort these by hand"
46+
)
47+
48+
var (
49+
outputOrder = []string{
50+
proposals,
51+
warning,
52+
features,
53+
bugs,
54+
other,
55+
documentation,
56+
unknown,
57+
}
58+
59+
fromTag = flag.String("from", "", "The tag or commit to start from.")
60+
)
61+
62+
func main() {
63+
flag.Parse()
64+
os.Exit(run())
65+
}
66+
67+
func lastTag() string {
68+
if fromTag != nil && *fromTag != "" {
69+
return *fromTag
70+
}
71+
cmd := exec.Command("git", "describe", "--tags", "--abbrev=0")
72+
out, err := cmd.Output()
73+
if err != nil {
74+
return firstCommit()
75+
}
76+
return string(bytes.TrimSpace(out))
77+
}
78+
79+
func firstCommit() string {
80+
cmd := exec.Command("git", "rev-list", "--max-parents=0", "HEAD")
81+
out, err := cmd.Output()
82+
if err != nil {
83+
return "UNKNOWN"
84+
}
85+
return string(bytes.TrimSpace(out))
86+
}
87+
88+
func run() int {
89+
lastTag := lastTag()
90+
cmd := exec.Command("git", "rev-list", lastTag+"..HEAD", "--merges", "--pretty=format:%B") //nolint:gosec
91+
92+
merges := map[string][]string{
93+
features: {},
94+
bugs: {},
95+
documentation: {},
96+
warning: {},
97+
other: {},
98+
unknown: {},
99+
}
100+
out, err := cmd.CombinedOutput()
101+
if err != nil {
102+
fmt.Println("Error")
103+
fmt.Println(string(out))
104+
return 1
105+
}
106+
107+
commits := []*commit{}
108+
outLines := strings.Split(string(out), "\n")
109+
for _, line := range outLines {
110+
line = strings.TrimSpace(line)
111+
last := len(commits) - 1
112+
switch {
113+
case strings.HasPrefix(line, "commit"):
114+
commits = append(commits, &commit{})
115+
case strings.HasPrefix(line, "Merge"):
116+
commits[last].merge = line
117+
continue
118+
case line == "":
119+
default:
120+
commits[last].body = line
121+
}
122+
}
123+
124+
for _, c := range commits {
125+
body := strings.TrimSpace(c.body)
126+
var key, prNumber, fork string
127+
switch {
128+
case strings.HasPrefix(body, ":sparkles:"), strings.HasPrefix(body, "✨"):
129+
key = features
130+
body = strings.TrimPrefix(body, ":sparkles:")
131+
body = strings.TrimPrefix(body, "✨")
132+
case strings.HasPrefix(body, ":bug:"), strings.HasPrefix(body, "🐛"):
133+
key = bugs
134+
body = strings.TrimPrefix(body, ":bug:")
135+
body = strings.TrimPrefix(body, "🐛")
136+
case strings.HasPrefix(body, ":book:"), strings.HasPrefix(body, "📖"):
137+
key = documentation
138+
body = strings.TrimPrefix(body, ":book:")
139+
body = strings.TrimPrefix(body, "📖")
140+
if strings.Contains(body, "CAEP") || strings.Contains(body, "proposal") {
141+
key = proposals
142+
}
143+
case strings.HasPrefix(body, ":seedling:"), strings.HasPrefix(body, "🌱"):
144+
key = other
145+
body = strings.TrimPrefix(body, ":seedling:")
146+
body = strings.TrimPrefix(body, "🌱")
147+
case strings.HasPrefix(body, ":warning:"), strings.HasPrefix(body, "⚠️"):
148+
key = warning
149+
body = strings.TrimPrefix(body, ":warning:")
150+
body = strings.TrimPrefix(body, "⚠️")
151+
default:
152+
key = unknown
153+
}
154+
155+
body = strings.TrimSpace(body)
156+
if body == "" {
157+
continue
158+
}
159+
body = fmt.Sprintf("- %s", body)
160+
_, _ = fmt.Sscanf(c.merge, "Merge pull request %s from %s", &prNumber, &fork)
161+
if key == documentation {
162+
merges[key] = append(merges[key], prNumber)
163+
continue
164+
}
165+
merges[key] = append(merges[key], formatMerge(body, prNumber))
166+
}
167+
168+
// TODO Turn this into a link (requires knowing the project name + organization)
169+
fmt.Printf("Changes since %v\n---\n", lastTag)
170+
171+
for _, key := range outputOrder {
172+
mergeslice := merges[key]
173+
if len(mergeslice) == 0 {
174+
continue
175+
}
176+
177+
switch key {
178+
case documentation:
179+
fmt.Printf(
180+
":book: Additionally, there have been %d contributions to our documentation and book. (%s) \n\n",
181+
len(mergeslice),
182+
strings.Join(mergeslice, ", "),
183+
)
184+
default:
185+
fmt.Println("## " + key)
186+
for _, merge := range mergeslice {
187+
fmt.Println(merge)
188+
}
189+
fmt.Println()
190+
}
191+
}
192+
193+
fmt.Println("")
194+
fmt.Println("_Thanks to all our contributors!_ 😊")
195+
196+
return 0
197+
}
198+
199+
type commit struct {
200+
merge string
201+
body string
202+
}
203+
204+
func formatMerge(line, prNumber string) string {
205+
if prNumber == "" {
206+
return line
207+
}
208+
return fmt.Sprintf("%s (%s)", line, prNumber)
209+
}

0 commit comments

Comments
 (0)