Skip to content

Commit

Permalink
Add missing release targets and tools
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Hros <[email protected]>
  • Loading branch information
chess-knight committed Jan 8, 2024
1 parent e180c9e commit 4339be1
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ clean-bin: ## Remove all generated helper binaries
rm -rf $(BIN_DIR)
rm -rf $(TOOLS_BIN_DIR)

.PHONY: clean-release
clean-release: ## Remove the release folder
rm -rf $(RELEASE_DIR)

.PHONY: clean-release-git
clean-release-git: ## Restores the git files usually modified during a release
git restore ./*manager_config_patch.yaml ./*manager_pull_policy.yaml

##@ Build

.PHONY: build
Expand Down Expand Up @@ -443,8 +451,7 @@ release: clean-release ## Builds and push container images using the latest git
@if ! [ -z "$$(git status --porcelain)" ]; then echo "Your local git repository contains uncommitted changes, use git clean before proceeding."; exit 1; fi
git checkout "${RELEASE_TAG}"
# Set the manifest image to the production bucket.
$(MAKE) set-manifest-image MANIFEST_IMG=$(IMAGE_PREFIX)/cso MANIFEST_TAG=$(RELEASE_TAG) TARGET_RESOURCE="./config/default/manager_config_patch.yaml"
$(MAKE) set-manifest-image MANIFEST_IMG=$(IMAGE_PREFIX)/cspo MANIFEST_TAG=$(RELEASE_TAG)
$(MAKE) set-manifest-image MANIFEST_IMG=$(IMAGE_PREFIX)/cspo MANIFEST_TAG=$(RELEASE_TAG) TARGET_RESOURCE="./config/default/manager_config_patch.yaml"
$(MAKE) set-manifest-pull-policy TARGET_RESOURCE="./config/default/manager_pull_policy.yaml"
## Build the manifests
$(MAKE) release-manifests clean-release-git
Expand Down
209 changes: 209 additions & 0 deletions hack/tools/release/notes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
// +build tools

/*
Copyright 2022 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.
*/

//go:build tools
package main

import (
"bytes"
"flag"
"fmt"
"os"
"os/exec"
"strings"
)

/*
This tool prints all the titles of all PRs from previous release to HEAD.
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,
}

fromTag = flag.String("from", "", "The tag or commit to start from.")
)

func main() {
flag.Parse()
os.Exit(run())
}

func lastTag() string {
if fromTag != nil && *fromTag != "" {
return *fromTag
}
cmd := exec.Command("git", "describe", "--tags", "--abbrev=0")
out, err := cmd.Output()
if err != nil {
return firstCommit()
}
return string(bytes.TrimSpace(out))
}

func firstCommit() string {
cmd := exec.Command("git", "rev-list", "--max-parents=0", "HEAD")
out, err := cmd.Output()
if err != nil {
return "UNKNOWN"
}
return string(bytes.TrimSpace(out))
}

func run() int {
lastTag := lastTag()
cmd := exec.Command("git", "rev-list", lastTag+"..HEAD", "--merges", "--pretty=format:%B") //nolint:gosec

merges := map[string][]string{
features: {},
bugs: {},
documentation: {},
warning: {},
other: {},
unknown: {},
}
out, err := cmd.CombinedOutput()
if err != nil {
fmt.Println("Error")
fmt.Println(string(out))
return 1
}

commits := []*commit{}
outLines := strings.Split(string(out), "\n")
for _, line := range outLines {
line = strings.TrimSpace(line)
last := len(commits) - 1
switch {
case strings.HasPrefix(line, "commit"):
commits = append(commits, &commit{})
case strings.HasPrefix(line, "Merge"):
commits[last].merge = line
continue
case line == "":
default:
commits[last].body = line
}
}

for _, c := range commits {
body := strings.TrimSpace(c.body)
var key, prNumber, fork string
switch {
case strings.HasPrefix(body, ":sparkles:"), strings.HasPrefix(body, "✨"):
key = features
body = strings.TrimPrefix(body, ":sparkles:")
body = strings.TrimPrefix(body, "✨")
case strings.HasPrefix(body, ":bug:"), strings.HasPrefix(body, "🐛"):
key = bugs
body = strings.TrimPrefix(body, ":bug:")
body = strings.TrimPrefix(body, "🐛")
case strings.HasPrefix(body, ":book:"), strings.HasPrefix(body, "📖"):
key = documentation
body = strings.TrimPrefix(body, ":book:")
body = strings.TrimPrefix(body, "📖")
if strings.Contains(body, "CAEP") || strings.Contains(body, "proposal") {
key = proposals
}
case strings.HasPrefix(body, ":seedling:"), strings.HasPrefix(body, "🌱"):
key = other
body = strings.TrimPrefix(body, ":seedling:")
body = strings.TrimPrefix(body, "🌱")
case strings.HasPrefix(body, ":warning:"), strings.HasPrefix(body, "⚠️"):
key = warning
body = strings.TrimPrefix(body, ":warning:")
body = strings.TrimPrefix(body, "⚠️")
default:
key = unknown
}

body = strings.TrimSpace(body)
if body == "" {
continue
}
body = fmt.Sprintf("- %s", body)
_, _ = fmt.Sscanf(c.merge, "Merge pull request %s from %s", &prNumber, &fork)
if key == documentation {
merges[key] = append(merges[key], prNumber)
continue
}
merges[key] = append(merges[key], formatMerge(body, prNumber))
}

// TODO Turn this into a link (requires knowing the project name + organization)
fmt.Printf("Changes since %v\n---\n", lastTag)

for _, key := range outputOrder {
mergeslice := merges[key]
if len(mergeslice) == 0 {
continue
}

switch key {
case documentation:
fmt.Printf(
":book: Additionally, there have been %d contributions to our documentation and book. (%s) \n\n",
len(mergeslice),
strings.Join(mergeslice, ", "),
)
default:
fmt.Println("## " + key)
for _, merge := range mergeslice {
fmt.Println(merge)
}
fmt.Println()
}
}

fmt.Println("")
fmt.Println("_Thanks to all our contributors!_ 😊")

return 0
}

type commit struct {
merge string
body string
}

func formatMerge(line, prNumber string) string {
if prNumber == "" {
return line
}
return fmt.Sprintf("%s (%s)", line, prNumber)
}

0 comments on commit 4339be1

Please sign in to comment.