Skip to content

Commit

Permalink
build: Adapt to new Go toolchain versioning change in 1.21 (#150)
Browse files Browse the repository at this point in the history
* build: Adapt to new Go toolchain versioning change in 1.21

* github: bump CI test timeouts
  • Loading branch information
radeksimko authored Aug 23, 2023
1 parent 035724c commit 7c0cd8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
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

0 comments on commit 7c0cd8c

Please sign in to comment.