goreleaser-action/src/main.ts

58 lines
1.7 KiB
TypeScript
Raw Normal View History

import * as git from './git';
2019-09-20 20:23:45 +00:00
import * as installer from './installer';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import {dirname} from 'path';
2019-09-20 20:23:45 +00:00
async function run(): Promise<void> {
2019-09-20 20:23:45 +00:00
try {
const distribution = core.getInput('distribution') || 'goreleaser';
2019-09-20 20:23:45 +00:00
const version = core.getInput('version') || 'latest';
const args = core.getInput('args');
const workdir = core.getInput('workdir') || '.';
const isInstallOnly = /^true$/i.test(core.getInput('install-only'));
const goreleaser = await installer.getGoReleaser(distribution, version);
core.info(`GoReleaser ${version} installed successfully`);
if (isInstallOnly) {
const goreleaserDir = dirname(goreleaser);
core.addPath(goreleaserDir);
core.debug(`Added ${goreleaserDir} to PATH`);
return;
} else if (!args) {
core.setFailed('args input required');
return;
}
2019-09-20 20:23:45 +00:00
if (workdir && workdir !== '.') {
core.info(`Using ${workdir} as working directory`);
process.chdir(workdir);
}
2020-06-24 00:24:58 +00:00
const commit = await git.getShortCommit();
const tag = await git.getTag();
const isTagDirty = await git.isTagDirty(tag);
2019-09-20 21:08:16 +00:00
let snapshot = '';
if (args.split(' ').indexOf('release') > -1) {
if (isTagDirty) {
core.info(`No tag found for commit ${commit}. Snapshot forced`);
if (!args.includes('--snapshot')) {
snapshot = ' --snapshot';
}
} else {
core.info(`${tag} tag found for commit ${commit}`);
2019-09-20 21:11:26 +00:00
}
2019-09-20 21:08:16 +00:00
}
if (!('GORELEASER_CURRENT_TAG' in process.env)) {
process.env.GORELEASER_CURRENT_TAG = tag;
}
await exec.exec(`${goreleaser} ${args}${snapshot}`);
2019-09-20 20:23:45 +00:00
} catch (error) {
core.setFailed(error.message);
}
}
run();