Merge pull request #30 from actions/obsolete-endpoint

Update from obsolete endpoint
This commit is contained in:
Zachary Eisinger 2019-10-22 10:50:14 -07:00 committed by GitHub
commit c0e4e5bdd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 91 additions and 64 deletions

View File

@ -26,7 +26,6 @@ const fs_1 = require("fs");
const os = __importStar(require("os")); const os = __importStar(require("os"));
const path = __importStar(require("path")); const path = __importStar(require("path"));
const semver = __importStar(require("semver")); const semver = __importStar(require("semver"));
const util = __importStar(require("util"));
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
if (!tempDirectory) { if (!tempDirectory) {
let baseLocation; let baseLocation;
@ -175,39 +174,29 @@ class DotnetCoreInstaller {
getDownloadUrls(osSuffixes, version) { getDownloadUrls(osSuffixes, version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let downloadUrls = []; let downloadUrls = [];
let releasesJSON = yield this.getReleasesJson(); const httpCallbackClient = new httpClient.HttpClient('actions/setup-dotnet', [], {});
core.debug('Releases: ' + releasesJSON); const releasesJsonUrl = yield this.getReleasesJsonUrl(httpCallbackClient, version.split('.'));
let releasesInfo = JSON.parse(yield releasesJSON.readBody()); let releasesJSON = yield httpCallbackClient.get(releasesJsonUrl);
let releasesInfo = JSON.parse(yield releasesJSON.readBody())['releases'];
releasesInfo = releasesInfo.filter((releaseInfo) => { releasesInfo = releasesInfo.filter((releaseInfo) => {
return (releaseInfo['version-sdk'] === version || return (releaseInfo['sdk']['version'] === version ||
releaseInfo['version-sdk-display'] === version); releaseInfo['sdk']['version-display'] === version);
}); });
if (releasesInfo.length != 0) { if (releasesInfo.length != 0) {
let release = releasesInfo[0]; let release = releasesInfo[0];
let blobUrl = release['blob-sdk']; let files = release['sdk']['files'];
let dlcUrl = release['dlc--sdk']; files = files.filter((file) => {
let fileName = release['sdk-' + osSuffixes[0]] if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) {
? release['sdk-' + osSuffixes[0]] return (file['url'].endsWith('.zip') || file['url'].endsWith('.tar.gz'));
: release['sdk-' + osSuffixes[1]];
if (!!fileName) {
fileName = fileName.trim();
// For some latest version, the filename itself can be full download url.
// Do a very basic check for url(instead of regex) as the url is only for downloading and
// is coming from .net core releases json and not some ransom user input
if (fileName.toLowerCase().startsWith('https://')) {
downloadUrls.push(fileName);
}
else {
if (!!blobUrl) {
downloadUrls.push(util.format('%s%s', blobUrl.trim(), fileName));
}
if (!!dlcUrl) {
downloadUrls.push(util.format('%s%s', dlcUrl.trim(), fileName));
}
} }
});
if (files.length > 0) {
files.forEach((file) => {
downloadUrls.push(file['url']);
});
} }
else { else {
throw `The specified version's download links are not correctly formed in the supported versions document => ${DotNetCoreReleasesUrl}`; throw `The specified version's download links are not correctly formed in the supported versions document => ${releasesJsonUrl}`;
} }
} }
else { else {
@ -221,9 +210,23 @@ class DotnetCoreInstaller {
return downloadUrls; return downloadUrls;
}); });
} }
getReleasesJson() { getReleasesJsonUrl(httpCallbackClient, versionParts) {
var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {}); return __awaiter(this, void 0, void 0, function* () {
return httpCallbackClient.get(DotNetCoreReleasesUrl); const releasesIndex = yield httpCallbackClient.get(DotNetCoreIndexUrl);
let releasesInfo = JSON.parse(yield releasesIndex.readBody())['releases-index'];
releasesInfo = releasesInfo.filter((info) => {
// channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x.
const sdkParts = info['channel-version'].split('.');
if (versionParts.length >= 2 && versionParts[1] != 'x') {
return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1];
}
return versionParts[0] == sdkParts[0];
});
if (releasesInfo.length === 0) {
throw `Could not find info for version ${versionParts.join('.')} at ${DotNetCoreIndexUrl}`;
}
return releasesInfo[0]['releases.json'];
});
} }
getFallbackDownloadUrls(version) { getFallbackDownloadUrls(version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -306,4 +309,4 @@ class DotnetCoreInstaller {
} }
} }
exports.DotnetCoreInstaller = DotnetCoreInstaller; exports.DotnetCoreInstaller = DotnetCoreInstaller;
const DotNetCoreReleasesUrl = 'https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases.json'; const DotNetCoreIndexUrl = 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json';

