Skip to content

Commit

Permalink
HD-11: Allow Logging Command Results (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Carlos Taveras authored Mar 24, 2022
1 parent e99ede0 commit 0d5d4bc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 70 deletions.
103 changes: 41 additions & 62 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ 487:
/***/ 910:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand All @@ -28,7 +28,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.issue = exports.issueCommand = void 0;
const os = __importStar(__nccwpck_require__(37));
const utils_1 = __nccwpck_require__(742);
const utils_1 = __nccwpck_require__(759);
/**
* Commands
*
Expand Down Expand Up @@ -100,7 +100,7 @@ function escapeProperty(s) {

/***/ }),

/***/ 389:
/***/ 371:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand Down Expand Up @@ -135,12 +135,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getIDToken = exports.getState = exports.saveState = exports.group = exports.endGroup = exports.startGroup = exports.info = exports.notice = exports.warning = exports.error = exports.debug = exports.isDebug = exports.setFailed = exports.setCommandEcho = exports.setOutput = exports.getBooleanInput = exports.getMultilineInput = exports.getInput = exports.addPath = exports.setSecret = exports.exportVariable = exports.ExitCode = void 0;
const command_1 = __nccwpck_require__(487);
const file_command_1 = __nccwpck_require__(940);
const utils_1 = __nccwpck_require__(742);
const command_1 = __nccwpck_require__(910);
const file_command_1 = __nccwpck_require__(671);
const utils_1 = __nccwpck_require__(759);
const os = __importStar(__nccwpck_require__(37));
const path = __importStar(__nccwpck_require__(17));
const oidc_utils_1 = __nccwpck_require__(637);
const oidc_utils_1 = __nccwpck_require__(512);
/**
* The code to exit an action
*/
Expand Down Expand Up @@ -419,7 +419,7 @@ exports.getIDToken = getIDToken;

/***/ }),

/***/ 940:
/***/ 671:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand Down Expand Up @@ -450,7 +450,7 @@ exports.issueCommand = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
const fs = __importStar(__nccwpck_require__(147));
const os = __importStar(__nccwpck_require__(37));
const utils_1 = __nccwpck_require__(742);
const utils_1 = __nccwpck_require__(759);
function issueCommand(command, message) {
const filePath = process.env[`GITHUB_${command}`];
if (!filePath) {
Expand All @@ -468,7 +468,7 @@ exports.issueCommand = issueCommand;

/***/ }),

/***/ 637:
/***/ 512:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand All @@ -484,9 +484,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.OidcClient = void 0;
const http_client_1 = __nccwpck_require__(278);
const auth_1 = __nccwpck_require__(484);
const core_1 = __nccwpck_require__(389);
const http_client_1 = __nccwpck_require__(150);
const auth_1 = __nccwpck_require__(319);
const core_1 = __nccwpck_require__(371);
class OidcClient {
static createHttpClient(allowRetry = true, maxRetry = 10) {
const requestOptions = {
Expand Down Expand Up @@ -552,7 +552,7 @@ exports.OidcClient = OidcClient;

/***/ }),

/***/ 742:
/***/ 759:
/***/ ((__unused_webpack_module, exports) => {

"use strict";
Expand Down Expand Up @@ -599,7 +599,7 @@ exports.toCommandProperties = toCommandProperties;

/***/ }),

/***/ 484:
/***/ 319:
/***/ ((__unused_webpack_module, exports) => {

"use strict";
Expand Down Expand Up @@ -665,15 +665,15 @@ exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHand

/***/ }),

/***/ 278:
/***/ 150:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
const http = __nccwpck_require__(685);
const https = __nccwpck_require__(687);
const pm = __nccwpck_require__(341);
const pm = __nccwpck_require__(499);
let tunnel;
var HttpCodes;
(function (HttpCodes) {
Expand Down Expand Up @@ -1092,7 +1092,7 @@ class HttpClient {
if (useProxy) {
// If using proxy, need tunnel
if (!tunnel) {
tunnel = __nccwpck_require__(295);
tunnel = __nccwpck_require__(125);
}
const agentOptions = {
maxSockets: maxSockets,
Expand Down Expand Up @@ -1210,7 +1210,7 @@ exports.HttpClient = HttpClient;

/***/ }),

/***/ 341:
/***/ 499:
/***/ ((__unused_webpack_module, exports) => {

"use strict";
Expand Down Expand Up @@ -1275,15 +1275,15 @@ exports.checkBypass = checkBypass;

/***/ }),

/***/ 295:
/***/ 125:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

module.exports = __nccwpck_require__(870);
module.exports = __nccwpck_require__(615);


/***/ }),

/***/ 870:
/***/ 615:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";
Expand Down Expand Up @@ -1555,7 +1555,7 @@ exports.debug = debug; // for test

/***/ }),

