Skip to content

Commit

Permalink
Add Ubuntu mono check for NuGetCommandV2 (#20818)
Browse files Browse the repository at this point in the history
* Add Ubuntu mono check for NuGetCommandV2

* Regenerate NuGetCommandV2

* Add NuGetCommandV2 ubuntu L0s

---------

Co-authored-by: Coby Allred <[email protected]>
  • Loading branch information
cobya and Coby Allred authored Jan 31, 2025
1 parent 32b9a32 commit 4e6f4d0
Show file tree
Hide file tree
Showing 40 changed files with 3,850 additions and 362 deletions.
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();
61 changes: 61 additions & 0 deletions Tasks/NuGetCommandV2/Tests/RestoreTests/singleslnUbuntu24Mono.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.registerNugetUbuntu24Mock();

tmr.run();
Loading

0 comments on commit 4e6f4d0

Please sign in to comment.