Skip to content

Commit

Permalink
feat: allow skipping snapshots for java strategies (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 authored Aug 8, 2022
1 parent 354b1dc commit 3430693
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
4 changes: 4 additions & 0 deletions schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export interface ReleaserConfig {
// Java-only
extraFiles?: ExtraFile[];
snapshotLabels?: string[];
skipSnapshot?: boolean;
}

export interface CandidateReleasePullRequest {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1179,6 +1181,7 @@ function extractReleaserConfig(
separatePullRequests: config['separate-pull-requests'],
labels: config['label']?.split(','),
releaseLabels: config['release-label']?.split(','),
skipSnapshot: config['skip-snapshot'],
};
}

Expand Down Expand Up @@ -1498,6 +1501,7 @@ function mergeReleaserConfig(
defaultConfig.pullRequestTitlePattern,
separatePullRequests:
pathConfig.separatePullRequests ?? defaultConfig.separatePullRequests,
skipSnapshot: pathConfig.skipSnapshot ?? defaultConfig.skipSnapshot,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/strategies/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface BaseStrategyOptions {
extraFiles?: ExtraFile[];
versionFile?: string;
snapshotLabels?: string[]; // Java-only
skipSnapshot?: boolean; // Java-only
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/strategies/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -154,6 +156,10 @@ export class Java extends BaseStrategy {
commits: Commit[],
latestRelease?: Release
): Promise<boolean> {
if (this.skipSnapshot) {
return false;
}

const component = await this.getComponent();
logger.debug('component:', component);

Expand Down
18 changes: 18 additions & 0 deletions test/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions test/strategies/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 3430693

Please sign in to comment.