Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 backported fixes for Makefile and release workflow #1693

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,31 @@ permissions:

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

permissions:
contents: write
# This workflow is only of value to the metal3-io/baremetal-operator repository and
# would always fail in forks
if: github.repository == 'metal3-io/baremetal-operator'
runs-on: ubuntu-latest
steps:
- name: Export RELEASE_TAG var
run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
- name: checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: Install go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '1.20'
- name: Generate release notes
run: |
make release-notes
- name: Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1
with:
draft: true
files: out/*
body_path: releasenotes/releasenotes.md
- name: Export RELEASE_TAG var
run: echo "RELEASE_TAG=${GITHUB_REF:10}" >> $GITHUB_ENV
- name: checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: Install go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: '1.20'
- name: Generate release notes
run: |
make release-notes
- name: Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1
with:
draft: true
files: out/*
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 @@ -326,15 +326,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
Loading