View File

@ -186,44 +186,47 @@ export class DotnetCoreInstaller {
osSuffixes: string[], osSuffixes: string[],
version: string version: string
): Promise<string[]> { ): Promise<string[]> {
let downloadUrls = []; let downloadUrls: string[] = [];
let releasesJSON = await this.getReleasesJson();
core.debug('Releases: ' + releasesJSON);
let releasesInfo = JSON.parse(await releasesJSON.readBody()); const httpCallbackClient = new httpClient.HttpClient(
'actions/setup-dotnet',
[],
{}
);
const releasesJsonUrl: string = await this.getReleasesJsonUrl(
httpCallbackClient,
version.split('.')
);
let releasesJSON = await httpCallbackClient.get(releasesJsonUrl);
let releasesInfo: any[] = JSON.parse(await releasesJSON.readBody())[
'releases'
];
releasesInfo = releasesInfo.filter((releaseInfo: any) => { releasesInfo = releasesInfo.filter((releaseInfo: any) => {
return ( return (
releaseInfo['version-sdk'] === version || releaseInfo['sdk']['version'] === version ||
releaseInfo['version-sdk-display'] === version releaseInfo['sdk']['version-display'] === version
); );
}); });
if (releasesInfo.length != 0) { if (releasesInfo.length != 0) {
let release = releasesInfo[0]; let release = releasesInfo[0];
let blobUrl: string = release['blob-sdk']; let files: any[] = release['sdk']['files'];
let dlcUrl: string = release['dlc--sdk']; files = files.filter((file: any) => {
let fileName: string = release['sdk-' + osSuffixes[0]] if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) {
? release['sdk-' + osSuffixes[0]] return (
: release['sdk-' + osSuffixes[1]]; file['url'].endsWith('.zip') || file['url'].endsWith('.tar.gz')
);
if (!!fileName) {
fileName = fileName.trim();
// For some latest version, the filename itself can be full download url.
// Do a very basic check for url(instead of regex) as the url is only for downloading and
// is coming from .net core releases json and not some ransom user input
if (fileName.toLowerCase().startsWith('https://')) {
downloadUrls.push(fileName);
} else {
if (!!blobUrl) {
downloadUrls.push(util.format('%s%s', blobUrl.trim(), fileName));
}
if (!!dlcUrl) {
downloadUrls.push(util.format('%s%s', dlcUrl.trim(), fileName));
}
} }
});
if (files.length > 0) {
files.forEach((file: any) => {
downloadUrls.push(file['url']);
});
} else { } else {
throw `The specified version's download links are not correctly formed in the supported versions document => ${DotNetCoreReleasesUrl}`; throw `The specified version's download links are not correctly formed in the supported versions document => ${releasesJsonUrl}`;
} }
} else { } else {
console.log( console.log(
@ -241,9 +244,30 @@ export class DotnetCoreInstaller {
return downloadUrls; return downloadUrls;
} }
private getReleasesJson(): Promise<HttpClientResponse> { private async getReleasesJsonUrl(
var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {}); httpCallbackClient: httpClient.HttpClient,
return httpCallbackClient.get(DotNetCoreReleasesUrl); versionParts: string[]
): Promise<string> {
const releasesIndex: HttpClientResponse = await httpCallbackClient.get(
DotNetCoreIndexUrl
);
let releasesInfo: any[] = JSON.parse(await releasesIndex.readBody())[
'releases-index'
];
releasesInfo = releasesInfo.filter((info: any) => {
// channel-version is the first 2 elements of the version (e.g. 2.1), filter out versions that don't match 2.1.x.
const sdkParts: string[] = info['channel-version'].split('.');
if (versionParts.length >= 2 && versionParts[1] != 'x') {
return versionParts[0] == sdkParts[0] && versionParts[1] == sdkParts[1];
}
return versionParts[0] == sdkParts[0];
});
if (releasesInfo.length === 0) {
throw `Could not find info for version ${versionParts.join(
'.'
)} at ${DotNetCoreIndexUrl}`;
}
return releasesInfo[0]['releases.json'];
} }
private async getFallbackDownloadUrls(version: string): Promise<string[]> { private async getFallbackDownloadUrls(version: string): Promise<string[]> {
@ -350,5 +374,5 @@ export class DotnetCoreInstaller {
private arch: string; private arch: string;
} }
const DotNetCoreReleasesUrl: string = const DotNetCoreIndexUrl: string =
'https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases.json'; 'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json';