Skip to content

Commit 4e6f4d0

Browse files
cobyaCoby Allred
and
Coby Allred
authored
Add Ubuntu mono check for NuGetCommandV2 (#20818)
* Add Ubuntu mono check for NuGetCommandV2 * Regenerate NuGetCommandV2 * Add NuGetCommandV2 ubuntu L0s --------- Co-authored-by: Coby Allred <[email protected]>
1 parent 32b9a32 commit 4e6f4d0

40 files changed

+3850
-362
lines changed

Diff for: Tasks/NuGetCommandV2/Strings/resources.resjson/en-US/resources.resjson

+4-2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135
"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.",
136136
"loc.messages.Error_NugetFailedWithCodeAndErr": "The nuget command failed with exit code(%s) and error(%s)",
137137
"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'.",
138-
"loc.messages.Error_IncludeNuGetOrgEnabled": "Packages failed to restore. Edit your build task and set 'includeNuGetOrg' to 'false' or deselect 'Use packages from NuGet.org'.",
139-
"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."
138+
"loc.messages.Error_IncludeNuGetOrgEnabled": "Packages failed to restore. Edit your build task and set 'includeNuGetOrg' to 'false' or deselect 'Use packages from NuGet.org'."
139+
"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.",
140+
"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.",
141+
"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."
140142
}

Diff for: Tasks/NuGetCommandV2/Tests/L0.ts

+37
Original file line numberDiff line numberDiff line change
@@ -448,4 +448,41 @@ describe('NuGetCommand Suite', function () {
448448
assert(tr.failed, 'should have failed');
449449
done();
450450
});
451+
452+
it('restore succeeds on ubuntu 22', (done: Mocha.Done) => {
453+
let tp = path.join(__dirname, './RestoreTests/singleslnUbuntu22.js')
454+
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
455+
456+
tr.run();
457+
assert(tr.invokedToolCount == 1, 'should have run NuGet once');
458+
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');
459+
assert(tr.stdOutContained('NuGet output here'), "should have nuget output");
460+
assert(tr.succeeded, 'should have succeeded');
461+
assert.equal(tr.errorIssues.length, 0, "should have no errors");
462+
done();
463+
});
464+
465+
it('restore succeeds on ubuntu 24 with mono', (done: Mocha.Done) => {
466+
let tp = path.join(__dirname, './RestoreTests/singleslnUbuntu24Mono.js')
467+
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
468+
469+
tr.run();
470+
assert(tr.invokedToolCount == 1, 'should have run NuGet once');
471+
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');
472+
assert(tr.stdOutContained('NuGet output here'), "should have nuget output");
473+
assert(tr.succeeded, 'should have succeeded');
474+
assert.equal(tr.errorIssues.length, 0, "should have no errors");
475+
done();
476+
});
477+
478+
it('restore fails on ubuntu 24 without mono', (done: Mocha.Done) => {
479+
let tp = path.join(__dirname, './RestoreTests/failUbuntu24NoMono.js')
480+
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
481+
482+
tr.run();
483+
assert(tr.failed, 'should have failed');
484+
assert.equal(tr.errorIssues.length, 1, "should have 1 error");
485+
assert(tr.invokedToolCount == 0, 'should have run no tools');
486+
done();
487+
});
451488
});

Diff for: Tasks/NuGetCommandV2/Tests/NugetMockHelper.ts

+16
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ export class NugetMockHelper {
6262
nMockHelper.registerNugetUtilityMockUnix(this.tmr, projectFile);
6363
}
6464

