Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a6cd01

Browse files
authored
fix: do not get releases.json if version is specific (#502)
closes #489
1 parent a386515 commit 9a6cd01

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

__tests__/github.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ describe('getRelease', () => {
8686
expect(release?.tag_name).toEqual('v2.7.0');
8787
});
8888

89+
it('skips JSON check for specific version v2.8.1', async () => {
90+
const release = await github.getRelease('goreleaser', 'v2.8.1');
91+
expect(release).not.toBeNull();
92+
expect(release?.tag_name).toEqual('v2.8.1');
93+
});
94+
95+
it('skips JSON check for specific version without v prefix', async () => {
96+
const release = await github.getRelease('goreleaser', '2.8.1');
97+
expect(release).not.toBeNull();
98+
expect(release?.tag_name).toEqual('v2.8.1');
99+
});
100+
89101
it('unknown GoReleaser Pro release', async () => {
90102
await expect(github.getRelease('goreleaser-pro', 'foo')).rejects.toThrow(
91103
new Error('Cannot find GoReleaser release foo in https://goreleaser.com/static/releases-pro.json')

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/github.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ export const getReleaseTag = async (distribution: string, version: string): Prom
1919
if (version === 'nightly') {
2020
return {tag_name: version};
2121
}
22+
23+
// If version is a specific version (not a range), skip the JSON check
24+
const cleanVersion: string = cleanTag(version);
25+
if (semver.valid(cleanVersion)) {
26+
let tag = version.startsWith('v') ? version : `v${version}`;
27+
28+
// Handle GoReleaser Pro suffix for versions < 2.7.0, but only if not already present
29+
// TODO: remove all this `-pro` thing at some point.
30+
if (goreleaser.isPro(distribution) && semver.lt(cleanVersion, '2.7.0') && !tag.endsWith('-pro')) {
31+
tag = tag + goreleaser.distribSuffix(distribution);
32+
}
33+
34+
return {tag_name: tag};
35+
}
36+
2237
const tag: string = (await resolveVersion(distribution, version)) || version;
2338
const suffix: string = goreleaser.distribSuffix(distribution);
2439
const url = `https://goreleaser.com/static/releases${suffix}.json`;

0 commit comments

Comments
 (0)