Skip to content

Commit

Permalink
Merge pull request metal3-io#1636 from Nordix/tuomo/fix-release-note-…
Browse files Browse the repository at this point in the history
…generator

🌱 add support for beta/rc releases in release notes
  • Loading branch information
metal3-io-bot authored Mar 26, 2024
2 parents 4f45b88 + 1ff7cb8 commit d46e201
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions: {}

jobs:
build:
name: release
name: tag release
runs-on: ubuntu-latest

permissions:
Expand All @@ -36,4 +36,4 @@ jobs:
with:
draft: true
files: out/*
body_path: releasenotes/releasenotes.md
body_path: releasenotes/${{ env.RELEASE_TAG }}.md
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,15 @@ mod: ## Clean up go module settings
## Release
## --------------------------------------
RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null)
PREVIOUS_TAG ?= $(shell git tag -l | grep -B 1 "^$(RELEASE_TAG)" | head -n 1)
RELEASE_NOTES_DIR := releasenotes
PREVIOUS_TAG ?= $(shell git tag -l | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+" | sort -V | grep -B1 $(RELEASE_TAG) | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$$" | head -n 1 2>/dev/null)

$(RELEASE_NOTES_DIR):
mkdir -p $(RELEASE_NOTES_DIR)/

.PHONY: release-notes
release-notes: $(RELEASE_NOTES_DIR)
go run ./hack/tools/release_notes.go --from=$(PREVIOUS_TAG) > $(RELEASE_NOTES_DIR)/releasenotes.md
go run ./hack/tools/release/notes.go --from=$(PREVIOUS_TAG) > $(RELEASE_NOTES_DIR)/$(RELEASE_TAG).md

go-version: ## Print the go version we use to compile our binaries and images
@echo $(GO_VERSION)
Expand Down
44 changes: 39 additions & 5 deletions hack/tools/release_notes.go → hack/tools/release/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const (
superseded = ":recycle: Superseded or Reverted"
)

const (
warningTemplate = ":rotating_light: This is a %s. Use it only for testing purposes. If you find any bugs, file an [issue](https://github.com/metal3-io/baremetal-operator/issues/new/).\n\n"
)

var (
outputOrder = []string{
warning,
Expand Down Expand Up @@ -85,6 +89,14 @@ func lastTag() string {
return string(bytes.TrimSpace(out))
}

func isBeta(tag string) bool {
return strings.Contains(tag, "-beta.")
}

func isRC(tag string) bool {
return strings.Contains(tag, "-rc.")
}

func firstCommit() string {
cmd := exec.Command("git", "rev-list", "--max-parents=0", "HEAD")
out, err := cmd.Output()
Expand All @@ -97,7 +109,7 @@ func firstCommit() string {
func run() int {
lastTag := lastTag()
latestTag := latestTag()
cmd := exec.Command("git", "rev-list", lastTag+"..HEAD", "--merges", "--pretty=format:%B")
cmd := exec.Command("git", "rev-list", lastTag+"..HEAD", "--merges", "--pretty=format:%B") // #nosec G204:gosec

merges := map[string][]string{
features: {},
Expand Down Expand Up @@ -174,12 +186,15 @@ func run() int {
merges[key] = append(merges[key], formatMerge(body, prNumber))
}

// Add empty superseded section
merges[superseded] = append(merges[superseded], "- `<insert superseded bumps and reverts here>`")
// Add empty superseded section, if not beta/rc, we don't cleanup those notes
if !isBeta(latestTag) && !isRC(latestTag) {
merges[superseded] = append(merges[superseded], "- `<insert superseded bumps and reverts here>`")
}

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

// print the changes by category
for _, key := range outputOrder {
mergeslice := merges[key]
if len(mergeslice) > 0 {
Expand All @@ -189,10 +204,29 @@ func run() int {
}
fmt.Println()
}

// if we're doing beta/rc, print breaking changes and hide the rest of the changes
if key == warning {
if isBeta(latestTag) {
fmt.Printf(warningTemplate, "BETA RELEASE")
}
if isRC(latestTag) {
fmt.Printf(warningTemplate, "RELEASE CANDIDATE")
}
if isBeta(latestTag) || isRC(latestTag) {
fmt.Printf("<details>\n")
fmt.Printf("<summary>More details about the release</summary>\n\n")
}
}
}

// then close the details if we had it open
if isBeta(latestTag) || isRC(latestTag) {
fmt.Printf("</details>\n\n")
}

fmt.Printf("The container image for this release is: %v\n", latestTag)
fmt.Println("\nThanks to all our contributors! 😊")
fmt.Printf("The image for this release is: %v\n", latestTag)
fmt.Println("\n_Thanks to all our contributors!_ 😊")

return 0
}
Expand Down

0 comments on commit d46e201

Please sign in to comment.