diff --git a/docs/cli.md b/docs/cli.md index cfbb5d80b..4bd7763e8 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -51,6 +51,7 @@ Extra options: | `--versioning-strategy` | [`VersioningStrategyType`](/docs/customizing.md#versioning-strategies) | Override method of determining SemVer version bumps based on commits. Defaults to `default` | | `--bump-minor-pre-major` | `boolean` | Configuration option for the versioning strategy. If set, will bump the minor version for breaking changes for versions < 1.0.0 | | `--bump-patch-for-minor-pre-major` | `boolean` | Configuration option for the versioning strategy. If set, will bump the patch version for features for versions < 1.0.0 | +| `--prerelease-type` | `string` | Configuration option for the prerelese versioning strategy. If prerelease strategy used and type set, will set the prerelese part of the version to the provided value in case prerelease part is not present. | | `--draft` | `boolean` | If set, create releases as drafts | | `--prerelease` | `boolean` | If set, create releases that are pre-major or pre-release version marked as pre-release on Github| | `--draft-pull-request` | `boolean` | If set, create pull requests as drafts | @@ -101,6 +102,7 @@ need to specify your release options: | `--versioning-strategy` | VersioningStrategy | Override method of determining SemVer version bumps based on commits. Defaults to `default` | | `--bump-minor-pre-major` | boolean | Configuration option for the versioning strategy. If set, will bump the minor version for breaking changes for versions < 1.0.0 | | `--bump-patch-for-minor-pre-major` | boolean | Configuration option for the versioning strategy. If set, will bump the patch version for features for versions < 1.0.0 | +| `--prerelease-type` | `string` | Configuration option for the prerelese versioning strategy. If prerelease strategy used and type set, will set the prerelese part of the version to the provided value in case prerelease part is not present. | | `--draft-pull-request` | boolean | If set, create pull requests as drafts | | `--label` | string | Comma-separated list of labels to apply to the release pull requests. Defaults to `autorelease: pending` |`autorelease: tagged` | | `--changelog-path` | `string` | Override the path to the managed CHANGELOG. Defaults to `CHANGELOG.md` | diff --git a/docs/customizing.md b/docs/customizing.md index 125689878..56593a3da 100644 --- a/docs/customizing.md +++ b/docs/customizing.md @@ -45,6 +45,8 @@ version given a list of parsed commits. | `always-bump-major` | Always bump major version | | `service-pack` | Designed for Java backport fixes. Uses Maven's specification for service pack versions (e.g. 1.2.3-sp.1) | +| `prerelease` | Bumping prerelease number (eg. 1.2.0-beta01 to 1.2.0-beta02) or if prerelease type is set, using that in the prerelease part (eg. 1.2.1 to 1.3.0-beta) | + ### Adding additional versioning strategy types To add a new versioning strategy, create a new class that implements the diff --git a/docs/manifest-releaser.md b/docs/manifest-releaser.md index a8bf0d075..7d53ae130 100644 --- a/docs/manifest-releaser.md +++ b/docs/manifest-releaser.md @@ -172,6 +172,9 @@ defaults (those are documented in comments) // absence defaults to false "bump-patch-for-minor-pre-major": true, + // setting the type of prerelease in case of prerelease strategy + "prerelease-type": true, + // set default conventional commit => changelog sections mapping/appearance. // absence defaults to https://git.io/JqCZL "changelog-sections": [...], diff --git a/schemas/config.json b/schemas/config.json index b92c20e34..5ad05830b 100644 --- a/schemas/config.json +++ b/schemas/config.json @@ -20,6 +20,10 @@ "description": "Feature changes only bump semver patch if version < 1.0.0", "type": "boolean" }, + "prerelease-type": { + "description": "Configuration option for the prerelese versioning strategy. If prerelease strategy used and type set, will set the prerelese part of the version to the provided value in case prerelease part is not present.", + "type": "boolean" + }, "versioning": { "description": "Versioning strategy. Defaults to `default`", "type": "string" @@ -290,7 +294,11 @@ "type": { "description": "The name of the plugin.", "type": "string", - "enum": ["cargo-workspace", "maven-workspace", "node-workspace"] + "enum": [ + "cargo-workspace", + "maven-workspace", + "node-workspace" + ] }, "updateAllPackages": { "description": "Whether to force updating all packages regardless of the dependency tree. Defaults to `false`.", diff --git a/src/strategies/base.ts b/src/strategies/base.ts index 57a80a6c6..20a45b6ef 100644 --- a/src/strategies/base.ts +++ b/src/strategies/base.ts @@ -678,7 +678,6 @@ export abstract class BaseStrategy implements Strategy { } isPublishedVersion(_version: Version): boolean { - // todo: skip pre-releases return true; } diff --git a/src/versioning-strategies/prerelease.ts b/src/versioning-strategies/prerelease.ts index fc0ca708f..1fcbadf96 100644 --- a/src/versioning-strategies/prerelease.ts +++ b/src/versioning-strategies/prerelease.ts @@ -30,6 +30,10 @@ interface PrereleaseVersioningStrategyOptions prereleaseType?: string; } +/** + * Regex to match the last set of numbers in a string + * Example: 1.2.3-beta01-01 -> 01 + */ const PRERELEASE_NUMBER = /(?\d+)(?=\D*$)/; abstract class AbstractPrereleaseVersionUpdate implements VersionUpdater { @@ -39,10 +43,21 @@ abstract class AbstractPrereleaseVersionUpdate implements VersionUpdater { this.prereleaseType = prereleaseType; } + /** + * Returns the new bumped prerelease version + * + * That is, if the current version is 1.2.3-beta01, the next prerelease version + * will be 1.2.3-beta02. If no number is found, the prerelease version will be + * 1.2.3-beta. If multiple numbers are found, the last set of numbers will be + * incremented, e.g. 1.2.3-beta01-01 -> 1.2.3-beta01-02. + * + * @param {prerelease} string The current version + * @returns {Version} The bumped version + */ protected bumpPrerelease(prerelease: string): string { const match = prerelease.match(PRERELEASE_NUMBER); - let nextPrerelease = `${prerelease}.0`; + let nextPrerelease = `${prerelease}.1`; if (match?.groups) { const numberLength = match.groups.number.length; diff --git a/test/versioning-strategies/prerelease.ts b/test/versioning-strategies/prerelease.ts index 6002f8b78..41b1a6f30 100644 --- a/test/versioning-strategies/prerelease.ts +++ b/test/versioning-strategies/prerelease.ts @@ -88,8 +88,9 @@ describe('PrereleaseVersioningStrategy', () => { const expectedBumps: Record = { '1.2.3': '2.0.0-beta', '0.1.2': '1.0.0-beta', - '1.0.0-beta': '1.0.0-beta.0', - '2.0.0-beta': '2.0.0-beta.0', + '1.0.0-alpha': '1.0.0-alpha.1', + '1.0.0-beta': '1.0.0-beta.1', + '2.0.0-beta': '2.0.0-beta.1', '1.0.1-beta': '2.0.0-beta', '1.1.0-beta': '2.0.0-beta', '1.1.1-beta': '2.0.0-beta', @@ -195,10 +196,12 @@ describe('PrereleaseVersioningStrategy', () => { const expectedBumps: Record = { '1.2.3': '1.3.0-beta', '0.1.2': '0.2.0-beta', - '1.0.0-beta': '1.0.0-beta.0', - '2.0.0-beta': '2.0.0-beta.0', + '1.0.0-alpha': '1.0.0-alpha.1', + '1.0.0-beta': '1.0.0-beta.1', + '2.0.0-beta': '2.0.0-beta.1', '1.0.1-beta': '1.1.0-beta', - '1.1.0-beta': '1.1.0-beta.0', + '1.1.0-alpha': '1.1.0-alpha.1', + '1.1.0-beta': '1.1.0-beta.1', '1.1.1-beta': '1.2.0-beta', '1.0.0-beta01': '1.0.0-beta02', '2.0.0-beta01': '2.0.0-beta02', @@ -284,7 +287,8 @@ describe('PrereleaseVersioningStrategy', () => { describe('with prerelease type', () => { const expectedBumps: Record = { '1.2.3': '1.2.4-beta', - '1.2.4-beta': '1.2.4-beta.0', + '1.2.4-alpha': '1.2.4-alpha.1', + '1.2.4-beta': '1.2.4-beta.1', '1.0.0-beta01': '1.0.0-beta02', '2.0.0-beta01': '2.0.0-beta02', '1.0.1-beta01': '1.0.1-beta02',