Skip to content

Commit

Permalink
Fix error to await get/create rg and test
Browse files Browse the repository at this point in the history
  • Loading branch information
snehapar9 committed Sep 18, 2023
1 parent 9c6b50f commit 4379e84
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 55 deletions.
49 changes: 26 additions & 23 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ var azurecontainerapps = /** @class */ (function () {
*/
azurecontainerapps.setupResources = function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
// Get the Container App name if it was provided, or generate it from build variables
this.containerAppName = this.getContainerAppName();
Expand All @@ -200,22 +200,26 @@ var azurecontainerapps = /** @class */ (function () {
return [4 /*yield*/, this.getLocation()];
case 1:
// Get the location to deploy resources to, if provided, or use the default location
_a.location = _d.sent();
_a.location = _e.sent();
// Get the resource group to deploy to if it was provided, or generate it from the Container App name
this.resourceGroup = this.getOrCreateResourceGroup(this.containerAppName, this.location);
// Determine if the Container App currently exists
_b = this;
return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, this.resourceGroup)];
return [4 /*yield*/, this.getOrCreateResourceGroup(this.containerAppName, this.location)];
case 2:
// Get the resource group to deploy to if it was provided, or generate it from the Container App name
_b.resourceGroup = _e.sent();
// Determine if the Container App currently exists
_b.containerAppExists = _d.sent();
if (!!this.containerAppExists) return [3 /*break*/, 4];
_c = this;
return [4 /*yield*/, this.getOrCreateContainerAppEnvironment(this.containerAppName, this.resourceGroup, this.location)];
return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, this.resourceGroup)];
case 3:
_c.containerAppEnvironment = _d.sent();
_d.label = 4;
case 4: return [2 /*return*/];
// Determine if the Container App currently exists
_c.containerAppExists = _e.sent();
if (!!this.containerAppExists) return [3 /*break*/, 5];
_d = this;
return [4 /*yield*/, this.getOrCreateContainerAppEnvironment(this.containerAppName, this.resourceGroup, this.location)];
case 4:
_d.containerAppEnvironment = _e.sent();
_e.label = 5;
case 5: return [2 /*return*/];
}
});
});
Expand Down Expand Up @@ -5152,26 +5156,25 @@ var ContainerAppHelper = /** @class */ (function () {
*/
ContainerAppHelper.prototype.createContainerAppEnvironment = function (name, resourceGroup, location) {
return __awaiter(this, void 0, void 0, function () {
var util, command, _a, _b, err_12;
return __generator(this, function (_c) {
switch (_c.label) {
var util, command, err_12;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
util = new Utility_1.Utility();
core.debug("Attempting to create Container App Environment with name \"" + name + "\" in resource group \"" + resourceGroup + "\"");
_c.label = 1;
_a.label = 1;
case 1:
_c.trys.push([1, 3, , 4]);
command = "containerapp env create -n " + name + " -g " + resourceGroup;
_a.trys.push([1, 3, , 4]);
command = "az containerapp env create -n " + name + " -g " + resourceGroup;
if (!util.isNullOrEmpty(location)) {
command += " -l " + location;
}
_b = (_a = util).executeAndthrowIfError;
return [4 /*yield*/, io.which('az', true)];
return [4 /*yield*/, cpExec("" + command)];
case 2:
_b.apply(_a, [_c.sent(), command, "Unable to create Azure Container App Environment via 'az containerapp env create' command."]);
_a.sent();
return [3 /*break*/, 4];
case 3:
err_12 = _c.sent();
err_12 = _a.sent();
core.error(err_12.message);
throw err_12;
case 4: return [2 /*return*/];
Expand Down
30 changes: 17 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ var azurecontainerapps = /** @class */ (function () {
*/
azurecontainerapps.setupResources = function () {
return __awaiter(this, void 0, void 0, function () {
var _a, _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
var _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
// Get the Container App name if it was provided, or generate it from build variables
this.containerAppName = this.getContainerAppName();
Expand All @@ -193,22 +193,26 @@ var azurecontainerapps = /** @class */ (function () {
return [4 /*yield*/, this.getLocation()];
case 1:
// Get the location to deploy resources to, if provided, or use the default location
_a.location = _d.sent();
_a.location = _e.sent();
// Get the resource group to deploy to if it was provided, or generate it from the Container App name
this.resourceGroup = this.getOrCreateResourceGroup(this.containerAppName, this.location);
// Determine if the Container App currently exists
_b = this;
return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, this.resourceGroup)];
return [4 /*yield*/, this.getOrCreateResourceGroup(this.containerAppName, this.location)];
case 2:
// Get the resource group to deploy to if it was provided, or generate it from the Container App name
_b.resourceGroup = _e.sent();
// Determine if the Container App currently exists
_b.containerAppExists = _d.sent();
if (!!this.containerAppExists) return [3 /*break*/, 4];
_c = this;
return [4 /*yield*/, this.getOrCreateContainerAppEnvironment(this.containerAppName, this.resourceGroup, this.location)];
return [4 /*yield*/, this.appHelper.doesContainerAppExist(this.containerAppName, this.resourceGroup)];
case 3:
_c.containerAppEnvironment = _d.sent();
_d.label = 4;
case 4: return [2 /*return*/];
// Determine if the Container App currently exists
_c.containerAppExists = _e.sent();
if (!!this.containerAppExists) return [3 /*break*/, 5];
_d = this;
return [4 /*yield*/, this.getOrCreateContainerAppEnvironment(this.containerAppName, this.resourceGroup, this.location)];
case 4:
_d.containerAppEnvironment = _e.sent();
_e.label = 5;
case 5: return [2 /*return*/];
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class azurecontainerapps {
this.location = await this.getLocation();

// Get the resource group to deploy to if it was provided, or generate it from the Container App name
this.resourceGroup = this.getOrCreateResourceGroup(this.containerAppName, this.location);
this.resourceGroup = await this.getOrCreateResourceGroup(this.containerAppName, this.location);

// Determine if the Container App currently exists
this.containerAppExists = await this.appHelper.doesContainerAppExist(this.containerAppName, this.resourceGroup);
Expand Down Expand Up @@ -238,7 +238,7 @@ export class azurecontainerapps {
* @param location - The location to deploy resources to.
* @returns The name of the resource group to use for the task.
*/
private static async getOrCreateResourceGroup(containerAppName: string, location: string): string {
private static async getOrCreateResourceGroup(containerAppName: string, location: string): Promise<string> {
// Get the resource group to deploy to if it was provided, or generate it from the Container App name
let resourceGroup: string = core.getInput('resourceGroup', {required: false});
if (util.isNullOrEmpty(resourceGroup)) {
Expand Down
19 changes: 9 additions & 10 deletions src/ContainerAppHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,26 +414,25 @@ var ContainerAppHelper = /** @class */ (function () {
*/
ContainerAppHelper.prototype.createContainerAppEnvironment = function (name, resourceGroup, location) {
return __awaiter(this, void 0, void 0, function () {
var util, command, _a, _b, err_12;
return __generator(this, function (_c) {
switch (_c.label) {
var util, command, err_12;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
util = new Utility_1.Utility();
core.debug("Attempting to create Container App Environment with name \"" + name + "\" in resource group \"" + resourceGroup + "\"");
_c.label = 1;
_a.label = 1;
case 1:
_c.trys.push([1, 3, , 4]);
command = "containerapp env create -n " + name + " -g " + resourceGroup;
_a.trys.push([1, 3, , 4]);
command = "az containerapp env create -n " + name + " -g " + resourceGroup;
if (!util.isNullOrEmpty(location)) {
command += " -l " + location;
}
_b = (_a = util).executeAndthrowIfError;
return [4 /*yield*/, io.which('az', true)];
return [4 /*yield*/, cpExec("" + command)];
case 2:
_b.apply(_a, [_c.sent(), command, "Unable to create Azure Container App Environment via 'az containerapp env create' command."]);
_a.sent();
return [3 /*break*/, 4];
case 3:
err_12 = _c.sent();
err_12 = _a.sent();
core.error(err_12.message);
throw err_12;
case 4: return [2 /*return*/];
Expand Down
9 changes: 2 additions & 7 deletions src/ContainerAppHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,11 @@ export class ContainerAppHelper {
const util = new Utility();
core.debug(`Attempting to create Container App Environment with name "${name}" in resource group "${resourceGroup}"`);
try {
let command = `containerapp env create -n ${name} -g ${resourceGroup}`;
let command = `az containerapp env create -n ${name} -g ${resourceGroup}`;
if (!util.isNullOrEmpty(location)) {
command += ` -l ${location}`;
}

util.executeAndthrowIfError(
await io.which('az', true),
command,
`Unable to create Azure Container App Environment via 'az containerapp env create' command.`
);
await cpExec(`${command}`);
} catch (err) {
core.error(err.message);
throw err;
Expand Down

0 comments on commit 4379e84

Please sign in to comment.