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

build: Adapt to new Go toolchain versioning change in 1.21 #150

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ jobs:
go test -v -race ./...

- name: E2E tests
timeout-minutes: 35
timeout-minutes: 70
env:
E2E_TESTING: 1
run: |
go test -timeout=30m -v ./...
go test -timeout=60m -v ./...
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