goreleaser-action/src/main.ts

55 lines
1.5 KiB
TypeScript
Raw Permalink 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';
2019-09-26 12:17:18 +00:00
import * as fs from 'fs';
2019-09-20 20:23:45 +00:00
2019-09-22 05:17:07 +00:00
export async function run(silent?: boolean) {
2019-09-20 20:23:45 +00:00
try {
const version = core.getInput('version') || 'latest';
const args = core.getInput('args');
2019-09-26 12:17:18 +00:00
const key = core.getInput('key');
const workdir = core.getInput('workdir') || '.';
2019-09-20 20:23:45 +00:00
const goreleaser = await installer.getGoReleaser(version);
const commit = await git.getShortCommit();
const tag = await git.getTag();
const isTagDirty = await git.isTagDirty(tag);
if (workdir && workdir !== '.') {
core.info(`📂 Using ${workdir} as working directory...`);
process.chdir(workdir);
}
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
}
2019-09-26 12:17:18 +00:00
if (key) {
core.info('🔑 Importing signing key...');
2019-09-26 12:17:18 +00:00
let path = `${process.env.HOME}/key.asc`;
2019-09-28 18:50:20 +00:00
fs.writeFileSync(path, key, {mode: 0o600});
2019-09-26 12:17:18 +00:00
await exec.exec('gpg', ['--import', path], {
silent: silent
2019-09-28 18:50:20 +00:00
});
2019-09-26 12:17:18 +00:00
}
core.info('🏃 Running GoReleaser...');
2019-09-22 05:17:07 +00:00
await exec.exec(`${goreleaser} ${args}${snapshot}`, undefined, {
silent: silent
});
2019-09-20 20:23:45 +00:00
} catch (error) {
core.setFailed(error.message);
}
}
run();