update logic of outputting dotnet-version

This commit is contained in:
IvanZosimov
2023-05-16 14:58:18 +02:00
parent e8501859aa
commit fefaa59d2e
3 changed files with 82 additions and 25 deletions

View File

@ -197,7 +197,7 @@ export class DotnetCoreInstaller {
}
}
public async installDotnet(): Promise<string> {
public async installDotnet(): Promise<string | null> {
const windowsDefaultOptions = [
'-NoLogo',
'-Sta',
@ -271,14 +271,13 @@ export class DotnetCoreInstaller {
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 matchedResult = regex.exec(stdout);
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;
}