Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion Tasks/GoToolV0/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ describe('GoToolV0 Suite', function() {
let tr: MockTestRunner = new MockTestRunner(tp);
await tr.runAsync();
assert(tr.succeeded, 'Should have succeeded');
assert(tr.stdOutContained('##vso[task.setvariable variable=GOROOT'), 'Should set GOROOT');
// GOROOT should NOT be set for modern Go versions (1.21.3 >= 1.9)
assert(tr.stdOutContained('Skipping GOROOT for modern Go version'), 'Should skip GOROOT for modern version');
assert(tr.stdOutContained('##vso[task.setvariable variable=GOPATH'), 'Should set GOPATH');
assert(tr.stdOutContained('##vso[task.setvariable variable=GOBIN'), 'Should set GOBIN');
});
Expand Down Expand Up @@ -224,4 +225,32 @@ describe('GoToolV0 Suite', function() {
assert(tr.failed, 'Should have failed');
assert(tr.stdOutContained('Invalid download URL'), 'Should reject unsupported URL from environment variable');
});

// GOROOT behavior tests (issue #20796)
it('Should NOT set GOROOT for modern Go versions (>= 1.9)', async () => {
let tp = path.join(__dirname, 'L0GorootModernVersion.js');
let tr: MockTestRunner = new MockTestRunner(tp);
await tr.runAsync();
assert(tr.succeeded, 'Should have succeeded');
assert(tr.stdOutContained('Skipping GOROOT for modern Go version'), 'Should skip GOROOT for Go >= 1.9');
assert(!tr.stdOutContained('##vso[task.setvariable variable=GOROOT'), 'Should NOT set GOROOT for modern versions');
});

it('Should set GOROOT for legacy Go versions (< 1.9)', async () => {
let tp = path.join(__dirname, 'L0GorootLegacyVersion.js');
let tr: MockTestRunner = new MockTestRunner(tp);
await tr.runAsync();
assert(tr.succeeded, 'Should have succeeded');
assert(tr.stdOutContained('Setting GOROOT for Go version < 1.9'), 'Should set GOROOT for Go < 1.9');
assert(tr.stdOutContained('##vso[task.setvariable variable=GOROOT'), 'Should set GOROOT for legacy versions');
});

it('Should NOT set GOROOT for Go 1.9.0 (boundary version)', async () => {
let tp = path.join(__dirname, 'L0GorootBoundaryVersion.js');
let tr: MockTestRunner = new MockTestRunner(tp);
await tr.runAsync();
assert(tr.succeeded, 'Should have succeeded');
assert(tr.stdOutContained('Skipping GOROOT for modern Go version'), 'Should skip GOROOT for Go 1.9.0');
assert(!tr.stdOutContained('##vso[task.setvariable variable=GOROOT'), 'Should NOT set GOROOT for Go 1.9.0');
});
});
37 changes: 37 additions & 0 deletions Tasks/GoToolV0/Tests/L0GorootBoundaryVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'gotool.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

// Test Go 1.9.0 exactly (boundary version) - GOROOT should NOT be set
tmr.setInput('version', '1.9.0');

// Mock environment variables
process.env['Agent.TempDirectory'] = path.join(__dirname, 'temp');

// Mock tool lib functions
tmr.registerMock('azure-pipelines-tool-lib/tool', {
findLocalTool: function(toolName: string, version: string) {
console.log('Found cached Go version');
return '/mock/cache/go/1.9.0';
},
prependPath: function(toolPath: string) {
console.log(`Adding to PATH: ${toolPath}`);
}
});

// Mock os module
tmr.registerMock('os', {
platform: () => 'linux',
arch: () => 'x64'
});

// Mock telemetry
tmr.registerMock('azure-pipelines-tasks-utility-common/telemetry', {
emitTelemetry: function(area: string, feature: string, properties: any) {
console.log(`Telemetry: ${area}.${feature}`);
}
});

