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

Add go app that updates changelog automatically #1872

Closed
wants to merge 15 commits into from

Conversation

joshcarp
Copy link
Contributor

updatechangelog unrelease CHANGELOG.md: adds Unreleased section into CHANGELOG.md
updatechangelog --version=v1.17.0 release CHANGELOG.md: removes Unreleased sections from CHANGELOG.md and adds the v1.17.0 into the changelog, including the links:

$ updatechangelog --version=v1.16.0 release CHANGELOG.md
# Changelog

-## [Unreleased]
+## [v1.16.0] - 2023-02-28

 - Update built-in Well-Known Types to Protobuf v22.0.
 - Fixes a bug in `buf format` where C-style block comments in which every
@@ -827,7 +827,7 @@ buf check breaking proto --against .git#branch=master,subdir=proto

 Initial beta release.

-[Unreleased]: https://github.com/bufbuild/buf/compare/v1.14.0...HEAD
+[v1.16.0]: https://github.com/bufbuild/buf/compare/v1.14.0...v1.16.0
 [v1.14.0]: https://github.com/bufbuild/buf/compare/v1.13.1...v1.14.0
 [v1.13.1]: https://github.com/bufbuild/buf/compare/v1.13.0...v1.13.1
 [v1.13.0]: https://github.com/bufbuild/buf/compare/v1.12.0...v1.13.0
$ updatechangelog unrelease CHANGELOG.md
 # Changelog

+## [Unreleased]
+
+- No changes yet.
+
 ## [v1.16.0] - 2023-02-28

 - Update built-in Well-Known Types to Protobuf v22.0.
@@ -827,6 +832,7 @@ buf check breaking proto --against .git#branch=master,subdir=proto

 Initial beta release.

+[Unreleased]: https://github.com/bufbuild/buf/compare/v1.16.0...HEAD
 [v1.16.0]: https://github.com/bufbuild/buf/compare/v1.14.0...v1.16.0
 [v1.14.0]: https://github.com/bufbuild/buf/compare/v1.13.1...v1.14.0
 [v1.13.1]: https://github.com/bufbuild/buf/compare/v1.13.0...v1.13.1

make/buf/all.mk Outdated Show resolved Hide resolved
private/pkg/changelog/cmd/update-changelog/main.go Outdated Show resolved Hide resolved
}

func unrelease(data []byte, repo string) []byte {
re := regexp.MustCompile(`# Changelog`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MustCompile will panic, should get the error and handle it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already use static regexps in global vars, is this okay? having a block like this:

var (
	lastLinkRegexp         = regexp.MustCompile(fmt.Sprintf(`\[v%s\].*?v%s\.\.\.v%s`, semverRegex, semverRegex, semverRegex))
	headerRegexp           = regexp.MustCompile(`# Changelog`)
	unreleasedHeaderRegexp = regexp.MustCompile(fmt.Sprintf(`\[Unreleased\]: (.*?)v%s\.\.\.HEAD`, semverRegex))
	unreleasedLinkRegexp   = regexp.MustCompile(`## \[Unreleased\]`)
	repoRegexp             = regexp.MustCompile(`\[.*?]: (.*?)\/compare`)
)

seems to be reasonable to me because it's never going to change?

private/pkg/changelog/cmd/update-changelog/main.go Outdated Show resolved Hide resolved
private/pkg/changelog/cmd/update-changelog/main.go Outdated Show resolved Hide resolved
private/pkg/changelog/cmd/update-changelog/main.go Outdated Show resolved Hide resolved
private/pkg/changelog/cmd/update-changelog/main.go Outdated Show resolved Hide resolved

const semverRegex = `((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)`

func main() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally we'd do if err := run(); err != nil style, grep the codebase for examples

@CLAassistant
Copy link

CLAassistant commented Apr 29, 2023

CLA assistant check
All committers have signed the CLA.

@joshcarp joshcarp closed this May 1, 2023
@joshcarp joshcarp reopened this Jun 23, 2023
@joshcarp joshcarp requested a review from bufdev June 26, 2023 14:52
@bufdev bufdev closed this Oct 18, 2023
@bufdev bufdev deleted the automated-changelog branch November 27, 2023 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants