Skip to content

Commit

Permalink
Merge pull request #25 from crazy-max/throw-error
Browse files Browse the repository at this point in the history
Throw error message instead of exit code
  • Loading branch information
crazy-max committed May 14, 2021
2 parents 1882cef + a2173f5 commit 180a839
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -56,7 +56,27 @@ jobs:
if: always()
uses: crazy-max/ghaction-dump-context@v1

error:
error-msg:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Build
continue-on-error: true
uses: ./
with:
files: |
./test/config.hcl
set: |
*.platform=linux/amd64,linux/ppc64le,linux/s390x
-
name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1

error-check:
runs-on: ubuntu-latest
steps:
-
Expand Down
16 changes: 10 additions & 6 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion src/exec.ts
Expand Up @@ -7,7 +7,7 @@ export interface ExecResult {
stderr: string;
}

export const exec = async (command: string, args: string[] = [], silent: boolean): Promise<ExecResult> => {
export const exec = async (command: string, args: string[] = [], silent?: boolean): Promise<ExecResult> => {
let stdout: string = '';
let stderr: string = '';

Expand Down
16 changes: 10 additions & 6 deletions src/main.ts
@@ -1,5 +1,6 @@
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 @@ -15,18 +16,21 @@ async function run(): Promise<void> {
return;
}

const buildxVersion = await buildx.getVersion();
core.info(`Using buildx ${buildxVersion}`);
const bxVersion = await buildx.getVersion();
core.debug(`buildx version: ${bxVersion}`);

let inputs: context.Inputs = await context.getInputs();
const args: string[] = await context.getArgs(inputs, buildxVersion);
const inputs: context.Inputs = await context.getInputs();
const args: string[] = await context.getArgs(inputs, bxVersion);

core.startGroup(`Bake definition`);
await exec.exec('docker', [...args, '--print']);
core.endGroup();

core.info(`Building...`);
await exec.exec('docker', args);
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]}`);
}
});
} catch (error) {
core.setFailed(error.message);
}
Expand Down

0 comments on commit 180a839

Please sign in to comment.