From d676ddb7ec28630df4cca14b260733053565f636 Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Fri, 2 Dec 2022 12:54:48 +0100 Subject: [PATCH] go: use only major version in the module name (#86) Following on https://github.com/cucumber/messages/pull/107 we can conclude that 1. only major versions should be used in go module files 2. some project will have been released with a major.minor.patch version This change will ensure that when a new major release is made: `module github.com/example/project/v0` will become `module github.com/example/project/v1` and: `module github.com/example/project/v0.X.X` will become: `module github.com/example/project/v0`. This should fix the incorrect module names on the next major version. --- CHANGELOG.md | 2 ++ polyglot-release | 10 +++++--- .../go-three-digit-version/CHANGELOG.md | 18 +++++++++++++ tests/fixtures/go-three-digit-version/go.mod | 3 +++ tests/fixtures/go/go.mod | 2 +- tests/only-release-go-three-digit-version.sh | 2 ++ ...hree-digit-version.sh.expected.git-commits | 25 +++++++++++++++++++ tests/only-release-go.sh.expected.git-commits | 4 +-- 8 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 tests/fixtures/go-three-digit-version/CHANGELOG.md create mode 100644 tests/fixtures/go-three-digit-version/go.mod create mode 100644 tests/only-release-go-three-digit-version.sh create mode 100644 tests/only-release-go-three-digit-version.sh.expected.git-commits diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c46588..2570f63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## [Unreleased] +### Fixed +- Go: Only use major version in go module ([#86](https://github.com/cucumber/polyglot-release/pull/86)) ## [1.2.0] - 2022-11-09 ### Added diff --git a/polyglot-release b/polyglot-release index 5b8f7be..8dbf5b3 100755 --- a/polyglot-release +++ b/polyglot-release @@ -106,12 +106,16 @@ function pre_release_go() { check_for_tools "go" "jq" "sed" } function release_go() { - MODULE_WITH_NEW_VERSION=$( + local new_major_version + new_major_version="$(echo "$NEW_VERSION" | sed -E 's/^([0-9]+)\.[0-9]+\.[0-9]+$/\1/')" + # The sed below also captures 3-digit versions + local module_with_new_version + module_with_new_version=$( go mod edit -json | jq -r '.Module.Path' | - sed -E "s/(.*)v[0-9]+.[0-9]+.[0-9]+$/\1v$NEW_VERSION/" + sed -E "s/(.*)v[0-9]+(\.[0-9]+\.[0-9]+)?$/\1v$new_major_version/" ) - go mod edit -module "$MODULE_WITH_NEW_VERSION" + go mod edit -module "$module_with_new_version" } function post_release_go() { # noop diff --git a/tests/fixtures/go-three-digit-version/CHANGELOG.md b/tests/fixtures/go-three-digit-version/CHANGELOG.md new file mode 100644 index 0000000..5c5d610 --- /dev/null +++ b/tests/fixtures/go-three-digit-version/CHANGELOG.md @@ -0,0 +1,18 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + +## [Unreleased] + +### Fixed +- This is a test + +## [0.0.1] - 2000-01-01 + +## [0.0.0] - 2000-01-01 + +[Unreleased]: https://github.com/cucumber/polyglot-release/compare/v0.0.1...main +[0.0.1]: https://github.com/cucumber/polyglot-release/compare/v0.0.0...v0.0.1 diff --git a/tests/fixtures/go-three-digit-version/go.mod b/tests/fixtures/go-three-digit-version/go.mod new file mode 100644 index 0000000..2053071 --- /dev/null +++ b/tests/fixtures/go-three-digit-version/go.mod @@ -0,0 +1,3 @@ +module github.com/example/project/v0.0.1 + +go 1.18 diff --git a/tests/fixtures/go/go.mod b/tests/fixtures/go/go.mod index 2053071..e70a7b9 100644 --- a/tests/fixtures/go/go.mod +++ b/tests/fixtures/go/go.mod @@ -1,3 +1,3 @@ -module github.com/example/project/v0.0.1 +module github.com/example/project/v0 go 1.18 diff --git a/tests/only-release-go-three-digit-version.sh b/tests/only-release-go-three-digit-version.sh new file mode 100644 index 0000000..0a531c5 --- /dev/null +++ b/tests/only-release-go-three-digit-version.sh @@ -0,0 +1,2 @@ +# fixture: go-three-digit-version +polyglot-release 1.0.0 diff --git a/tests/only-release-go-three-digit-version.sh.expected.git-commits b/tests/only-release-go-three-digit-version.sh.expected.git-commits new file mode 100644 index 0000000..89e27e8 --- /dev/null +++ b/tests/only-release-go-three-digit-version.sh.expected.git-commits @@ -0,0 +1,25 @@ + +** +Prepare release v1.0.0 + +Created-by: polyglot-release v-develop + + +diff --git a/CHANGELOG.md b/CHANGELOG.md +--- a/CHANGELOG.md ++++ b/CHANGELOG.md +@@ -9,0 +10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ++## [1.0.0] - 2000-01-01 +@@ -15 +16 @@ and this project adheres to [Semantic Versioning](http://semver.org/). +-## [0.0.0] - 2000-01-01 ++## 0.0.0 - 2000-01-01 +@@ -17 +18,2 @@ and this project adheres to [Semantic Versioning](http://semver.org/). +-[Unreleased]: https://github.com/cucumber/polyglot-release/compare/v0.0.1...main ++[Unreleased]: https://github.com/cucumber/polyglot-release/compare/v1.0.0...main ++[1.0.0]: https://github.com/cucumber/polyglot-release/compare/v0.0.1...main +diff --git a/go.mod b/go.mod +--- a/go.mod ++++ b/go.mod +@@ -1 +1 @@ +-module github.com/example/project/v0.0.1 ++module github.com/example/project/v1 diff --git a/tests/only-release-go.sh.expected.git-commits b/tests/only-release-go.sh.expected.git-commits index f7867b8..cf17540 100644 --- a/tests/only-release-go.sh.expected.git-commits +++ b/tests/only-release-go.sh.expected.git-commits @@ -21,5 +21,5 @@ diff --git a/go.mod b/go.mod --- a/go.mod +++ b/go.mod @@ -1 +1 @@ --module github.com/example/project/v0.0.1 -+module github.com/example/project/v1.0.0 +-module github.com/example/project/v0 ++module github.com/example/project/v1