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

View File

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

View File

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