Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions plugins/gradle/__tests__/gradle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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"));
});
Expand Down
58 changes: 25 additions & 33 deletions plugins/gradle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,27 @@ 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;

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);
}
});

// 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,
Expand Down Expand Up @@ -229,14 +244,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,
]);
}
await publish();

await execPromise("git", [
"push",
Expand All @@ -252,39 +260,32 @@ 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`);
}
await publish();

return canaryVersion;
}
);

// 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 }) => {
Expand Down Expand Up @@ -332,16 +333,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`);
}
await publish();

return preReleaseVersions;
}
Expand Down