Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use built-in getExecOutput #292

Merged
merged 1 commit into from Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file modified .github/goreleaser-action.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 16 additions & 74 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 0 additions & 34 deletions src/exec.ts

This file was deleted.

19 changes: 12 additions & 7 deletions src/git.ts
@@ -1,12 +1,17 @@
import * as exec from './exec';
import * as exec from '@actions/exec';

const git = async (args: string[] = []): Promise<string> => {
return await exec.exec(`git`, args, true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
return res.stdout.trim();
});
return await exec
.getExecOutput(`git`, args, {
ignoreReturnCode: true,
silent: true
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr);
}
return res.stdout.trim();
});
};

export async function getTag(): Promise<string> {
Expand Down
5 changes: 2 additions & 3 deletions src/installer.ts
Expand Up @@ -15,7 +15,6 @@ export async function getGoReleaser(distribution: string, version: string): Prom
throw new Error(`Cannot find GoReleaser ${version} release`);
}

core.info(`✅ GoReleaser version found: ${release.tag_name}`);
const filename = getFilename(distribution);
const downloadUrl = util.format(
'https://github.com/goreleaser/%s/releases/download/%s/%s',
Expand All @@ -24,11 +23,11 @@ export async function getGoReleaser(distribution: string, version: string): Prom
filename
);

core.info(`⬇️ Downloading ${downloadUrl}...`);
core.info(`Downloading ${downloadUrl}`);
const downloadPath: string = await tc.downloadTool(downloadUrl);
core.debug(`Downloaded to ${downloadPath}`);

core.info('📦 Extracting GoReleaser...');
core.info('Extracting GoReleaser');
let extPath: string;
if (osPlat == 'win32') {
extPath = await tc.extractZip(downloadPath);
Expand Down
12 changes: 6 additions & 6 deletions src/main.ts
Expand Up @@ -12,19 +12,20 @@ async function run(): Promise<void> {
const workdir = core.getInput('workdir') || '.';
const isInstallOnly = /^true$/i.test(core.getInput('install-only'));
const goreleaser = await installer.getGoReleaser(distribution, version);
core.info(`GoReleaser installed successfully`);
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) {
throw new Error('args input required');
core.setFailed('args input required');
return;
}

if (workdir && workdir !== '.') {
core.info(`📂 Using ${workdir} as working directory...`);
core.info(`Using ${workdir} as working directory`);
process.chdir(workdir);
}

Expand All @@ -35,16 +36,15 @@ async function run(): Promise<void> {
let snapshot = '';
if (args.split(' ').indexOf('release') > -1) {
if (isTagDirty) {
core.info(`⚠️ No tag found for commit ${commit}. Snapshot forced`);
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(`${tag} tag found for commit ${commit}`);
}
}

core.info('🏃 Running GoReleaser...');
if (!('GORELEASER_CURRENT_TAG' in process.env)) {
process.env.GORELEASER_CURRENT_TAG = tag;
}
Expand Down