Skip to content

Commit

Permalink
Checking for builds being skipped and setting output
Browse files Browse the repository at this point in the history
  • Loading branch information
AkhileshNS committed Jun 3, 2021
1 parent 1c98a6d commit d34b6ed
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 8 additions & 2 deletions src/steps/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ export const ansi_colors = {
magenta: '\u001b[35m',
blue: '\u001b[94m',
red: '\u001b[91m'
};
};

export const error_outputs = {
SKIPPED_WRONG_BRANCH: "Pushed to branch other than [main, master], skipping build".toLowerCase()
}

0 comments on commit d34b6ed

Please # to comment.