mirror of
https://github.com/goreleaser/goreleaser-action.git
synced 2026-05-19 08:51:54 +00:00
feat: add version-file input
You can now use .tool-versions file to specify GoReleaser version to download
This commit is contained in:
parent
6c92f1d350
commit
e0b67d079f
6 changed files with 96 additions and 22 deletions
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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
41
src/version.ts
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue