Skip to content

Commit

Permalink
report snapshot version to GH
Browse files Browse the repository at this point in the history
  • Loading branch information
sugarmanz committed Mar 5, 2022
1 parent c5920a3 commit cf11837
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 40 deletions.
14 changes: 7 additions & 7 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 Down Expand Up @@ -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
55 changes: 22 additions & 33 deletions plugins/gradle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand All @@ -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 }) => {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit cf11837

Please sign in to comment.