Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add sdkver max major version configuration option #282

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions dist/bump/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions dist/cli/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 25 additions & 3 deletions dist/validate/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ initial-development: false # OPTIONAL, defaults to `true`
| `release-branches` | `/^release\/.*\d+\.\d+\.*$/` | A regex specifying from which branch(es) only `PATCH` version bump are allowed. |
| `prereleases` | `undefined` | A string specifying the prereleases prefix. |
| `sdkver-create-release-branches` | `false` | For SdkVer versioning scheme only: push a new branch if an RC or release build is performed on a non-release branch. If this config value is boolean `true`, the branch shall be of the form `release/N.N`. If this value is set to a string, it shall be used as the branch name prefix and appended with the major and minor release numbers, e.g. config value `"rel/"` results in a branch named `rel/N.N`. |
| `sdkver-max-major` | `0` | For SdkVer versioning scheme only: do not bump major version when breaking changes are found in case the maximum configured major version is already reached. |

> :bulb: By default `commisery-action` will search for the file `.commisery.yml`.
You can specify a different file with the `config` input parameter.
12 changes: 11 additions & 1 deletion src/bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ export async function bumpSdkVer(
createChangelog: boolean
): Promise<boolean> {
const isReleaseBranch = branchName.match(config.releaseBranches) !== null;
const hasBreakingChange = bumpInfo.processedCommits.some(
let hasBreakingChange = bumpInfo.processedCommits.some(
c => c.message?.breakingChange
);
if (!bumpInfo.foundVersion) return false; // should never happen
Expand All @@ -763,6 +763,16 @@ export async function bumpSdkVer(

let cv = SemVer.copy(bumpInfo.foundVersion);

// Do not bump major version when breaking change is found in case
// the max configured major version is already reached
if (
config.sdkverMaxMajor !== undefined &&
config.sdkverMaxMajor > 0 &&
cv.major >= config.sdkverMaxMajor
) {
hasBreakingChange = false;
}

// Get the latest draft release matching our current version's prefix.
// Don't look at the draft version on a release branch; the current version
// should always reflect the version to be bumped (as no dev releases are
Expand Down
23 changes: 21 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const CONFIG_ITEMS = [
"release-branches",
"prereleases",
"sdkver-create-release-branches",
"sdkver-max-major",
];

const VERSION_SCHEMES = ["semver", "sdkver"];
Expand Down Expand Up @@ -107,6 +108,7 @@ export class Configuration {
tags: IConfigurationRules = DEFAULT_ACCEPTED_TAGS;
rules: Map<string, IRuleConfigItem> = new Map<string, IRuleConfigItem>();
sdkverCreateReleaseBranches?: string = undefined;
sdkverMaxMajor = 0;

set initialDevelopment(initialDevelopment: boolean) {
this._initialDevelopment = initialDevelopment;
Expand Down Expand Up @@ -365,14 +367,30 @@ export class Configuration {
);
}
break;

case "sdkver-max-major":
/* Example YAML:
* sdkver-max-major: 1 # defaults to 0
*/
if (typeof data[key] === "number") {
this.sdkverMaxMajor = data[key];
} else {
throw new Error(
`Incorrect type '${typeof data[
key
]}' for '${key}', must be '${typeof this.sdkverMaxMajor}'!`
);
}
break;
}
}
if (
this.sdkverCreateReleaseBranches !== undefined &&
(this.sdkverCreateReleaseBranches !== undefined ||
this.sdkverMaxMajor !== 0) &&
this.versionScheme !== "sdkver"
) {
core.warning(
"The configuration option `sdkver-create-release-branches` is only relevant " +
"The configuration options `sdkver-create-release-branches` and `sdkver-max-major` are only relevant " +
'when the `version-scheme` is set to `"sdkver"`.'
);
}
Expand Down Expand Up @@ -411,6 +429,7 @@ export class Configuration {
config.tags = JSON.parse(JSON.stringify(this.tags));
config.rules = new Map(JSON.parse(JSON.stringify(Array.from(this.rules))));
config.sdkverCreateReleaseBranches = this.sdkverCreateReleaseBranches;
config.sdkverMaxMajor = this.sdkverMaxMajor;
return config;
}
}
Expand Down
Loading
Loading