Skip to content

Commit

Permalink
Merge pull request #1896 from sentony93/gradle-plugin-minor-enhancement
Browse files Browse the repository at this point in the history
Small gradle plugin enhancement
  • Loading branch information
hipstersmoothie committed Mar 22, 2021
2 parents 9554fd2 + a00a3c2 commit de31da8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
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

0 comments on commit de31da8

Please sign in to comment.