/***/ 965:
/***/ 896:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";
Expand All @@ -1573,20 +1573,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core_1 = __nccwpck_require__(389);
const child_process_1 = __nccwpck_require__(81);
const core_1 = __nccwpck_require__(371);
const util_1 = __nccwpck_require__(837);
const scripts_1 = __nccwpck_require__(184);
const login_1 = __importDefault(__nccwpck_require__(612));
const child_process_1 = __nccwpck_require__(81);
const scripts_1 = __nccwpck_require__(878);
const login_1 = __importDefault(__nccwpck_require__(106));
const herokuAction = (0, scripts_1.herokuActionSetup)((0, core_1.getInput)('app_name'));
(0, login_1.default)()
.then(() => __awaiter(void 0, void 0, void 0, function* () {
yield (0, util_1.promisify)(child_process_1.exec)(herokuAction('push'));
(0, core_1.info)('Your Docker image was built and pushed to Heroku Container Registry.');
const { stdout } = yield (0, util_1.promisify)(child_process_1.exec)(herokuAction('push'));
(0, core_1.info)('Your Docker image was built and pushed to Heroku Container Registry. 🏗');
(0, core_1.info)(`stdout: ${stdout}`);
}))
.then(() => __awaiter(void 0, void 0, void 0, function* () {
yield (0, util_1.promisify)(child_process_1.exec)(herokuAction('release'));
(0, core_1.info)('Your Appliction was deployed successfully.');
(0, core_1.info)('Your Appliction was deployed successfully. 🚀');
}))
.catch(error => {
(0, core_1.setFailed)(`Something went wrong building your image. [Error]: ${error.message}`);
Expand All @@ -1595,34 +1596,11 @@ const herokuAction = (0, scripts_1.herokuActionSetup)((0, core_1.getInput)('app_

/***/ }),

/***/ 612:
/***/ 106:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
Expand All @@ -1633,18 +1611,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(389));
const core_1 = __nccwpck_require__(371);
const child_process_1 = __nccwpck_require__(81);
const util_1 = __nccwpck_require__(837);
const scripts_1 = __nccwpck_require__(184);
const scripts_1 = __nccwpck_require__(878);
function herokuLogin() {
return __awaiter(this, void 0, void 0, function* () {
try {
yield (0, util_1.promisify)(child_process_1.exec)((0, scripts_1.authenticationScript)(core.getInput('email'), core.getInput('api_key')));
core.info('Logged in successfully.');
const { stdout } = yield (0, util_1.promisify)(child_process_1.exec)((0, scripts_1.authenticationScript)((0, core_1.getInput)('email'), (0, core_1.getInput)('api_key')));
(0, core_1.info)('Logged in successfully. 🔐');
(0, core_1.info)(`stdout: ${stdout}`);
}
catch (error) {
core.setFailed(`Authentication process failed. Error: ${error.message}`);
(0, core_1.setFailed)(`Authentication process failed. Error: ${error.message}`);
}
});
}
Expand All @@ -1653,14 +1632,14 @@ exports["default"] = herokuLogin;

/***/ }),

/***/ 184:
/***/ 878:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.herokuActionSetup = exports.authenticationScript = void 0;
const core_1 = __nccwpck_require__(389);
const core_1 = __nccwpck_require__(371);
const authenticationScript = (username, password) => `echo ${password} | docker login --username=${username} registry.heroku.com --password-stdin`;
exports.authenticationScript = authenticationScript;
const herokuActionSetup = (appName) => {
Expand Down Expand Up @@ -1811,7 +1790,7 @@ module.exports = require("util");
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var __webpack_exports__ = __nccwpck_require__(965);
/******/ var __webpack_exports__ = __nccwpck_require__(896);
/******/ module.exports = __webpack_exports__;
/******/
/******/ })()
Expand Down
11 changes: 7 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getInput, info, setFailed } from "@actions/core";
import { exec } from "child_process";
import { promisify } from "util";
import { exec } from "child_process";

import { herokuActionSetup } from "./lib/scripts";
import herokuLogin from "./lib/login";
Expand All @@ -9,12 +9,15 @@ const herokuAction = herokuActionSetup(getInput('app_name'));

herokuLogin()
.then(async () => {
await promisify(exec)(herokuAction('push'));
info('Your Docker image was built and pushed to Heroku Container Registry.');
const { stdout } = await promisify(exec)(herokuAction('push'));

info('Your Docker image was built and pushed to Heroku Container Registry. 🏗');
info(`stdout: ${stdout}`);
})
.then(async () => {
await promisify(exec)(herokuAction('release'));
info('Your Appliction was deployed successfully.')

info('Your Appliction was deployed successfully. 🚀');
})
.catch(error => {
setFailed(`Something went wrong building your image. [Error]: ${(error as Error).message}`);
Expand Down
10 changes: 6 additions & 4 deletions lib/login.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import * as core from "@actions/core";
import { getInput, info, setFailed } from "@actions/core";
import { exec } from "child_process";
import { promisify } from "util";

import { authenticationScript } from "./scripts";

export default async function herokuLogin() {
try {
await promisify(exec)(authenticationScript(core.getInput('email'), core.getInput('api_key')));
core.info('Logged in successfully.');
const { stdout } = await promisify(exec)(authenticationScript(getInput('email'), getInput('api_key')));

info('Logged in successfully. 🔐');
info(`stdout: ${stdout}`)
} catch (error) {
core.setFailed(`Authentication process failed. Error: ${(error as Error).message}`);
setFailed(`Authentication process failed. Error: ${(error as Error).message}`);
}
}

0 comments on commit 0d5d4bc

Please sign in to comment.