Skip to content

Commit 3430693

Browse files
authored
feat: allow skipping snapshots for java strategies (#1555)
1 parent 354b1dc commit 3430693

6 files changed

Lines changed: 60 additions & 0 deletions

File tree

schemas/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@
171171
"snapshot-label": {
172172
"description": "Label to add to snapshot pull request. Used by `java` strategies.",
173173
"type": "string"
174+
},
175+
"skip-snapshot": {
176+
"description": "If set, do not propose snapshot pull requests. Used by `java` strategies.",
177+
"type": "boolean"
174178
}
175179
}
176180
}

src/manifest.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export interface ReleaserConfig {
105105
// Java-only
106106
extraFiles?: ExtraFile[];
107107
snapshotLabels?: string[];
108+
skipSnapshot?: boolean;
108109
}
109110

110111
export interface CandidateReleasePullRequest {
@@ -142,6 +143,7 @@ interface ReleaserConfigJson {
142143
'extra-files'?: ExtraFile[];
143144
'version-file'?: string;
144145
'snapshot-label'?: string; // Java-only
146+
'skip-snapshot'?: boolean; // Java-only
145147
}
146148

147149
export interface ManifestOptions {
@@ -1179,6 +1181,7 @@ function extractReleaserConfig(
11791181
separatePullRequests: config['separate-pull-requests'],
11801182
labels: config['label']?.split(','),
11811183
releaseLabels: config['release-label']?.split(','),
1184+
skipSnapshot: config['skip-snapshot'],
11821185
};
11831186
}
11841187

@@ -1498,6 +1501,7 @@ function mergeReleaserConfig(
14981501
defaultConfig.pullRequestTitlePattern,
14991502
separatePullRequests:
15001503
pathConfig.separatePullRequests ?? defaultConfig.separatePullRequests,
1504+
skipSnapshot: pathConfig.skipSnapshot ?? defaultConfig.skipSnapshot,
15011505
};
15021506
}
15031507

src/strategies/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export interface BaseStrategyOptions {
7575
extraFiles?: ExtraFile[];
7676
versionFile?: string;
7777
snapshotLabels?: string[]; // Java-only
78+
skipSnapshot?: boolean; // Java-only
7879
}
7980

8081
/**

src/strategies/java.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export interface JavaBuildUpdatesOption extends BuildUpdatesOptions {
5858
export class Java extends BaseStrategy {
5959
protected readonly snapshotVersioning: VersioningStrategy;
6060
protected readonly snapshotLabels: string[];
61+
readonly skipSnapshot: boolean;
6162

6263
constructor(options: BaseStrategyOptions) {
6364
options.changelogSections = options.changelogSections ?? CHANGELOG_SECTIONS;
@@ -68,6 +69,7 @@ export class Java extends BaseStrategy {
6869
super(options);
6970
this.snapshotVersioning = new JavaAddSnapshot(parentVersioningStrategy);
7071
this.snapshotLabels = options.snapshotLabels || DEFAULT_SNAPSHOT_LABELS;
72+
this.skipSnapshot = options.skipSnapshot ?? false;
7173
}
7274

7375
async buildReleasePullRequest(
@@ -154,6 +156,10 @@ export class Java extends BaseStrategy {
154156
commits: Commit[],
155157
latestRelease?: Release
156158
): Promise<boolean> {
159+
if (this.skipSnapshot) {
160+
return false;
161+
}
162+
157163
const component = await this.getComponent();
158164
logger.debug('component:', component);
159165

test/factory.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {ServicePackVersioningStrategy} from '../src/versioning-strategies/servic
3131
import {DependencyManifest} from '../src/versioning-strategies/dependency-manifest';
3232
import {GitHubChangelogNotes} from '../src/changelog-notes/github';
3333
import {DefaultChangelogNotes} from '../src/changelog-notes/default';
34+
import {Java} from '../src/strategies/java';
3435

3536
describe('factory', () => {
3637
let github: GitHub;
@@ -197,6 +198,23 @@ describe('factory', () => {
197198
expect(innerVersioningStrategy.bumpMinorPreMajor).to.be.true;
198199
expect(innerVersioningStrategy.bumpPatchForMinorPreMajor).to.be.true;
199200
});
201+
it('should handle skipping snapshots', async () => {
202+
const strategy = await buildStrategy({
203+
github,
204+
releaseType: 'java',
205+
bumpMinorPreMajor: true,
206+
bumpPatchForMinorPreMajor: true,
207+
extraFiles: ['path1/foo1.java', 'path2/foo2.java'],
208+
skipSnapshot: true,
209+
});
210+
expect(strategy).instanceof(Java);
211+
const javaStrategy = strategy as Java;
212+
expect(javaStrategy.extraFiles).to.eql([
213+
'path1/foo1.java',
214+
'path2/foo2.java',
215+
]);
216+
expect(javaStrategy.skipSnapshot).to.be.true;
217+
});
200218
it('should handle extra-files', async () => {
201219
const strategy = await buildStrategy({
202220
github,

test/strategies/java.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,33 @@ describe('Java', () => {
132132
assertNoHasUpdate(release!.updates, 'CHANGELOG.md');
133133
});
134134

135+
it('skips a snapshot bump PR', async () => {
136+
const strategy = new Java({
137+
targetBranch: 'main',
138+
github,
139+
skipSnapshot: true,
140+
});
141+
142+
const latestRelease = {
143+
tag: new TagName(Version.parse('2.3.3')),
144+
sha: 'abc123',
145+
notes: 'some notes',
146+
};
147+
const release = await strategy.buildReleasePullRequest(
148+
COMMITS_NO_SNAPSHOT,
149+
latestRelease,
150+
false,
151+
DEFAULT_LABELS
152+
);
153+
154+
expect(release?.version?.toString()).to.eql('2.3.4');
155+
expect(release?.title.toString()).to.eql('chore(main): release 2.3.4');
156+
expect(release?.headRefName).to.eql('release-please--branches--main');
157+
expect(release?.draft).to.eql(false);
158+
expect(release?.labels).to.eql(DEFAULT_LABELS);
159+
assertHasUpdate(release!.updates, 'CHANGELOG.md');
160+
});
161+
135162
it('use snapshot latest release', async () => {
136163
const strategy = new Java({
137164
targetBranch: 'main',

0 commit comments

Comments
 (0)