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
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
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
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
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
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
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
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
186 changes: 186 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,189 @@ test("Throw SemanticReleaseError if invalid config", async (t) => {
t.is(errors[8].code, "ENOGHTOKEN");
});

test("Publish a release without assets on a main release branch", async (t) => {
const owner = "test_user";
const repo = "test_repo";
const env = { GITHUB_TOKEN: "github_token" };
const nextRelease = {
gitTag: "v1.0.0",
name: "v1.0.0",
notes: "Test release note body",
};
const options = { repositoryUrl: `https://github.com/${owner}/${repo}.git` };
const releaseUrl = `https://github.com/${owner}/${repo}/releases/${nextRelease.version}`;
const releaseId = 1;

const fetch = fetchMock
.sandbox()
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
permissions: {
push: true,
},
clone_url: `https://api.github.local/${owner}/${repo}.git`,
})
.postOnce(
`https://api.github.local/repos/${owner}/${repo}/releases`,
{ html_url: releaseUrl, id: releaseId },
{
body: {
tag_name: nextRelease.gitTag,
name: nextRelease.name,
body: nextRelease.notes,
prerelease: false,
make_latest: "true",
},
},
);

const result = await t.context.m.publish(
{},
{
cwd,
env,
options,
branch: { type: "release", main: true },
nextRelease,
logger: t.context.logger,
},
{
Octokit: TestOctokit.defaults((options) => ({
...options,
request: { ...options.request, fetch },
})),
},
);

t.is(result.url, releaseUrl);
t.is(result.name, "GitHub release");
t.is(result.id, releaseId);
t.deepEqual(t.context.log.args[0], ["Verify GitHub authentication"]);
t.true(t.context.log.calledWith("Published GitHub release: %s", releaseUrl));
t.true(fetch.done());
});

test("Publish a release without assets on a non-main release branch", async (t) => {
const owner = "test_user";
const repo = "test_repo";
const env = { GITHUB_TOKEN: "github_token" };
const nextRelease = {
gitTag: "v1.0.0",
name: "v1.0.0",
notes: "Test release note body",
};
const options = { repositoryUrl: `https://github.com/${owner}/${repo}.git` };
const releaseUrl = `https://github.com/${owner}/${repo}/releases/${nextRelease.version}`;
const releaseId = 1;

const fetch = fetchMock
.sandbox()
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
permissions: {
push: true,
},
clone_url: `https://api.github.local/${owner}/${repo}.git`,
})
.postOnce(
`https://api.github.local/repos/${owner}/${repo}/releases`,
{ html_url: releaseUrl, id: releaseId },
{
body: {
tag_name: nextRelease.gitTag,
name: nextRelease.name,
body: nextRelease.notes,
prerelease: true,
make_latest: "false",
},
},
);

const result = await t.context.m.publish(
{},
{
cwd,
env,
options,
branch: { type: "release" },
nextRelease,
logger: t.context.logger,
},
{
Octokit: TestOctokit.defaults((options) => ({
...options,
request: { ...options.request, fetch },
})),
},
);

t.is(result.url, releaseUrl);
t.is(result.name, "GitHub release");
t.is(result.id, releaseId);
t.deepEqual(t.context.log.args[0], ["Verify GitHub authentication"]);
t.true(t.context.log.calledWith("Published GitHub release: %s", releaseUrl));
t.true(fetch.done());
});

test("Publish a release without assets on a maintenance branch", async (t) => {
const owner = "test_user";
const repo = "test_repo";
const env = { GITHUB_TOKEN: "github_token" };
const nextRelease = {
gitTag: "v1.0.0",
name: "v1.0.0",
notes: "Test release note body",
};
const options = { repositoryUrl: `https://github.com/${owner}/${repo}.git` };
const releaseUrl = `https://github.com/${owner}/${repo}/releases/${nextRelease.version}`;
const releaseId = 1;

const fetch = fetchMock
.sandbox()
.getOnce(`https://api.github.local/repos/${owner}/${repo}`, {
permissions: {
push: true,
},
clone_url: `https://api.github.local/${owner}/${repo}.git`,
})
.postOnce(
`https://api.github.local/repos/${owner}/${repo}/releases`,
{ html_url: releaseUrl, id: releaseId },
{
body: {
tag_name: nextRelease.gitTag,
name: nextRelease.name,
body: nextRelease.notes,
prerelease: false,
make_latest: "false",
},
},
);

const result = await t.context.m.publish(
{},
{
cwd,
env,
options,
branch: { type: "maintenance" },
nextRelease,
logger: t.context.logger,
},
{
Octokit: TestOctokit.defaults((options) => ({
...options,
request: { ...options.request, fetch },
})),
},
);

t.is(result.url, releaseUrl);
t.is(result.name, "GitHub release");
t.is(result.id, releaseId);
t.deepEqual(t.context.log.args[0], ["Verify GitHub authentication"]);
t.true(t.context.log.calledWith("Published GitHub release: %s", releaseUrl));
t.true(fetch.done());
});

test("Publish a release with an array of assets", async (t) => {
const owner = "test_user";
const repo = "test_repo";
Expand Down Expand Up @@ -227,6 +410,7 @@ test("Publish a release with an array of assets", async (t) => {
body: nextRelease.notes,
draft: true,
prerelease: false,
make_latest: "true",
},
},
)
Expand Down Expand Up @@ -322,6 +506,7 @@ test("Publish a release with release information in assets", async (t) => {
body: nextRelease.notes,
draft: true,
prerelease: true,
make_latest: "false",
},
},
)
Expand Down Expand Up @@ -718,6 +903,7 @@ test("Verify, release and notify success", async (t) => {
body: nextRelease.notes,
draft: true,
prerelease: false,
make_latest: "true",
},
},
)
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");
});
Loading