Change the logic to support A.B.Cxx

This commit is contained in:
IvanZosimov 2023-04-10 16:23:29 +02:00
parent 920b830bd1
commit 4f6b2f576a
1 changed files with 13 additions and 15 deletions

View File

@ -12,7 +12,7 @@ import {IS_LINUX, IS_WINDOWS} from './utils';
import {QualityOptions} from './setup-dotnet'; import {QualityOptions} from './setup-dotnet';
export interface DotnetVersion { export interface DotnetVersion {
type: string; type: string | null;
value: string; value: string;
qualityFlag: boolean; qualityFlag: boolean;
} }
@ -27,22 +27,25 @@ export class DotnetVersionResolver {
} }
private async resolveVersionInput(): Promise<void> { private async resolveVersionInput(): Promise<void> {
if (!semver.validRange(this.inputVersion)) { const isLatestPatchSyntax = /^\d+\.\d+\.\d{1}x{2}$/.test(this.inputVersion);
if (!semver.validRange(this.inputVersion) && !isLatestPatchSyntax) {
throw new Error( throw new Error(
`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x` `'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B, A.B.x, A, A.x, A.B.Cxx`
); );
} }
if (semver.valid(this.inputVersion)) { if (semver.valid(this.inputVersion)) {
this.resolvedArgument.type = 'version'; this.resolvedArgument.type = 'version';
this.resolvedArgument.value = this.inputVersion; this.resolvedArgument.value = this.inputVersion;
} else if (!this.inputVersion) {
this.resolvedArgument.type = null;
} else { } else {
this.resolvedArgument.type = 'channel';
const [major, minor] = this.inputVersion.split('.'); const [major, minor] = this.inputVersion.split('.');
if (isLatestPatchSyntax) {
if (this.isNumericTag(major)) { this.resolvedArgument.value = this.inputVersion;
this.resolvedArgument.type = 'channel'; } else if (this.isNumericTag(major) && this.isNumericTag(minor)) {
if (this.isNumericTag(minor)) { this.resolvedArgument.value = `${major}.${minor}`;
this.resolvedArgument.value = `${major}.${minor}`; } else {
} else {
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], { const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
allowRetries: true, allowRetries: true,
maxRetries: 3 maxRetries: 3
@ -51,7 +54,6 @@ export class DotnetVersionResolver {
httpClient, httpClient,
[major, minor] [major, minor]
); );
}
} }
this.resolvedArgument.qualityFlag = +major >= 6 ? true : false; this.resolvedArgument.qualityFlag = +major >= 6 ? true : false;
} }
@ -61,11 +63,7 @@ export class DotnetVersionResolver {
return /^\d+$/.test(versionTag); return /^\d+$/.test(versionTag);
} }
public async createDotNetVersion(): Promise<{ public async createDotNetVersion(): Promise<DotnetVersion> {
type: string;
value: string;
qualityFlag: boolean;
}> {
await this.resolveVersionInput(); await this.resolveVersionInput();
if (!this.resolvedArgument.type) { if (!this.resolvedArgument.type) {
return this.resolvedArgument; return this.resolvedArgument;