Skip to content

Commit 2409b93

Browse files
authored
Users/tedeshpa/fix use dot net task preview version issue m158 (#11602)
* Added minimum agent version supported fpr UseDotNet task (#11477) * [UseDotNetV2]fix to handle dotnet release preview channels (#11577) * fix to handle dotnet release preview channels * adding L0s * url shorten, minor ux fix
1 parent affcc0d commit 2409b93

File tree

9 files changed

+307
-41
lines changed

9 files changed

+307
-41
lines changed

Tasks/UseDotNetV2/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"loc.messages.InvalidChannelObject": "Object cannot be used as Channel, required properties such as channel-version, releases.json is missing.",
8080
"loc.messages.ReleasesIndexBodyIncorrect": "Parsed releases index body is not correct. Kindly see if the releases-index section is not empty in the file.",
8181
"loc.messages.InvalidVersionObject": "Releases.json has a release with invalid %s object: %s",
82+
"loc.messages.InvalidVersion": "Invalid version specified %s",
8283
"loc.messages.FilesDataIsIncorrectInVersion": "In release %s for version %s, File data is incorrect (might have missing required fields, such as name, rid and url): %s",
8384
"loc.messages.VersionFilesDataIncorrect": "Version's files data is missing or has missing required fields.",
8485
"loc.messages.VersionInformationNotComplete": "Version: %s required information is not complete in releases.json file. Error: %s",
@@ -92,5 +93,6 @@
9293
"loc.messages.FailedToFindGlobalJson": "Failed to find global.json at and inside path: %s",
9394
"loc.messages.FailedToReadGlobalJson": "The global.json at path: '%s' has the wrong format. For information about global.json, visit here: https://docs.microsoft.com/en-us/dotnet/core/tools/global-json. Error while trying to read: %s",
9495
"loc.messages.VersionNumberHasTheWrongFormat": "The version number: %s doesn't have the correct format. Versions can be given in the following formats: 2.x => Install latest in major version. 2.2.x => Install latest in major and minor version. 2.2.104 => Install exact version. Find the value of `version` for installing SDK/Runtime, from the releases.json. The link to releases.json of that major.minor version can be found in [**releases-index file.**](https://github.com/dotnet/core/blob/master/release-notes/releases-index.json). Like link to releases.json for 2.2 version is https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/2.2/releases.json",
95-
"loc.messages.OnlyExplicitVersionAllowed": "Only explicit versions and accepted, such as: 2.2.301. Version: %s is not valid."
96+
"loc.messages.OnlyExplicitVersionAllowed": "Only explicit versions and accepted, such as: 2.2.301. Version: %s is not valid.",
97+
"loc.messages.SupportPhaseNotPresentInChannel": "support-phase is not present in the channel with channel-version %s."
9698
}

Tasks/UseDotNetV2/Tests/L0.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ describe('UseDotNet', function () {
150150

151151
it("[VersionFetcher.DotNetCoreVersionFetcher] getVersionInfo should throw if version for pacakge type can not be found, and error message should contain the package type", (done) => {
152152
process.env["__failat__"] = "versionnotfound";
153+
process.env["__versionspec__"] = "2.2.999-cantbefound-234";
153154
let tr = new ttm.MockTestRunner(path.join(__dirname, "versionFetcherGetVersionInfoFailTests.js"));
154155
tr.run();
155156
runValidations(() => {
@@ -160,6 +161,7 @@ describe('UseDotNet', function () {
160161

161162
it("[VersionFetcher.DotNetCoreVersionFetcher] getVersionInfo should throw if getting channel fails", (done) => {
162163
process.env["__failat__"] = "channelfetch";
164+
process.env["__versionspec__"] = "2.2.999-cantbefound-234";
163165
let tr = new ttm.MockTestRunner(path.join(__dirname, "versionFetcherGetVersionInfoFailTests.js"));
164166
tr.run();
165167
runValidations(() => {
@@ -168,6 +170,32 @@ describe('UseDotNet', function () {
168170
}, tr, done);
169171
});
170172

173+
it("[VersionFetcher.DotNetCoreVersionFetcher] getVersionInfo should throw if includePreviewVersion is false and only 1 channel and is preview", (done) => {
174+
process.env["__failat__"] = "versionnotfound";
175+
process.env["__versionspec__"] = "3.x";
176+
let tr = new ttm.MockTestRunner(path.join(__dirname, "versionFetcherGetVersionInfoFailTests.js"));
177+
tr.run();
178+
runValidations(() => {
179+
assert(tr.succeeded == false, ("Should have failed as channels could not be fetched."));
180+
assert(tr.stdout.indexOf("MatchingVersionNotFound") > -1, "Should not have found a matching version.");
181+
assert(tr.stdout.indexOf("VersionNotFound") > -1, "Should have thrown with VersionNotFound error.");
182+
}, tr, done);
183+
});
184+
185+
it("[VersionFetcher.DotNetCoreVersionFetcher] getVersionInfo should throw if preview versions included and version not found", (done) => {
186+
process.env["__failat__"] = "versionnotfound";
187+
process.env["__versionspec__"] = "4.40.x";
188+
process.env["__inlcudepreviewversion__"] = "true";
189+
let tr = new ttm.MockTestRunner(path.join(__dirname, "versionFetcherGetVersionInfoFailTests.js"));
190+
tr.run();
191+
runValidations(() => {
192+
assert(tr.succeeded == false, ("Should have failed as channels could not be fetched."));
193+
assert(tr.stdout.indexOf("MatchingVersionNotFound") > -1, "Should not have found a matching version.");
194+
assert(tr.stdout.indexOf("VersionNotFound") > -1, "Should have thrown with VersionNotFound error.");
195+
}, tr, done);
196+
});
197+
198+
171199
it("[VersionFetcher.DotNetCoreVersionFetcher] getVersionInfo should return correct version info for a correct version spec", (done) => {
172200
process.env["__versionspec__"] = "2.2.103";
173201
let tr = new ttm.MockTestRunner(path.join(__dirname, "versionFetcherGetVersionInfoTestsCorrect.js"));
@@ -233,6 +261,26 @@ describe('UseDotNet', function () {
233261
}, tr, done);
234262
});
235263

264+
it("[VersionFetcher.DotNetCoreVersionFetcher] getVersionInfo should return latest version info if includePreviewVersion is true and only 1 channel and is preview", (done) => {
265+
process.env["__versionspec__"] = "3.x";
266+
process.env["__inlcudepreviewversion__"] = "true";
267+
let tr = new ttm.MockTestRunner(path.join(__dirname, "versionFetcherGetVersionInfoTestsCorrect.js"));
268+
tr.run();
269+
runValidations(() => {
270+
assert(tr.succeeded == true, ("Should have returned the correct version info."));
271+
}, tr, done);
272+
});
273+
274+
it("[VersionFetcher.DotNetCoreVersionFetcher] getVersionInfo should return latest version info if includePreviewVersion is false and latest version is preview", (done) => {
275+
process.env["__versionspec__"] = "4.x";
276+
process.env["__inlcudepreviewversion__"] = "false";
277+
let tr = new ttm.MockTestRunner(path.join(__dirname, "versionFetcherGetVersionInfoTestsCorrect.js"));
278+
tr.run();
279+
runValidations(() => {
280+
assert(tr.succeeded == true, ("Should have returned the correct version info."));
281+
}, tr, done);
282+
});
283+
236284
it("[VersionFetcher.DotNetCoreVersionFetcher] getDownloadUrl should throw if VersionFilesData doesn't contain download URL", (done) => {
237285
process.env["__ostype__"] = "win";
238286
process.env["__getmachineosfail__"] = "false";

Tasks/UseDotNetV2/Tests/versionFetcherGetVersionInfoFailTests.ts

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,28 @@ mockery.registerMock('typed-rest-client/HttpClient', {
1515
get: function (url: string, headers) {
1616
if (url == DotNetCoreReleasesIndexUrl && process.env["__failat__"] == "versionnotfound") {
1717
return new Promise((resolve, reject) => {
18-
resolve(new HttpClientResponse(`{"releases-index": [{"channel-version": "2.2","releases.json": "${ReleasesJsonUrl2}"}]}`))
18+
resolve(new HttpClientResponse(`{
19+
"releases-index": [
20+
{
21+
"channel-version": "2.2",
22+
"releases.json": "${ReleasesJsonUrl2}"
23+
},
24+
{
25+
"channel-version": "3.0",
26+
"releases.json": "${ReleasesJsonUrl3}",
27+
"support-phase": "preview"
28+
},
29+
{
30+
"channel-version": "4.0",
31+
"releases.json": "${ReleasesJsonUrl4}"
32+
},
33+
{
34+
"channel-version": "4.1",
35+
"releases.json": "${ReleasesJsonUrl5}",
36+
"support-phase": "preview"
37+
}
38+
]
39+
}`))
1940
});
2041
}
2142
else if (url == DotNetCoreReleasesIndexUrl && process.env["__failat__"] == "channelfetch") {
@@ -25,7 +46,62 @@ mockery.registerMock('typed-rest-client/HttpClient', {
2546
}
2647
else if (url == ReleasesJsonUrl2) {
2748
return new Promise((resolve, reject) => {
28-
resolve(new HttpClientResponse(`{"releases": [{"version": "2.2.104","files": ["rid":"winx64", "url": "https://dotnetWindowsDownloadUrl.com"]}]}`));
49+
resolve(new HttpClientResponse(`{
50+
"releases": [
51+
{
52+
"version": "2.2.104",
53+
"files": [
54+
"rid": "winx64",
55+
"url": "https://dotnetWindowsDownloadUrl.com"
56+
]
57+
}
58+
]
59+
}`));
60+
});
61+
}
62+
else if (url == ReleasesJsonUrl3) {
63+
return new Promise((resolve, reject) => {
64+
resolve(new HttpClientResponse(`{
65+
"releases": [
66+
{
67+
"version": "3.0.104",
68+
"files": [
69+
"rid": "winx64",
70+
"url": "https://dotnetWindowsDownloadUrl.com"
71+
]
72+
}
73+
]
74+
}`));
75+
});
76+
}
77+
else if (url == ReleasesJsonUrl4) {
78+
return new Promise((resolve, reject) => {
79+
resolve(new HttpClientResponse(`{
80+
"releases": [
81+
{
82+
"version": "4.0.102",
83+
"files": [
84+
"rid": "winx64",
85+
"url": "https://dotnetWindowsDownloadUrl.com"
86+
]
87+
}
88+
]
89+
}`));
90+
});
91+
}
92+
else if (url == ReleasesJsonUrl5) {
93+
return new Promise((resolve, reject) => {
94+
resolve(new HttpClientResponse(`{
95+
"releases": [
96+
{
97+
"version": "4.1.100",
98+
"files": [
99+
"rid": "winx64",
100+
"url": "https://dotnetWindowsDownloadUrl.com"
101+
]
102+
}
103+
]
104+
}`));
29105
});
30106
}
31107
}
@@ -37,9 +113,23 @@ import { DotNetCoreVersionFetcher } from "../versionfetcher";
37113

38114
const DotNetCoreReleasesIndexUrl: string = "https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases-index.json";
39115
const ReleasesJsonUrl2: string = "https://releases.file.com/version2.2.json"
116+
const ReleasesJsonUrl3: string = "https://releases.file.com/version3.0.json"
117+
const ReleasesJsonUrl4: string = "https://releases.file.com/version4.0.json"
118+
const ReleasesJsonUrl5: string = "https://releases.file.com/version4.1.json"
40119

41120
let versionFetcher = new DotNetCoreVersionFetcher();
42-
versionFetcher.getVersionInfo("2.2.999-cantbefound-234", "sdk", false)
121+
versionFetcher.getVersionInfo(process.env["__versionspec__"], "sdk", process.env["__inlcudepreviewversion__"] == "true")
43122
.catch((ex) => {
44-
tl.setResult(tl.TaskResult.Failed, "FailedAsExpected");
123+
if(process.env["__versionspec__"] == "2.2.999-cantbefound-234") {
124+
tl.setResult(tl.TaskResult.Failed, "FailedAsExpected");
125+
}
126+
else if(process.env["__versionspec__"] == "3.x" && process.env["__inlcudepreviewversion__"] != "true") {
127+
tl.setResult(tl.TaskResult.Failed, "FailedAsExpected");
128+
}
129+
else if(process.env["__versionspec__"] == "4.40.x" && process.env["__inlcudepreviewversion__"] == "true") {
130+
tl.setResult(tl.TaskResult.Failed, "FailedAsExpected");
131+
}
132+
else {
133+
tl.setResult(tl.TaskResult.Succeeded, "succeeded");
134+
}
45135
});

0 commit comments

Comments
 (0)