mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2026-04-10 01:54:18 +00:00
Ignore non-version branches, reset diagnostics between tests
This commit is contained in:
parent
cfbfddabdd
commit
ec20cad99a
17 changed files with 2358 additions and 1307 deletions
|
|
@ -5,6 +5,7 @@ import { DefaultTagFormatter } from './DefaultTagFormatter';
|
|||
/** Default tag formatter which allows a prefix to be specified */
|
||||
export class BranchVersioningTagFormatter extends DefaultTagFormatter {
|
||||
|
||||
private onVersionBranch: boolean;
|
||||
private major: number;
|
||||
private minor?: number;
|
||||
|
||||
|
|
@ -17,13 +18,19 @@ export class BranchVersioningTagFormatter extends DefaultTagFormatter {
|
|||
return new RegExp(pattern);
|
||||
}
|
||||
|
||||
constructor(config: ActionConfig, private branchName: string) {
|
||||
constructor(config: ActionConfig, branchName: string) {
|
||||
super(config);
|
||||
const pattern = config.versionFromBranch === true ?
|
||||
new RegExp("[0-9]+.[0-9]+$|[0-9]+$") :
|
||||
this.getRegex(config.versionFromBranch as string);
|
||||
const result = pattern.exec(branchName);
|
||||
|
||||
if (result === null) {
|
||||
this.major = NaN;
|
||||
this.onVersionBranch = false;
|
||||
return;
|
||||
}
|
||||
|
||||
let branchVersion: string;
|
||||
switch (result?.length) {
|
||||
case 1:
|
||||
|
|
@ -36,6 +43,8 @@ export class BranchVersioningTagFormatter extends DefaultTagFormatter {
|
|||
throw new Error(`Unable to parse version from branch named '${branchName}' using pattern '${pattern}'`);
|
||||
}
|
||||
|
||||
this.onVersionBranch = true;
|
||||
|
||||
const versionValues = branchVersion.split('.');
|
||||
if (versionValues.length > 2) {
|
||||
throw new Error(`The version string '${branchVersion}' parsed from branch '${branchName}' is invalid. It must be in the format 'major.minor' or 'major'`);
|
||||
|
|
@ -52,7 +61,24 @@ export class BranchVersioningTagFormatter extends DefaultTagFormatter {
|
|||
}
|
||||
}
|
||||
|
||||
public override GetPattern(): string {
|
||||
let pattern = super.GetPattern();
|
||||
if (!this.onVersionBranch) {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
if(this.minor === undefined) {
|
||||
return pattern.replace('*[0-9].*[0-9].*[0-9]', `${this.major}.*[0-9].*[0-9]`);
|
||||
}
|
||||
|
||||
return pattern.replace('*[0-9].*[0-9].*[0-9]', `${this.major}.${this.minor}.*[0-9]`);
|
||||
}
|
||||
|
||||
override IsValid(tag: string): boolean {
|
||||
if (!this.onVersionBranch) {
|
||||
return super.IsValid(tag);
|
||||
}
|
||||
|
||||
if (!super.IsValid(tag)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -66,8 +92,12 @@ export class BranchVersioningTagFormatter extends DefaultTagFormatter {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
override Parse(tag: string): [major: number, minor: number, patch: number] {
|
||||
if (!this.onVersionBranch) {
|
||||
return super.Parse(tag);
|
||||
}
|
||||
|
||||
const parsed = super.Parse(tag);
|
||||
return [this.major, this.minor || parsed[1], parsed[2]];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue