From de804a56b7a693a998dfc076f891e267618f1323 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 21 Oct 2020 21:07:52 +0200 Subject: [PATCH] Throw error message instead of exit code Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 58 +++++++++++++++++++++++++++++++++++++++ __tests__/context.test.ts | 2 +- dist/index.js | 14 ++++++---- src/exec.ts | 2 +- src/main.ts | 14 ++++++---- 5 files changed, 76 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7204adc..0ac8010 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -197,6 +197,64 @@ jobs: if: always() uses: crazy-max/ghaction-dump-context@v1 + error: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2.3.3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Build + continue-on-error: true + uses: ./ + with: + context: ./test + file: ./test/Dockerfile + platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x + push: true + tags: localhost:5000/name/app:latest + - + name: Dump context + if: always() + uses: crazy-max/ghaction-dump-context@v1 + + docker-driver: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + push: + - true + - false + services: + registry: + image: registry:2 + ports: + - 5000:5000 + steps: + - + name: Checkout + uses: actions/checkout@v2.3.3 + - + name: Build + continue-on-error: ${{ matrix.push }} + uses: ./ + with: + context: ./test + file: ./test/Dockerfile + push: ${{ matrix.push }} + tags: localhost:5000/name/app:latest + - + name: Dump context + if: always() + uses: crazy-max/ghaction-dump-context@v1 + multi: runs-on: ubuntu-latest strategy: diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 6cc1bd6..4c87e1b 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -1,7 +1,7 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as context from '../src/context'; import * as buildx from '../src/buildx'; +import * as context from '../src/context'; jest.spyOn(context, 'defaultContext').mockImplementation((): string => { return 'https://github.com/docker/build-push-action.git#test-jest'; diff --git a/dist/index.js b/dist/index.js index 30b0c18..aec73e3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2377,19 +2377,17 @@ const fs = __importStar(__webpack_require__(747)); const os = __importStar(__webpack_require__(87)); const buildx = __importStar(__webpack_require__(295)); const context = __importStar(__webpack_require__(842)); +const exec = __importStar(__webpack_require__(757)); const stateHelper = __importStar(__webpack_require__(647)); const core = __importStar(__webpack_require__(186)); -const exec = __importStar(__webpack_require__(514)); function run() { return __awaiter(this, void 0, void 0, function* () { try { if (os.platform() !== 'linux') { - core.setFailed('Only supported on linux platform'); - return; + throw new Error(`Only supported on linux platform`); } if (!(yield buildx.isAvailable())) { - core.setFailed(`Buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`); - return; + throw new Error(`Buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`); } stateHelper.setTmpDir(context.tmpDir()); const buildxVersion = yield buildx.getVersion(); @@ -2398,7 +2396,11 @@ function run() { let inputs = yield context.getInputs(defContext); core.info(`🏃 Starting build...`); const args = yield context.getArgs(inputs, defContext, buildxVersion); - yield exec.exec('docker', args); + yield exec.exec('docker', args).then(res => { + if (res.stderr != '' && !res.success) { + throw new Error(`buildx call failed with: ${res.stderr.match(/(.*)\s*$/)[0]}`); + } + }); const imageID = yield buildx.getImageID(); if (imageID) { core.info('🛒 Extracting digest...'); diff --git a/src/exec.ts b/src/exec.ts index 3d0c4ce..00257e1 100644 --- a/src/exec.ts +++ b/src/exec.ts @@ -7,7 +7,7 @@ export interface ExecResult { stderr: string; } -export const exec = async (command: string, args: string[] = [], silent: boolean): Promise => { +export const exec = async (command: string, args: string[] = [], silent?: boolean): Promise => { let stdout: string = ''; let stderr: string = ''; diff --git a/src/main.ts b/src/main.ts index 948aec2..4a0fae7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,20 +2,18 @@ import * as fs from 'fs'; import * as os from 'os'; import * as buildx from './buildx'; import * as context from './context'; +import * as exec from './exec'; import * as stateHelper from './state-helper'; import * as core from '@actions/core'; -import * as exec from '@actions/exec'; async function run(): Promise { try { if (os.platform() !== 'linux') { - core.setFailed('Only supported on linux platform'); - return; + throw new Error(`Only supported on linux platform`); } if (!(await buildx.isAvailable())) { - core.setFailed(`Buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`); - return; + throw new Error(`Buildx is required. See https://github.com/docker/setup-buildx-action to set up buildx.`); } stateHelper.setTmpDir(context.tmpDir()); @@ -27,7 +25,11 @@ async function run(): Promise { core.info(`🏃 Starting build...`); const args: string[] = await context.getArgs(inputs, defContext, buildxVersion); - await exec.exec('docker', args); + await exec.exec('docker', args).then(res => { + if (res.stderr != '' && !res.success) { + throw new Error(`buildx call failed with: ${res.stderr.match(/(.*)\s*$/)![0]}`); + } + }); const imageID = await buildx.getImageID(); if (imageID) {