From b0e63297881e0898787dac1b8dcbbfaba9f3d017 Mon Sep 17 00:00:00 2001 From: mvlassis Date: Wed, 28 Aug 2024 14:12:15 +0300 Subject: [PATCH] Update if-else blocks to be more legible --- dist/channel/index.js | 54 ++++++++------------------------- dist/check-libraries/index.js | 54 ++++++++------------------------- dist/promote-charm/index.js | 54 ++++++++------------------------- dist/release-charm/index.js | 54 ++++++++------------------------- dist/release-libraries/index.js | 54 ++++++++------------------------- dist/upload-bundle/index.js | 54 ++++++++------------------------- dist/upload-charm/index.js | 54 ++++++++------------------------- src/services/bundle/bundle.ts | 34 +++++++++------------ 8 files changed, 98 insertions(+), 314 deletions(-) diff --git a/dist/channel/index.js b/dist/channel/index.js index ab64993..045adff 100644 --- a/dist/channel/index.js +++ b/dist/channel/index.js @@ -42604,29 +42604,6 @@ __exportStar(__nccwpck_require__(6366), exports); "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) { @@ -42638,31 +42615,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Bundle = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const exec = __importStar(__nccwpck_require__(1514)); +const core_1 = __nccwpck_require__(2186); +const exec_1 = __nccwpck_require__(1514); class Bundle { publish(path, channel) { return __awaiter(this, void 0, void 0, function* () { - core.exportVariable('CHARMCRAFT_AUTH', core.getInput('credentials')); + (0, core_1.exportVariable)('CHARMCRAFT_AUTH', (0, core_1.getInput)('credentials')); process.chdir(path); - const result = yield exec.getExecOutput('charmcraft', ['pack']); - if (result.exitCode === 0) { - const lastLine = result.stderr.trim().split('\n').pop(); - if (lastLine) { - const bundleName = lastLine.split(' ')[1]; - yield exec.exec('charmcraft', [ - 'upload', - bundleName, - '--release', - channel, - ]); - } - else { - throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); - } + const result = yield (0, exec_1.getExecOutput)('charmcraft', ['pack']); + if (result.exitCode !== 0) { + throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + } + const lastLine = result.stderr.trim().split('\n').pop(); + if (lastLine) { + const bundleName = lastLine.split(' ')[1]; + yield (0, exec_1.exec)('charmcraft', ['upload', bundleName, '--release', channel]); } else { - throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); } }); } diff --git a/dist/check-libraries/index.js b/dist/check-libraries/index.js index 761901c..634ae96 100644 --- a/dist/check-libraries/index.js +++ b/dist/check-libraries/index.js @@ -42799,29 +42799,6 @@ __exportStar(__nccwpck_require__(6366), exports); "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) { @@ -42833,31 +42810,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Bundle = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const exec = __importStar(__nccwpck_require__(1514)); +const core_1 = __nccwpck_require__(2186); +const exec_1 = __nccwpck_require__(1514); class Bundle { publish(path, channel) { return __awaiter(this, void 0, void 0, function* () { - core.exportVariable('CHARMCRAFT_AUTH', core.getInput('credentials')); + (0, core_1.exportVariable)('CHARMCRAFT_AUTH', (0, core_1.getInput)('credentials')); process.chdir(path); - const result = yield exec.getExecOutput('charmcraft', ['pack']); - if (result.exitCode === 0) { - const lastLine = result.stderr.trim().split('\n').pop(); - if (lastLine) { - const bundleName = lastLine.split(' ')[1]; - yield exec.exec('charmcraft', [ - 'upload', - bundleName, - '--release', - channel, - ]); - } - else { - throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); - } + const result = yield (0, exec_1.getExecOutput)('charmcraft', ['pack']); + if (result.exitCode !== 0) { + throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + } + const lastLine = result.stderr.trim().split('\n').pop(); + if (lastLine) { + const bundleName = lastLine.split(' ')[1]; + yield (0, exec_1.exec)('charmcraft', ['upload', bundleName, '--release', channel]); } else { - throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); } }); } diff --git a/dist/promote-charm/index.js b/dist/promote-charm/index.js index 99ba303..a2bea3f 100644 --- a/dist/promote-charm/index.js +++ b/dist/promote-charm/index.js @@ -42683,29 +42683,6 @@ __exportStar(__nccwpck_require__(6366), exports); "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) { @@ -42717,31 +42694,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Bundle = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const exec = __importStar(__nccwpck_require__(1514)); +const core_1 = __nccwpck_require__(2186); +const exec_1 = __nccwpck_require__(1514); class Bundle { publish(path, channel) { return __awaiter(this, void 0, void 0, function* () { - core.exportVariable('CHARMCRAFT_AUTH', core.getInput('credentials')); + (0, core_1.exportVariable)('CHARMCRAFT_AUTH', (0, core_1.getInput)('credentials')); process.chdir(path); - const result = yield exec.getExecOutput('charmcraft', ['pack']); - if (result.exitCode === 0) { - const lastLine = result.stderr.trim().split('\n').pop(); - if (lastLine) { - const bundleName = lastLine.split(' ')[1]; - yield exec.exec('charmcraft', [ - 'upload', - bundleName, - '--release', - channel, - ]); - } - else { - throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); - } + const result = yield (0, exec_1.getExecOutput)('charmcraft', ['pack']); + if (result.exitCode !== 0) { + throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + } + const lastLine = result.stderr.trim().split('\n').pop(); + if (lastLine) { + const bundleName = lastLine.split(' ')[1]; + yield (0, exec_1.exec)('charmcraft', ['upload', bundleName, '--release', channel]); } else { - throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); } }); } diff --git a/dist/release-charm/index.js b/dist/release-charm/index.js index 21b324c..841b3b2 100644 --- a/dist/release-charm/index.js +++ b/dist/release-charm/index.js @@ -42695,29 +42695,6 @@ __exportStar(__nccwpck_require__(6366), exports); "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) { @@ -42729,31 +42706,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Bundle = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const exec = __importStar(__nccwpck_require__(1514)); +const core_1 = __nccwpck_require__(2186); +const exec_1 = __nccwpck_require__(1514); class Bundle { publish(path, channel) { return __awaiter(this, void 0, void 0, function* () { - core.exportVariable('CHARMCRAFT_AUTH', core.getInput('credentials')); + (0, core_1.exportVariable)('CHARMCRAFT_AUTH', (0, core_1.getInput)('credentials')); process.chdir(path); - const result = yield exec.getExecOutput('charmcraft', ['pack']); - if (result.exitCode === 0) { - const lastLine = result.stderr.trim().split('\n').pop(); - if (lastLine) { - const bundleName = lastLine.split(' ')[1]; - yield exec.exec('charmcraft', [ - 'upload', - bundleName, - '--release', - channel, - ]); - } - else { - throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); - } + const result = yield (0, exec_1.getExecOutput)('charmcraft', ['pack']); + if (result.exitCode !== 0) { + throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + } + const lastLine = result.stderr.trim().split('\n').pop(); + if (lastLine) { + const bundleName = lastLine.split(' ')[1]; + yield (0, exec_1.exec)('charmcraft', ['upload', bundleName, '--release', channel]); } else { - throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); } }); } diff --git a/dist/release-libraries/index.js b/dist/release-libraries/index.js index 01bcd36..845d68a 100644 --- a/dist/release-libraries/index.js +++ b/dist/release-libraries/index.js @@ -42826,29 +42826,6 @@ __exportStar(__nccwpck_require__(6366), exports); "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) { @@ -42860,31 +42837,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Bundle = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const exec = __importStar(__nccwpck_require__(1514)); +const core_1 = __nccwpck_require__(2186); +const exec_1 = __nccwpck_require__(1514); class Bundle { publish(path, channel) { return __awaiter(this, void 0, void 0, function* () { - core.exportVariable('CHARMCRAFT_AUTH', core.getInput('credentials')); + (0, core_1.exportVariable)('CHARMCRAFT_AUTH', (0, core_1.getInput)('credentials')); process.chdir(path); - const result = yield exec.getExecOutput('charmcraft', ['pack']); - if (result.exitCode === 0) { - const lastLine = result.stderr.trim().split('\n').pop(); - if (lastLine) { - const bundleName = lastLine.split(' ')[1]; - yield exec.exec('charmcraft', [ - 'upload', - bundleName, - '--release', - channel, - ]); - } - else { - throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); - } + const result = yield (0, exec_1.getExecOutput)('charmcraft', ['pack']); + if (result.exitCode !== 0) { + throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + } + const lastLine = result.stderr.trim().split('\n').pop(); + if (lastLine) { + const bundleName = lastLine.split(' ')[1]; + yield (0, exec_1.exec)('charmcraft', ['upload', bundleName, '--release', channel]); } else { - throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); } }); } diff --git a/dist/upload-bundle/index.js b/dist/upload-bundle/index.js index 13f85ca..8ca749f 100644 --- a/dist/upload-bundle/index.js +++ b/dist/upload-bundle/index.js @@ -42674,29 +42674,6 @@ __exportStar(__nccwpck_require__(6366), exports); "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) { @@ -42708,31 +42685,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Bundle = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const exec = __importStar(__nccwpck_require__(1514)); +const core_1 = __nccwpck_require__(2186); +const exec_1 = __nccwpck_require__(1514); class Bundle { publish(path, channel) { return __awaiter(this, void 0, void 0, function* () { - core.exportVariable('CHARMCRAFT_AUTH', core.getInput('credentials')); + (0, core_1.exportVariable)('CHARMCRAFT_AUTH', (0, core_1.getInput)('credentials')); process.chdir(path); - const result = yield exec.getExecOutput('charmcraft', ['pack']); - if (result.exitCode === 0) { - const lastLine = result.stderr.trim().split('\n').pop(); - if (lastLine) { - const bundleName = lastLine.split(' ')[1]; - yield exec.exec('charmcraft', [ - 'upload', - bundleName, - '--release', - channel, - ]); - } - else { - throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); - } + const result = yield (0, exec_1.getExecOutput)('charmcraft', ['pack']); + if (result.exitCode !== 0) { + throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + } + const lastLine = result.stderr.trim().split('\n').pop(); + if (lastLine) { + const bundleName = lastLine.split(' ')[1]; + yield (0, exec_1.exec)('charmcraft', ['upload', bundleName, '--release', channel]); } else { - throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); } }); } diff --git a/dist/upload-charm/index.js b/dist/upload-charm/index.js index aff46a0..af85af3 100644 --- a/dist/upload-charm/index.js +++ b/dist/upload-charm/index.js @@ -42714,29 +42714,6 @@ __exportStar(__nccwpck_require__(6366), exports); "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) { @@ -42748,31 +42725,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Bundle = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const exec = __importStar(__nccwpck_require__(1514)); +const core_1 = __nccwpck_require__(2186); +const exec_1 = __nccwpck_require__(1514); class Bundle { publish(path, channel) { return __awaiter(this, void 0, void 0, function* () { - core.exportVariable('CHARMCRAFT_AUTH', core.getInput('credentials')); + (0, core_1.exportVariable)('CHARMCRAFT_AUTH', (0, core_1.getInput)('credentials')); process.chdir(path); - const result = yield exec.getExecOutput('charmcraft', ['pack']); - if (result.exitCode === 0) { - const lastLine = result.stderr.trim().split('\n').pop(); - if (lastLine) { - const bundleName = lastLine.split(' ')[1]; - yield exec.exec('charmcraft', [ - 'upload', - bundleName, - '--release', - channel, - ]); - } - else { - throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); - } + const result = yield (0, exec_1.getExecOutput)('charmcraft', ['pack']); + if (result.exitCode !== 0) { + throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + } + const lastLine = result.stderr.trim().split('\n').pop(); + if (lastLine) { + const bundleName = lastLine.split(' ')[1]; + yield (0, exec_1.exec)('charmcraft', ['upload', bundleName, '--release', channel]); } else { - throw new Error(`charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`); + throw new Error('Failed to extract the bundle name from the output of charmcraft pack.'); } }); } diff --git a/src/services/bundle/bundle.ts b/src/services/bundle/bundle.ts index 032520b..a8153e4 100644 --- a/src/services/bundle/bundle.ts +++ b/src/services/bundle/bundle.ts @@ -1,32 +1,26 @@ -import * as core from '@actions/core'; -import * as exec from '@actions/exec'; +import { exportVariable, getInput } from '@actions/core'; +import { exec, getExecOutput } from '@actions/exec'; class Bundle { async publish(path: string, channel: string) { - core.exportVariable('CHARMCRAFT_AUTH', core.getInput('credentials')); + exportVariable('CHARMCRAFT_AUTH', getInput('credentials')); process.chdir(path); - const result = await exec.getExecOutput('charmcraft', ['pack']); - if (result.exitCode === 0) { - const lastLine = result.stderr.trim().split('\n').pop(); - if (lastLine) { - const bundleName = lastLine.split(' ')[1]; - await exec.exec('charmcraft', [ - 'upload', - bundleName, - '--release', - channel, - ]); - } else { - throw new Error( - 'Failed to extract the bundle name from the output of charmcraft pack.', - ); - } - } else { + const result = await getExecOutput('charmcraft', ['pack']); + if (result.exitCode !== 0) { throw new Error( `charmcraft pack ran unsuccessfully with exit code ${result.exitCode}.`, ); } + const lastLine = result.stderr.trim().split('\n').pop(); + if (lastLine) { + const bundleName = lastLine.split(' ')[1]; + await exec('charmcraft', ['upload', bundleName, '--release', channel]); + } else { + throw new Error( + 'Failed to extract the bundle name from the output of charmcraft pack.', + ); + } } }