Skip to content

Commit

Permalink
Merge pull request #2391 from jBouyoud/fix-latest-release
Browse files Browse the repository at this point in the history
Fix release creation on oldVersions
  • Loading branch information
hipstersmoothie committed Sep 6, 2023
2 parents 9f4bc81 + b08c1fe commit b351c58
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
57 changes: 51 additions & 6 deletions packages/core/src/__tests__/auto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,8 @@ describe("Auto", () => {
"releaseNotes",
"v1.2.4",
false,
""
"",
true
);
expect(afterRelease).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -977,6 +978,45 @@ describe("Auto", () => {
);
});

test("should publish non latest release on inOldVersionBranch", async () => {
const auto = new Auto({ ...defaults, plugins: [] });
auto.logger = dummyLog();
await auto.loadConfig();
auto.git!.getLatestRelease = () => Promise.resolve("1.2.3");

jest.spyOn(auto.git!, "publish").mockReturnValueOnce({ data: {} } as any);
jest
.spyOn(auto.release!, "generateReleaseNotes")
.mockImplementation(() => Promise.resolve("releaseNotes"));
auto.release!.getCommitsInRelease = () =>
Promise.resolve([makeCommitFromMsg("Test Commit")]);

auto.hooks.getPreviousVersion.tap("test", () => "1.2.4");
const afterRelease = jest.fn();
auto.hooks.afterRelease.tap("test", afterRelease);
jest.spyOn(auto.release!, "getCommits").mockImplementation();

await auto.runRelease();
expect(auto.release!.generateReleaseNotes).toHaveBeenCalledWith(
"v1.2.3",
undefined,
undefined
);
expect(auto.git!.publish).toHaveBeenCalledWith(
"releaseNotes",
"v1.2.4",
false,
"",
true
);
expect(afterRelease).toHaveBeenCalledWith(
expect.objectContaining({
lastRelease: "v1.2.3",
newVersion: "v1.2.4",
})
);
});

test("should use --to commit target", async () => {
const auto = new Auto({ ...defaults, plugins: [] });
auto.logger = dummyLog();
Expand All @@ -1001,7 +1041,8 @@ describe("Auto", () => {
"releaseNotes",
"v1.2.4",
false,
"abc"
"abc",
true
);
});

Expand Down Expand Up @@ -1061,7 +1102,8 @@ describe("Auto", () => {
"releaseNotes",
"v1.2.4",
true,
""
"",
false
);
expect(afterRelease).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down Expand Up @@ -1101,7 +1143,8 @@ describe("Auto", () => {
"releaseNotes",
"v1.2.4",
false,
""
"",
true
);
expect(afterRelease).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down Expand Up @@ -1141,7 +1184,8 @@ describe("Auto", () => {
"releaseNotes",
"v1.3.0",
false,
""
"",
true
);
expect(afterRelease).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down Expand Up @@ -1181,7 +1225,8 @@ describe("Auto", () => {
"releaseNotes",
"v1.2.3+1",
false,
""
"",
true
);
expect(afterRelease).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/auto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ export default class Auto {
options.fullReleaseNotes,
options.newVersion,
options.isPrerelease,
options.to
options.to,
options.isPrerelease ? false: !this.inOldVersionBranch(),
);

this.logger.log.info(release.data.html_url);
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,8 @@ export default class Git {
releaseNotes: string,
tag: string,
prerelease = false,
fallbackCommit?: string
fallbackCommit?: string,
latestRelease = false
) {
this.logger.verbose.info("Creating release on GitHub for tag:", tag);

Expand All @@ -867,6 +868,7 @@ export default class Git {
name: tag,
body: releaseNotes,
prerelease,
make_latest: latestRelease,
});

this.logger.veryVerbose.info("Got response from createRelease\n", result);
Expand Down

0 comments on commit b351c58

Please sign in to comment.