Skip to content

Commit 538900f

Browse files
committed
extension: update go to go1.23.1
We want to use the latest go when developing our own release/testing support tools and scripts. So, let's update go.mod to do so. After go1.21, we shouldn't use `go run` to run the extension/tools/installtools script. The purpose of `installtools` is to install tools needed by integration tests and are compatible with the go version in the system. We arranged the CI systems to test with the go versions we support. If we use `go run` from our project, the toolchain switch will occur and may change `GOROOT`/`PATH` to enforce the compiled script to use the upgraded toolchain. That makes the CI setup useless. Therefore, in this CL, we build the binary (it's ok to build the binary with go1.23.1+), and then run the installed binary ourselves so the execution of the binary doesn't get affected by the modified GOROOT/PATH. Kokoro CI also uses the installtools script when building the docker container. (build/Dockerfile) There, the script source code is copied over to a scratch space and run with `go run <go file>` outside the vscode-go project repo. So, there is no go toolchain version switch involved already. And currently we test only with the latest go in Kokoro, so this toolchain switch issue doesn't apply. For #3411 Change-Id: I3e116cf48fb431196359ec42049e70c0b75814ef Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/616677 kokoro-CI: kokoro <[email protected]> Reviewed-by: Hongxiang Jiang <[email protected]> Commit-Queue: Hyang-Ah Hana Kim <[email protected]>
1 parent 151e9d9 commit 538900f

File tree

5 files changed

+27
-34
lines changed

5 files changed

+27
-34
lines changed

Diff for: .github/workflows/test-long-all.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,19 @@ jobs:
3737
check-latest: true
3838
cache: true
3939

40-
- name: Install dependencies
40+
- name: Install NPM dependencies
4141
run: npm ci
4242
working-directory: ./extension
4343

4444
- name: Compile
4545
run: npm run vscode:prepublish
4646
working-directory: ./extension
4747

48-
- name: Install Go tools (Modules mode)
48+
- name: Install tools dependencies
4949
run: |
50-
go version
51-
go run ./tools/installtools/main.go
50+
go install ./tools/installtools
51+
installtools
5252
working-directory: ./extension
53-
env:
54-
GO111MODULE: on
55-
EXT: "${{ matrix.os == 'windows-latest' && '.exe' || ''}}"
5653

5754
- name: Run unit tests
5855
run: npm run unit-test

Diff for: .github/workflows/test-long.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,19 @@ jobs:
3636
check-latest: true
3737
cache: true
3838

39-
- name: Install dependencies
39+
- name: Install NPM dependencies
4040
run: npm ci
4141
working-directory: ./extension
4242

4343
- name: Compile
4444
run: npm run vscode:prepublish
4545
working-directory: ./extension
4646

47-
- name: Install Go tools (Modules mode)
47+
- name: Install tools dependencies
4848
run: |
49-
go version
50-
go run ./tools/installtools/main.go
49+
go install ./tools/installtools
50+
installtools
5151
working-directory: ./extension
52-
env:
53-
GO111MODULE: on
54-
EXT: "${{ matrix.os == 'windows-latest' && '.exe' || ''}}"
5552

5653
- name: Run unit tests
5754
run: npm run unit-test

Diff for: .github/workflows/test-smoke.yml

+3-6
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,11 @@ jobs:
4343
run: npm run vscode:prepublish
4444
working-directory: ./extension
4545

46-
- name: Install Go tools (Modules mode)
46+
- name: Install tools dependencies
4747
run: |
48-
go version
49-
go run ./tools/installtools/main.go
48+
go install ./tools/installtools
49+
installtools
5050
working-directory: ./extension
51-
env:
52-
GO111MODULE: on
53-
EXT: "${{ matrix.os == 'windows-latest' && '.exe' || ''}}"
5451

5552
- name: Run unit tests
5653
run: npm run unit-test

Diff for: extension/go.mod

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/golang/vscode-go/extension
22

3-
go 1.21
4-
5-
toolchain go1.21.9
3+
go 1.23.1
64

75
require (
86
github.com/golang/vscode-go v0.0.0-00010101000000-000000000000

Diff for: extension/tools/installtools/main.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
// license that can be found in the LICENSE file.
44

55
// Binary installtools is a helper that installs Go tools extension tests depend on.
6+
// In order to allow this script to use the go version in the sytem or your choice,
7+
// avoid running this with `go run` (that may auto-upgrade the toolchain to meet
8+
// the go version requirement in extension/go.mod).
9+
// Instead, build this script, and run the compiled executable.
10+
// For example,
11+
//
12+
// go build -o /tmp/script . && /tmp/script
613
package main
714

815
import (
@@ -61,6 +68,7 @@ func main() {
6168
if ver < 21 {
6269
exitf("unsupported go version: 1.%v", ver)
6370
}
71+
fmt.Printf("installing tools for go1.%d...\n", ver)
6472

6573
bin, err := goBin()
6674
if err != nil {
@@ -80,7 +88,9 @@ func exitf(format string, args ...interface{}) {
8088
// goVersion returns an integer N if go's version is 1.N.
8189
func goVersion() (int, error) {
8290
cmd := exec.Command("go", "list", "-e", "-f", `{{context.ReleaseTags}}`, "--", "unsafe")
83-
cmd.Env = append(os.Environ(), "GO111MODULE=off")
91+
// GO111MODULE=off implicitly disables GOTOOLCHAIN switch,
92+
// but let's make sure it doesn't change.
93+
cmd.Env = append(os.Environ(), "GO111MODULE=off", "GOTOOLCHAIN=local")
8494
out, err := cmd.Output()
8595
if err != nil {
8696
return 0, fmt.Errorf("go list error: %v", err)
@@ -106,7 +116,8 @@ func goBin() (string, error) {
106116
if gobin := os.Getenv("GOBIN"); gobin != "" {
107117
return gobin, nil
108118
}
109-
out, err := exec.Command("go", "env", "GOPATH").Output()
119+
cmd := exec.Command("go", "env", "GOPATH")
120+
out, err := cmd.Output()
110121
if err != nil {
111122
return "", err
112123
}
@@ -119,21 +130,14 @@ func goBin() (string, error) {
119130

120131
func installTools(binDir string, goMinorVersion int) error {
121132
installCmd := "install"
122-
if goMinorVersion < 16 {
123-
installCmd = "get"
124-
}
125133

126-
dir := ""
127-
if installCmd == "get" { // run `go get` command from an empty directory.
128-
dir = os.TempDir()
129-
}
130-
env := append(os.Environ(), "GO111MODULE=on")
134+
// For tools installation, ensure GOTOOLCHAIN=auto.
135+
env := append(os.Environ(), "GO111MODULE=on", "GOTOOLCHAIN=auto")
131136
for _, tool := range tools {
132137
ver := pickVersion(goMinorVersion, tool.versions, pickLatest(tool.path, tool.preferPreview))
133138
path := tool.path + "@" + ver
134139
cmd := exec.Command("go", installCmd, path)
135140
cmd.Env = env
136-
cmd.Dir = dir
137141
fmt.Println("go", installCmd, path)
138142
if out, err := cmd.CombinedOutput(); err != nil {
139143
return fmt.Errorf("installing %v: %s\n%v", path, out, err)

0 commit comments

Comments
 (0)