Skip to content

Commit

Permalink
cmd/gorelease: support for non-starting first version
Browse files Browse the repository at this point in the history
Fixes golang/go#40267

Change-Id: Ie90929fb6479c50c9a8659b0c4211d66dbd54198
Reviewed-on: https://go-review.googlesource.com/c/exp/+/320229
Trust: Jean de Klerk <[email protected]>
Run-TryBot: Jean de Klerk <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Jay Conrod <[email protected]>
  • Loading branch information
jeanbza committed Jun 25, 2021
1 parent 7a70d7c commit fa9d1d1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
11 changes: 9 additions & 2 deletions cmd/gorelease/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ func (e *usageError) Error() string {
}

type baseVersionError struct {
err error
err error
modPath string
}

func (e *baseVersionError) Error() string {
return fmt.Sprintf("could not find base version: %v", e.err)
firstVersion := "v0.1.0"
_, major, _ := module.SplitPathVersion(e.modPath)
if major != "" {
firstVersion = major[1:] + ".0.0"
}

return fmt.Sprintf("could not find base version. Consider setting -version=%s if this is a first release, or explicitly set -base=none: %v", firstVersion, e.err)
}

func (e *baseVersionError) Unwrap() error {
Expand Down
3 changes: 1 addition & 2 deletions cmd/gorelease/gorelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ func checkModPath(modPath string) error {
func inferBaseVersion(ctx context.Context, modPath, max string) (baseVersion string, err error) {
defer func() {
if err != nil {
err = &baseVersionError{err: err}
err = &baseVersionError{err: err, modPath: modPath}
}
}()

Expand Down Expand Up @@ -817,7 +817,6 @@ func loadVersions(ctx context.Context, modPath string) (versions []string, err e
cmd := exec.CommandContext(ctx, "go", "list", "-m", "-versions", "--", modPath)
cmd.Env = copyEnv(ctx, cmd.Env)
cmd.Dir = tmpDir
cmd.Env = append(cmd.Env, "GO111MODULE=on")
out, err := cmd.Output()
if err != nil {
return nil, cleanCmdError(err)
Expand Down
5 changes: 4 additions & 1 deletion cmd/gorelease/gorelease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ func readTest(testPath string) (*test, error) {
return nil, fmt.Errorf("%s:%d: %v", testPath, lineNum, err)
}
case "proxyVersions":
parts := strings.Split(value, ",")
if len(value) == 0 {
break
}
proxyVersions := make(map[module.Version]bool)
parts := strings.Split(value, ",")
for _, modpathWithVersion := range parts {
vParts := strings.Split(modpathWithVersion, "@")
if len(vParts) != 2 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/gorelease/testdata/basic/v3_autobase_verify_error.test
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ version=v3.0.0-ignore
release=v3.1.0
error=true
-- want --
could not find base version: no versions found lower than v3.1.0
could not find base version. Consider setting -version=v3.0.0 if this is a first release, or explicitly set -base=none: no versions found lower than v3.1.0
12 changes: 12 additions & 0 deletions cmd/gorelease/testdata/first/v1_2_3_explicit_none_base.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mod=example.com/first
base=none
release=v1.2.3
proxyVersions=
-- want --
v1.2.3 is a valid semantic version for this release.
-- go.mod --
module example.com/first

go 1.12
-- p.go --
package p

0 comments on commit fa9d1d1

Please sign in to comment.