From cf1183796bf8045d8e80fcb8dfdb37bd3770515e Mon Sep 17 00:00:00 2001 From: Jeremiah Zucker Date: Sat, 5 Mar 2022 14:16:52 -0500 Subject: [PATCH 1/3] report snapshot version to GH --- plugins/gradle/__tests__/gradle.test.ts | 14 +++---- plugins/gradle/src/index.ts | 55 ++++++++++--------------- 2 files changed, 29 insertions(+), 40 deletions(-) diff --git a/plugins/gradle/__tests__/gradle.test.ts b/plugins/gradle/__tests__/gradle.test.ts index f1ce40ff0..e031a376b 100644 --- a/plugins/gradle/__tests__/gradle.test.ts +++ b/plugins/gradle/__tests__/gradle.test.ts @@ -175,7 +175,7 @@ describe("Gradle Plugin", () => { exec.mockReturnValueOnce(properties).mockImplementation(spy); const mockLog = jest.spyOn(logger.log, "info"); - await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "canary123" , dryRun: true}); + await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "-canary123" , dryRun: true}); expect(spy).toHaveBeenCalledTimes(0) expect(mockLog).toHaveBeenCalledTimes(1) @@ -189,9 +189,9 @@ describe("Gradle Plugin", () => { const spy = jest.fn(); exec.mockReturnValueOnce(properties).mockImplementation(spy); - const canaryVersion = await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "canary123" }); + const canaryVersion = await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "-canary123" }); - expect(canaryVersion).toBe("1.0.0-canary123") + expect(canaryVersion).toBe("1.0.0-canary123-SNAPSHOT") }); test("should not increment version - canary w/ default snapshot", async () => { @@ -202,9 +202,9 @@ describe("Gradle Plugin", () => { const spy = jest.fn(); exec.mockReturnValueOnce(properties).mockImplementation(spy); - const canaryVersion = await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "canary123" }); + const canaryVersion = await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "-canary123" }); - expect(canaryVersion).toBe("1.0.0-canary123") + expect(canaryVersion).toBe("1.0.0-canary123-SNAPSHOT") }); test("should update gradle version for publish - canary w/ default snapshot", async () => { @@ -232,7 +232,7 @@ describe("Gradle Plugin", () => { const spy = jest.fn(); exec.mockReturnValueOnce(properties).mockImplementation(spy); - await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "canary123" }); + await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "-canary123" }); expect(spy).toHaveBeenCalledWith(expect.stringMatching("gradle"), [ "publish", @@ -248,7 +248,7 @@ describe("Gradle Plugin", () => { exec.mockReturnValueOnce(properties).mockImplementation(spy); const mockLog = jest.spyOn(logger.log, "warn"); - await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "canary123" }); + await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "-canary123" }); expect(mockLog).toHaveBeenCalledWith(expect.stringMatching("Publish task not found in gradle")); }); diff --git a/plugins/gradle/src/index.ts b/plugins/gradle/src/index.ts index f4cc3e826..ec183d239 100644 --- a/plugins/gradle/src/index.ts +++ b/plugins/gradle/src/index.ts @@ -144,6 +144,19 @@ export default class GradleReleasePluginPlugin implements IPlugin { /** Tap into auto plugin points. */ apply(auto: Auto) { + const publish = async () => { + const { publish } = this.properties; + + if (publish) { + await execPromise(this.options.gradleCommand, [ + "publish", + ...this.options.gradleOptions, + ]); + } else { + auto.logger.log.warn(`Publish task not found in gradle`); + } + }; + auto.hooks.validateConfig.tapPromise(this.name, async (name, options) => { if (name === this.name || name === `@auto-it/${this.name}`) { return validatePluginConfiguration(this.name, pluginOptions, options); @@ -229,14 +242,7 @@ export default class GradleReleasePluginPlugin implements IPlugin { ); auto.hooks.publish.tapPromise(this.name, async () => { - const { publish } = this.properties; - - if (publish) { - await execPromise(this.options.gradleCommand, [ - "publish", - ...this.options.gradleOptions, - ]); - } + publish(); await execPromise("git", [ "push", @@ -252,39 +258,31 @@ export default class GradleReleasePluginPlugin implements IPlugin { async ({ dryRun, canaryIdentifier }) => { const releaseVersion = await getVersion( this.options.gradleCommand, - this.options.gradleOptions + this.options.gradleOptions, ); - const canaryVersion = `${releaseVersion}-${canaryIdentifier}`; + const { snapshotSuffix = defaultSnapshotSuffix } = this.properties; + const canaryVersion = `${releaseVersion}${canaryIdentifier}${snapshotSuffix}`; if (dryRun) { auto.logger.log.info(`Would have published: ${canaryVersion}`); return canaryVersion; } - const canaryReleaseVersion = `${canaryVersion}${defaultSnapshotSuffix}` await this.updateGradleVersion( - canaryReleaseVersion, - `Prerelease version: ${canaryReleaseVersion} [skip ci]`, + canaryVersion, + `Prerelease version: ${canaryVersion} [skip ci]`, false, false ); - const { publish } = this.properties; - - if (publish) { - await execPromise(this.options.gradleCommand, [ - "publish", - ...this.options.gradleOptions, - ]); - } else { - auto.logger.log.warn(`Publish task not found in gradle`); - } + publish(); return canaryVersion; } ); + // TODO: We should at least report the correct version to GH -- which could include next auto.hooks.next.tapPromise( this.name, async (preReleaseVersions, { dryRun, bump }) => { @@ -332,16 +330,7 @@ export default class GradleReleasePluginPlugin implements IPlugin { false ); - const { publish } = this.properties; - - if (publish) { - await execPromise(this.options.gradleCommand, [ - "publish", - ...this.options.gradleOptions, - ]); - } else { - auto.logger.log.warn(`Publish task not found in gradle`); - } + publish(); return preReleaseVersions; } From 7c4682f8160fb08874834e7023879f91ae13de14 Mon Sep 17 00:00:00 2001 From: Jeremiah Zucker Date: Sat, 5 Mar 2022 14:25:53 -0500 Subject: [PATCH 2/3] fix test and await on publishing --- plugins/gradle/__tests__/gradle.test.ts | 2 +- plugins/gradle/src/index.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/gradle/__tests__/gradle.test.ts b/plugins/gradle/__tests__/gradle.test.ts index e031a376b..ec22d1b41 100644 --- a/plugins/gradle/__tests__/gradle.test.ts +++ b/plugins/gradle/__tests__/gradle.test.ts @@ -215,7 +215,7 @@ describe("Gradle Plugin", () => { const spy = jest.fn(); exec.mockReturnValueOnce(properties).mockImplementation(spy); - await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "canary123" }); + await hooks.canary.promise({ bump: Auto.SEMVER.patch, canaryIdentifier: "-canary123" }); expect(spy).toHaveBeenCalledWith(expect.stringMatching("gradle"), [ "updateVersion", diff --git a/plugins/gradle/src/index.ts b/plugins/gradle/src/index.ts index ec183d239..f51c7aa6d 100644 --- a/plugins/gradle/src/index.ts +++ b/plugins/gradle/src/index.ts @@ -144,6 +144,7 @@ export default class GradleReleasePluginPlugin implements IPlugin { /** Tap into auto plugin points. */ apply(auto: Auto) { + /** Call gradle publish, if exists, otherwise log warning */ const publish = async () => { const { publish } = this.properties; @@ -242,7 +243,7 @@ export default class GradleReleasePluginPlugin implements IPlugin { ); auto.hooks.publish.tapPromise(this.name, async () => { - publish(); + await publish(); await execPromise("git", [ "push", @@ -276,7 +277,7 @@ export default class GradleReleasePluginPlugin implements IPlugin { false ); - publish(); + await publish(); return canaryVersion; } @@ -330,7 +331,7 @@ export default class GradleReleasePluginPlugin implements IPlugin { false ); - publish(); + await publish(); return preReleaseVersions; } From 4322adfcb86f4a4b19eee30679c88a92b3d98de7 Mon Sep 17 00:00:00 2001 From: Jeremiah Zucker Date: Sat, 5 Mar 2022 14:45:08 -0500 Subject: [PATCH 3/3] add todos --- plugins/gradle/src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/gradle/src/index.ts b/plugins/gradle/src/index.ts index f51c7aa6d..c241dee27 100644 --- a/plugins/gradle/src/index.ts +++ b/plugins/gradle/src/index.ts @@ -164,6 +164,7 @@ export default class GradleReleasePluginPlugin implements IPlugin { } }); + // TODO: Is this where we can introspect PR files for .api? auto.hooks.beforeRun.tap(this.name, async () => { this.properties = await getProperties( this.options.gradleCommand, @@ -284,6 +285,7 @@ export default class GradleReleasePluginPlugin implements IPlugin { ); // TODO: We should at least report the correct version to GH -- which could include next + // Maybe, we should publish to `version-SNAPSHOT` _and_ `version-next-SNAPSHOT`? auto.hooks.next.tapPromise( this.name, async (preReleaseVersions, { dryRun, bump }) => {