65+
public registerNugetMacOsMock() {
66+
nMockHelper.registerNugetMacOsMock(this.tmr);
67+
}
68+
69+
public registerNugetWindowsMock() {
70+
nMockHelper.registerNugetWindowsMock(this.tmr);
71+
}
72+
73+
public registerNugetUbuntu22Mock() {
74+
nMockHelper.registerNugetUbuntu22Mock(this.tmr);
75+
}
76+
77+
public registerNugetUbuntu24Mock() {
78+
nMockHelper.registerNugetUbuntu24Mock(this.tmr);
79+
}
80+
6581
public registerVstsNuGetPushRunnerMock() {
6682
this.tmr.registerMock('./Common/VstsNuGetPushToolUtilities', {
6783
getBundledVstsNuGetPushLocation: function() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import ma = require('azure-pipelines-task-lib/mock-answer');
2+
import tmrm = require('azure-pipelines-task-lib/mock-run');
3+
import path = require('path');
4+
import util = require('../NugetMockHelper');
5+
6+
let taskPath = path.join(__dirname, '../..', 'nugetcommandmain.js');
7+
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
8+
let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr);
9+
10+
nmh.setNugetVersionInputDefault();
11+
tmr.setInput('command', 'restore');
12+
tmr.setInput('solution', 'single.sln');
13+
tmr.setInput('selectOrConfig', 'config');
14+
15+
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
16+
"osType": {
17+
"osType" : "Linux"
18+
},
19+
"checkPath": {
20+
"~/myagent/_work/1/s/single.sln": true,
21+
"/usr/bin/mono": true
22+
},
23+
"which": {},
24+
"exec": {},
25+
"exist": {
26+
"~/myagent/_work/_tasks/NuGet/nuget.exe": true,
27+
"~/myagent/_work/_tasks/NuGet/CredentialProvider.TeamBuild.exe": true
28+
},
29+
"stats": {
30+
"~/myagent/_work/1/s/single.sln": {
31+
"isFile": true
32+
}
33+
},
34+
"findMatch": {
35+
"single.sln" : ["~/myagent/_work/1/s/single.sln"]
36+
}
37+
};
38+
tmr.setAnswers(a);
39+
40+
process.env['AGENT_HOMEDIRECTORY'] = "~/myagent/_work/1";
41+
process.env['BUILD_SOURCESDIRECTORY'] = "~/myagent/_work/1/s",
42+
process.env['ENDPOINT_AUTH_SYSTEMVSSCONNECTION'] = "{\"json\" : \"value\"}";
43+
process.env['ENDPOINT_URL_SYSTEMVSSCONNECTION'] = "https://example.visualstudio.com/defaultcollection";
44+
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = "~/myagent/_work/1/s";
45+
process.env['SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'] = "https://example.visualstudio.com/defaultcollection";
46+
47+
nmh.registerDefaultNugetVersionMock();
48+
nmh.registerToolRunnerMock();
49+
nmh.registerNugetConfigMock();
50+
nmh.registerNugetUtilityMockUnix(["~/myagent/_work/1/s/single.sln"]);
51+
nmh.registerNugetUbuntu24Mock();
52+
53+
tmr.run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import ma = require('azure-pipelines-task-lib/mock-answer');
2+
import tmrm = require('azure-pipelines-task-lib/mock-run');
3+
import path = require('path');
4+
import util = require('../NugetMockHelper');
5+
6+
let taskPath = path.join(__dirname, '../..', 'nugetcommandmain.js');
7+
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
8+
let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr);
9+
10+
nmh.setNugetVersionInputDefault();
11+
tmr.setInput('command', 'restore');
12+
tmr.setInput('solution', 'single.sln');
13+
tmr.setInput('selectOrConfig', 'config');
14+
15+
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
16+
"osType": {
17+
"osType" : "Linux"
18+
},
19+
"checkPath": {
20+
"~/myagent/_work/1/s/single.sln": true,
21+
"/usr/bin/mono": true
22+
},
23+
"which": {
24+
"mono":"/usr/bin/mono"
25+
},
26+
"exec": {
27+
"/usr/bin/mono c:\\from\\tool\\installer\\nuget.exe restore ~/myagent/_work/1/s/single.sln -NonInteractive": {
28+
"code": 0,
29+
"stdout": "NuGet output here",
30+
"stderr": ""
31+
}
32+
},
33+
"exist": {
34+
"~/myagent/_work/_tasks/NuGet/nuget.exe": true,
35+
"~/myagent/_work/_tasks/NuGet/CredentialProvider.TeamBuild.exe": true
36+
},
37+
"stats": {
38+
"~/myagent/_work/1/s/single.sln": {
39+
"isFile": true
40+
}
41+
},
42+
"findMatch": {
43+
"single.sln" : ["~/myagent/_work/1/s/single.sln"]
44+
}
45+
};
46+
tmr.setAnswers(a);
47+
48+
process.env['AGENT_HOMEDIRECTORY'] = "~/myagent/_work/1";
49+
process.env['BUILD_SOURCESDIRECTORY'] = "~/myagent/_work/1/s",
50+
process.env['ENDPOINT_AUTH_SYSTEMVSSCONNECTION'] = "{\"json\" : \"value\"}";
51+
process.env['ENDPOINT_URL_SYSTEMVSSCONNECTION'] = "https://example.visualstudio.com/defaultcollection";
52+
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = "~/myagent/_work/1/s";
53+
process.env['SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'] = "https://example.visualstudio.com/defaultcollection";
54+
55+
nmh.registerDefaultNugetVersionMock();
56+
nmh.registerToolRunnerMock();
57+
nmh.registerNugetConfigMock();
58+
nmh.registerNugetUtilityMockUnix(["~/myagent/_work/1/s/single.sln"]);
59+
nmh.registerNugetUbuntu22Mock();
60+
61+
tmr.run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import ma = require('azure-pipelines-task-lib/mock-answer');
2+
import tmrm = require('azure-pipelines-task-lib/mock-run');
3+
import path = require('path');
4+
import util = require('../NugetMockHelper');
5+
6+
let taskPath = path.join(__dirname, '../..', 'nugetcommandmain.js');
7+
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);
8+
let nmh: util.NugetMockHelper = new util.NugetMockHelper(tmr);
9+
10+
nmh.setNugetVersionInputDefault();
11+
tmr.setInput('command', 'restore');
12+
tmr.setInput('solution', 'single.sln');
13+
tmr.setInput('selectOrConfig', 'config');
14+
15+
let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
16+
"osType": {
17+
"osType" : "Linux"
18+
},
19+
"checkPath": {
20+
"~/myagent/_work/1/s/single.sln": true,
21+
"/usr/bin/mono": true
22+
},
23+
"which": {
24+
"mono":"/usr/bin/mono"
25+
},
26+
"exec": {
27+
"/usr/bin/mono c:\\from\\tool\\installer\\nuget.exe restore ~/myagent/_work/1/s/single.sln -NonInteractive": {
28+
"code": 0,
29+
"stdout": "NuGet output here",
30+
"stderr": ""
31+
}
32+
},
33+
"exist": {
34+
"~/myagent/_work/_tasks/NuGet/nuget.exe": true,
35+
"~/myagent/_work/_tasks/NuGet/CredentialProvider.TeamBuild.exe": true
36+
},
37+
"stats": {
38+
"~/myagent/_work/1/s/single.sln": {
39+
"isFile": true
40+
}
41+
},
42+
"findMatch": {
43+
"single.sln" : ["~/myagent/_work/1/s/single.sln"]
44+
}
45+
};
46+
tmr.setAnswers(a);
47+
48+
process.env['AGENT_HOMEDIRECTORY'] = "~/myagent/_work/1";
49+
process.env['BUILD_SOURCESDIRECTORY'] = "~/myagent/_work/1/s",
50+
process.env['ENDPOINT_AUTH_SYSTEMVSSCONNECTION'] = "{\"json\" : \"value\"}";
51+
process.env['ENDPOINT_URL_SYSTEMVSSCONNECTION'] = "https://example.visualstudio.com/defaultcollection";
52+
process.env['SYSTEM_DEFAULTWORKINGDIRECTORY'] = "~/myagent/_work/1/s";
53+
process.env['SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'] = "https://example.visualstudio.com/defaultcollection";
54+
55+
nmh.registerDefaultNugetVersionMock();
56+
nmh.registerToolRunnerMock();
57+
nmh.registerNugetConfigMock();
58+
nmh.registerNugetUtilityMockUnix(["~/myagent/_work/1/s/single.sln"]);
59+
nmh.registerNugetUbuntu24Mock();
60+
61+
tmr.run();

0 commit comments

Comments
 (0)