From 1695055e1dbd129b189c2dd9b810fed4cf914180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Thu, 7 Apr 2022 14:32:45 +0200 Subject: [PATCH] Add ability to run Docker workflow without pushing --- .github/workflows/docker-build-and-push.yml | 13 ++++++++----- package.json | 2 +- src/lib/child-process-promisified.ts | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker-build-and-push.yml b/.github/workflows/docker-build-and-push.yml index 4a308fff..1407eeca 100644 --- a/.github/workflows/docker-build-and-push.yml +++ b/.github/workflows/docker-build-and-push.yml @@ -2,13 +2,15 @@ name: docker-build-and-push on: workflow_dispatch: - pull_request_target: - types: - - labeled + inputs: + push_to_docker_hub: + description: Push to Docker Hub + type: boolean + required: true + default: false jobs: docker: - if: contains(github.event.pull_request.labels.*.name, 'docker-push') || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest steps: - name: Checkout @@ -30,7 +32,8 @@ jobs: tags: sqren/backport:dev - name: Test image before push run: docker run --rm -v $(pwd):/app:ro -v ~/.backport:/root/.backport sqren/backport:dev -v - - name: Build and push + - name: Push to Docker Hub + if: github.event.inputs.push_to_docker_hub == 'true' uses: docker/build-push-action@v2 with: context: ./docker diff --git a/package.json b/package.json index de2d4144..a0f3f32a 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "postinstall": "test -f ./dist/scripts/runPostinstall.js && node ./dist/scripts/runPostinstall.js || echo 'Dist folder missing'", "version": "echo \"Bumping version\" && yarn extractPackageVersion && git add src/utils/packageVersion.ts && yarn tsc", "prepare": "husky install", - "prepublishOnly": "yarn lint && yarn tsc", + "prepublishOnly": "rm -rf ./dist/ && yarn lint && yarn tsc", "extractPackageVersion": "node -p \"'export const PACKAGE_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" | prettier --parser typescript > src/utils/packageVersion.ts", "lint-and-test": "yarn tsc && yarn lint && yarn test-all", "lint": "echo \"Running lint\" && eslint './**/*.{ts,js}'", diff --git a/src/lib/child-process-promisified.ts b/src/lib/child-process-promisified.ts index 0ba0cf73..712b7fd7 100644 --- a/src/lib/child-process-promisified.ts +++ b/src/lib/child-process-promisified.ts @@ -25,6 +25,9 @@ export async function spawnPromise( stderr: string; stdout: string; }> { + const fullCmd = `${cmd} ${cmdArgs.join(' ')}`; + logger.info(`Running command: "${fullCmd}"`); + return new Promise(function (resolve, reject) { const subprocess = childProcess.spawn(cmd, cmdArgs, { cwd }); let stderr = ''; @@ -39,9 +42,6 @@ export async function spawnPromise( }); subprocess.on('close', (code) => { - const fullCmd = `${cmd} ${cmdArgs.join(' ')}`; - logger.info(`Running command: "${fullCmd}"`); - if (code === 0 || code === null) { resolve({ cmdArgs, code, stderr, stdout }); } else {