Implement dotnet-version output

This commit is contained in:
IvanZosimov 2022-09-27 15:13:09 +02:00
parent 0705ef0281
commit a77dbf07aa
4 changed files with 60 additions and 2 deletions

View File

@ -17,6 +17,9 @@ inputs:
description: 'Optional OWNER for using packages from GitHub Package Registry organizations/users other than the current repository''s owner. Only used if a GPR URL is also provided in source-url'
config-file:
description: 'Optional NuGet.config location, if your NuGet.config isn''t located in the root of the repo.'
outputs:
dotnet-version:
description: 'Contains the installed by action .NET SDK version for reuse.'
runs:
using: 'node16'
main: 'dist/index.js'

25
dist/index.js vendored
View File

@ -356,8 +356,25 @@ class DotnetCoreInstaller {
if (exitCode) {
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);
}
return this.outputDotnetVersion(stdout);
});
}
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;
let regExpressions = [
installedByScriptPattern,
preinstalledOnRunnerPattern
];
for (let regExp of regExpressions) {
if (regExp.test(logs)) {
resolvedVersion = logs.match(regExp).groups.version;
break;
}
}
return resolvedVersion;
}
}
exports.DotnetCoreInstaller = DotnetCoreInstaller;
DotnetCoreInstaller.installationDirectoryWindows = path_1.default.join(process.env['PROGRAMFILES'] + '', 'dotnet');
@ -408,6 +425,7 @@ const core = __importStar(__nccwpck_require__(2186));
const installer_1 = __nccwpck_require__(1480);
const fs = __importStar(__nccwpck_require__(7147));
const path_1 = __importDefault(__nccwpck_require__(1017));
const semver_1 = __importDefault(__nccwpck_require__(5911));
const auth = __importStar(__nccwpck_require__(8527));
const qualityOptions = [
'daily',
@ -429,6 +447,7 @@ function run() {
// Proxy, auth, (etc) are still set up, even if no version is identified
//
const versions = core.getMultilineInput('dotnet-version');
let installedDotnetVersions = [];
const globalJsonFileInput = core.getInput('global-json-file');
if (globalJsonFileInput) {
const globalJsonPath = path_1.default.join(process.cwd(), globalJsonFileInput);
@ -454,7 +473,8 @@ function run() {
const uniqueVersions = new Set(versions);
for (const version of uniqueVersions) {
dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality);
yield dotnetInstaller.installDotnet();
let installedVersion = yield dotnetInstaller.installDotnet();
installedDotnetVersions.push(installedVersion);
}
installer_1.DotnetCoreInstaller.addToPath();
}
@ -463,6 +483,9 @@ function run() {
if (sourceUrl) {
auth.configAuthentication(sourceUrl, configFile);
}
core.setOutput('dotnet-version', semver_1.default.maxSatisfying(installedDotnetVersions, '*', {
includePrerelease: true
}));
const matchersPath = path_1.default.join(__dirname, '..', '.github');
core.info(`##[add-matcher]${path_1.default.join(matchersPath, 'csc.json')}`);
}

View File

@ -238,5 +238,27 @@ export class DotnetCoreInstaller {
if (exitCode) {
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);
}
return this.outputDotnetVersion(stdout);
}
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;
let regExpressions: RegExp[] = [
installedByScriptPattern,
preinstalledOnRunnerPattern
];
for (let regExp of regExpressions) {
if (regExp.test(logs)) {
resolvedVersion = logs.match(regExp)!.groups!.version;
break;
}
}
return resolvedVersion;
}
}

View File

@ -2,6 +2,7 @@ import * as core from '@actions/core';
import {DotnetCoreInstaller} from './installer';
import * as fs from 'fs';
import path from 'path';
import semver from 'semver';
import * as auth from './authutil';
const qualityOptions = [
@ -26,6 +27,7 @@ export async function run() {
// Proxy, auth, (etc) are still set up, even if no version is identified
//
const versions = core.getMultilineInput('dotnet-version');
let installedDotnetVersions: string[] = [];
const globalJsonFileInput = core.getInput('global-json-file');
if (globalJsonFileInput) {
@ -60,7 +62,8 @@ export async function run() {
const uniqueVersions = new Set<string>(versions);
for (const version of uniqueVersions) {
dotnetInstaller = new DotnetCoreInstaller(version, quality);
await dotnetInstaller.installDotnet();
let installedVersion = await dotnetInstaller.installDotnet();
installedDotnetVersions.push(installedVersion);
}
DotnetCoreInstaller.addToPath();
}
@ -71,6 +74,13 @@ export async function run() {
auth.configAuthentication(sourceUrl, configFile);
}
core.setOutput(
'dotnet-version',
semver.maxSatisfying(installedDotnetVersions, '*', {
includePrerelease: true
})
);
const matchersPath = path.join(__dirname, '..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'csc.json')}`);
} catch (error) {