Skip to content

Commit

Permalink
feat: implement custom prerelease type (#2083)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalosisz authored Oct 26, 2023
1 parent 71dcc7b commit 97b0542
Show file tree
Hide file tree
Showing 18 changed files with 383 additions and 150 deletions.
1 change: 1 addition & 0 deletions __snapshots__/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ Options:
the minor for non-breaking changes prior to
the first major release
[boolean] [default: false]
--prerelease-type type of the prerelease, e.g., alpha [string]
--extra-files extra files for the strategy to consider
[string]
--version-file path to version file to update, e.g.,
Expand Down
2 changes: 2 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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` |
Expand Down
2 changes: 2 additions & 0 deletions docs/customizing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/manifest-releaser.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": "beta",

// set default conventional commit => changelog sections mapping/appearance.
// absence defaults to https://git.io/JqCZL
"changelog-sections": [...],
Expand Down
10 changes: 9 additions & 1 deletion schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "string"
},
"versioning": {
"description": "Versioning strategy. Defaults to `default`",
"type": "string"
Expand Down Expand Up @@ -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`.",
Expand Down
7 changes: 7 additions & 0 deletions src/bin/release-please.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ interface ManifestArgs {
interface VersioningArgs {
bumpMinorPreMajor?: boolean;
bumpPatchForMinorPreMajor?: boolean;
prereleaseType?: string;
releaseAs?: string;

// only for Ruby: TODO replace with generic bootstrap option
Expand Down Expand Up @@ -275,6 +276,10 @@ function pullRequestStrategyOptions(yargs: yargs.Argv): yargs.Argv {
default: false,
type: 'boolean',
})
.option('prerelease-type', {
describe: 'type of the prerelease, e.g., alpha',
type: 'string',
})
.option('extra-files', {
describe: 'extra files for the strategy to consider',
type: 'string',
Expand Down Expand Up @@ -447,6 +452,7 @@ const createReleasePullRequestCommand: yargs.CommandModule<
draftPullRequest: argv.draftPullRequest,
bumpMinorPreMajor: argv.bumpMinorPreMajor,
bumpPatchForMinorPreMajor: argv.bumpPatchForMinorPreMajor,
prereleaseType: argv.prereleaseType,
changelogPath: argv.changelogPath,
changelogType: argv.changelogType,
changelogHost: argv.changelogHost,
Expand Down Expand Up @@ -711,6 +717,7 @@ const bootstrapCommand: yargs.CommandModule<{}, BootstrapArgs> = {
draftPullRequest: argv.draftPullRequest,
bumpMinorPreMajor: argv.bumpMinorPreMajor,
bumpPatchForMinorPreMajor: argv.bumpPatchForMinorPreMajor,
prereleaseType: argv.prereleaseType,
changelogPath: argv.changelogPath,
changelogHost: argv.changelogHost,
changelogSections: argv.changelogSections,
Expand Down
1 change: 1 addition & 0 deletions src/factories/versioning-strategy-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface VersioningStrategyFactoryOptions {
type?: VersioningStrategyType;
bumpMinorPreMajor?: boolean;
bumpPatchForMinorPreMajor?: boolean;
prereleaseType?: string;
github: GitHub;
}

Expand Down
1 change: 1 addition & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export async function buildStrategy(
type: options.versioning,
bumpMinorPreMajor: options.bumpMinorPreMajor,
bumpPatchForMinorPreMajor: options.bumpPatchForMinorPreMajor,
prereleaseType: options.prereleaseType,
});
const changelogNotes = buildChangelogNotes({
type: options.changelogType || 'default',
Expand Down
4 changes: 4 additions & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export interface ReleaserConfig {
versioning?: VersioningStrategyType;
bumpMinorPreMajor?: boolean;
bumpPatchForMinorPreMajor?: boolean;
prereleaseType?: string;

// Strategy options
releaseAs?: string;
Expand Down Expand Up @@ -148,6 +149,7 @@ interface ReleaserConfigJson {
versioning?: VersioningStrategyType;
'bump-minor-pre-major'?: boolean;
'bump-patch-for-minor-pre-major'?: boolean;
'prerelease-type'?: string;
'changelog-sections'?: ChangelogSection[];
'release-as'?: string;
'skip-github-release'?: boolean;
Expand Down Expand Up @@ -1290,6 +1292,7 @@ function extractReleaserConfig(
releaseType: config['release-type'],
bumpMinorPreMajor: config['bump-minor-pre-major'],
bumpPatchForMinorPreMajor: config['bump-patch-for-minor-pre-major'],
prereleaseType: config['prerelease-type'],
versioning: config['versioning'],
changelogSections: config['changelog-sections'],
changelogPath: config['changelog-path'],
Expand Down Expand Up @@ -1635,6 +1638,7 @@ function mergeReleaserConfig(
bumpPatchForMinorPreMajor:
pathConfig.bumpPatchForMinorPreMajor ??
defaultConfig.bumpPatchForMinorPreMajor,
prereleaseType: pathConfig.prereleaseType ?? defaultConfig.prereleaseType,
versioning: pathConfig.versioning ?? defaultConfig.versioning,
changelogSections:
pathConfig.changelogSections ?? defaultConfig.changelogSections,
Expand Down
4 changes: 4 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export class Version {
const buildPart = this.build ? `+${this.build}` : '';
return `${this.major}.${this.minor}.${this.patch}${preReleasePart}${buildPart}`;
}

get isPreMajor(): boolean {
return this.major < 1;
}
}

export type VersionsMap = Map<string, Version>;
6 changes: 3 additions & 3 deletions src/versioning-strategies/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {ConventionalCommit} from '../commit';
import {Version} from '../version';
import {logger as defaultLogger, Logger} from '../util/logger';

interface DefaultVersioningStrategyOptions {
export interface DefaultVersioningStrategyOptions {
bumpMinorPreMajor?: boolean;
bumpPatchForMinorPreMajor?: boolean;
logger?: Logger;
Expand Down Expand Up @@ -89,13 +89,13 @@ export class DefaultVersioningStrategy implements VersioningStrategy {
}

if (breaking > 0) {
if (version.major < 1 && this.bumpMinorPreMajor) {
if (version.isPreMajor && this.bumpMinorPreMajor) {
return new MinorVersionUpdate();
} else {
return new MajorVersionUpdate();
}
} else if (features > 0) {
if (version.major < 1 && this.bumpPatchForMinorPreMajor) {
if (version.isPreMajor && this.bumpPatchForMinorPreMajor) {
return new PatchVersionUpdate();
} else {
return new MinorVersionUpdate();
Expand Down
4 changes: 2 additions & 2 deletions src/versioning-strategies/dependency-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ export class DependencyManifest extends DefaultVersioningStrategy {

let dependencyBump: VersionUpdater;
if (breaking > 0) {
if (version.major < 1 && this.bumpMinorPreMajor) {
if (version.isPreMajor && this.bumpMinorPreMajor) {
dependencyBump = new MinorVersionUpdate();
} else {
dependencyBump = new MajorVersionUpdate();
}
} else if (features > 0) {
if (version.major < 1 && this.bumpPatchForMinorPreMajor) {
if (version.isPreMajor && this.bumpPatchForMinorPreMajor) {
dependencyBump = new PatchVersionUpdate();
} else {
dependencyBump = new MinorVersionUpdate();
Expand Down
Loading

0 comments on commit 97b0542

Please sign in to comment.