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

Automatically generates release note and binaries on release #126

Merged
merged 9 commits into from
Jan 5, 2023
2 changes: 1 addition & 1 deletion .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: "Build artifacts"
run: make distclean build-reproducible
- name: "Generate release note"
run: go run ./contrib/generate_release_note/main.go ${{ env.VERSION }} ./artifacts/build_report ./CHANGELOG.md
run: go run ./contrib/generate_release_note/main.go ${{ env.VERSION }} ./artifacts/build_report ./RELEASE_NOTE.md
- name: "Create release"
id: create_release
uses: actions/create-release@v1
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#110](https://github.com/line/lbm/pull/110) apply GovMint on x/foundation
* [\#111](https://github.com/line/lbm/pull/111) Bump github.com/line/lbm-sdk from 66988a235 to 0.46.0-rc9
* (build) [\#113](https://github.com/line/lbm/pull/113) enable to use libsodium version ostracon
* (build) [\#126](https://github.com/line/lbm/pull/126) Automatic creation of release note and binaries

### Improvements

Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,16 @@ dbbackend:
endif

build-reproducible: go.sum
$(DOCKER) rm latest-build || true
$(DOCKER) rm latest-build || true > /dev/null 2>&1
# to be implemented for: 'darwin/amd64 linux/arm64 windows/amd64'
$(DOCKER) run --volume=$(CURDIR):/sources:ro \
# to be implemented: 'darwin/amd64 linux/arm64 windows/amd64' \
--env TARGET_PLATFORMS='linux/amd64' \
--env APP=lbm \
--env VERSION=$(VERSION) \
--env COMMIT=$(COMMIT) \
--env LEDGER_ENABLED=$(LEDGER_ENABLED) \
--name latest-build lbm/rbuilder:latest
--name latest-build \
lbm/rbuilder:latest
$(DOCKER) cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/
$(DOCKER) rm latest-build

Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# LBM Release Note

This is a sample release note. If you see this message in the release note, please ensure that `./RELEASE_NOTE.md` is written correctly.
32 changes: 6 additions & 26 deletions contrib/generate_release_note/main.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
//go:build exclude
// +build exclude

// This program is used to create a release note from build_report and CHANGELOG.md. It is used to create release builds
// This program is used to create a release note from build_report and RELEASE_NOTE.md. It is used to create release builds
// with release-build.yml in Github Actions.
//
// go run ./contrib/generate_release_note/main.go ${{ env.VERSION }} ./artifacts/build_report ./CHANGELOG.md
// go run ./contrib/generate_release_note/main.go ${{ env.VERSION }} ./artifacts/build_report ./RELEASE_NOTE.md

package main

import (
"errors"
"fmt"
"os"
"regexp"
"strings"
)

func main() {
args := os.Args
if len(args) != 4 {
fmt.Println("please add os.Args release version, build_report path and CHANGELOG.md path, example: go run main.go v7.0.0 ../../artifacts/build_report ../../CHANGELOG.md")
fmt.Println("please add os.Args release version, build_report path and RELEASE_NOTE.md path, example: go run main.go v7.0.0 ../../artifacts/build_report ../../RELEASE_NOTE.md")
os.Exit(1)
}

Expand All @@ -31,14 +29,13 @@ func main() {
fmt.Printf("file error: %s\n", err)
}

changelog, err := FindChangelog(changelogPath, args[1])
changelog, err := os.ReadFile(changelogPath)
if err != nil {
fmt.Printf("cannot find changelog: %s\n", err)
fmt.Printf("cannot find release note: %s\n", err)
}

note := strings.Builder{}
note.WriteString(fmt.Sprintf("# LBM %s Release Notes\n", args[1]))
note.WriteString(changelog)
note.Write(changelog)
note.WriteString("\n")
note.WriteString("```\n")
note.Write(buildReport)
Expand All @@ -55,20 +52,3 @@ func main() {
fmt.Printf("cannot write to releasenote: %s\n", err)
}
}

// FindChangelog extracts the contents of the first `##` (level-2 section) described in the given markdown file. If the
// section title doesn't contain the `version` string, it's assumed not to be a description of the relevant version.
func FindChangelog(file, version string) (string, error) {
data, err := os.ReadFile(file)
if err != nil {
return "", errors.New("read changelog file failed")
}

changelogs := string(data)
reg := regexp.MustCompile(`(?ms).*?(^##[^#].*?)((^##[^#]).*|\z)`)
result := reg.FindStringSubmatch(changelogs)
if len(result) > 1 && strings.Contains(strings.Split(result[1], "\n")[0], version) {
return result[1], nil
}
return fmt.Sprintf("## %s\n_(changes relating to %s aren't described in `CHANGELOG.md`)_\n<!-- See also: contrib/generate_release_note/main.go -->", version, version), nil
}