Add "pre-release" mode (MINOR)

This commit is contained in:
Paul Hatcherian 2023-01-15 11:25:01 -06:00
parent 8b3b8f89c6
commit ddf8faf6a4
11 changed files with 93 additions and 5 deletions

View file

@ -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;

View file

@ -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`);

View file

@ -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 };