Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions lib/is-latest-release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function isLatestRelease({ type, main }) {
return type === "release" && main ? "true" : "false";
Copy link
Copy Markdown
Member

@travi travi Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wouldnt be safe to specifically target the main branch since master is still common and there are other patterns that teams use for naming their stable release branch. this would need to consider how the release branches are defined for the specific project

Copy link
Copy Markdown
Contributor Author

@pfarnach pfarnach Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @travi thanks for looking at my PR!

I'm having trouble finding explicit docs about the branch object (the closest thing I could find is here) so I'm going off my very cursory understanding of the source code. It seems like main in this context is a boolean (rather than a string representing the branch name) that's set here, based on the index of the branch that's passed into the config. In any case, that also doesn't seem very reliable unless there's something ensuring the main/master/whatever branch is the first element there.

Would it be enough to just check the type value and remove the main check? From what I can tell, the other possible values are maintenance and prerelease but could use a gut-check on that.

Copy link
Copy Markdown
Member

@travi travi Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you did find the closest thing to documentation on that detail. with the lack of a better doc, i went spelunking through what the core package passes to this lifecycle method to refresh my understanding. looks like i landed in the same places you explored. some of this is from before i joined the project and doesnt always stick in my brain properly. i think you landed on the correct approach.

Would it be enough to just check the type value and remove the main check? From what I can tell, the other possible values are maintenance and prerelease but could use a gut-check on that.

main accounts for "next"-type releases. not a prerelease, not a maintenance release. normal release, but not to the default channel. so given that, main is needed for determining "latest" and you've handled it appropriately here.

sorry for my confusion before and thanks for your patience

Copy link
Copy Markdown
Contributor

@viceice viceice Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check seems not enough, we use this branches config:

{
  "branches": [
    {
      "name": "maint/+([0-9])?(.{+([0-9]),x}).x",
      "range": "${name.replace(/^maint\\//g, '')}"
    },
    "main"
  ]
}

https://github.com/containerbase/base/blob/main/.releaserc.json

Copy link
Copy Markdown
Contributor Author

@pfarnach pfarnach Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you put "main" first in the array, does it work?

Copy link
Copy Markdown
Contributor

@viceice viceice Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, then it doesn't accept the maintenace branches and treats them as next.

but that was not the reason. i'v debugged a little and found the this change was not enough when using assets.
after asset upload there's a patch call which also makes the release as latest by default. I've created a fix

}
2 changes: 2 additions & 0 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import globAssets from "./glob-assets.js";
import resolveConfig from "./resolve-config.js";
import { toOctokitOptions } from "./octokit.js";
import isPrerelease from "./is-prerelease.js";
import isLatestRelease from "./is-latest-release.js";

const debug = debugFactory("semantic-release:github");

Expand Down Expand Up @@ -52,6 +53,7 @@ export default async function publish(pluginConfig, context, { Octokit }) {
name: template(releaseNameTemplate)(context),
body: template(releaseBodyTemplate)(context),
prerelease: isPrerelease(branch),
make_latest: isLatestRelease(branch),
};

debug("release object: %O", release);
Expand Down
39 changes: 39 additions & 0 deletions test/is-latest-release.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import test from "ava";
import isLatestRelease from "../lib/is-latest-release.js";

test("Test for empty object", (t) => {
const branch = {};
t.is(isLatestRelease(branch), "false");
});

test("Test if type release and main is used correctly", (t) => {
const branch = {
type: "release",
main: true,
};
t.is(isLatestRelease(branch), "true");
});

test("Test if type prerelease is used correctly", (t) => {
const branch = {
type: "prerelease",
main: true,
};
t.is(isLatestRelease(branch), "false");
});

test("Test if type main property as boolean is used correctly", (t) => {
const branch = {
type: "release",
main: false,
};
t.is(isLatestRelease(branch), "false");
});

