Skip to content

Commit

Permalink
extension: update go to go1.23.1
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
hyangah committed Oct 16, 2024
1 parent 151e9d9 commit 538900f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 34 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/test-long-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,19 @@ jobs:
check-latest: true
cache: true

- name: Install dependencies
- name: Install NPM dependencies
run: npm ci
working-directory: ./extension

- name: Compile
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
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/test-long.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,19 @@ jobs:
check-latest: true
cache: true

- name: Install dependencies
- name: Install NPM dependencies
run: npm ci
working-directory: ./extension

- name: Compile
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
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/test-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions extension/go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 15 additions & 11 deletions extension/tools/installtools/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
}
Expand All @@ -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)
Expand Down

0 comments on commit 538900f

Please sign in to comment.