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

tap the next hook and tag prerelease versions for cocoapods #1713

Merged
merged 3 commits into from
Jan 14, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions plugins/cocoapods/__tests__/cocoapods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe("Cocoapods Plugin", () => {
logger: logger,
prefixRelease,
git: {
getLastTagNotInBaseBranch: async () => undefined,
getLatestRelease: async () => "0.0.1",
getPullRequest: async () => ({
data: {
Expand Down Expand Up @@ -438,6 +439,50 @@ describe("Cocoapods Plugin", () => {
});
});

describe("next hook", () => {
test("should return prerelease versions on dryrun", async () => {
mockPodspec(specWithVersion("0.0.1"));

const versions = await hooks.next.promise(["0.0.1", "0.0.2"], {
bump: Auto.SEMVER.minor,
dryRun: true,
commits: [],
fullReleaseNotes: "",
releaseNotes: "",
});
expect(versions).toStrictEqual(["0.0.1", "0.0.2", "0.1.0-next.0"]);
});
test("should tag with next version", async () => {
jest.spyOn(Auto, "getCurrentBranch").mockReturnValue("next");
let podSpec = specWithVersion("0.0.1");
jest
.spyOn(utilities, "getPodspecContents")
.mockImplementation(() => podSpec);
const mock = jest
.spyOn(utilities, "writePodspecContents")
.mockImplementation((path, contents) => {
podSpec = contents;
});

const versions = await hooks.next.promise([], {
bump: Auto.SEMVER.major,
dryRun: false,
commits: [],
fullReleaseNotes: "",
releaseNotes: "",
});

expect(versions).toContain("1.0.0-next.0");
expect(exec).toBeCalledTimes(4);
expect(exec).toHaveBeenCalledWith("git", ["checkout", "./Test.podspec"]);

expect(mock).toHaveBeenLastCalledWith(
expect.any(String),
specWithVersion("1.0.0-next.0")
);
});
});

describe("publish hook", () => {
test("should push to trunk if no specsRepo in options", async () => {
mockPodspec(specWithVersion("0.0.1"));
Expand Down
54 changes: 54 additions & 0 deletions plugins/cocoapods/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
validatePluginConfiguration,
ILogger,
getPrNumberFromEnv,
DEFAULT_PRERELEASE_BRANCHES,
getCurrentBranch,
determineNextVersion,
} from "@auto-it/core";

import { inc, ReleaseType } from "semver";
Expand Down Expand Up @@ -277,6 +280,57 @@ export default class CocoapodsPlugin implements IPlugin {
}
);

auto.hooks.next.tapPromise(
this.name,
async (preReleaseVersions, { bump, dryRun }) => {
if (!auto.git) {
return preReleaseVersions;
}

const prereleaseBranches =
auto.config?.prereleaseBranches ?? DEFAULT_PRERELEASE_BRANCHES;
const branch = getCurrentBranch() || "";
const prereleaseBranch = prereleaseBranches.includes(branch)
? branch
: prereleaseBranches[0];
const lastRelease = await auto.git.getLatestRelease();
const current =
(await auto.git.getLastTagNotInBaseBranch(prereleaseBranch)) ||
(await auto.getCurrentVersion(lastRelease));
const prerelease = determineNextVersion(
lastRelease,
current,
bump,
prereleaseBranch
);

preReleaseVersions.push(prerelease);

if (dryRun) {
return preReleaseVersions;
}

await execPromise("git", [
"tag",
prerelease,
"-m",
`"Tag pre-release: ${prerelease}"`,
]);

await execPromise("git", ["push", auto.remote, branch, "--tags"]);

updatePodspecVersion(this.options.podspecPath, prerelease);

// Publish the next podspec, committing it isn't needed for specs push
await this.publishPodSpec(podLogLevel);

// Reset changes to podspec file since it doesn't need to be committed
await execPromise("git", ["checkout", this.options.podspecPath]);

return preReleaseVersions;
}
);

auto.hooks.beforeShipIt.tapPromise(this.name, async ({ dryRun }) => {
if (dryRun) {
auto.logger.log.info(logMessage('dryRun - running "pod lib lint"'));
Expand Down