test("Test maintenance branch returns false", (t) => {
const branch = {
type: "maintenance",
main: false,
};
t.is(isLatestRelease(branch), "false");
});
17 changes: 16 additions & 1 deletion test/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ test("Publish a release without creating discussion", async (t) => {
name: nextRelease.name,
body: nextRelease.notes,
prerelease: false,
make_latest: "true",
},
},
);
Expand Down Expand Up @@ -117,6 +118,7 @@ test("Publish a release and create discussion", async (t) => {
name: nextRelease.name,
body: nextRelease.notes,
prerelease: false,
make_latest: "true",
discussion_category_name: pluginConfig.discussionCategoryName,
},
},
Expand Down Expand Up @@ -182,6 +184,7 @@ test("Publish a release on a channel", async (t) => {
name: nextRelease.name,
body: nextRelease.notes,
prerelease: true,
make_latest: "false",
},
},
);
Expand Down Expand Up @@ -212,7 +215,7 @@ test("Publish a release on a channel", async (t) => {
t.true(fetch.done());
});

test("Publish a prerelease wihtout creating discussion", async (t) => {
test("Publish a prerelease without creating discussion", async (t) => {
const owner = "test_user";
const repo = "test_repo";
const env = { GITHUB_TOKEN: "github_token" };
Expand Down Expand Up @@ -242,6 +245,7 @@ test("Publish a prerelease wihtout creating discussion", async (t) => {
name: nextRelease.name,
body: nextRelease.notes,
prerelease: true,
make_latest: "false",
},
},
);
Expand Down Expand Up @@ -305,6 +309,7 @@ test("Publish a prerelease and create discussion", async (t) => {
name: nextRelease.name,
body: nextRelease.notes,
prerelease: true,
make_latest: "false",
discussion_category_name: pluginConfig.discussionCategoryName,
},
},
Expand Down Expand Up @@ -371,6 +376,7 @@ test("Publish a maintenance release", async (t) => {
name: nextRelease.name,
body: nextRelease.notes,
prerelease: false,
make_latest: "false",
},
},
);
Expand Down Expand Up @@ -448,6 +454,7 @@ test("Publish a release with one asset", async (t) => {
body: nextRelease.notes,
draft: true,
prerelease: false,
make_latest: "true",
},
},
)
Expand Down Expand Up @@ -535,6 +542,7 @@ test("Publish a release with one asset and custom github url", async (t) => {
body: nextRelease.notes,
draft: true,
prerelease: false,
make_latest: "true",
},
},
)
Expand Down Expand Up @@ -616,6 +624,7 @@ test("Publish a release with an array of missing assets", async (t) => {
body: nextRelease.notes,
draft: true,
prerelease: false,
make_latest: "true",
},
},
)
Expand Down Expand Up @@ -705,6 +714,7 @@ test("Publish a release with asset and create discussion", async (t) => {
body: nextRelease.notes,
draft: true,
prerelease: false,
make_latest: "true",
},
},
)
Expand Down Expand Up @@ -790,6 +800,7 @@ test("Publish a draft release", async (t) => {
body: nextRelease.notes,
draft: true,
prerelease: false,
make_latest: "true",
},
},
);
Expand Down Expand Up @@ -862,6 +873,7 @@ test("Publish a draft release with one asset", async (t) => {
body: nextRelease.notes,
draft: true,
prerelease: false,
make_latest: "true",
},
},
)
Expand Down Expand Up @@ -934,6 +946,7 @@ test("Publish a release when env.GITHUB_URL is set to https://github.com (Defaul
name: nextRelease.name,
body: nextRelease.notes,
prerelease: false,
make_latest: "true",
},
},
);
Expand Down Expand Up @@ -997,6 +1010,7 @@ test("Publish a custom release body", async (t) => {
name: nextRelease.name,
body: `To install this run npm install package@${nextRelease.name}\n\n${nextRelease.notes}`,
prerelease: false,
make_latest: "true",
},
},
);
Expand Down Expand Up @@ -1060,6 +1074,7 @@ test("Publish a custom release name", async (t) => {
name: `omg its the best release: ${nextRelease.name} 🌈🌈`,
body: nextRelease.notes,
prerelease: false,
make_latest: "true",
},
},
);
Expand Down