/
main.ts
54 lines (47 loc) · 1.64 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import * as git from './git';
import * as installer from './installer';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import {dirname} from 'path';
async function run(): Promise<void> {
try {
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(version);
core.info(`✅ GoReleaser installed successfully`);
if (isInstallOnly) {
const goreleaserDir = dirname(goreleaser);
core.addPath(goreleaserDir);
core.debug(`Added ${goreleaserDir} to PATH`);
return;
} else if (!args) {
throw new Error('args input required');
}
if (workdir && workdir !== '.') {
core.info(`📂 Using ${workdir} as working directory...`);
process.chdir(workdir);
}
const commit = await git.getShortCommit();
const tag = await git.getTag();
const isTagDirty = await git.isTagDirty(tag);
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}`);
}
}
core.info('🏃 Running GoReleaser...');
process.env.GORELEASER_CURRENT_TAG = tag;
await exec.exec(`${goreleaser} ${args}${snapshot}`);
} catch (error) {
core.setFailed(error.message);
}
}
run();