13
0
Fork 0
mirror of https://github.com/goreleaser/goreleaser-action.git synced 2026-07-03 11:39:36 +00:00

test(nightly): add regression coverage for release ordering

This commit is contained in:
copilot-swe-agent[bot] 2026-05-18 13:52:48 +00:00 committed by GitHub
parent ac0749f5a2
commit 92327ec481
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 6 deletions

View file

@ -104,3 +104,16 @@ describe('getRelease', () => {
);
});
});
describe('latestNightlyRelease', () => {
it('returns the newest nightly by published_at even when API order is wrong', () => {
const release = github.latestNightlyRelease([
{tag_name: 'v2.16.0-c9b458fa-nightly', published_at: '2026-05-12T01:27:50Z'},
{tag_name: 'v2.16.0-6724de64-nightly', published_at: '2026-05-13T01:32:53Z'},
{tag_name: 'v2.16.0-2827930b-nightly', published_at: '2026-05-17T01:34:11Z'},
{tag_name: 'v2.15.4', published_at: '2026-04-21T14:07:57Z'}
]);
expect(release?.tag_name).toEqual('v2.16.0-2827930b-nightly');
});
});

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

View file

@ -38,6 +38,13 @@ export const isNightlyTag = (tag: string): boolean => {
return nightlyTagRegex.test(tag);
};
export const latestNightlyRelease = (releases: Array<GitHubRelease>): GitHubRelease | undefined => {
return releases
.filter(r => nightlyTagRegex.test(r.tag_name))
.sort((a, b) => (b.published_at || '').localeCompare(a.published_at || ''))
.shift();
};
export const getRelease = async (distribution: string, version: string): Promise<GitHubRelease> => {
if (version === 'latest') {
core.warning("You are using 'latest' as default version. Will lock to '~> v2'.");
@ -114,11 +121,7 @@ const resolveNightly = async (distribution: string): Promise<GitHubRelease> => {
return <Array<GitHubRelease>>JSON.parse(body);
});
// GitHub's /releases endpoint is not reliably ordered by published_at, so sort explicitly.
const match = releases
.filter(r => nightlyTagRegex.test(r.tag_name))
.sort((a, b) => (b.published_at || '').localeCompare(a.published_at || ''))
.shift();
const match = latestNightlyRelease(releases);
if (!match) {
throw new Error(`No '<version>-<sha>-nightly' release found in ${url}`);
}