Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ ___

![GoRelease Action](.github/goreleaser-action.png)

* [Usage](#usage)
* [Workflow](#workflow)
* [Run on new tag](#run-on-new-tag)
* [Signing](#signing)
* [Upload artifacts](#upload-artifacts)
* [Install Only](#install-only)
* [Customizing](#customizing)
* [inputs](#inputs)
* [outputs](#outputs)
* [environment variables](#environment-variables)
* [Limitation](#limitation)
* [Development](#development)
* [License](#license)
- [Usage](#usage)
- [Workflow](#workflow)
- [Run on new tag](#run-on-new-tag)
- [Signing](#signing)
- [Upload artifacts](#upload-artifacts)
- [Install Only](#install-only)
- [Customizing](#customizing)
- [inputs](#inputs)
- [`version-file`](#version-file)
- [outputs](#outputs)
- [environment variables](#environment-variables)
- [Limitation](#limitation)
- [Migrating from v3](#migrating-from-v3)
- [Development](#development)
- [License](#license)

## Usage

Expand Down Expand Up @@ -183,12 +185,33 @@ Following inputs can be used as `step.with` keys
|------------------|---------|--------------|------------------------------------------------------------------|
| `distribution` | String | `goreleaser` | GoReleaser distribution, either `goreleaser` or `goreleaser-pro` |
| `version`**¹** | String | `~> v2` | GoReleaser version |
| `version-file` | String | | Gets the version of GoReleaser to use from a file. |
| `args` | String | | Arguments to pass to GoReleaser |
| `workdir` | String | `.` | Working directory (below repository root) |
| `install-only` | Bool | `false` | Just install GoReleaser |

> **¹** Can be a fixed version like `v0.117.0` or a max satisfying semver one like `~> 0.132`. In this case this will return `v0.132.1`.

#### `version-file`

Gets the version of GoReleaser to use from a file.

The path must be relative to the root of the project, or the `workdir` if defined.

This parameter supports `.tool-versions` files.

<details>
<summary>Example</summary>

```yml
uses: goreleaser/goreleaser-action@v7
with:
version-file: .tool-versions
# ...
```

</details>

### outputs

Following outputs are available
Expand Down
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ inputs:
required: false
version:
description: 'GoReleaser version'
default: '~> v2'
required: false
version-file:
description: |
Gets the version of GoReleaser to use from a file.
The path must be relative to the root of the project, or the `workdir` if defined.
This parameter supports `.tool-versions` files.
Only works with `install-mode: binary` (the default).
required: false
args:
description: 'Arguments to pass to GoReleaser'
Expand Down
10 changes: 5 additions & 5 deletions dist/index.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const osArch: string = os.arch();
export interface Inputs {
distribution: string;
version: string;
versionFile: string;
args: string;
workdir: string;
installOnly: boolean;
Expand All @@ -15,7 +16,8 @@ export interface Inputs {
export async function getInputs(): Promise<Inputs> {
return {
distribution: core.getInput('distribution') || 'goreleaser',
version: core.getInput('version') || '~> v2',
version: core.getInput('version'),
versionFile: core.getInput('version-file'),
args: core.getInput('args'),
workdir: core.getInput('workdir') || '.',
installOnly: core.getBooleanInput('install-only')
Expand Down
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import * as context from './context';
import * as goreleaser from './goreleaser';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import {getRequestedVersion} from './version';

async function run(): Promise<void> {
try {
const inputs: context.Inputs = await context.getInputs();
const bin = await goreleaser.install(inputs.distribution, inputs.version);
core.info(`GoReleaser ${inputs.version} installed successfully`);
const version = getRequestedVersion(inputs);
const bin = await goreleaser.install(inputs.distribution, version);
core.info(`GoReleaser ${version} installed successfully`);

if (inputs.installOnly) {
const goreleaserDir = path.dirname(bin);
Expand Down
41 changes: 41 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as core from '@actions/core';
import * as fs from 'fs';
import path from 'path';
import {Inputs} from './context';

export function getRequestedVersion(inputs: Inputs): string {
let requestedVersion = inputs.version;
let versionFilePath = inputs.versionFile;

if (requestedVersion && versionFilePath) {
core.warning(
`Both version (${requestedVersion}) and version-file (${versionFilePath}) inputs are specified, only version will be used`
);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if it would be better to simplify all this making version-file having precedence

so, if version-file is given, use it, or error

otherwise, use version, which would also mean we don't need to manually default to ~> v2

wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a better solution indeed because then I can revert all the changes about how the default version is computed.

I've taken much inspiration from the current implementation in the goreleaser action, so I've essentially implemented the same behavior.

Let me change it with your suggestion.


if (requestedVersion == '' && versionFilePath) {
const workingDirectory = inputs.workdir;
if (workingDirectory) {
versionFilePath = path.join(workingDirectory, versionFilePath);
}

if (!fs.existsSync(versionFilePath)) {
throw new Error(`The specified GoReleaser version file at: ${versionFilePath} does not exist`);
}
Comment on lines +11 to +18

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This always resolves version-file relative to workdir when workdir is set (including common monorepo setups where workdir is a subdirectory). That makes it impossible to reference a version file in the repo root while also using a non-root workdir, despite the docs saying the path can be relative to the root or workdir. Consider resolving relative paths by checking both candidates (repo root path first, then path.join(workdir, versionFile)), or updating the docs to state that version-file is interpreted relative to workdir when provided.

Copilot uses AI. Check for mistakes.

const content = fs.readFileSync(versionFilePath, 'utf-8');

if (path.basename(versionFilePath) === '.tool-versions') {
// asdf/mise file.
const match = content.match(/^goreleaser\s+([^\n#]+)/m);

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser requires goreleaser to start at column 0. .tool-versions files sometimes contain leading whitespace; allowing optional leading spaces (e.g., ^\\s*goreleaser\\s+... with the m flag) would make the parsing more robust without changing intended behavior.

Suggested change
const match = content.match(/^goreleaser\s+([^\n#]+)/m);
const match = content.match(/^\s*goreleaser\s+([^\n#]+)/m);

Copilot uses AI. Check for mistakes.
requestedVersion = match ? 'v' + match[1].trim().replace(/^v/gi, '') : '';

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If .tool-versions doesn’t contain a goreleaser ... entry, this sets requestedVersion to an empty string, which will likely cause a confusing failure later during install. Prefer throwing a clear error when no matching entry is found (e.g., file exists but no goreleaser line), so users get an actionable message.

Suggested change
requestedVersion = match ? 'v' + match[1].trim().replace(/^v/gi, '') : '';
if (!match) {
throw new Error(
`No 'goreleaser' entry found in ${versionFilePath}. ` +
"Please add a line like 'goreleaser <version>' or specify the version input directly."
);
}
requestedVersion = 'v' + match[1].trim().replace(/^v/gi, '');

Copilot uses AI. Check for mistakes.
}
}

if (!requestedVersion) {
// default to latest v2 release
requestedVersion = '~> v2';
}

return requestedVersion;
}