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

@ -67,7 +67,7 @@ jobs:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
# 'latest', 'nightly', or a semver
version: latest
version: '~> v1'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@ -96,7 +96,7 @@ Or with a condition on GoReleaser step:
uses: goreleaser/goreleaser-action@v5
if: startsWith(github.ref, 'refs/tags/')
with:
version: latest
version: '~> v1'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@ -121,7 +121,7 @@ the [Import GPG](https://github.com/crazy-max/ghaction-import-gpg) GitHub Action
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
version: '~> v1'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@ -146,7 +146,7 @@ purpose. You can do that with the [actions/upload-artifact](https://github.com/a
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
version: '~> v1'
args: release --clean
workdir: myfolder
env:
@ -182,7 +182,7 @@ Following inputs can be used as `step.with` keys
| Name | Type | Default | Description |
|------------------|---------|--------------|------------------------------------------------------------------|
| `distribution` | String | `goreleaser` | GoReleaser distribution, either `goreleaser` or `goreleaser-pro` |
| `version`**¹** | String | `latest` | GoReleaser version |
| `version`**¹** | String | `~> v1` | GoReleaser version |
| `args` | String | | Arguments to pass to GoReleaser |
| `workdir` | String | `.` | Working directory (below repository root) |
| `install-only` | Bool | `false` | Just install GoReleaser |
@ -221,7 +221,7 @@ secret named `GH_PAT`, the step will look like this:
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
version: latest
version: '~> v1'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}

View file

@ -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();

View file

@ -18,6 +18,16 @@ describe('install', () => {
expect(fs.existsSync(bin)).toBe(true);
}, 100000);
it('acquires latest v1 version of GoReleaser', async () => {
const bin = await goreleaser.install('goreleaser', '~> v1');
expect(fs.existsSync(bin)).toBe(true);
}, 100000);
it('acquires latest v1 version of GoReleaser Pro', async () => {
const bin = await goreleaser.install('goreleaser-pro', '~> v1');
expect(fs.existsSync(bin)).toBe(true);
}, 100000);
it('acquires latest version of GoReleaser Pro', async () => {
const bin = await goreleaser.install('goreleaser-pro', 'latest');
expect(fs.existsSync(bin)).toBe(true);

View file

@ -13,7 +13,7 @@ inputs:
required: false
version:
description: 'GoReleaser version'
default: 'latest'
default: '~> v1'
required: false
args:
description: 'Arguments to pass to GoReleaser'

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -15,7 +15,7 @@ export interface Inputs {
export async function getInputs(): Promise<Inputs> {
return {
distribution: core.getInput('distribution') || 'goreleaser',
version: core.getInput('version') || 'latest',
version: core.getInput('version') || '~> v1',
args: core.getInput('args'),
workdir: core.getInput('workdir') || '.',
installOnly: core.getBooleanInput('install-only')

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) {