Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small gradle plugin enhancement #1896

Merged
merged 1 commit into from Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions plugins/gradle/__tests__/gradle.test.ts
Expand Up @@ -192,6 +192,23 @@ describe("Gradle Plugin", () => {
expect(canaryVersion).toBe("1.0.0-canary123")
});

test("should update gradle version for publish - canary w/ default snapshot", async () => {
const properties = "version: 1.0.0-SNAPSHOT";
exec.mockReturnValueOnce(properties);
await hooks.beforeRun.promise({} as any);

const spy = jest.fn();
exec.mockReturnValueOnce(properties).mockImplementation(spy);

await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "canary123" });

expect(spy).toHaveBeenCalledWith(expect.stringMatching("gradle"), [
"updateVersion",
"-Prelease.useAutomaticVersion=true",
`-Prelease.newVersion=1.0.0-canary123-SNAPSHOT`,
]);
});

test("should publish if available - canary", async () => {
const properties = "publish: yes";
exec.mockReturnValueOnce(properties);
Expand Down Expand Up @@ -256,7 +273,7 @@ describe("Gradle Plugin", () => {
expect(nextVersion[0]).toBe("1.0.0-next.0")
});

test("should version release with snapshot suffix - next", async () => {
test("should update gradle version for publish with snapshot suffix - next", async () => {
const properties = "this doesn't matter";
exec.mockReturnValueOnce(properties);
await hooks.beforeRun.promise({} as any);
Expand All @@ -268,12 +285,9 @@ describe("Gradle Plugin", () => {
await hooks.next.promise([], { bump: Auto.SEMVER.major, commits: [], fullReleaseNotes: "", releaseNotes: "" });

expect(spy).toHaveBeenCalledWith(expect.stringMatching("gradle"), [
"release",
"updateVersion",
"-Prelease.useAutomaticVersion=true",
`-Prelease.newVersion=1.0.0-SNAPSHOT`,
"-x createReleaseTag",
"-x preTagCommit",
"-x commitNewVersion",
]);
});

Expand Down
13 changes: 11 additions & 2 deletions plugins/gradle/src/index.ts
Expand Up @@ -106,8 +106,8 @@ export default class GradleReleasePluginPlugin implements IPlugin {
private readonly updateGradleVersion = async (
version: string,
commitMsg?: string,
commit = true,
buildFlag = true
buildFlag = true,
commit = true
) => {
if (buildFlag) {
// don't create release, tag, or commit since auto will do this
Expand Down Expand Up @@ -259,6 +259,14 @@ export default class GradleReleasePluginPlugin implements IPlugin {
return canaryVersion;
}

const canaryReleaseVersion = `${canaryVersion}${defaultSnapshotSuffix}`
await this.updateGradleVersion(
canaryReleaseVersion,
`Prerelease version: ${canaryReleaseVersion} [skip ci]`,
false,
false
);

const { publish } = this.properties;

if (publish) {
Expand Down Expand Up @@ -317,6 +325,7 @@ export default class GradleReleasePluginPlugin implements IPlugin {
await this.updateGradleVersion(
preReleaseSnapshotVersion,
`Prerelease version: ${preReleaseSnapshotVersion} [skip ci]`,
false,
false
);

Expand Down