Skip to content

Commit

Permalink
build: Adapt to new Go toolchain versioning change in 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Aug 23, 2023
1 parent 035724c commit 9b57d2b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/build/install_go_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ import (
"github.com/hashicorp/go-version"
)

var v1_21 = version.Must(version.NewVersion("1.21"))

// installGoVersion installs given version of Go using Go
// according to https://golang.org/doc/manage-install
func (gb *GoBuild) installGoVersion(ctx context.Context, v *version.Version) (Go, error) {
versionString := v.Core().String()
goVersion := v.String()

// trim 0 patch versions as that's how Go does it :shrug:
shortVersion := strings.TrimSuffix(versionString, ".0")
pkgURL := fmt.Sprintf("golang.org/dl/go%s", shortVersion)
// trim 0 patch versions as that's how Go does it
// for versions prior to 1.21
// See https://github.com/golang/go/issues/62136
if v.LessThan(v1_21) {
versionString := v.Core().String()
goVersion = strings.TrimSuffix(versionString, ".0")
}
pkgURL := fmt.Sprintf("golang.org/dl/go%s", goVersion)

gb.log().Printf("go getting %q", pkgURL)
cmd := exec.CommandContext(ctx, "go", "get", pkgURL)
Expand All @@ -36,7 +43,7 @@ func (gb *GoBuild) installGoVersion(ctx context.Context, v *version.Version) (Go
return Go{}, fmt.Errorf("unable to install Go %s: %w\n%s", v, err, out)
}

cmdName := fmt.Sprintf("go%s", shortVersion)
cmdName := fmt.Sprintf("go%s", goVersion)

gb.log().Printf("downloading go %q", v)
cmd = exec.CommandContext(ctx, cmdName, "download")
Expand Down

0 comments on commit 9b57d2b

Please sign in to comment.