mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2026-04-09 01:24:17 +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
|
|
@ -2,10 +2,10 @@
|
|||
import * as exec from '@actions/exec';
|
||||
import { DebugManager } from './DebugManager';
|
||||
|
||||
const debugManager = DebugManager.getInstance();
|
||||
|
||||
export const cmd = async (command: string, ...args: any): Promise<string> => {
|
||||
|
||||
const debugManager = DebugManager.getInstance();
|
||||
|
||||
if (debugManager.isReplayMode()) {
|
||||
return debugManager.replayCommand(command, args);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
import exp from "constants";
|
||||
import { ActionConfig } from "./ActionConfig";
|
||||
|
||||
|
||||
/** Utility class for managing debug mode and diagnostic information */
|
||||
export class DebugManager {
|
||||
|
||||
private constructor() { }
|
||||
|
||||
private static instance: DebugManager;
|
||||
|
|
@ -16,6 +14,12 @@ export class DebugManager {
|
|||
return DebugManager.instance;
|
||||
}
|
||||
|
||||
/** Clears the singleton instance of the DebugManager (used for testing) */
|
||||
public static clearState() {
|
||||
DebugManager.instance = new DebugManager();
|
||||
}
|
||||
|
||||
|
||||
private debugEnabled: boolean = false;
|
||||
private replayMode: boolean = false;
|
||||
private diagnosticInfo: DiagnosticInfo | null = null;
|
||||
|
|
|
|||
|
|
@ -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]];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { expect, test } from '@jest/globals'
|
|||
import { runAction } from '../src/action';
|
||||
import { ConfigurationProvider } from './ConfigurationProvider';
|
||||
import { ActionConfig } from './ActionConfig';
|
||||
import exp from 'constants';
|
||||
import { DebugManager } from './DebugManager';
|
||||
|
||||
const windows = process.platform === "win32";
|
||||
const timeout = 30000;
|
||||
|
|
@ -42,6 +42,7 @@ const createTestRepo = (repoDefaultConfig?: Partial<ActionConfig>) => {
|
|||
run(`git merge ${branch}`);
|
||||
},
|
||||
runAction: async (inputs?: Partial<ActionConfig>) => {
|
||||
DebugManager.clearState();
|
||||
let config = new ActionConfig();
|
||||
config = { ...config, ...{ versionFormat: "${major}.${minor}.${patch}+${increment}" }, ...repoDefaultConfig, ...inputs };
|
||||
process.chdir(repoDirectory);
|
||||
|
|
@ -187,32 +188,6 @@ test('Version pulled from last release branch', async () => {
|
|||
expect(result.formattedVersion).toBe('5.6.8+0');
|
||||
}, timeout);
|
||||
|
||||
/* Removed for now
|
||||
test('Tags on branches are used', async () => {
|
||||
|
||||
// This test checks that tags are counted correctly even if they are not on
|
||||
// the main branch:
|
||||
// master o--o--o--o <- expecting v0.0.2
|
||||
// \
|
||||
// release o--o <- taged v0.0.1
|
||||
|
||||
|
||||
const repo = createTestRepo(); // 0.0.0+0
|
||||
|
||||
repo.makeCommit('Initial Commit'); // 0.0.1+0
|
||||
repo.makeCommit('Second Commit'); // 0.0.1+1
|
||||
repo.makeCommit('Third Commit'); // 0.1.1+2
|
||||
repo.exec('git checkout -b release/0.0.1')
|
||||
repo.makeCommit('Fourth Commit'); // 0.1.1+3
|
||||
repo.exec('git tag v0.0.1');
|
||||
repo.exec('git checkout master');
|
||||
repo.makeCommit('Fifth Commit'); // 0.0.2.0
|
||||
const result = await repo.runAction();
|
||||
|
||||
expect(result.formattedVersion).toBe('0.0.2+0');
|
||||
});
|
||||
*/
|
||||
|
||||
test('Merged tags do not affect version', async () => {
|
||||
|
||||
// This test checks that merges don't override tags
|
||||
|
|
|
|||
|
|
@ -40,16 +40,14 @@ export class BumpAlwaysVersionClassifier extends DefaultVersionClassifier {
|
|||
type = VersionType.Major;
|
||||
} else if (this.minorPattern(commit)) {
|
||||
type = VersionType.Minor;
|
||||
} else if (this.patchPattern(commit) ||
|
||||
(major === 0 && minor === 0 && patch === 0 && commitSet.commits.length > 0)) {
|
||||
type = VersionType.Patch;
|
||||
} else {
|
||||
if (this.patchPattern(commit) ||
|
||||
(major === 0 && minor === 0 && patch === 0 && commitSet.commits.length > 0)) {
|
||||
type = VersionType.Patch;
|
||||
} else {
|
||||
type = VersionType.None;
|
||||
increment++;
|
||||
}
|
||||
type = VersionType.None;
|
||||
}
|
||||
|
||||
|
||||
if (this.enablePrereleaseMode && major === 0) {
|
||||
switch (type) {
|
||||
case VersionType.Major:
|
||||
|
|
@ -62,7 +60,9 @@ export class BumpAlwaysVersionClassifier extends DefaultVersionClassifier {
|
|||
patch += 1;
|
||||
increment = 0;
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
increment++;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (type) {
|
||||
|
|
@ -80,7 +80,9 @@ export class BumpAlwaysVersionClassifier extends DefaultVersionClassifier {
|
|||
patch += 1;
|
||||
increment = 0;
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
increment++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ export class DefaultVersionClassifier implements VersionClassifier {
|
|||
// - commit 4 - v2.0.1+0
|
||||
|
||||
const versionsMatch = lastRelease.currentMajor === major && lastRelease.currentMinor === minor && lastRelease.currentPatch === patch;
|
||||
const currentIncremement = versionsMatch ? increment : 0;
|
||||
return new VersionClassification(VersionType.None, currentIncremement, false, <number>lastRelease.currentMajor, <number>lastRelease.currentMinor, <number>lastRelease.currentPatch);
|
||||
const currentIncrement = versionsMatch ? increment : 0;
|
||||
return new VersionClassification(VersionType.None, currentIncrement, false, <number>lastRelease.currentMajor, <number>lastRelease.currentMinor, <number>lastRelease.currentPatch);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue