feat: add version-file input

You can now use .tool-versions file to specify GoReleaser version to download
This commit is contained in:
Alexis Couvreur 2026-02-23 19:35:37 -05:00
parent 6c92f1d350
commit e0b67d079f
6 changed files with 96 additions and 22 deletions

View file

@ -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
@ -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

View file

@ -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'

10
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

View file

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

View file

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

41
src/version.ts Normal file
View file

@ -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`
);
}
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`);
}
const content = fs.readFileSync(versionFilePath, 'utf-8');
if (path.basename(versionFilePath) === '.tool-versions') {
// asdf/mise file.
const match = content.match(/^goreleaser\s+([^\n#]+)/m);
requestedVersion = match ? 'v' + match[1].trim().replace(/^v/gi, '') : '';
}
}
if (!requestedVersion) {
// default to latest v2 release
requestedVersion = '~> v2';
}
return requestedVersion;
}