Skip to content

Commit 97b0542

Browse files
authored
feat: implement custom prerelease type (#2083)
1 parent 71dcc7b commit 97b0542

18 files changed

Lines changed: 383 additions & 150 deletions

File tree

__snapshots__/cli.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ Options:
188188
the minor for non-breaking changes prior to
189189
the first major release
190190
[boolean] [default: false]
191+
--prerelease-type type of the prerelease, e.g., alpha [string]
191192
--extra-files extra files for the strategy to consider
192193
[string]
193194
--version-file path to version file to update, e.g.,

docs/cli.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Extra options:
5151
| `--versioning-strategy` | [`VersioningStrategyType`](/docs/customizing.md#versioning-strategies) | Override method of determining SemVer version bumps based on commits. Defaults to `default` |
5252
| `--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 |
5353
| `--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 |
54+
| `--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. |
5455
| `--draft` | `boolean` | If set, create releases as drafts |
5556
| `--prerelease` | `boolean` | If set, create releases that are pre-major or pre-release version marked as pre-release on Github|
5657
| `--draft-pull-request` | `boolean` | If set, create pull requests as drafts |
@@ -101,6 +102,7 @@ need to specify your release options:
101102
| `--versioning-strategy` | VersioningStrategy | Override method of determining SemVer version bumps based on commits. Defaults to `default` |
102103
| `--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 |
103104
| `--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 |
105+
| `--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. |
104106
| `--draft-pull-request` | boolean | If set, create pull requests as drafts |
105107
| `--label` | string | Comma-separated list of labels to apply to the release pull requests. Defaults to `autorelease: pending` |`autorelease: tagged` |
106108
| `--changelog-path` | `string` | Override the path to the managed CHANGELOG. Defaults to `CHANGELOG.md` |

docs/customizing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ version given a list of parsed commits.
4545
| `always-bump-major` | Always bump major version |
4646
| `service-pack` | Designed for Java backport fixes. Uses Maven's specification for service pack versions (e.g. 1.2.3-sp.1) |
4747

48+
| `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) |
49+
4850
### Adding additional versioning strategy types
4951

5052
To add a new versioning strategy, create a new class that implements the

docs/manifest-releaser.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ defaults (those are documented in comments)
172172
// absence defaults to false
173173
"bump-patch-for-minor-pre-major": true,
174174

175+
// setting the type of prerelease in case of prerelease strategy
176+
"prerelease-type": "beta",
177+
175178
// set default conventional commit => changelog sections mapping/appearance.
176179
// absence defaults to https://git.io/JqCZL
177180
"changelog-sections": [...],

schemas/config.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"description": "Feature changes only bump semver patch if version < 1.0.0",
2121
"type": "boolean"
2222
},
23+
"prerelease-type": {
24+
"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.",
25+
"type": "string"
26+
},
2327
"versioning": {
2428
"description": "Versioning strategy. Defaults to `default`",
2529
"type": "string"
@@ -290,7 +294,11 @@
290294
"type": {
291295
"description": "The name of the plugin.",
292296
"type": "string",
293-
"enum": ["cargo-workspace", "maven-workspace", "node-workspace"]
297+
"enum": [
298+
"cargo-workspace",
299+
"maven-workspace",
300+
"node-workspace"
301+
]
294302
},
295303
"updateAllPackages": {
296304
"description": "Whether to force updating all packages regardless of the dependency tree. Defaults to `false`.",

src/bin/release-please.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ interface ManifestArgs {
6363
interface VersioningArgs {
6464
bumpMinorPreMajor?: boolean;
6565
bumpPatchForMinorPreMajor?: boolean;
66+
prereleaseType?: string;
6667
releaseAs?: string;
6768

6869
// only for Ruby: TODO replace with generic bootstrap option
@@ -275,6 +276,10 @@ function pullRequestStrategyOptions(yargs: yargs.Argv): yargs.Argv {
275276
default: false,
276277
type: 'boolean',
277278
})
279+
.option('prerelease-type', {
280+
describe: 'type of the prerelease, e.g., alpha',
281+
type: 'string',
282+
})
278283
.option('extra-files', {
279284
describe: 'extra files for the strategy to consider',
280285
type: 'string',
@@ -447,6 +452,7 @@ const createReleasePullRequestCommand: yargs.CommandModule<
447452
draftPullRequest: argv.draftPullRequest,
448453
bumpMinorPreMajor: argv.bumpMinorPreMajor,
449454
bumpPatchForMinorPreMajor: argv.bumpPatchForMinorPreMajor,
455+
prereleaseType: argv.prereleaseType,
450456
changelogPath: argv.changelogPath,
451457
changelogType: argv.changelogType,
452458
changelogHost: argv.changelogHost,
@@ -711,6 +717,7 @@ const bootstrapCommand: yargs.CommandModule<{}, BootstrapArgs> = {
711717
draftPullRequest: argv.draftPullRequest,
712718
bumpMinorPreMajor: argv.bumpMinorPreMajor,
713719
bumpPatchForMinorPreMajor: argv.bumpPatchForMinorPreMajor,
720+
prereleaseType: argv.prereleaseType,
714721
changelogPath: argv.changelogPath,
715722
changelogHost: argv.changelogHost,
716723
changelogSections: argv.changelogSections,

src/factories/versioning-strategy-factory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface VersioningStrategyFactoryOptions {
2828
type?: VersioningStrategyType;
2929
bumpMinorPreMajor?: boolean;
3030
bumpPatchForMinorPreMajor?: boolean;
31+
prereleaseType?: string;
3132
github: GitHub;
3233
}
3334

src/factory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export async function buildStrategy(
119119
type: options.versioning,
120120
bumpMinorPreMajor: options.bumpMinorPreMajor,
121121
bumpPatchForMinorPreMajor: options.bumpPatchForMinorPreMajor,
122+
prereleaseType: options.prereleaseType,
122123
});
123124
const changelogNotes = buildChangelogNotes({
124125
type: options.changelogType || 'default',

src/manifest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export interface ReleaserConfig {
9494
versioning?: VersioningStrategyType;
9595
bumpMinorPreMajor?: boolean;
9696
bumpPatchForMinorPreMajor?: boolean;
97+
prereleaseType?: string;
9798

9899
// Strategy options
99100
releaseAs?: string;
@@ -148,6 +149,7 @@ interface ReleaserConfigJson {
148149
versioning?: VersioningStrategyType;
149150
'bump-minor-pre-major'?: boolean;
150151
'bump-patch-for-minor-pre-major'?: boolean;
152+
'prerelease-type'?: string;
151153
'changelog-sections'?: ChangelogSection[];
152154
'release-as'?: string;
153155
'skip-github-release'?: boolean;
@@ -1290,6 +1292,7 @@ function extractReleaserConfig(
12901292
releaseType: config['release-type'],
12911293
bumpMinorPreMajor: config['bump-minor-pre-major'],
12921294
bumpPatchForMinorPreMajor: config['bump-patch-for-minor-pre-major'],
1295+
prereleaseType: config['prerelease-type'],
12931296
versioning: config['versioning'],
12941297
changelogSections: config['changelog-sections'],
12951298
changelogPath: config['changelog-path'],
@@ -1635,6 +1638,7 @@ function mergeReleaserConfig(
16351638
bumpPatchForMinorPreMajor:
16361639
pathConfig.bumpPatchForMinorPreMajor ??
16371640
defaultConfig.bumpPatchForMinorPreMajor,
1641+
prereleaseType: pathConfig.prereleaseType ?? defaultConfig.prereleaseType,
16381642
versioning: pathConfig.versioning ?? defaultConfig.versioning,
16391643
changelogSections:
16401644
pathConfig.changelogSections ?? defaultConfig.changelogSections,

src/version.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ export class Version {
8282
const buildPart = this.build ? `+${this.build}` : '';
8383
return `${this.major}.${this.minor}.${this.patch}${preReleasePart}${buildPart}`;
8484
}
85+
86+
get isPreMajor(): boolean {
87+
return this.major < 1;
88+
}
8589
}
8690

8791
export type VersionsMap = Map<string, Version>;

0 commit comments

Comments
 (0)