Skip to content

Commit e169331

Browse files
author
Zachary Eisinger
committed
Rebuild dist package
1 parent 4039072 commit e169331

File tree

1 file changed

+117
-28
lines changed

1 file changed

+117
-28
lines changed

dist/index.js

Lines changed: 117 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17392,7 +17392,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1739217392
});
1739317393
};
1739417394
Object.defineProperty(exports, "__esModule", { value: true });
17395-
exports.DotnetCoreInstaller = void 0;
17395+
exports.DotnetCoreInstaller = exports.DotNetVersionInfo = void 0;
1739617396
// Load tempDirectory before it gets wiped by tool-cache
1739717397
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
1739817398
const core = __importStar(__webpack_require__(470));
@@ -17421,30 +17421,103 @@ if (!tempDirectory) {
1742117421
}
1742217422
tempDirectory = path.join(baseLocation, 'actions', 'temp');
1742317423
}
17424-
class DotnetCoreInstaller {
17424+
/**
17425+
* Represents the inputted version information
17426+
*/
17427+
class DotNetVersionInfo {
1742517428
constructor(version) {
17426-
if (semver.valid(semver.clean(version) || '') == null) {
17427-
throw 'Implicit version not permitted';
17429+
this.isExactVersionSet = false;
17430+
// Check for exact match
17431+
if (semver.valid(semver.clean(version) || '') != null) {
17432+
this.fullversion = semver.clean(version);
17433+
this.isExactVersionSet = true;
17434+
return;
17435+
}
17436+
//Note: No support for previews when using generic
17437+
let parts = version.split('.');
17438+
if (parts.length < 2 || parts.length > 3)
17439+
this.throwInvalidVersionFormat();
17440+
if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') {
17441+
this.throwInvalidVersionFormat();
17442+
}
17443+
let major = this.getVersionNumberOrThrow(parts[0]);
17444+
let minor = this.getVersionNumberOrThrow(parts[1]);
17445+
this.fullversion = major + '.' + minor;
17446+
}
17447+
getVersionNumberOrThrow(input) {
17448+
try {
17449+
if (!input || input.trim() === '')
17450+
this.throwInvalidVersionFormat();
17451+
let number = Number(input);
17452+
if (Number.isNaN(number) || number < 0)
17453+
this.throwInvalidVersionFormat();
17454+
return number;
17455+
}
17456+
catch (_a) {
17457+
this.throwInvalidVersionFormat();
17458+
return -1;
1742817459
}
17429-
this.version = version;
17460+
}
17461+
throwInvalidVersionFormat() {
17462+
throw 'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*';
17463+
}
17464+
/**
17465+
* If true exacatly one version should be resolved
17466+
*/
17467+
isExactVersion() {
17468+
return this.isExactVersionSet;
17469+
}
17470+
version() {
17471+
return this.fullversion;
17472+
}
17473+
}
17474+
exports.DotNetVersionInfo = DotNetVersionInfo;
17475+
/**
17476+
* Represents a resolved version from the Web-Api
17477+
*/
17478+
class ResolvedVersionInfo {
17479+
constructor(downloadUrls, resolvedVersion) {
17480+
if (downloadUrls.length === 0) {
17481+
throw 'DownloadUrls can not be empty';
17482+
}
17483+
if (!resolvedVersion) {
17484+
throw 'Resolved version is invalid';
17485+
}
17486+
this.downloadUrls = downloadUrls;
17487+
this.resolvedVersion = resolvedVersion;
17488+
}
17489+
}
17490+
class DotnetCoreInstaller {
17491+
constructor(version) {
17492+
this.versionInfo = new DotNetVersionInfo(version);
1743017493
this.cachedToolName = 'dncs';
1743117494
this.arch = 'x64';
1743217495
}
1743317496
installDotnet() {
1743417497
return __awaiter(this, void 0, void 0, function* () {
1743517498
// Check cache
17436-
let toolPath;
17499+
let toolPath = '';
1743717500
let osSuffixes = yield this.detectMachineOS();
1743817501
let parts = osSuffixes[0].split('-');
1743917502
if (parts.length > 1) {
1744017503
this.arch = parts[1];
1744117504
}
17442-
toolPath = this.getLocalTool();
17505+
// If version is not generic -> look up cache
17506+
if (this.versionInfo.isExactVersion())
17507+
toolPath = this.getLocalTool(this.versionInfo.version());
1744317508
if (!toolPath) {
1744417509
// download, extract, cache
17445-
console.log('Getting a download url', this.version);
17446-
let downloadUrls = yield this.getDownloadUrls(osSuffixes, this.version);
17447-
toolPath = yield this.downloadAndInstall(downloadUrls);
17510+
console.log('Getting a download url', this.versionInfo.version());
17511+
let resolvedVersionInfo = yield this.resolveInfos(osSuffixes, this.versionInfo);
17512+
//Check if cache exists for resolved version
17513+
toolPath = this.getLocalTool(resolvedVersionInfo.resolvedVersion);
17514+
if (!toolPath) {
17515+
//If not exists install it
17516+
toolPath = yield this.downloadAndInstall(resolvedVersionInfo);
17517+
}
17518+
else {
17519+
console.log('Using cached tool');
17520+
}
1744817521
}
1744917522
else {
1745017523
console.log('Using cached tool');
@@ -17455,9 +17528,9 @@ class DotnetCoreInstaller {
1745517528
core.addPath(toolPath);
1745617529
});
1745717530
}
17458-
getLocalTool() {
17459-
console.log('Checking tool cache');
17460-
return tc.find(this.cachedToolName, this.version, this.arch);
17531+
getLocalTool(version) {
17532+
console.log('Checking tool cache', version);
17533+
return tc.find(this.cachedToolName, version, this.arch);
1746117534
}
1746217535
detectMachineOS() {
1746317536
return __awaiter(this, void 0, void 0, function* () {
@@ -17517,18 +17590,18 @@ class DotnetCoreInstaller {
1751717590
return osSuffix;
1751817591
});
1751917592
}
17520-
downloadAndInstall(downloadUrls) {
17593+
downloadAndInstall(resolvedVersionInfo) {
1752117594
return __awaiter(this, void 0, void 0, function* () {
1752217595
let downloaded = false;
1752317596
let downloadPath = '';
17524-
for (const url of downloadUrls) {
17597+
for (const url of resolvedVersionInfo.downloadUrls) {
1752517598
try {
1752617599
downloadPath = yield tc.downloadTool(url);
1752717600
downloaded = true;
1752817601
break;
1752917602
}
1753017603
catch (error) {
17531-
console.log('Could Not Download', url, JSON.stringify(error));
17604+
console.log('Could not Download', url, JSON.stringify(error));
1753217605
}
1753317606
}
1753417607
if (!downloaded) {
@@ -17541,31 +17614,40 @@ class DotnetCoreInstaller {
1754117614
: yield tc.extractTar(downloadPath);
1754217615
// cache tool
1754317616
console.log('Caching tool');
17544-
let cachedDir = yield tc.cacheDir(extPath, this.cachedToolName, this.version, this.arch);
17545-
console.log('Successfully installed', this.version);
17617+
let cachedDir = yield tc.cacheDir(extPath, this.cachedToolName, resolvedVersionInfo.resolvedVersion, this.arch);
17618+
console.log('Successfully installed', resolvedVersionInfo.resolvedVersion);
1754617619
return cachedDir;
1754717620
});
1754817621
}
1754917622
// OsSuffixes - The suffix which is a part of the file name ex- linux-x64, windows-x86
1755017623
// Type - SDK / Runtime
17551-
// Version - Version of the SDK/Runtime
17552-
getDownloadUrls(osSuffixes, version) {
17624+
// versionInfo - versionInfo of the SDK/Runtime
17625+
resolveInfos(osSuffixes, versionInfo) {
1755317626
return __awaiter(this, void 0, void 0, function* () {
17554-
let downloadUrls = [];
1755517627
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
1755617628
allowRetries: true,
1755717629
maxRetries: 3
1755817630
});
17559-
const releasesJsonUrl = yield this.getReleasesJsonUrl(httpClient, version.split('.'));
17631+
const releasesJsonUrl = yield this.getReleasesJsonUrl(httpClient, versionInfo.version().split('.'));
1756017632
const releasesResponse = yield httpClient.getJson(releasesJsonUrl);
1756117633
const releasesResult = releasesResponse.result || {};
1756217634
let releasesInfo = releasesResult['releases'];
1756317635
releasesInfo = releasesInfo.filter((releaseInfo) => {
17564-
return (releaseInfo['sdk']['version'] === version ||
17565-
releaseInfo['sdk']['version-display'] === version);
17636+
return (semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version()) ||
17637+
semver.satisfies(releaseInfo['sdk']['version-display'], versionInfo.version()));
1756617638
});
17639+
// Exclude versions that are newer than the latest if using not exact
17640+
if (!versionInfo.isExactVersion()) {
17641+
let latestSdk = releasesResult['latest-sdk'];
17642+
releasesInfo = releasesInfo.filter((releaseInfo) => semver.lte(releaseInfo['sdk']['version'], latestSdk));
17643+
}
17644+
// Sort for latest version
17645+
releasesInfo = releasesInfo.sort((a, b) => semver.rcompare(a['sdk']['version'], b['sdk']['version']));
17646+
let downloadedVersion = '';
17647+
let downloadUrls = [];
1756717648
if (releasesInfo.length != 0) {
1756817649
let release = releasesInfo[0];
17650+
downloadedVersion = release['sdk']['version'];
1756917651
let files = release['sdk']['files'];
1757017652
files = files.filter((file) => {
1757117653
if (file['rid'] == osSuffixes[0] || file['rid'] == osSuffixes[1]) {
@@ -17582,14 +17664,21 @@ class DotnetCoreInstaller {
1758217664
}
1758317665
}
1758417666
else {
17585-
console.log(`Could not fetch download information for version ${version}`);
17586-
downloadUrls = yield this.getFallbackDownloadUrls(version);
17667+
console.log(`Could not fetch download information for version ${versionInfo.version()}`);
17668+
if (versionInfo.isExactVersion()) {
17669+
console.log('Using fallback');
17670+
downloadUrls = yield this.getFallbackDownloadUrls(versionInfo.version());
17671+
downloadedVersion = versionInfo.version();
17672+
}
17673+
else {
17674+
console.log('Unable to use fallback, version is generic!');
17675+
}
1758717676
}
1758817677
if (downloadUrls.length == 0) {
17589-
throw `Could not construct download URL. Please ensure that specified version ${version} is valid.`;
17678+
throw `Could not construct download URL. Please ensure that specified version ${versionInfo.version()}/${downloadedVersion} is valid.`;
1759017679
}
1759117680
core.debug(`Got download urls ${downloadUrls}`);
17592-
return downloadUrls;
17681+
return new ResolvedVersionInfo(downloadUrls, downloadedVersion);
1759317682
});
1759417683
}
1759517684
getReleasesJsonUrl(httpClient, versionParts) {

0 commit comments

Comments
 (0)