From b27d861e6b4bec52a48eb06ba6f0d83e73fd109b Mon Sep 17 00:00:00 2001 From: snehapar9 Date: Tue, 19 Sep 2023 15:38:15 -0700 Subject: [PATCH] Refactor and test --- dist/index.js | 38 +++++++++++++------------------------- src/ContainerAppHelper.js | 16 ++++++++-------- src/ContainerAppHelper.ts | 16 ++++++++-------- src/Utility.js | 22 +++++----------------- src/Utility.ts | 12 +----------- 5 files changed, 35 insertions(+), 69 deletions(-) diff --git a/dist/index.js b/dist/index.js index e22affd2..5e9317d0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5156,7 +5156,7 @@ var ContainerAppHelper = /** @class */ (function () { return [3 /*break*/, 4]; case 3: err_10 = _b.sent(); - core.setFailed(err_10.message); + core.error(err_10.message); throw err_10; case 4: return [2 /*return*/]; } @@ -5185,7 +5185,7 @@ var ContainerAppHelper = /** @class */ (function () { return [2 /*return*/, !stderr ? stdout : null]; case 3: err_11 = _b.sent(); - core.error(err_11.message); + core.warning(err_11.message); return [2 /*return*/, null]; case 4: return [2 /*return*/]; } @@ -5223,7 +5223,7 @@ var ContainerAppHelper = /** @class */ (function () { return [3 /*break*/, 4]; case 3: err_12 = _b.sent(); - core.setFailed(err_12.message); + core.error(err_12.message); throw err_12; case 4: return [2 /*return*/]; } @@ -5250,13 +5250,13 @@ var ContainerAppHelper = /** @class */ (function () { case 2: _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; if (stderr) { - core.error('Failed to disable ingress for Container App, Error: ' + stderr); + core.warning('Failed to disable ingress for Container App, Error: ' + stderr); throw new Error(stderr); } return [3 /*break*/, 4]; case 3: err_13 = _b.sent(); - core.setFailed(err_13.message); + core.error(err_13.message); throw err_13; case 4: return [2 /*return*/]; } @@ -5286,13 +5286,13 @@ var ContainerAppHelper = /** @class */ (function () { case 2: _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; if (stderr) { - core.error('Failed to set the ACR details for Container App, Error: ' + stderr); + core.warning('Failed to set the ACR details for Container App, Error: ' + stderr); throw new Error(stderr); } return [3 /*break*/, 4]; case 3: err_14 = _b.sent(); - core.setFailed(err_14.message); + core.error(err_14.message); throw err_14; case 4: return [2 /*return*/]; } @@ -5329,7 +5329,7 @@ var ContainerAppHelper = /** @class */ (function () { return [3 /*break*/, 4]; case 3: err_15 = _b.sent(); - core.setFailed(err_15.message); + core.error(err_15.message); throw err_15; case 4: return [2 /*return*/]; } @@ -5911,24 +5911,12 @@ var Utility = /** @class */ (function () { */ Utility.prototype.setAzureCliDynamicInstall = function () { return __awaiter(this, void 0, void 0, function () { - var _a, stdout, stderr, error_2; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _b.trys.push([0, 2, , 3]); - return [4 /*yield*/, cpExec("az config set extension.use_dynamic_install=yes_without_prompt")]; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, cpExec("az config set extension.use_dynamic_install=yes_without_prompt")]; case 1: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.error("Unable to set Azure CLI to dynamically install extensions. Error: " + stderr); - throw new Error("Unable to set Azure CLI to dynamically install extensions. Error: " + stderr); - } - return [3 /*break*/, 3]; - case 2: - error_2 = _b.sent(); - core.setFailed("Error: " + error_2.message); - throw error_2; // Re-throw the error - case 3: return [2 /*return*/]; + _a.sent(); + return [2 /*return*/]; } }); }); diff --git a/src/ContainerAppHelper.js b/src/ContainerAppHelper.js index 142233a7..6308a656 100644 --- a/src/ContainerAppHelper.js +++ b/src/ContainerAppHelper.js @@ -382,7 +382,7 @@ var ContainerAppHelper = /** @class */ (function () { return [3 /*break*/, 4]; case 3: err_10 = _b.sent(); - core.setFailed(err_10.message); + core.error(err_10.message); throw err_10; case 4: return [2 /*return*/]; } @@ -411,7 +411,7 @@ var ContainerAppHelper = /** @class */ (function () { return [2 /*return*/, !stderr ? stdout : null]; case 3: err_11 = _b.sent(); - core.error(err_11.message); + core.warning(err_11.message); return [2 /*return*/, null]; case 4: return [2 /*return*/]; } @@ -449,7 +449,7 @@ var ContainerAppHelper = /** @class */ (function () { return [3 /*break*/, 4]; case 3: err_12 = _b.sent(); - core.setFailed(err_12.message); + core.error(err_12.message); throw err_12; case 4: return [2 /*return*/]; } @@ -476,13 +476,13 @@ var ContainerAppHelper = /** @class */ (function () { case 2: _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; if (stderr) { - core.error('Failed to disable ingress for Container App, Error: ' + stderr); + core.warning('Failed to disable ingress for Container App, Error: ' + stderr); throw new Error(stderr); } return [3 /*break*/, 4]; case 3: err_13 = _b.sent(); - core.setFailed(err_13.message); + core.error(err_13.message); throw err_13; case 4: return [2 /*return*/]; } @@ -512,13 +512,13 @@ var ContainerAppHelper = /** @class */ (function () { case 2: _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; if (stderr) { - core.error('Failed to set the ACR details for Container App, Error: ' + stderr); + core.warning('Failed to set the ACR details for Container App, Error: ' + stderr); throw new Error(stderr); } return [3 /*break*/, 4]; case 3: err_14 = _b.sent(); - core.setFailed(err_14.message); + core.error(err_14.message); throw err_14; case 4: return [2 /*return*/]; } @@ -555,7 +555,7 @@ var ContainerAppHelper = /** @class */ (function () { return [3 /*break*/, 4]; case 3: err_15 = _b.sent(); - core.setFailed(err_15.message); + core.error(err_15.message); throw err_15; case 4: return [2 /*return*/]; } diff --git a/src/ContainerAppHelper.ts b/src/ContainerAppHelper.ts index c0f4309b..c76f7395 100644 --- a/src/ContainerAppHelper.ts +++ b/src/ContainerAppHelper.ts @@ -248,7 +248,7 @@ export class ContainerAppHelper { throw new Error(stderr); } } catch (err) { - core.setFailed(err.message); + core.error(err.message); throw err; } } @@ -265,7 +265,7 @@ export class ContainerAppHelper { const {stdout, stderr} = await cpExec(`${command}`); return !stderr ? stdout : null; } catch (err) { - core.error(err.message); + core.warning(err.message); return null; } } @@ -290,7 +290,7 @@ export class ContainerAppHelper { throw new Error(stderr); } } catch (err) { - core.setFailed(err.message); + core.error(err.message); throw err; } } @@ -306,11 +306,11 @@ export class ContainerAppHelper { const command = `az containerapp ingress disable -n ${name} -g ${resourceGroup}`; const {stdout, stderr} = await cpExec(`${command}`); if (stderr) { - core.error('Failed to disable ingress for Container App, Error: ' + stderr); + core.warning('Failed to disable ingress for Container App, Error: ' + stderr); throw new Error(stderr); } } catch (err) { - core.setFailed(err.message); + core.error(err.message); throw err; } } @@ -329,11 +329,11 @@ export class ContainerAppHelper { const command = `az containerapp registry set -n ${name} -g ${resourceGroup} --server ${acrName}.azurecr.io --username ${acrUsername} --password ${acrPassword}`; const {stdout, stderr} = await cpExec(`${command}`); if (stderr) { - core.error('Failed to set the ACR details for Container App, Error: ' + stderr); + core.warning('Failed to set the ACR details for Container App, Error: ' + stderr); throw new Error(stderr); } } catch (err) { - core.setFailed(err.message); + core.error(err.message); throw err; } } @@ -360,7 +360,7 @@ export class ContainerAppHelper { throw new Error(stderr); } } catch (err) { - core.setFailed(err.message); + core.error(err.message); throw err; } } diff --git a/src/Utility.js b/src/Utility.js index 87993b49..95edc17f 100644 --- a/src/Utility.js +++ b/src/Utility.js @@ -94,24 +94,12 @@ var Utility = /** @class */ (function () { */ Utility.prototype.setAzureCliDynamicInstall = function () { return __awaiter(this, void 0, void 0, function () { - var _a, stdout, stderr, error_2; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _b.trys.push([0, 2, , 3]); - return [4 /*yield*/, cpExec("az config set extension.use_dynamic_install=yes_without_prompt")]; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, cpExec("az config set extension.use_dynamic_install=yes_without_prompt")]; case 1: - _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; - if (stderr) { - core.error("Unable to set Azure CLI to dynamically install extensions. Error: " + stderr); - throw new Error("Unable to set Azure CLI to dynamically install extensions. Error: " + stderr); - } - return [3 /*break*/, 3]; - case 2: - error_2 = _b.sent(); - core.setFailed("Error: " + error_2.message); - throw error_2; // Re-throw the error - case 3: return [2 /*return*/]; + _a.sent(); + return [2 /*return*/]; } }); }); diff --git a/src/Utility.ts b/src/Utility.ts index 51f5f107..9f9fa0eb 100644 --- a/src/Utility.ts +++ b/src/Utility.ts @@ -44,17 +44,7 @@ export class Utility { * Azure Container Apps module being dynamically installed while it's still in preview. */ public async setAzureCliDynamicInstall() { - try { - const { stdout, stderr } = await cpExec(`az config set extension.use_dynamic_install=yes_without_prompt`); - if (stderr) { - core.error(`Unable to set Azure CLI to dynamically install extensions. Error: ${stderr}`); - throw new Error(`Unable to set Azure CLI to dynamically install extensions. Error: ${stderr}`); - } - } - catch (error) { - core.setFailed(`Error: ${error.message}`); - throw error; // Re-throw the error - } + await cpExec(`az config set extension.use_dynamic_install=yes_without_prompt`); } /**