mirror of
https://github.com/PaulHatch/semantic-version.git
synced 2025-12-27 04:58:17 +00:00
Merge pull request #88 from PaulHatch/pre-release-mode
Add "pre-release" mode
This commit is contained in:
commit
1fb98ec223
11 changed files with 93 additions and 5 deletions
|
|
@ -54,6 +54,10 @@ inputs:
|
|||
description: "The output method used to generate list of users, 'csv' or 'json'. Default is 'csv'."
|
||||
required: true
|
||||
default: "csv"
|
||||
enable_prerelease_mode:
|
||||
description: Prevents pre-v1.0.0 version from automatically incrementing the major version. If enabled, when the major version is 0, major releases will be treated as minor and minor as patch. Note that the version_type output is unchanged.
|
||||
required: true
|
||||
default: "false"
|
||||
outputs:
|
||||
major:
|
||||
description: "Current major number"
|
||||
|
|
|
|||
17
dist/index.js
vendored
17
dist/index.js
vendored
|
|
@ -428,7 +428,8 @@ function run() {
|
|||
namespace: core.getInput('namespace'),
|
||||
bumpEachCommit: core.getInput('bump_each_commit') === 'true',
|
||||
searchCommitBody: core.getInput('search_commit_body') === 'true',
|
||||
userFormatType: core.getInput('user_format_type')
|
||||
userFormatType: core.getInput('user_format_type'),
|
||||
enablePrereleaseMode: core.getInput('enable_prerelease_mode') === 'true',
|
||||
};
|
||||
if (config.versionFormat === '' && core.getInput('format') !== '') {
|
||||
core.warning(`The 'format' input is deprecated, use 'versionFormat' instead`);
|
||||
|
|
@ -818,6 +819,7 @@ class DefaultVersionClassifier {
|
|||
const searchBody = config.searchCommitBody;
|
||||
this.majorPattern = this.parsePattern(config.majorPattern, config.majorFlags, searchBody);
|
||||
this.minorPattern = this.parsePattern(config.minorPattern, config.minorFlags, searchBody);
|
||||
this.enablePrereleaseMode = config.enablePrereleaseMode;
|
||||
}
|
||||
parsePattern(pattern, flags, searchBody) {
|
||||
if (pattern.startsWith('/') && pattern.endsWith('/')) {
|
||||
|
|
@ -834,6 +836,19 @@ class DefaultVersionClassifier {
|
|||
}
|
||||
}
|
||||
getNextVersion(current, type) {
|
||||
if (this.enablePrereleaseMode && current.major === 0) {
|
||||
switch (type) {
|
||||
case VersionType_1.VersionType.Major:
|
||||
return { major: current.major, minor: current.minor + 1, patch: 0 };
|
||||
case VersionType_1.VersionType.Minor:
|
||||
case VersionType_1.VersionType.Patch:
|
||||
return { major: current.major, minor: current.minor, patch: current.patch + 1 };
|
||||
case VersionType_1.VersionType.None:
|
||||
return { major: current.major, minor: current.minor, patch: current.patch };
|
||||
default:
|
||||
throw new Error(`Unknown change type: ${type}`);
|
||||
}
|
||||
}
|
||||
switch (type) {
|
||||
case VersionType_1.VersionType.Major:
|
||||
return { major: current.major + 1, minor: 0, patch: 0 };
|
||||
|
|
|
|||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
|
@ -30,6 +30,8 @@ class ActionConfig {
|
|||
this.searchCommitBody = false;
|
||||
/** The output method used to generate list of users, 'csv' or 'json'. Default is 'csv'. */
|
||||
this.userFormatType = "csv";
|
||||
/** Prevents pre-v1.0.0 version from automatically incrementing the major version. If enabled, when the major version is 0, major releases will be treated as minor and minor as patch. Note that the versionType output is unchanged. */
|
||||
this.enablePrereleaseMode = false;
|
||||
}
|
||||
}
|
||||
exports.ActionConfig = ActionConfig;
|
||||
|
|
|
|||
|
|
@ -75,7 +75,8 @@ function run() {
|
|||
namespace: core.getInput('namespace'),
|
||||
bumpEachCommit: core.getInput('bump_each_commit') === 'true',
|
||||
searchCommitBody: core.getInput('search_commit_body') === 'true',
|
||||
userFormatType: core.getInput('user_format_type')
|
||||
userFormatType: core.getInput('user_format_type'),
|
||||
enablePrereleaseMode: core.getInput('enable_prerelease_mode') === 'true',
|
||||
};
|
||||
if (config.versionFormat === '' && core.getInput('format') !== '') {
|
||||
core.warning(`The 'format' input is deprecated, use 'versionFormat' instead`);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class DefaultVersionClassifier {
|
|||
const searchBody = config.searchCommitBody;
|
||||
this.majorPattern = this.parsePattern(config.majorPattern, config.majorFlags, searchBody);
|
||||
this.minorPattern = this.parsePattern(config.minorPattern, config.minorFlags, searchBody);
|
||||
this.enablePrereleaseMode = config.enablePrereleaseMode;
|
||||
}
|
||||
parsePattern(pattern, flags, searchBody) {
|
||||
if (pattern.startsWith('/') && pattern.endsWith('/')) {
|
||||
|
|
@ -33,6 +34,19 @@ class DefaultVersionClassifier {
|
|||
}
|
||||
}
|
||||
getNextVersion(current, type) {
|
||||
if (this.enablePrereleaseMode && current.major === 0) {
|
||||
switch (type) {
|
||||
case VersionType_1.VersionType.Major:
|
||||
return { major: current.major, minor: current.minor + 1, patch: 0 };
|
||||
case VersionType_1.VersionType.Minor:
|
||||
case VersionType_1.VersionType.Patch:
|
||||
return { major: current.major, minor: current.minor, patch: current.patch + 1 };
|
||||
case VersionType_1.VersionType.None:
|
||||
return { major: current.major, minor: current.minor, patch: current.patch };
|
||||
default:
|
||||
throw new Error(`Unknown change type: ${type}`);
|
||||
}
|
||||
}
|
||||
switch (type) {
|
||||
case VersionType_1.VersionType.Major:
|
||||
return { major: current.major + 1, minor: 0, patch: 0 };
|
||||
|
|
|
|||
|
|
@ -101,6 +101,9 @@ it will be given the new version if the build were to be retriggered, for exampl
|
|||
search_commit_body: false
|
||||
# The output method used to generate list of users, 'csv' or 'json'.
|
||||
user_format_type: "csv"
|
||||
# Prevents pre-v1.0.0 version from automatically incrementing the major version.
|
||||
# If enabled, when the major version is 0, major releases will be treated as minor and minor as patch. Note that the version_type output is unchanged.
|
||||
enable_prerelease_mode: true
|
||||
```
|
||||
|
||||
## Outputs
|
||||
|
|
|
|||
|
|
@ -26,4 +26,6 @@ export class ActionConfig {
|
|||
public searchCommitBody: boolean = false;
|
||||
/** The output method used to generate list of users, 'csv' or 'json'. Default is 'csv'. */
|
||||
public userFormatType: string = "csv";
|
||||
/** Prevents pre-v1.0.0 version from automatically incrementing the major version. If enabled, when the major version is 0, major releases will be treated as minor and minor as patch. Note that the versionType output is unchanged. */
|
||||
public enablePrereleaseMode: boolean = false;
|
||||
}
|
||||
|
|
@ -836,4 +836,34 @@ test('Prerelease tags are ignored on current commit', async () => {
|
|||
await validate('1.1.0+3');
|
||||
repo.makeCommit(`Commit ${i++}`);
|
||||
await validate('1.1.0+4');
|
||||
}, 15000);
|
||||
|
||||
test('Pre-release mode does not update major version if major version is 0', async () => {
|
||||
const repo = createTestRepo({ tagPrefix: '', versionFormat: "${major}.${minor}.${patch}", enablePrereleaseMode: true });
|
||||
|
||||
repo.makeCommit('Initial Commit');
|
||||
expect(( await repo.runAction()).formattedVersion).toBe('0.0.1');
|
||||
repo.makeCommit('Second Commit (MINOR)');
|
||||
expect(( await repo.runAction()).formattedVersion).toBe('0.0.1');
|
||||
repo.makeCommit('Third Commit (MAJOR)');
|
||||
expect(( await repo.runAction()).formattedVersion).toBe('0.1.0');
|
||||
repo.exec('git tag 0.1.0');
|
||||
repo.makeCommit('Fourth Commit (MAJOR)');
|
||||
expect(( await repo.runAction()).formattedVersion).toBe('0.2.0');
|
||||
}, 15000);
|
||||
|
||||
test('Pre-release mode updates major version if major version is not 0', async () => {
|
||||
const repo = createTestRepo({ tagPrefix: '', versionFormat: "${major}.${minor}.${patch}", enablePrereleaseMode: true });
|
||||
|
||||
repo.makeCommit('Initial Commit');
|
||||
repo.exec('git tag 1.0.0');
|
||||
repo.makeCommit('Second Commit');
|
||||
expect(( await repo.runAction()).formattedVersion).toBe('1.0.1');
|
||||
repo.makeCommit('Third Commit (MINOR)');
|
||||
expect(( await repo.runAction()).formattedVersion).toBe('1.1.0');
|
||||
repo.makeCommit('Fourth Commit (MAJOR)');
|
||||
expect(( await repo.runAction()).formattedVersion).toBe('2.0.0');
|
||||
repo.exec('git tag 2.0.0');
|
||||
repo.makeCommit('Fifth Commit (MAJOR)');
|
||||
expect(( await repo.runAction()).formattedVersion).toBe('3.0.0');
|
||||
}, 15000);
|
||||
|
|
@ -48,7 +48,8 @@ export async function run() {
|
|||
namespace: core.getInput('namespace'),
|
||||
bumpEachCommit: core.getInput('bump_each_commit') === 'true',
|
||||
searchCommitBody: core.getInput('search_commit_body') === 'true',
|
||||
userFormatType: core.getInput('user_format_type')
|
||||
userFormatType: core.getInput('user_format_type'),
|
||||
enablePrereleaseMode: core.getInput('enable_prerelease_mode') === 'true',
|
||||
};
|
||||
|
||||
if (config.versionFormat === '' && core.getInput('format') !== '') {
|
||||
|
|
|
|||
|
|
@ -10,11 +10,13 @@ export class DefaultVersionClassifier implements VersionClassifier {
|
|||
|
||||
protected majorPattern: (commit: CommitInfo) => boolean;
|
||||
protected minorPattern: (commit: CommitInfo) => boolean;
|
||||
protected enablePrereleaseMode: boolean;
|
||||
|
||||
constructor(config: ActionConfig) {
|
||||
const searchBody = config.searchCommitBody;
|
||||
this.majorPattern = this.parsePattern(config.majorPattern, config.majorFlags, searchBody);
|
||||
this.minorPattern = this.parsePattern(config.minorPattern, config.minorFlags, searchBody);
|
||||
this.enablePrereleaseMode = config.enablePrereleaseMode;
|
||||
}
|
||||
|
||||
protected parsePattern(pattern: string, flags: string, searchBody: boolean): (pattern: CommitInfo) => boolean {
|
||||
|
|
@ -32,7 +34,21 @@ export class DefaultVersionClassifier implements VersionClassifier {
|
|||
}
|
||||
|
||||
protected getNextVersion(current: ReleaseInformation, type: VersionType): ({ major: number, minor: number, patch: number }) {
|
||||
|
||||
|
||||
if (this.enablePrereleaseMode && current.major === 0) {
|
||||
switch (type) {
|
||||
case VersionType.Major:
|
||||
return { major: current.major, minor: current.minor + 1, patch: 0 };
|
||||
case VersionType.Minor:
|
||||
case VersionType.Patch:
|
||||
return { major: current.major, minor: current.minor, patch: current.patch + 1 };
|
||||
case VersionType.None:
|
||||
return { major: current.major, minor: current.minor, patch: current.patch };
|
||||
default:
|
||||
throw new Error(`Unknown change type: ${type}`);
|
||||
}
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case VersionType.Major:
|
||||
return { major: current.major + 1, minor: 0, patch: 0 };
|
||||
|
|
|
|||
Loading…
Reference in a new issue