Skip to content

Commit 84a43ef

Browse files
authored
feat: add include-v-in-release-name config option (#2633)
This adds a new configuration option `include-v-in-release-name` that controls whether the `v` prefix is included in GitHub release names. Previously, the release name was hardcoded to always include the `v` prefix (e.g., `v1.2.3`). This change allows users to opt out of the `v` prefix by setting `include-v-in-release-name: false` in their release-please config. The default behavior is unchanged (`true`), maintaining backwards compatibility. Changes: - Added `include-v-in-release-name` to config schema - Added `includeVInReleaseName` to ReleaserConfig interface - Updated BaseStrategy to use the new option when building release name - Added serialization support in release-please-config updater - Added tests for the new functionality Example config: ```json { "include-v-in-tag": false, "include-v-in-release-name": false, "packages": { ".": { "release-type": "node" } } } ``` With the above config, releases would be named `1.2.3` instead of `v1.2.3`.
1 parent 009c2a6 commit 84a43ef

File tree

5 files changed

+79
-2
lines changed

5 files changed

+79
-2
lines changed

schemas/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
"description": "When tagging a release, include `v` in the tag. Defaults to `false`.",
8787
"type": "boolean"
8888
},
89+
"include-v-in-release-name": {
90+
"description": "Include `v` in the GitHub release name. Defaults to `true`.",
91+
"type": "boolean"
92+
},
8993
"changelog-type": {
9094
"description": "The type of changelog to use. Defaults to `default`.",
9195
"type": "string",
@@ -471,6 +475,7 @@
471475
"extra-label": true,
472476
"include-component-in-tag": true,
473477
"include-v-in-tag": true,
478+
"include-v-in-release-name": true,
474479
"changelog-type": true,
475480
"changelog-host": true,
476481
"changelog-path": true,

src/manifest.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export interface ReleaserConfig {
113113
packageName?: string;
114114
includeComponentInTag?: boolean;
115115
includeVInTag?: boolean;
116+
includeVInReleaseName?: boolean;
116117
pullRequestTitlePattern?: string;
117118
pullRequestHeader?: string;
118119
pullRequestFooter?: string;
@@ -172,6 +173,7 @@ interface ReleaserConfigJson {
172173
'extra-label'?: string;
173174
'include-component-in-tag'?: boolean;
174175
'include-v-in-tag'?: boolean;
176+
'include-v-in-release-name'?: boolean;
175177
'changelog-type'?: ChangelogNotesType;
176178
'changelog-host'?: string;
177179
'pull-request-title-pattern'?: string;
@@ -1393,6 +1395,7 @@ function extractReleaserConfig(
13931395
extraFiles: config['extra-files'],
13941396
includeComponentInTag: config['include-component-in-tag'],
13951397
includeVInTag: config['include-v-in-tag'],
1398+
includeVInReleaseName: config['include-v-in-release-name'],
13961399
changelogType: config['changelog-type'],
13971400
pullRequestTitlePattern: config['pull-request-title-pattern'],
13981401
pullRequestHeader: config['pull-request-header'],
@@ -1750,6 +1753,8 @@ function mergeReleaserConfig(
17501753
includeComponentInTag:
17511754
pathConfig.includeComponentInTag ?? defaultConfig.includeComponentInTag,
17521755
includeVInTag: pathConfig.includeVInTag ?? defaultConfig.includeVInTag,
1756+
includeVInReleaseName:
1757+
pathConfig.includeVInReleaseName ?? defaultConfig.includeVInReleaseName,
17531758
tagSeparator: pathConfig.tagSeparator ?? defaultConfig.tagSeparator,
17541759
pullRequestTitlePattern:
17551760
pathConfig.pullRequestTitlePattern ??

src/strategies/base.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export interface BaseStrategyOptions {
7575
changelogNotes?: ChangelogNotes;
7676
includeComponentInTag?: boolean;
7777
includeVInTag?: boolean;
78+
includeVInReleaseName?: boolean;
7879
pullRequestTitlePattern?: string;
7980
pullRequestHeader?: string;
8081
pullRequestFooter?: string;
@@ -110,6 +111,7 @@ export abstract class BaseStrategy implements Strategy {
110111
private releaseAs?: string;
111112
protected includeComponentInTag: boolean;
112113
protected includeVInTag: boolean;
114+
protected includeVInReleaseName: boolean;
113115
protected initialVersion?: string;
114116
readonly pullRequestTitlePattern?: string;
115117
readonly pullRequestHeader?: string;
@@ -147,6 +149,7 @@ export abstract class BaseStrategy implements Strategy {
147149
options.changelogNotes || new DefaultChangelogNotes(options);
148150
this.includeComponentInTag = options.includeComponentInTag ?? true;
149151
this.includeVInTag = options.includeVInTag ?? true;
152+
this.includeVInReleaseName = options.includeVInReleaseName ?? true;
150153
this.pullRequestTitlePattern = options.pullRequestTitlePattern;
151154
this.pullRequestHeader = options.pullRequestHeader;
152155
this.pullRequestFooter = options.pullRequestFooter;
@@ -698,10 +701,11 @@ export abstract class BaseStrategy implements Strategy {
698701
this.tagSeparator,
699702
this.includeVInTag
700703
);
704+
const versionPrefix = this.includeVInReleaseName ? 'v' : '';
701705
const releaseName =
702706
component && this.includeComponentInTag
703-
? `${component}: v${version.toString()}`
704-
: `v${version.toString()}`;
707+
? `${component}: ${versionPrefix}${version.toString()}`
708+
: `${versionPrefix}${version.toString()}`;
705709
return {
706710
name: releaseName,
707711
tag,

src/updaters/release-please-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function releaserConfigToJsonConfig(
7272
'release-label': config.releaseLabels?.join(','),
7373
'include-component-in-tag': config.includeComponentInTag,
7474
'include-v-in-tag': config.includeVInTag,
75+
'include-v-in-release-name': config.includeVInReleaseName,
7576
'changelog-type': config.changelogType,
7677
'changelog-host': config.changelogHost,
7778
'pull-request-title-pattern': config.pullRequestTitlePattern,

test/strategies/base.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,5 +452,67 @@ describe('Strategy', () => {
452452
expect(release, 'Release').to.not.be.undefined;
453453
expect(release!.tag.toString()).to.eql('1.2.3');
454454
});
455+
it('skips v in release name', async () => {
456+
const strategy = new TestStrategy({
457+
targetBranch: 'main',
458+
github,
459+
component: 'google-cloud-automl',
460+
includeComponentInTag: false,
461+
includeVInReleaseName: false,
462+
});
463+
const release = await strategy.buildRelease({
464+
title: 'chore(main): release v1.2.3',
465+
headBranchName: 'release-please/branches/main',
466+
baseBranchName: 'main',
467+
number: 1234,
468+
body: new PullRequestBody([]).toString(),
469+
labels: [],
470+
files: [],
471+
sha: 'abc123',
472+
});
473+
expect(release, 'Release').to.not.be.undefined;
474+
expect(release!.name).to.eql('1.2.3');
475+
});
476+
it('skips v in release name with component', async () => {
477+
const strategy = new TestStrategy({
478+
targetBranch: 'main',
479+
github,
480+
component: 'google-cloud-automl',
481+
includeComponentInTag: true,
482+
includeVInReleaseName: false,
483+
});
484+
const release = await strategy.buildRelease({
485+
title: 'chore(main): release v1.2.3',
486+
headBranchName: 'release-please/branches/main',
487+
baseBranchName: 'main',
488+
number: 1234,
489+
body: new PullRequestBody([]).toString(),
490+
labels: [],
491+
files: [],
492+
sha: 'abc123',
493+
});
494+
expect(release, 'Release').to.not.be.undefined;
495+
expect(release!.name).to.eql('google-cloud-automl: 1.2.3');
496+
});
497+
it('includes v in release name by default', async () => {
498+
const strategy = new TestStrategy({
499+
targetBranch: 'main',
500+
github,
501+
component: 'google-cloud-automl',
502+
includeComponentInTag: false,
503+
});
504+
const release = await strategy.buildRelease({
505+
title: 'chore(main): release v1.2.3',
506+
headBranchName: 'release-please/branches/main',
507+
baseBranchName: 'main',
508+
number: 1234,
509+
body: new PullRequestBody([]).toString(),
510+
labels: [],
511+
files: [],
512+
sha: 'abc123',
513+
});
514+
expect(release, 'Release').to.not.be.undefined;
515+
expect(release!.name).to.eql('v1.2.3');
516+
});
455517
});
456518
});

0 commit comments

Comments
 (0)