From d34b6ed33be87ccc3fffd51e62424e54664b9856 Mon Sep 17 00:00:00 2001 From: AkhileshNS Date: Thu, 3 Jun 2021 21:35:16 +0530 Subject: [PATCH] Checking for builds being skipped and setting output --- action.yml | 2 +- src/index.ts | 5 +++++ src/steps/deploy.ts | 10 ++++++++-- src/util.ts | 6 +++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 4c14bba..418a22f 100644 --- a/action.yml +++ b/action.yml @@ -18,7 +18,7 @@ inputs: required: false branch: description: "The branch that you would like to deploy to Heroku" - default: "HEAD" + default: "main" required: false dontuseforce: description: "Set this to true if you don't want to use --force when switching branches" diff --git a/src/index.ts b/src/index.ts index 70170ca..eb62957 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,6 +14,11 @@ import * as steps from './steps'; steps.addConfigVars(heroku) && steps.deploy(heroku) && (await steps.performHealthCheck(heroku)) + + core.setOutput( + "status", + "Successfully deployed heroku app from branch " + heroku.branch + ); } catch (error) { core.setFailed(error); } diff --git a/src/steps/deploy.ts b/src/steps/deploy.ts index e09e886..a04d471 100644 --- a/src/steps/deploy.ts +++ b/src/steps/deploy.ts @@ -2,7 +2,7 @@ import * as core from '@actions/core'; import { execSync } from 'child_process'; import { IHeroku } from '../types'; -import { ansi_colors } from '../util'; +import { ansi_colors, error_outputs } from '../util'; export const deployDocker = (heroku: IHeroku) => { if (heroku.usedocker) { @@ -39,7 +39,13 @@ export const deployGit = (heroku: IHeroku, shouldThrowError = false) => { ? `\`git subtree split --prefix=${heroku.appdir} ${heroku.branch}\`` : heroku.branch try { - execSync(`git push ${force} heroku ${finalBranch}:refs/head/main`, { maxBuffer: 104857600 }); + const output = execSync(`git push ${force} heroku ${finalBranch}:refs/head/main`, { maxBuffer: 104857600 }).toString(); + if (output.toLowerCase().includes(error_outputs.SKIPPED_WRONG_BRANCH)) { + throw new Error(` + Unable to deploy code because the deployed branch is not 'main' or 'master' + (Heroku only allows this branch to be deployed) + `); + } } catch (err) { if (shouldThrowError) { throw err; diff --git a/src/util.ts b/src/util.ts index ff1de2c..b23ee9f 100644 --- a/src/util.ts +++ b/src/util.ts @@ -4,4 +4,8 @@ export const ansi_colors = { magenta: '\u001b[35m', blue: '\u001b[94m', red: '\u001b[91m' -}; \ No newline at end of file +}; + +export const error_outputs = { + SKIPPED_WRONG_BRANCH: "Pushed to branch other than [main, master], skipping build".toLowerCase() +} \ No newline at end of file