feat: lock this major version of the action to use '~> v1' as 'latest' (#461)

* feat: warn about using 'latest'

* feat: use "~> v1" as latest

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* feat: default to "~> v1" instead of "latest"

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2024-05-10 13:30:10 -03:00 committed by GitHub
parent 2953d07480
commit f1dbd532c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 35 additions and 24 deletions

View file

@ -8,8 +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') {
return getLatestRelease(distribution);
core.warning("You are using 'latest' as default version. Will lock to '~> v1'.");
return getReleaseTag(distribution, '~> v1');
}
return getReleaseTag(distribution, version);
};
@ -38,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) {