mirror of
https://github.com/actions/setup-dotnet.git
synced 2024-11-22 19:41:08 +07:00
update logic of outputting dotnet-version
This commit is contained in:
parent
e8501859aa
commit
fefaa59d2e
40
dist/index.js
vendored
40
dist/index.js
vendored
@ -439,7 +439,8 @@ class DotnetCoreInstaller {
|
|||||||
const regex = /(?<version>\d+\.\d+\.\d+[a-z0-9._-]*)/gm;
|
const regex = /(?<version>\d+\.\d+\.\d+[a-z0-9._-]*)/gm;
|
||||||
const matchedResult = regex.exec(stdout);
|
const matchedResult = regex.exec(stdout);
|
||||||
if (!matchedResult) {
|
if (!matchedResult) {
|
||||||
throw new Error(`Failed to parse installed by the script version of .NET`);
|
core.warning(`Failed to parse installed by the script version of .NET`);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return matchedResult.groups.version;
|
return matchedResult.groups.version;
|
||||||
}
|
}
|
||||||
@ -577,13 +578,18 @@ function run() {
|
|||||||
if (sourceUrl) {
|
if (sourceUrl) {
|
||||||
auth.configAuthentication(sourceUrl, configFile);
|
auth.configAuthentication(sourceUrl, configFile);
|
||||||
}
|
}
|
||||||
const comparisonRange = globalJsonFileInput
|
// const comparisonRange: string = globalJsonFileInput
|
||||||
? versions[versions.length - 1]
|
// ? versions[versions.length - 1]!
|
||||||
: '*';
|
// : '*';
|
||||||
const versionToOutput = semver_1.default.maxSatisfying(installedDotnetVersions, comparisonRange, {
|
// const versionToOutput = semver.maxSatisfying(
|
||||||
includePrerelease: true
|
// installedDotnetVersions,
|
||||||
});
|
// comparisonRange,
|
||||||
core.setOutput('dotnet-version', versionToOutput);
|
// {
|
||||||
|
// includePrerelease: true
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
// core.setOutput('dotnet-version', versionToOutput);
|
||||||
|
outputInstalledVersion(installedDotnetVersions, globalJsonFileInput);
|
||||||
const matchersPath = path_1.default.join(__dirname, '..', '.github');
|
const matchersPath = path_1.default.join(__dirname, '..', '.github');
|
||||||
core.info(`##[add-matcher]${path_1.default.join(matchersPath, 'csc.json')}`);
|
core.info(`##[add-matcher]${path_1.default.join(matchersPath, 'csc.json')}`);
|
||||||
}
|
}
|
||||||
@ -608,6 +614,24 @@ function getVersionFromGlobalJson(globalJsonPath) {
|
|||||||
}
|
}
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
function outputInstalledVersion(installedVersions, globalJsonFileInput) {
|
||||||
|
if (!installedVersions.length) {
|
||||||
|
core.info(`No .NET version was installed. The 'dotnet-version' output will not be set.`);
|
||||||
|
}
|
||||||
|
if (installedVersions.includes(null)) {
|
||||||
|
core.warning(`Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (globalJsonFileInput) {
|
||||||
|
const versionToOutput = installedVersions.at(-1);
|
||||||
|
core.setOutput('dotnet-version', versionToOutput);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const versionToOutput = semver_1.default.maxSatisfying(installedVersions, '*', {
|
||||||
|
includePrerelease: true
|
||||||
|
});
|
||||||
|
core.setOutput('dotnet-version', versionToOutput);
|
||||||
|
}
|
||||||
run();
|
run();
|
||||||
|
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ export class DotnetCoreInstaller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async installDotnet(): Promise<string> {
|
public async installDotnet(): Promise<string | null> {
|
||||||
const windowsDefaultOptions = [
|
const windowsDefaultOptions = [
|
||||||
'-NoLogo',
|
'-NoLogo',
|
||||||
'-Sta',
|
'-Sta',
|
||||||
@ -271,14 +271,13 @@ export class DotnetCoreInstaller {
|
|||||||
return this.parseInstalledVersion(stdout);
|
return this.parseInstalledVersion(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseInstalledVersion(stdout: string): string {
|
private parseInstalledVersion(stdout: string): string | null {
|
||||||
const regex = /(?<version>\d+\.\d+\.\d+[a-z0-9._-]*)/gm;
|
const regex = /(?<version>\d+\.\d+\.\d+[a-z0-9._-]*)/gm;
|
||||||
const matchedResult = regex.exec(stdout);
|
const matchedResult = regex.exec(stdout);
|
||||||
|
|
||||||
if (!matchedResult) {
|
if (!matchedResult) {
|
||||||
throw new Error(
|
core.warning(`Failed to parse installed by the script version of .NET`);
|
||||||
`Failed to parse installed by the script version of .NET`
|
return null;
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return matchedResult.groups!.version;
|
return matchedResult.groups!.version;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ export async function run() {
|
|||||||
// Proxy, auth, (etc) are still set up, even if no version is identified
|
// Proxy, auth, (etc) are still set up, even if no version is identified
|
||||||
//
|
//
|
||||||
const versions = core.getMultilineInput('dotnet-version');
|
const versions = core.getMultilineInput('dotnet-version');
|
||||||
const installedDotnetVersions: string[] = [];
|
const installedDotnetVersions: (string | null)[] = [];
|
||||||
|
|
||||||
const globalJsonFileInput = core.getInput('global-json-file');
|
const globalJsonFileInput = core.getInput('global-json-file');
|
||||||
if (globalJsonFileInput) {
|
if (globalJsonFileInput) {
|
||||||
@ -78,19 +78,20 @@ export async function run() {
|
|||||||
auth.configAuthentication(sourceUrl, configFile);
|
auth.configAuthentication(sourceUrl, configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
const comparisonRange: string = globalJsonFileInput
|
// const comparisonRange: string = globalJsonFileInput
|
||||||
? versions[versions.length - 1]!
|
// ? versions[versions.length - 1]!
|
||||||
: '*';
|
// : '*';
|
||||||
|
|
||||||
const versionToOutput = semver.maxSatisfying(
|
// const versionToOutput = semver.maxSatisfying(
|
||||||
installedDotnetVersions,
|
// installedDotnetVersions,
|
||||||
comparisonRange,
|
// comparisonRange,
|
||||||
{
|
// {
|
||||||
includePrerelease: true
|
// includePrerelease: true
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
core.setOutput('dotnet-version', versionToOutput);
|
// core.setOutput('dotnet-version', versionToOutput);
|
||||||
|
outputInstalledVersion(installedDotnetVersions, globalJsonFileInput);
|
||||||
|
|
||||||
const matchersPath = path.join(__dirname, '..', '.github');
|
const matchersPath = path.join(__dirname, '..', '.github');
|
||||||
core.info(`##[add-matcher]${path.join(matchersPath, 'csc.json')}`);
|
core.info(`##[add-matcher]${path.join(matchersPath, 'csc.json')}`);
|
||||||
@ -116,4 +117,37 @@ function getVersionFromGlobalJson(globalJsonPath: string): string {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function outputInstalledVersion(
|
||||||
|
installedVersions: (string | null)[],
|
||||||
|
globalJsonFileInput: string
|
||||||
|
): void {
|
||||||
|
if (!installedVersions.length) {
|
||||||
|
core.info(
|
||||||
|
`No .NET version was installed. The 'dotnet-version' output will not be set.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (installedVersions.includes(null)) {
|
||||||
|
core.warning(
|
||||||
|
`Failed to output the installed version of .NET. The 'dotnet-version' output will not be set.`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (globalJsonFileInput) {
|
||||||
|
const versionToOutput = installedVersions.at(-1);
|
||||||
|
core.setOutput('dotnet-version', versionToOutput);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const versionToOutput = semver.maxSatisfying(
|
||||||
|
installedVersions as string[],
|
||||||
|
'*',
|
||||||
|
{
|
||||||
|
includePrerelease: true
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
core.setOutput('dotnet-version', versionToOutput);
|
||||||
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
Loading…
Reference in New Issue
Block a user