diff --git a/.github/workflows/test-long-all.yml b/.github/workflows/test-long-all.yml index 020c0884..922cb212 100644 --- a/.github/workflows/test-long-all.yml +++ b/.github/workflows/test-long-all.yml @@ -37,7 +37,7 @@ jobs: check-latest: true cache: true - - name: Install dependencies + - name: Install NPM dependencies run: npm ci working-directory: ./extension @@ -45,14 +45,11 @@ jobs: run: npm run vscode:prepublish working-directory: ./extension - - name: Install Go tools (Modules mode) + - name: Install tools dependencies run: | - go version - go run ./tools/installtools/main.go + go install ./tools/installtools + installtools working-directory: ./extension - env: - GO111MODULE: on - EXT: "${{ matrix.os == 'windows-latest' && '.exe' || ''}}" - name: Run unit tests run: npm run unit-test diff --git a/.github/workflows/test-long.yml b/.github/workflows/test-long.yml index eb1e201a..dcf2dcc3 100644 --- a/.github/workflows/test-long.yml +++ b/.github/workflows/test-long.yml @@ -36,7 +36,7 @@ jobs: check-latest: true cache: true - - name: Install dependencies + - name: Install NPM dependencies run: npm ci working-directory: ./extension @@ -44,14 +44,11 @@ jobs: run: npm run vscode:prepublish working-directory: ./extension - - name: Install Go tools (Modules mode) + - name: Install tools dependencies run: | - go version - go run ./tools/installtools/main.go + go install ./tools/installtools + installtools working-directory: ./extension - env: - GO111MODULE: on - EXT: "${{ matrix.os == 'windows-latest' && '.exe' || ''}}" - name: Run unit tests run: npm run unit-test diff --git a/.github/workflows/test-smoke.yml b/.github/workflows/test-smoke.yml index a61f4a0a..5c061b7c 100644 --- a/.github/workflows/test-smoke.yml +++ b/.github/workflows/test-smoke.yml @@ -43,14 +43,11 @@ jobs: run: npm run vscode:prepublish working-directory: ./extension - - name: Install Go tools (Modules mode) + - name: Install tools dependencies run: | - go version - go run ./tools/installtools/main.go + go install ./tools/installtools + installtools working-directory: ./extension - env: - GO111MODULE: on - EXT: "${{ matrix.os == 'windows-latest' && '.exe' || ''}}" - name: Run unit tests run: npm run unit-test diff --git a/extension/go.mod b/extension/go.mod index 498b40bc..381084d2 100644 --- a/extension/go.mod +++ b/extension/go.mod @@ -1,8 +1,6 @@ module github.com/golang/vscode-go/extension -go 1.21 - -toolchain go1.21.9 +go 1.23.1 require ( github.com/golang/vscode-go v0.0.0-00010101000000-000000000000 diff --git a/extension/tools/installtools/main.go b/extension/tools/installtools/main.go index 85d2f4b3..4d683fae 100644 --- a/extension/tools/installtools/main.go +++ b/extension/tools/installtools/main.go @@ -3,6 +3,13 @@ // license that can be found in the LICENSE file. // Binary installtools is a helper that installs Go tools extension tests depend on. +// In order to allow this script to use the go version in the sytem or your choice, +// avoid running this with `go run` (that may auto-upgrade the toolchain to meet +// the go version requirement in extension/go.mod). +// Instead, build this script, and run the compiled executable. +// For example, +// +// go build -o /tmp/script . && /tmp/script package main import ( @@ -61,6 +68,7 @@ func main() { if ver < 21 { exitf("unsupported go version: 1.%v", ver) } + fmt.Printf("installing tools for go1.%d...\n", ver) bin, err := goBin() if err != nil { @@ -80,7 +88,9 @@ func exitf(format string, args ...interface{}) { // goVersion returns an integer N if go's version is 1.N. func goVersion() (int, error) { cmd := exec.Command("go", "list", "-e", "-f", `{{context.ReleaseTags}}`, "--", "unsafe") - cmd.Env = append(os.Environ(), "GO111MODULE=off") + // GO111MODULE=off implicitly disables GOTOOLCHAIN switch, + // but let's make sure it doesn't change. + cmd.Env = append(os.Environ(), "GO111MODULE=off", "GOTOOLCHAIN=local") out, err := cmd.Output() if err != nil { return 0, fmt.Errorf("go list error: %v", err) @@ -106,7 +116,8 @@ func goBin() (string, error) { if gobin := os.Getenv("GOBIN"); gobin != "" { return gobin, nil } - out, err := exec.Command("go", "env", "GOPATH").Output() + cmd := exec.Command("go", "env", "GOPATH") + out, err := cmd.Output() if err != nil { return "", err } @@ -119,21 +130,14 @@ func goBin() (string, error) { func installTools(binDir string, goMinorVersion int) error { installCmd := "install" - if goMinorVersion < 16 { - installCmd = "get" - } - dir := "" - if installCmd == "get" { // run `go get` command from an empty directory. - dir = os.TempDir() - } - env := append(os.Environ(), "GO111MODULE=on") + // For tools installation, ensure GOTOOLCHAIN=auto. + env := append(os.Environ(), "GO111MODULE=on", "GOTOOLCHAIN=auto") for _, tool := range tools { ver := pickVersion(goMinorVersion, tool.versions, pickLatest(tool.path, tool.preferPreview)) path := tool.path + "@" + ver cmd := exec.Command("go", installCmd, path) cmd.Env = env - cmd.Dir = dir fmt.Println("go", installCmd, path) if out, err := cmd.CombinedOutput(); err != nil { return fmt.Errorf("installing %v: %s\n%v", path, out, err)