goreleaser-action/src/main.ts

51 lines
1.5 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 version = core.getInput('version') || 'latest';
const isInstallOnly = /^true$/i.test(core.getInput('install-only'));
const workdir = core.getInput('workdir') || '.';
2019-09-20 20:23:45 +00:00
const goreleaser = await installer.getGoReleaser(version);
core.info(`✅ GoReleaser installed successfully`);
if (isInstallOnly) {
const goreleaserDir = dirname(goreleaser);
core.addPath(goreleaserDir);
core.debug(`Added ${goreleaserDir} to PATH`);
return;
}
const args = core.getInput('args', {required: true});
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
}
core.info('🏃 Running GoReleaser...');
await exec.exec(`${goreleaser} ${args}${snapshot}`);
2019-09-20 20:23:45 +00:00
} catch (error) {
core.setFailed(error.message);
}
}
run();