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

Add Ubuntu mono check for NuGetCommandV2 #20818

Merged
merged 3 commits into from
Jan 31, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
"loc.messages.Warning_UpdatingNuGetVersion": "Updating version of NuGet.exe to %s from %s. Behavior changes or breaking changes might occur as NuGet updates to a new version. If this is not desired, deselect the 'Check for Latest Version' option in the task.",
"loc.messages.Error_NugetFailedWithCodeAndErr": "The nuget command failed with exit code(%s) and error(%s)",
"loc.messages.Warning_IncludeNuGetOrgEnabled": "IncludeNugetOrg is currently enabled for this task. To resolve this warning, edit your build task and set 'includeNuGetOrg' to 'false' or deselect 'Use packages from NuGet.org'.",
"loc.messages.Error_IncludeNuGetOrgEnabled": "Packages failed to restore. Edit your build task and set 'includeNuGetOrg' to 'false' or deselect 'Use packages from NuGet.org'.",
"loc.messages.Warning_UnsupportedServiceConnectionAuth": "The service connection does not use a supported authentication method. Please use a service connection with personal access token based auth."
"loc.messages.Error_IncludeNuGetOrgEnabled": "Packages failed to restore. Edit your build task and set 'includeNuGetOrg' to 'false' or deselect 'Use packages from NuGet.org'."
"loc.messages.Warning_UnsupportedServiceConnectionAuth": "The service connection does not use a supported authentication method. Please use a service connection with personal access token based auth.",
"loc.messages.LIB_WhichNotFound_Linux": "Unable to locate executable file: '%s'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.",
"loc.messages.Error_IncompatibleUbuntuVersion": "The task has failed because you are using Ubuntu 24.04 or later without mono installed. See https://aka.ms/nuget-task-mono for more information."
}
37 changes: 37 additions & 0 deletions Tasks/NuGetCommandV2/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,41 @@ describe('NuGetCommand Suite', function () {
assert(tr.failed, 'should have failed');
done();
});

it('restore succeeds on ubuntu 22', (done: Mocha.Done) => {
let tp = path.join(__dirname, './RestoreTests/singleslnUbuntu22.js')
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();
assert(tr.invokedToolCount == 1, 'should have run NuGet once');
assert(tr.ran('/usr/bin/mono c:\\from\\tool\\installer\\nuget.exe restore ~/myagent/_work/1/s/single.sln -NonInteractive'), 'it should have run NuGet with mono');
assert(tr.stdOutContained('NuGet output here'), "should have nuget output");
assert(tr.succeeded, 'should have succeeded');
assert.equal(tr.errorIssues.length, 0, "should have no errors");
done();
});

it('restore succeeds on ubuntu 24 with mono', (done: Mocha.Done) => {
let tp = path.join(__dirname, './RestoreTests/singleslnUbuntu24Mono.js')
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();
assert(tr.invokedToolCount == 1, 'should have run NuGet once');
assert(tr.ran('/usr/bin/mono c:\\from\\tool\\installer\\nuget.exe restore ~/myagent/_work/1/s/single.sln -NonInteractive'), 'it should have run NuGet with mono');
assert(tr.stdOutContained('NuGet output here'), "should have nuget output");
assert(tr.succeeded, 'should have succeeded');
assert.equal(tr.errorIssues.length, 0, "should have no errors");
done();
});

it('restore fails on ubuntu 24 without mono', (done: Mocha.Done) => {
let tp = path.join(__dirname, './RestoreTests/failUbuntu24NoMono.js')
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();
assert(tr.failed, 'should have failed');
assert.equal(tr.errorIssues.length, 1, "should have 1 error");
assert(tr.invokedToolCount == 0, 'should have run no tools');
done();
});
});
16 changes: 16 additions & 0 deletions Tasks/NuGetCommandV2/Tests/NugetMockHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ export class NugetMockHelper {
nMockHelper.registerNugetUtilityMockUnix(this.tmr, projectFile);
}

public registerNugetMacOsMock() {
nMockHelper.registerNugetMacOsMock(this.tmr);
}

public registerNugetWindowsMock() {
nMockHelper.registerNugetWindowsMock(this.tmr);
}

public registerNugetUbuntu22Mock() {
nMockHelper.registerNugetUbuntu22Mock(this.tmr);
}

public registerNugetUbuntu24Mock() {
nMockHelper.registerNugetUbuntu24Mock(this.tmr);
}

public registerVstsNuGetPushRunnerMock() {
this.tmr.registerMock('./Common/VstsNuGetPushToolUtilities', {
getBundledVstsNuGetPushLocation: function() {
Expand Down
53 changes: 53 additions & 0 deletions Tasks/NuGetCommandV2/Tests/RestoreTests/failUbuntu24NoMono.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');
import util = require('../NugetMockHelper');

let taskPath = path.join(__dirname, '../..', 'nugetcommandmain.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr);

nmh.setNugetVersionInputDefault();
tmr.setInput('command', 'restore');
tmr.setInput('solution', 'single.sln');
tmr.setInput('selectOrConfig', 'config');

let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"osType": {
"osType" : "Linux"
},
"checkPath": {
"~/myagent/_work/1/s/single.sln": true,
"/usr/bin/mono": true
},
"which": {},
"exec": {},
"exist": {
"~/myagent/_work/_tasks/NuGet/nuget.exe": true,
"~/myagent/_work/_tasks/NuGet/CredentialProvider.TeamBuild.exe": true
},
"stats": {
"~/myagent/_work/1/s/single.sln": {
"isFile": true
}
},
"findMatch": {
"single.sln" : ["~/myagent/_work/1/s/single.sln"]
}
};
tmr.setAnswers(a);

process.env['AGENT_HOMEDIRECTORY'] = "~/myagent/_work/1";
process.env['BUILD_SOURCESDIRECTORY'] = "~/myagent/_work/1/s",
process.env['ENDPOINT_AUTH_SYSTEMVSSCONNECTION'] = "{\"json\" : \"value\"}";
process.env['ENDPOINT_URL_SYSTEMVSSCONNECTION'] = "https://example.visualstudio.com/defaultcollection";
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = "~/myagent/_work/1/s";
process.env['SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'] = "https://example.visualstudio.com/defaultcollection";

nmh.registerDefaultNugetVersionMock();
nmh.registerToolRunnerMock();
nmh.registerNugetConfigMock();
nmh.registerNugetUtilityMockUnix(["~/myagent/_work/1/s/single.sln"]);
nmh.registerNugetUbuntu24Mock();

tmr.run();
61 changes: 61 additions & 0 deletions Tasks/NuGetCommandV2/Tests/RestoreTests/singleslnUbuntu22.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');
import util = require('../NugetMockHelper');

let taskPath = path.join(__dirname, '../..', 'nugetcommandmain.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr);

nmh.setNugetVersionInputDefault();
tmr.setInput('command', 'restore');
tmr.setInput('solution', 'single.sln');
tmr.setInput('selectOrConfig', 'config');

let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"osType": {
"osType" : "Linux"
},
"checkPath": {
"~/myagent/_work/1/s/single.sln": true,
"/usr/bin/mono": true
},
"which": {
"mono":"/usr/bin/mono"
},
"exec": {
"/usr/bin/mono c:\\from\\tool\\installer\\nuget.exe restore ~/myagent/_work/1/s/single.sln -NonInteractive": {
"code": 0,
"stdout": "NuGet output here",
"stderr": ""
}
},
"exist": {
"~/myagent/_work/_tasks/NuGet/nuget.exe": true,
"~/myagent/_work/_tasks/NuGet/CredentialProvider.TeamBuild.exe": true
},
"stats": {
"~/myagent/_work/1/s/single.sln": {
"isFile": true
}
},
"findMatch": {
"single.sln" : ["~/myagent/_work/1/s/single.sln"]
}
};
tmr.setAnswers(a);

process.env['AGENT_HOMEDIRECTORY'] = "~/myagent/_work/1";
process.env['BUILD_SOURCESDIRECTORY'] = "~/myagent/_work/1/s",
process.env['ENDPOINT_AUTH_SYSTEMVSSCONNECTION'] = "{\"json\" : \"value\"}";
process.env['ENDPOINT_URL_SYSTEMVSSCONNECTION'] = "https://example.visualstudio.com/defaultcollection";
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = "~/myagent/_work/1/s";
process.env['SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'] = "https://example.visualstudio.com/defaultcollection";

nmh.registerDefaultNugetVersionMock();
nmh.registerToolRunnerMock();
nmh.registerNugetConfigMock();
nmh.registerNugetUtilityMockUnix(["~/myagent/_work/1/s/single.sln"]);
nmh.registerNugetUbuntu22Mock();

tmr.run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import ma = require('azure-pipelines-task-lib/mock-answer');
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');
import util = require('../NugetMockHelper');

let taskPath = path.join(__dirname, '../..', 'nugetcommandmain.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr);

nmh.setNugetVersionInputDefault();
tmr.setInput('command', 'restore');
tmr.setInput('solution', 'single.sln');
tmr.setInput('selectOrConfig', 'config');

let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"osType": {
"osType" : "Linux"
},
"checkPath": {
"~/myagent/_work/1/s/single.sln": true,
"/usr/bin/mono": true
},
"which": {
"mono":"/usr/bin/mono"
},
"exec": {
"/usr/bin/mono c:\\from\\tool\\installer\\nuget.exe restore ~/myagent/_work/1/s/single.sln -NonInteractive": {
"code": 0,
"stdout": "NuGet output here",
"stderr": ""
}
},
"exist": {
"~/myagent/_work/_tasks/NuGet/nuget.exe": true,
"~/myagent/_work/_tasks/NuGet/CredentialProvider.TeamBuild.exe": true
},
"stats": {
"~/myagent/_work/1/s/single.sln": {
"isFile": true
}
},
"findMatch": {
"single.sln" : ["~/myagent/_work/1/s/single.sln"]
}
};
tmr.setAnswers(a);

process.env['AGENT_HOMEDIRECTORY'] = "~/myagent/_work/1";
process.env['BUILD_SOURCESDIRECTORY'] = "~/myagent/_work/1/s",
process.env['ENDPOINT_AUTH_SYSTEMVSSCONNECTION'] = "{\"json\" : \"value\"}";
process.env['ENDPOINT_URL_SYSTEMVSSCONNECTION'] = "https://example.visualstudio.com/defaultcollection";
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = "~/myagent/_work/1/s";
process.env['SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'] = "https://example.visualstudio.com/defaultcollection";

nmh.registerDefaultNugetVersionMock();
nmh.registerToolRunnerMock();
nmh.registerNugetConfigMock();
nmh.registerNugetUtilityMockUnix(["~/myagent/_work/1/s/single.sln"]);
nmh.registerNugetUbuntu24Mock();

tmr.run();
Loading