diff --git a/schemas/config.json b/schemas/config.json index faa4f96c9..eb8df0071 100644 --- a/schemas/config.json +++ b/schemas/config.json @@ -171,6 +171,10 @@ "snapshot-label": { "description": "Label to add to snapshot pull request. Used by `java` strategies.", "type": "string" + }, + "skip-snapshot": { + "description": "If set, do not propose snapshot pull requests. Used by `java` strategies.", + "type": "boolean" } } } diff --git a/src/manifest.ts b/src/manifest.ts index 368cecb62..e70fe8356 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -105,6 +105,7 @@ export interface ReleaserConfig { // Java-only extraFiles?: ExtraFile[]; snapshotLabels?: string[]; + skipSnapshot?: boolean; } export interface CandidateReleasePullRequest { @@ -142,6 +143,7 @@ interface ReleaserConfigJson { 'extra-files'?: ExtraFile[]; 'version-file'?: string; 'snapshot-label'?: string; // Java-only + 'skip-snapshot'?: boolean; // Java-only } export interface ManifestOptions { @@ -1179,6 +1181,7 @@ function extractReleaserConfig( separatePullRequests: config['separate-pull-requests'], labels: config['label']?.split(','), releaseLabels: config['release-label']?.split(','), + skipSnapshot: config['skip-snapshot'], }; } @@ -1498,6 +1501,7 @@ function mergeReleaserConfig( defaultConfig.pullRequestTitlePattern, separatePullRequests: pathConfig.separatePullRequests ?? defaultConfig.separatePullRequests, + skipSnapshot: pathConfig.skipSnapshot ?? defaultConfig.skipSnapshot, }; } diff --git a/src/strategies/base.ts b/src/strategies/base.ts index 67d5f491d..a7d6d6166 100644 --- a/src/strategies/base.ts +++ b/src/strategies/base.ts @@ -75,6 +75,7 @@ export interface BaseStrategyOptions { extraFiles?: ExtraFile[]; versionFile?: string; snapshotLabels?: string[]; // Java-only + skipSnapshot?: boolean; // Java-only } /** diff --git a/src/strategies/java.ts b/src/strategies/java.ts index d95dea271..e2ef487c6 100644 --- a/src/strategies/java.ts +++ b/src/strategies/java.ts @@ -58,6 +58,7 @@ export interface JavaBuildUpdatesOption extends BuildUpdatesOptions { export class Java extends BaseStrategy { protected readonly snapshotVersioning: VersioningStrategy; protected readonly snapshotLabels: string[]; + readonly skipSnapshot: boolean; constructor(options: BaseStrategyOptions) { options.changelogSections = options.changelogSections ?? CHANGELOG_SECTIONS; @@ -68,6 +69,7 @@ export class Java extends BaseStrategy { super(options); this.snapshotVersioning = new JavaAddSnapshot(parentVersioningStrategy); this.snapshotLabels = options.snapshotLabels || DEFAULT_SNAPSHOT_LABELS; + this.skipSnapshot = options.skipSnapshot ?? false; } async buildReleasePullRequest( @@ -154,6 +156,10 @@ export class Java extends BaseStrategy { commits: Commit[], latestRelease?: Release ): Promise { + if (this.skipSnapshot) { + return false; + } + const component = await this.getComponent(); logger.debug('component:', component); diff --git a/test/factory.ts b/test/factory.ts index b261bd657..2253518f0 100644 --- a/test/factory.ts +++ b/test/factory.ts @@ -31,6 +31,7 @@ import {ServicePackVersioningStrategy} from '../src/versioning-strategies/servic import {DependencyManifest} from '../src/versioning-strategies/dependency-manifest'; import {GitHubChangelogNotes} from '../src/changelog-notes/github'; import {DefaultChangelogNotes} from '../src/changelog-notes/default'; +import {Java} from '../src/strategies/java'; describe('factory', () => { let github: GitHub; @@ -197,6 +198,23 @@ describe('factory', () => { expect(innerVersioningStrategy.bumpMinorPreMajor).to.be.true; expect(innerVersioningStrategy.bumpPatchForMinorPreMajor).to.be.true; }); + it('should handle skipping snapshots', async () => { + const strategy = await buildStrategy({ + github, + releaseType: 'java', + bumpMinorPreMajor: true, + bumpPatchForMinorPreMajor: true, + extraFiles: ['path1/foo1.java', 'path2/foo2.java'], + skipSnapshot: true, + }); + expect(strategy).instanceof(Java); + const javaStrategy = strategy as Java; + expect(javaStrategy.extraFiles).to.eql([ + 'path1/foo1.java', + 'path2/foo2.java', + ]); + expect(javaStrategy.skipSnapshot).to.be.true; + }); it('should handle extra-files', async () => { const strategy = await buildStrategy({ github, diff --git a/test/strategies/java.ts b/test/strategies/java.ts index cd337cab5..1d0471839 100644 --- a/test/strategies/java.ts +++ b/test/strategies/java.ts @@ -132,6 +132,33 @@ describe('Java', () => { assertNoHasUpdate(release!.updates, 'CHANGELOG.md'); }); + it('skips a snapshot bump PR', async () => { + const strategy = new Java({ + targetBranch: 'main', + github, + skipSnapshot: true, + }); + + const latestRelease = { + tag: new TagName(Version.parse('2.3.3')), + sha: 'abc123', + notes: 'some notes', + }; + const release = await strategy.buildReleasePullRequest( + COMMITS_NO_SNAPSHOT, + latestRelease, + false, + DEFAULT_LABELS + ); + + expect(release?.version?.toString()).to.eql('2.3.4'); + expect(release?.title.toString()).to.eql('chore(main): release 2.3.4'); + expect(release?.headRefName).to.eql('release-please--branches--main'); + expect(release?.draft).to.eql(false); + expect(release?.labels).to.eql(DEFAULT_LABELS); + assertHasUpdate(release!.updates, 'CHANGELOG.md'); + }); + it('use snapshot latest release', async () => { const strategy = new Java({ targetBranch: 'main',