Skip to content

Commit

Permalink
feat: use "~> v1" as latest
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed May 8, 2024
1 parent b4b0533 commit 2b76db6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
14 changes: 13 additions & 1 deletion __tests__/github.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, it} from '@jest/globals';
import { describe, expect, it } from '@jest/globals';
import * as github from '../src/github';

describe('getRelease', () => {
Expand Down Expand Up @@ -32,6 +32,18 @@ describe('getRelease', () => {
expect(release?.tag_name).not.toEqual('');
});

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

it('returns latest v1 GoReleaser GitHub release', async () => {
const release = await github.getRelease('goreleaser', '~> v1');
expect(release).not.toBeNull();
expect(release?.tag_name).not.toEqual('');
});

it('returns nightly GoReleaser GitHub release', async () => {
const release = await github.getRelease('goreleaser', 'nightly');
expect(release).not.toBeNull();
Expand Down
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.

20 changes: 3 additions & 17 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ export interface GitHubRelease {
}

export const getRelease = async (distribution: string, version: string): Promise<GitHubRelease> => {
// TODO: change this to ~> v2 on a future major, once goreleaser v2 is out
if (version === 'latest') {
core.warning(
"You are using 'latest' as default version. This might include breaking changes. It is recommended to use a SemVer to lock to a major version (e.g. ~> v1)."
);
return getLatestRelease(distribution);
core.warning("You are using 'latest' as default version. Will lock to '~> v1'.");
return getReleaseTag(distribution, '~> v1');
}
return getReleaseTag(distribution, version);
};
Expand Down Expand Up @@ -41,19 +40,6 @@ export const getReleaseTag = async (distribution: string, version: string): Prom
throw new Error(`Cannot find GoReleaser release ${version}${suffix} in ${url}`);
};

export const getLatestRelease = async (distribution: string): Promise<GitHubRelease> => {
const suffix: string = goreleaser.distribSuffix(distribution);
const url = `https://goreleaser.com/static/latest${suffix}`;
const http: httpm.HttpClient = new httpm.HttpClient('goreleaser-action');
const resp: httpm.HttpClientResponse = await http.get(url);
const body = await resp.readBody();
const statusCode = resp.message.statusCode || 500;
if (statusCode >= 400) {
throw new Error(`Failed to get GoReleaser release latest from ${url} with status code ${statusCode}: ${body}`);
}
return {tag_name: body};
};

const resolveVersion = async (distribution: string, version: string): Promise<string | null> => {
const allTags: Array<string> | null = await getAllTags(distribution);
if (!allTags) {
Expand Down

0 comments on commit 2b76db6

Please sign in to comment.