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

[DotnetCoreInstaller] Fetching download urls from releases.json file #7434

Merged
merged 11 commits into from
Jun 22, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"loc.input.label.packageType": "Package to install",
"loc.input.help.packageType": "Please select whether to install only runtime or full SDK.",
"loc.input.label.version": "Version",
"loc.input.help.version": "Specify exact version of .NET Core SDK or runtime to install.<br/><br/>Examples:<br/>1. To install 1.0.4 SDK, use 1.0.4<br/>2. To install 1.1.2 runtime, use 1.1.2<br/>2. To install 2.0 preview 2 runtime, use 2.0.0-preview2-25407-01<br/><br/>For getting more details about exact version of runtime (, refer [here](https://github.com/dotnet/core/blob/master/release-notes/releases.json)",
"loc.input.help.version": "Specify exact version of .NET Core SDK or runtime to install.<br/><br/>Examples:<br/>1. To install 1.0.4 SDK, use 1.0.4<br/>2. To install 1.1.2 runtime, use 1.1.2<br/>2. To install 2.0 preview 2 runtime, use 2.0.0-preview2-25407-01<br/><br/>For getting more details about exact version refer [here](https://github.com/dotnet/core/blob/master/release-notes/releases.json)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text is not up-to the mark. Can you specify the exact strings to look for in the json

"loc.messages.ToolFailed": "Tool install failed: %s",
"loc.messages.ImplicitVersionNotSupported": "Version should be a valid and explicit version: %s",
"loc.messages.getMachinePlatformFailed": "Failed to get machine platform details. Error: %s.",
Expand Down
7 changes: 3 additions & 4 deletions Tasks/DotNetCoreInstallerV0/Tests/InstallNix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ process.env["AGENT_TEMPDIRECTORY"] = "/agent/_temp";

let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"exec": {
"somedir/currdir/externals/get-os-distro.sh": {
"/somedir/currdir/externals/get-os-distro.sh": {
"code": 0,
"stdout": "Primary: linux" + os.EOL,
}
Expand All @@ -23,14 +23,13 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"osType": "Linux"
},
"which": {
"somedir/currdir/externals/get-os-distro.sh": "somedir/currdir/externals/get-os-distro.sh"
"/somedir/currdir/externals/get-os-distro.sh": "/somedir/currdir/externals/get-os-distro.sh"
},
"checkPath": {
"somedir/currdir/externals/get-os-distro.sh": true
"/somedir/currdir/externals/get-os-distro.sh": true
}
};

var ut = require('../utilities');
tr.registerMock('./utilities', {
getCurrentDir: function () {
return "/somedir/currdir";
Expand Down
18 changes: 16 additions & 2 deletions Tasks/DotNetCoreInstallerV0/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('DotNetCoreInstaller', function() {

runValidations(() => {
assert(tr.succeeded, "Should have succeeded");
assert(tr.stdout.indexOf("loc_mock_PrimaryUrlDownloadFailed 404 not found https://primary-url") >= -1, "should print primary url failure error")
assert(tr.stdout.indexOf("404 not found https://primary-url") > -1, "should print primary url failure error")
assert(tr.stdout.indexOf("Downloading tool from https://legacy-url") > -1, "should download from legacy url");
}, tr, done);
});
Expand Down Expand Up @@ -137,7 +137,7 @@ describe('DotNetCoreInstaller', function() {
assert(tr.stdout.indexOf("loc_mock_ToolToInstall sdk 1.0.4") > -1, "should print to-be-installed info");
assert(tr.stdout.indexOf("Checking local tool for dncs and version 1.0.4") > -1, "should check for local cached tool");
assert(tr.stdout.indexOf("loc_mock_InstallingAfresh") > -1, "should install fresh if cache miss");
assert(tr.stdout.indexOf("Changing attribute for file /somedir/currdir/externals/install-dotnet.sh to 777") > -1, "should iset executable attribute for install script");
assert(tr.stdout.indexOf("Changing attribute for file /somedir/currdir/externals/get-os-distro.sh to 777") > -1, "should iset executable attribute for install script");
assert(tr.stdout.indexOf("Downloading tool from https://primary-url") > -1, "should download from correct url");
assert(tr.stdout.indexOf("Extracting tar archive from /agent/_temp/someArchive.tar") > -1, "Should extract downloaded archive corectly");
assert(tr.stdout.indexOf("Caching dir /agent/_temp/someDir for tool dncs version 1.0.4") > -1, "should cache correctly");
Expand Down Expand Up @@ -184,5 +184,19 @@ describe('DotNetCoreInstaller', function() {
assert(tr.stdout.indexOf("prepending path: /agent/_tools/oldCacheDir") > -1, "should pre-prend to PATH");
}, tr, done);
});

it("[nix]Should download using DLC url if primary url does not work", (done) => {
process.env["__primary_url_failed__"] = "true";
let tp = path.join(__dirname, "InstallNix.js");
let tr = new ttm.MockTestRunner(tp);
tr.run();
delete process.env["__primary_url_failed__"];

runValidations(() => {
assert(tr.succeeded, "Should have succeeded");
assert(tr.stdout.indexOf("404 not found https://primary-url") > -1, "should print primary url failure error")
assert(tr.stdout.indexOf("Downloading tool from https://legacy-url") > -1, "should download from legacy url");
}, tr, done);
});
}
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 6 additions & 11 deletions Tasks/DotNetCoreInstallerV0/dotnetcoreinstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class DotnetCoreInstaller {
console.log(tl.loc("InstallingAfresh"));
let osSuffixes = this.detectMachineOS();
console.log(tl.loc("GettingDownloadUrl", this.packageType, this.version));
console.log("DotNetCoreReleaseFetcher ", JSON.stringify(DotNetCoreReleaseFetcher));
let downloadUrls = await DotNetCoreReleaseFetcher.getDownloadUrls(osSuffixes, this.version, this.packageType);
toolPath = await this.downloadAndInstall(downloadUrls);
} else {
Expand Down Expand Up @@ -68,16 +67,16 @@ class DotnetCoreInstaller {
let output: string = result.stdout;

let index;
if (index = output.indexOf("Primary:")) {
let primary = output.substr(index).split(os.EOL)[0];
if ((index = output.indexOf("Primary:")) >= 0) {
let primary = output.substr(index + "Primary:".length).split(os.EOL)[0];
osSuffix.push(primary);
console.log(tl.loc("PrimaryPlatform", primary));
}

if (index = output.indexOf("Legacy:")) {
let legacy = output.substr(index).split(os.EOL)[0];
if (index = output.indexOf("Legacy:") >= 0) {
let legacy = output.substr(index + "Legacy:".length).split(os.EOL)[0];
osSuffix.push(legacy);
console.log(tl.loc("PrimaryPlatform", legacy));
console.log(tl.loc("LegacyPlatform", legacy));
}

if (osSuffix.length == 0) {
Expand All @@ -92,13 +91,10 @@ class DotnetCoreInstaller {
let downloaded = false;
let downloadPath = "";
for (var i = 0; i < downloadUrls.length; i++) {
if (downloaded) {
break;
}

try {
downloadPath = await toolLib.downloadTool(downloadUrls[i]);
downloaded = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break here itself instead of having an if condition at the top

break;
} catch (error) {
tl.warning(tl.loc("CouldNotDownload", downloadUrls[i], JSON.stringify(error)));
}
Expand All @@ -117,7 +113,6 @@ class DotnetCoreInstaller {
let cachedDir = await toolLib.cacheDir(extPath, this.cachedToolName, this.version);
console.log(tl.loc("SuccessfullyInstalled", this.packageType, this.version));
return cachedDir;

}

private packageType: string;
Expand Down
8 changes: 4 additions & 4 deletions Tasks/DotNetCoreInstallerV0/releasesfetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { HttpClientResponse } from 'typed-rest-client/HttpClient';

export class DotNetCoreReleaseFetcher {

public static async getDownloadUrls(osSuffixes: string[], version: string, type: string) {
public static async getDownloadUrls(osSuffixes: string[], version: string, type: string): Promise<string[]> {
let downloadUrls = [];
let releasesCSV = await this.getReleasesJson();
let versionsInfo = JSON.parse(await releasesCSV.readBody());
let releasesJSON = await this.getReleasesJson();

let releasesInfo: any[] = versionsInfo.filter(releaseInfo => {
let releasesInfo = JSON.parse(await releasesJSON.readBody());
releasesInfo = releasesInfo.filter(releaseInfo => {
return releaseInfo['version-' + type] === version || releaseInfo['version-' + type + '-display'] === version;
});

Expand Down
2 changes: 1 addition & 1 deletion Tasks/DotNetCoreInstallerV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"label": "Version",
"defaultValue": "1.0.4",
"required": true,
"helpMarkDown": "Specify exact version of .NET Core SDK or runtime to install.<br/><br/>Examples:<br/>1. To install 1.0.4 SDK, use 1.0.4<br/>2. To install 1.1.2 runtime, use 1.1.2<br/>2. To install 2.0 preview 2 runtime, use 2.0.0-preview2-25407-01<br/><br/>For getting more details about exact version of runtime (, refer [here](https://github.com/dotnet/core/blob/master/release-notes/releases.json)"
"helpMarkDown": "Specify exact version of .NET Core SDK or runtime to install.<br/><br/>Examples:<br/>1. To install 1.0.4 SDK, use 1.0.4<br/>2. To install 1.1.2 runtime, use 1.1.2<br/>2. To install 2.0 preview 2 runtime, use 2.0.0-preview2-25407-01<br/><br/>For getting more details about exact version refer [here](https://github.com/dotnet/core/blob/master/release-notes/releases.json)"
}
],
"execution": {
Expand Down