Skip to content

Commit

Permalink
feat: lock this major version of the action to use '~> v1' as 'latest' (
Browse files Browse the repository at this point in the history
#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>
  • Loading branch information
caarlos0 authored May 10, 2024
1 parent 2953d07 commit f1dbd53
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 24 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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:
Expand Down Expand Up @@ -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 |
Expand Down Expand Up @@ -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 }}
Expand Down
12 changes: 12 additions & 0 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
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
10 changes: 10 additions & 0 deletions __tests__/goreleaser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ inputs:
required: false
version:
description: 'GoReleaser version'
default: 'latest'
default: '~> v1'
required: false
args:
description: 'Arguments to pass to GoReleaser'
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.

2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
17 changes: 3 additions & 14 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f1dbd53

Please sign in to comment.