Skip to content

Commit

Permalink
feat: update for goreleaser v2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Feb 11, 2025
1 parent d28c982 commit 842e7cc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
8 changes: 7 additions & 1 deletion __tests__/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ describe('getRelease', () => {
expect(release?.tag_name).toEqual('v0.182.1-pro');
});

it('returns v2.7.0 GoReleaser Pro GitHub release', async () => {
const release = await github.getRelease('goreleaser-pro', '~> v2.7');
expect(release).not.toBeNull();
expect(release?.tag_name).toEqual('v2.7.0');
});

it('unknown GoReleaser Pro release', async () => {
await expect(github.getRelease('goreleaser-pro', 'foo')).rejects.toThrow(
new Error('Cannot find GoReleaser release foo-pro in https://goreleaser.com/static/releases-pro.json')
new Error('Cannot find GoReleaser release foo in https://goreleaser.com/static/releases-pro.json')
);
});
});
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ export const getReleaseTag = async (distribution: string, version: string): Prom
const body = await resp.readBody();
const statusCode = resp.message.statusCode || 500;
if (statusCode >= 400) {
throw new Error(
`Failed to get GoReleaser release ${version}${suffix} from ${url} with status code ${statusCode}: ${body}`
);
throw new Error(`Failed to get GoReleaser release ${version} from ${url} with status code ${statusCode}: ${body}`);
}
const releases = <Array<GitHubRelease>>JSON.parse(body);
const res = releases.filter(r => r.tag_name === tag).shift();
if (res) {
return res;
}
throw new Error(`Cannot find GoReleaser release ${version}${suffix} in ${url}`);
throw new Error(`Cannot find GoReleaser release ${version} in ${url}`);
};

const resolveVersion = async (distribution: string, version: string): Promise<string | null> => {
Expand All @@ -48,7 +46,16 @@ const resolveVersion = async (distribution: string, version: string): Promise<st

const cleanTags: Array<string> = allTags.map(tag => cleanTag(tag));
const cleanVersion: string = cleanTag(version);
return semver.maxSatisfying(cleanTags, cleanVersion) + goreleaser.distribSuffix(distribution);
if (!semver.valid(cleanVersion) && !semver.validRange(cleanVersion)) {
// if the given version is invalid, return whatever we got.
return version;
}
const v = semver.maxSatisfying(cleanTags, cleanVersion);
if (semver.lt(v, '2.7.0')) {
// if its a version older than 2.7.0, append the suffix.
return v + goreleaser.distribSuffix(distribution);
}
return v;
};

interface GitHubTag {
Expand Down

0 comments on commit 842e7cc

Please sign in to comment.