Skip to content

Commit

Permalink
go: use only major version in the module name
Browse files Browse the repository at this point in the history
Following on cucumber/messages#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.
  • Loading branch information
mpkorstanje committed Nov 14, 2022
1 parent fc50e6f commit 735b135
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion polyglot-release
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,12 @@ function pre_release_go() {
check_for_tools "go" "jq" "sed"
}
function release_go() {
NEW_MAJOR_VERSION="$(echo "$NEW_VERSION" | sed -E 's/^([0-9]+)\.[0-9]+\.[0-9]+$/\1/')"
# The sed below also captures 3-digit versions
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"
}
Expand Down
18 changes: 18 additions & 0 deletions tests/fixtures/go-three-digit-version/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions tests/fixtures/go-three-digit-version/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/example/project/v0.0.1

go 1.18
2 changes: 1 addition & 1 deletion tests/fixtures/go/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/example/project/v0.0.1
module github.com/example/project/v0

go 1.18
2 changes: 2 additions & 0 deletions tests/only-release-go-three-digit-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# fixture: go-three-digit-version
polyglot-release 1.0.0
25 changes: 25 additions & 0 deletions tests/only-release-go-three-digit-version.sh.expected.git-commits
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tests/only-release-go.sh.expected.git-commits
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 735b135

Please sign in to comment.