Skip to content

Commit

Permalink
Use built-in getExecOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Jun 8, 2021
1 parent 707dc1f commit dcdff83
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 127 deletions.
97 changes: 24 additions & 73 deletions dist/index.js

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

38 changes: 24 additions & 14 deletions src/buildx.ts
@@ -1,28 +1,38 @@
import * as semver from 'semver';
import * as exec from './exec';
import * as exec from '@actions/exec';

export async function isAvailable(): Promise<Boolean> {
return await exec.exec(`docker`, ['buildx'], true).then(res => {
if (res.stderr != '' && !res.success) {
return false;
}
return res.success;
});
return await exec
.getExecOutput('docker', ['buildx'], {
ignoreReturnCode: true,
silent: true
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
return false;
}
return res.exitCode == 0;
});
}

export async function getVersion(): Promise<string> {
return await exec.exec(`docker`, ['buildx', 'version'], true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
return parseVersion(res.stdout);
});
return await exec
.getExecOutput('docker', ['buildx', 'version'], {
ignoreReturnCode: true,
silent: true
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr);
}
return parseVersion(res.stdout);
});
}

export async function parseVersion(stdout: string): Promise<string> {
const matches = /\sv?([0-9.]+)/.exec(stdout);
if (!matches) {
throw new Error(`Cannot parse Buildx version`);
throw new Error(`Cannot parse buildx version`);
}
return semver.clean(matches[1]);
}
34 changes: 0 additions & 34 deletions src/exec.ts

This file was deleted.

15 changes: 9 additions & 6 deletions src/main.ts
@@ -1,6 +1,5 @@
import * as buildx from './buildx';
import * as context from './context';
import * as mexec from './exec';
import * as core from '@actions/core';
import * as exec from '@actions/exec';

Expand All @@ -24,11 +23,15 @@ async function run(): Promise<void> {
await exec.exec('docker', [...args, '--print']);
core.endGroup();

await mexec.exec('docker', args).then(res => {
if (res.stderr.length > 0 && !res.success) {
throw new Error(`buildx bake failed with: ${res.stderr.match(/(.*)\s*$/)![0]}`);
}
});
await exec
.getExecOutput('docker', args, {
ignoreReturnCode: true
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(`buildx bake failed with: ${res.stderr.match(/(.*)\s*$/)![0].trim()}`);
}
});
} catch (error) {
core.setFailed(error.message);
}
Expand Down

0 comments on commit dcdff83

Please sign in to comment.