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

[BUG]: GoTool@0 sets GOROOT for subsequent steps, but shouldn't #20796

Open
4 of 7 tasks
dagood opened this issue Jan 21, 2025 · 0 comments
Open
4 of 7 tasks

[BUG]: GoTool@0 sets GOROOT for subsequent steps, but shouldn't #20796

dagood opened this issue Jan 21, 2025 · 0 comments

Comments

@dagood
Copy link
Member

dagood commented Jan 21, 2025

New issue checklist

Task name

GoTool@0

Task version

0.246.3

Issue Description

The task sets GOROOT:

##[debug]Go tool is cached under /Users/runner/hostedtoolcache/go/1.23.3/x64
##[debug]set GOROOT=/Users/runner/hostedtoolcache/go/1.23.3/x64
##[debug]Processed: ##vso[task.setvariable variable=GOROOT;isOutput=false;issecret=false;]/Users/runner/hostedtoolcache/go/1.23.3/x64

https://dev.azure.com/dnceng-public/public/_build/results?buildId=924196&view=logs&j=7fa8201e-1424-5163-cc6b-2afca1adf7af&t=e432957b-2dfa-524d-050f-31437c5f2997&l=92

This is not expected when using modern versions of Go. The GitHub Actions task has it right:

      // Go versions less than 1.9 require GOROOT to be set
      if (semver.lt(version, '1.9.0')) {
        core.info('Setting GOROOT for Go version < 1.9');
        core.exportVariable('GOROOT', installDir);
      }

This repo appears to set it unconditionally:

function setGoEnvironmentVariables(goRoot: string) {
tl.setVariable('GOROOT', goRoot);
let goPath: string = tl.getInput("goPath", false);

Originally I thought this was an issue with the agent and filed an issue, but now I've realized the issue is this setup task:

The reason it's not just unnecessary but potentially harmful to set GOROOT is menitoned in actions/runner-images#2655 and actions/runner-images#11331:

The problem with hardcoding a GOROOT is that if any other go tool is in use (for example, because one compiled Go tip), the environment variable will override its autodetected GOROOT. The result is that the GOROOT and the go binary will mismatch, leading to obscure errors.

Specific example: when we try to call the Go tip's go tool dist test, Go complains that "dist" doesn't exist, because it's looking in the wrong GOROOT. dist doesn't exist for the preinstalled Go, but it does exist in the just-compiled Go tip.

As a workaround, explicitly unsetting GOROOT in our CI that uses this setup task fixes go tool dist test for a Go tip build.

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

macOS

Relevant log output

##[debug]Go tool is cached under /Users/runner/hostedtoolcache/go/1.23.3/x64
##[debug]set GOROOT=/Users/runner/hostedtoolcache/go/1.23.3/x64
##[debug]Processed: ##vso[task.setvariable variable=GOROOT;isOutput=false;issecret=false;]/Users/runner/hostedtoolcache/go/1.23.3/x64

Full task logs with system.debug enabled

No response

Repro steps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant