mirror of
https://github.com/goreleaser/goreleaser-action
synced 2026-07-09 07:57:30 +00:00
Merge remote-tracking branch 'origin/master' into nightly
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
@@ -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;
|
||||
@@ -16,6 +17,7 @@ export async function getInputs(): Promise<Inputs> {
|
||||
return {
|
||||
distribution: core.getInput('distribution') || 'goreleaser',
|
||||
version: core.getInput('version') || '~> v2',
|
||||
versionFile: core.getInput('version-file'),
|
||||
args: core.getInput('args'),
|
||||
workdir: core.getInput('workdir') || '.',
|
||||
installOnly: core.getBooleanInput('install-only')
|
||||
|
||||
+4
-2
@@ -4,14 +4,16 @@ import yargs from 'yargs';
|
||||
import type {Arguments} from 'yargs';
|
||||
import * as context from './context';
|
||||
import * as goreleaser from './goreleaser';
|
||||
import {getRequestedVersion} from './version';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import {Inputs} from './context';
|
||||
|
||||
// Resolves the GoReleaser version to install.
|
||||
//
|
||||
// When `version-file` is set, it is read from disk and parsed; the resolved
|
||||
// value takes precedence over the `version` input. Otherwise, `version` is
|
||||
// returned as-is (it always has a default — see context.getInputs).
|
||||
export function getRequestedVersion(inputs: Inputs): string {
|
||||
if (!inputs.versionFile) {
|
||||
return inputs.version;
|
||||
}
|
||||
|
||||
const filePath = path.isAbsolute(inputs.versionFile)
|
||||
? inputs.versionFile
|
||||
: path.join(inputs.workdir || '.', inputs.versionFile);
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
throw new Error(`version-file not found: ${filePath}`);
|
||||
}
|
||||
|
||||
const basename = path.basename(filePath);
|
||||
const content = fs.readFileSync(filePath, 'utf-8');
|
||||
|
||||
switch (basename) {
|
||||
case '.tool-versions':
|
||||
return parseToolVersions(content, filePath);
|
||||
default:
|
||||
throw new Error(`Unsupported version-file: ${filePath} (only .tool-versions is supported)`);
|
||||
}
|
||||
}
|
||||
|
||||
// Parses a single `goreleaser <version>` entry out of a `.tool-versions` file
|
||||
// (asdf/mise format). Full-line `#` comments and inline `# ...` suffixes are
|
||||
// stripped. When a tool lists multiple fallback versions only the first is
|
||||
// used. Bare semvers are returned with a leading `v`; constraint expressions
|
||||
// (`~> v2`, `latest`, ...) are returned as-is.
|
||||
function parseToolVersions(content: string, filePath: string): string {
|
||||
for (const rawLine of content.split('\n')) {
|
||||
const line = rawLine.replace(/#.*$/, '').trim();
|
||||
if (!line) {
|
||||
continue;
|
||||
}
|
||||
const tokens = line.split(/\s+/);
|
||||
if (tokens[0] !== 'goreleaser') {
|
||||
continue;
|
||||
}
|
||||
const version = tokens[1];
|
||||
if (!version) {
|
||||
throw new Error(`No version specified for goreleaser in ${filePath}`);
|
||||
}
|
||||
return /^\d/.test(version) ? `v${version}` : version;
|
||||
}
|
||||
throw new Error(`No goreleaser entry found in ${filePath}`);
|
||||
}
|
||||
Reference in New Issue
Block a user