mirror of
https://github.com/actions/setup-dotnet.git
synced 2024-11-26 05:13:05 +07:00
Merge pull request #30 from actions/obsolete-endpoint
Update from obsolete endpoint
This commit is contained in:
commit
c0e4e5bdd4
@ -26,7 +26,6 @@ const fs_1 = require("fs");
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
const semver = __importStar(require("semver"));
|
||||
const util = __importStar(require("util"));
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
if (!tempDirectory) {
|
||||
let baseLocation;
|
||||
@ -175,39 +174,29 @@ class DotnetCoreInstaller {
|
||||
getDownloadUrls(osSuffixes, version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let downloadUrls = [];
|
||||
let releasesJSON = yield this.getReleasesJson();
|
||||
core.debug('Releases: ' + releasesJSON);
|
||||
let releasesInfo = JSON.parse(yield releasesJSON.readBody());
|
||||
const httpCallbackClient = new httpClient.HttpClient('actions/setup-dotnet', [], {});
|
||||
const releasesJsonUrl = yield this.getReleasesJsonUrl(httpCallbackClient, version.split('.'));
|
||||
let releasesJSON = yield httpCallbackClient.get(releasesJsonUrl);
|
||||
let releasesInfo = JSON.parse(yield releasesJSON.readBody())['releases'];
|
||||
releasesInfo = releasesInfo.filter((releaseInfo) => {
|
||||
return (releaseInfo['version-sdk'] === version ||
|
||||
releaseInfo['version-sdk-display'] === version);
|
||||
return (releaseInfo['sdk']['version'] === version ||
|
||||
releaseInfo['sdk']['version-display'] === version);
|
||||
});
|
||||
if (releasesInfo.length != 0) {
|
||||
let release = releasesInfo[0];
|
||||
let blobUrl = release['blob-sdk'];
|
||||
let dlcUrl = release['dlc--sdk'];
|
||||
let fileName = release['sdk-' + osSuffixes[0]]
|
||||
? release['sdk-' + osSuffixes[0]]
|
||||
: 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);
|
||||
let files = release['sdk']['files'];
|
||||
files = files.filter((file) => {
|
||||
if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) {
|
||||
return (file['url'].endsWith('.zip') || file['url'].endsWith('.tar.gz'));
|
||||
}
|
||||
});
|
||||
if (files.length > 0) {
|
||||
files.forEach((file) => {
|
||||
downloadUrls.push(file['url']);
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (!!blobUrl) {
|
||||
downloadUrls.push(util.format('%s%s', blobUrl.trim(), fileName));
|
||||
}
|
||||
if (!!dlcUrl) {
|
||||
downloadUrls.push(util.format('%s%s', dlcUrl.trim(), fileName));
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
@ -221,9 +210,23 @@ class DotnetCoreInstaller {
|
||||
return downloadUrls;
|
||||
});
|
||||
}
|
||||
getReleasesJson() {
|
||||
var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {});
|
||||
return httpCallbackClient.get(DotNetCoreReleasesUrl);
|
||||
getReleasesJsonUrl(httpCallbackClient, versionParts) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
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) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
@ -306,4 +309,4 @@ class 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';
|
||||
|
@ -186,44 +186,47 @@ export class DotnetCoreInstaller {
|
||||
osSuffixes: string[],
|
||||
version: string
|
||||
): Promise<string[]> {
|
||||
let downloadUrls = [];
|
||||
let releasesJSON = await this.getReleasesJson();
|
||||
core.debug('Releases: ' + releasesJSON);
|
||||
let downloadUrls: string[] = [];
|
||||
|
||||
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) => {
|
||||
return (
|
||||
releaseInfo['version-sdk'] === version ||
|
||||
releaseInfo['version-sdk-display'] === version
|
||||
releaseInfo['sdk']['version'] === version ||
|
||||
releaseInfo['sdk']['version-display'] === version
|
||||
);
|
||||
});
|
||||
|
||||
if (releasesInfo.length != 0) {
|
||||
let release = releasesInfo[0];
|
||||
let blobUrl: string = release['blob-sdk'];
|
||||
let dlcUrl: string = release['dlc--sdk'];
|
||||
let fileName: string = release['sdk-' + osSuffixes[0]]
|
||||
? release['sdk-' + osSuffixes[0]]
|
||||
: release['sdk-' + osSuffixes[1]];
|
||||
let files: any[] = release['sdk']['files'];
|
||||
files = files.filter((file: any) => {
|
||||
if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) {
|
||||
return (
|
||||
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);
|
||||
if (files.length > 0) {
|
||||
files.forEach((file: any) => {
|
||||
downloadUrls.push(file['url']);
|
||||
});
|
||||
} else {
|
||||
if (!!blobUrl) {
|
||||
downloadUrls.push(util.format('%s%s', blobUrl.trim(), fileName));
|
||||
}
|
||||
|
||||
if (!!dlcUrl) {
|
||||
downloadUrls.push(util.format('%s%s', dlcUrl.trim(), fileName));
|
||||
}
|
||||
}
|
||||
} 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 {
|
||||
console.log(
|
||||
@ -241,9 +244,30 @@ export class DotnetCoreInstaller {
|
||||
return downloadUrls;
|
||||
}
|
||||
|
||||
private getReleasesJson(): Promise<HttpClientResponse> {
|
||||
var httpCallbackClient = new httpClient.HttpClient('setup-dotnet', [], {});
|
||||
return httpCallbackClient.get(DotNetCoreReleasesUrl);
|
||||
private async getReleasesJsonUrl(
|
||||
httpCallbackClient: httpClient.HttpClient,
|
||||
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[]> {
|
||||
@ -350,5 +374,5 @@ export class DotnetCoreInstaller {
|
||||
private arch: string;
|
||||
}
|
||||
|
||||
const DotNetCoreReleasesUrl: string =
|
||||
'https://raw.githubusercontent.com/dotnet/core/master/release-notes/releases.json';
|
||||
const DotNetCoreIndexUrl: string =
|
||||
'https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json';
|
||||
|
Loading…
Reference in New Issue
Block a user