Change logic for getting the installed version

This commit is contained in:
IvanZosimov 2022-09-29 13:15:50 +02:00
parent 3fa46bb101
commit 168eb53ca5
3 changed files with 51 additions and 39 deletions

43
dist/index.js vendored
View File

@ -189,6 +189,7 @@ const exec = __importStar(__nccwpck_require__(1514));
const io = __importStar(__nccwpck_require__(7436));
const hc = __importStar(__nccwpck_require__(6255));
const fs_1 = __nccwpck_require__(7147);
const promises_1 = __nccwpck_require__(3292);
const path_1 = __importDefault(__nccwpck_require__(1017));
const semver_1 = __importDefault(__nccwpck_require__(5911));
const utils_1 = __nccwpck_require__(918);
@ -284,8 +285,8 @@ class DotnetCoreInstaller {
}
else {
// This is the default set in install-dotnet.sh
core.addPath(path_1.default.join(process.env['HOME'] + '', '.dotnet'));
core.exportVariable('DOTNET_ROOT', path_1.default.join(process.env['HOME'] + '', '.dotnet'));
core.addPath(DotnetCoreInstaller.installationDirectoryMac);
core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryMac);
}
}
}
@ -351,34 +352,29 @@ class DotnetCoreInstaller {
if (utils_1.IS_LINUX) {
scriptArguments.push('--install-dir', DotnetCoreInstaller.installationDirectoryLinux);
}
if (utils_1.IS_MAC) {
scriptArguments.push('--install-dir', DotnetCoreInstaller.installationDirectoryMac);
}
}
const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, { ignoreReturnCode: true });
if (exitCode) {
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);
}
return this.outputDotnetVersion(stdout);
return this.outputDotnetVersion(dotnetVersion.value, scriptArguments[scriptArguments.length - 1]);
});
}
outputDotnetVersion(logs) {
let resolvedVersion = '';
const installedByScriptPattern = /Installed version is (?<version>\d+\.\d+\.\d.*)$/m;
const preinstalledOnRunnerPattern = /.NET Core SDK with version '(?<version>\d+\.\d+\.\d.*)'/m;
const regExpressions = [
installedByScriptPattern,
preinstalledOnRunnerPattern
];
for (let regExp of regExpressions) {
if (regExp.test(logs)) {
resolvedVersion = logs.match(regExp).groups.version;
break;
}
}
return resolvedVersion;
outputDotnetVersion(version, installationPath) {
return __awaiter(this, void 0, void 0, function* () {
let versionsOnRunner = yield promises_1.readdir(installationPath);
let installedVersion = semver_1.default.maxSatisfying(versionsOnRunner, version);
return installedVersion;
});
}
}
exports.DotnetCoreInstaller = DotnetCoreInstaller;
DotnetCoreInstaller.installationDirectoryWindows = path_1.default.join(process.env['PROGRAMFILES'] + '', 'dotnet');
DotnetCoreInstaller.installationDirectoryLinux = '/usr/share/dotnet';
DotnetCoreInstaller.installationDirectoryMac = path_1.default.join(process.env['HOME'] + '', '.dotnet');
/***/ }),
@ -525,9 +521,10 @@ run();
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.IS_LINUX = exports.IS_WINDOWS = void 0;
exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0;
exports.IS_WINDOWS = process.platform === 'win32';
exports.IS_LINUX = process.platform === 'linux';
exports.IS_MAC = process.platform === 'darwin';
/***/ }),
@ -25715,6 +25712,14 @@ module.exports = require("fs");
/***/ }),
/***/ 3292:
/***/ ((module) => {
"use strict";
module.exports = require("fs/promises");
/***/ }),
/***/ 3685:
/***/ ((module) => {

View File

@ -4,9 +4,10 @@ import * as exec from '@actions/exec';
import * as io from '@actions/io';
import * as hc from '@actions/http-client';
import {chmodSync} from 'fs';
import {readdir} from 'fs/promises';
import path from 'path';
import semver from 'semver';
import {IS_LINUX, IS_WINDOWS} from './utils';
import {IS_LINUX, IS_WINDOWS, IS_MAC} from './utils';
import {QualityOptions} from './setup-dotnet';
export interface DotnetVersion {
@ -116,6 +117,10 @@ export class DotnetCoreInstaller {
'dotnet'
);
private static readonly installationDirectoryLinux = '/usr/share/dotnet';
private static readonly installationDirectoryMac = path.join(
process.env['HOME'] + '',
'.dotnet'
);
static addToPath() {
if (process.env['DOTNET_INSTALL_DIR']) {
@ -136,10 +141,10 @@ export class DotnetCoreInstaller {
);
} else {
// This is the default set in install-dotnet.sh
core.addPath(path.join(process.env['HOME'] + '', '.dotnet'));
core.addPath(DotnetCoreInstaller.installationDirectoryMac);
core.exportVariable(
'DOTNET_ROOT',
path.join(process.env['HOME'] + '', '.dotnet')
DotnetCoreInstaller.installationDirectoryMac
);
}
}
@ -229,6 +234,13 @@ export class DotnetCoreInstaller {
DotnetCoreInstaller.installationDirectoryLinux
);
}
if (IS_MAC) {
scriptArguments.push(
'--install-dir',
DotnetCoreInstaller.installationDirectoryMac
);
}
}
const {exitCode, stdout} = await exec.getExecOutput(
`"${scriptPath}"`,
@ -239,26 +251,20 @@ export class DotnetCoreInstaller {
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);
}
return this.outputDotnetVersion(stdout);
return this.outputDotnetVersion(
dotnetVersion.value,
scriptArguments[scriptArguments.length - 1]
);
}
private outputDotnetVersion(logs: string): string {
let resolvedVersion: string = '';
const installedByScriptPattern = /Installed version is (?<version>\d+\.\d+\.\d.*)$/m;
const preinstalledOnRunnerPattern = /.NET Core SDK with version '(?<version>\d+\.\d+\.\d.*)'/m;
private async outputDotnetVersion(
version,
installationPath
): Promise<string> {
let versionsOnRunner: string[] = await readdir(installationPath);
const regExpressions: RegExp[] = [
installedByScriptPattern,
preinstalledOnRunnerPattern
];
let installedVersion = semver.maxSatisfying(versionsOnRunner, version)!;
for (let regExp of regExpressions) {
if (regExp.test(logs)) {
resolvedVersion = logs.match(regExp)!.groups!.version;
break;
}
}
return resolvedVersion;
return installedVersion;
}
}

View File

@ -1,2 +1,3 @@
export const IS_WINDOWS = process.platform === 'win32';
export const IS_LINUX = process.platform === 'linux';
export const IS_MAC = process.platform === 'darwin';