tmr.run();
37 changes: 37 additions & 0 deletions Tasks/GoToolV0/Tests/L0GorootLegacyVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'gotool.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

// Test legacy Go version (< 1.9) - GOROOT SHOULD be set
tmr.setInput('version', '1.8.7');

// Mock environment variables
process.env['Agent.TempDirectory'] = path.join(__dirname, 'temp');

// Mock tool lib functions
tmr.registerMock('azure-pipelines-tool-lib/tool', {
findLocalTool: function(toolName: string, version: string) {
console.log('Found cached Go version');
return '/mock/cache/go/1.8.7';
},
prependPath: function(toolPath: string) {
console.log(`Adding to PATH: ${toolPath}`);
}
});

// Mock os module
tmr.registerMock('os', {
platform: () => 'linux',
arch: () => 'x64'
});

// Mock telemetry
tmr.registerMock('azure-pipelines-tasks-utility-common/telemetry', {
emitTelemetry: function(area: string, feature: string, properties: any) {
console.log(`Telemetry: ${area}.${feature}`);
}
});

tmr.run();
37 changes: 37 additions & 0 deletions Tasks/GoToolV0/Tests/L0GorootModernVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'gotool.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

// Test modern Go version (>= 1.9) - GOROOT should NOT be set
tmr.setInput('version', '1.23.3');

// Mock environment variables
process.env['Agent.TempDirectory'] = path.join(__dirname, 'temp');

// Mock tool lib functions
tmr.registerMock('azure-pipelines-tool-lib/tool', {
findLocalTool: function(toolName: string, version: string) {
console.log('Found cached Go version');
return '/mock/cache/go/1.23.3';
},
prependPath: function(toolPath: string) {
console.log(`Adding to PATH: ${toolPath}`);
}
});

// Mock os module
tmr.registerMock('os', {
platform: () => 'linux',
arch: () => 'x64'
});

// Mock telemetry
tmr.registerMock('azure-pipelines-tasks-utility-common/telemetry', {
emitTelemetry: function(area: string, feature: string, properties: any) {
console.log(`Telemetry: ${area}.${feature}`);
}
});

tmr.run();
16 changes: 13 additions & 3 deletions Tasks/GoToolV0/gotool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async function getGo(version: string, baseUrl?: string): Promise<string> {
tl.debug("Go tool is available under " + toolPath);
}

setGoEnvironmentVariables(toolPath);
setGoEnvironmentVariables(toolPath, resolved.filenameVersion);
const binPath = path.join(toolPath, 'bin');
toolLib.prependPath(binPath);
return resolved.filenameVersion;
Expand Down Expand Up @@ -126,8 +126,18 @@ function getDownloadUrl(filename: string, baseUrl?: string): string {
return `${base.replace(/\/+$/, '')}/${filename}`;
}

function setGoEnvironmentVariables(goRoot: string): void {
tl.setVariable('GOROOT', goRoot);
function setGoEnvironmentVariables(goRoot: string, version: string): void {
// Only set GOROOT for Go < 1.9; modern versions auto-detect it.
// Setting it explicitly breaks custom builds (e.g., Go tip). See: #20796
const parsed = parseGoVersion(version);

if (parsed.major < 1 || (parsed.major === 1 && parsed.minor < 9)) {
tl.debug('Setting GOROOT for Go version < 1.9');
tl.setVariable('GOROOT', goRoot);
} else {
tl.debug('Skipping GOROOT for modern Go version (>= 1.9)');
}

const goPath = tl.getInput("goPath", false);
const goBin = tl.getInput("goBin", false);
if (goPath) {
Expand Down
2 changes: 1 addition & 1 deletion Tasks/GoToolV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 265,
"Minor": 268,
"Patch": 0
},
"satisfies": [
Expand Down
2 changes: 1 addition & 1 deletion Tasks/GoToolV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 265,
"Minor": 268,
"Patch": 0
},
"satisfies": [
Expand Down