From 403feab604865b6798f958b1fbe659ecd508af02 Mon Sep 17 00:00:00 2001 From: Danny Song Date: Thu, 28 Sep 2023 12:56:20 -0700 Subject: [PATCH] Refactor logic for determining deployment type --- .../Providers/WebAppDeploymentProvider.ts | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/DeploymentProvider/Providers/WebAppDeploymentProvider.ts b/src/DeploymentProvider/Providers/WebAppDeploymentProvider.ts index 66444edc6..ca9939233 100644 --- a/src/DeploymentProvider/Providers/WebAppDeploymentProvider.ts +++ b/src/DeploymentProvider/Providers/WebAppDeploymentProvider.ts @@ -10,48 +10,49 @@ import { addAnnotation } from 'azure-actions-appservice-rest/Utilities/Annotatio export class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider { public async DeployWebAppStep() { - var deploymentType; let appPackage: Package = this.actionParams.package; let webPackage = appPackage.getPath(); + const validTypes = ["war", "jar", "ear", "zip", "static"]; + // kudu warm up await this.kuduServiceUtility.warmpUp(); - - let packageType = appPackage.getPackageType(); - - switch(packageType){ - case PackageType.war: - core.debug("Initiated deployment via kudu service for webapp war package : "+ webPackage); - deploymentType = "war"; - break; - case PackageType.jar: - core.debug("Initiated deployment via kudu service for webapp jar package : "+ webPackage); - deploymentType = "jar"; - break; - - case PackageType.folder: - let tempPackagePath = utility.generateTemporaryFolderOrZipPath(`${process.env.RUNNER_TEMP}`, false); - webPackage = await zipUtility.archiveFolder(webPackage, "", tempPackagePath) as string; - core.debug("Compressed folder into zip " + webPackage); - core.debug("Initiated deployment via kudu service for webapp package : "+ webPackage); - deploymentType = "zip"; - break; - - case PackageType.zip: - core.debug("Initiated deployment via kudu service for webapp zip package : "+ webPackage); - deploymentType = "zip"; - break; - - default: - if (!this.actionParams.type) { - throw new Error('Invalid App Service package or folder path provided: ' + webPackage); - } - break; + // If provided, type paramater takes precidence over file package type + if (this.actionParams.type != null && validTypes.includes(this.actionParams.type.toLowerCase())) { + core.debug("Initiated deployment via kudu service for webapp" + this.actionParams.type + "package : "+ webPackage); } - if (!this.actionParams.type){ - this.actionParams.type = deploymentType; + else { + // Retains the old behavior of determining the package type from the file extension if valid type is not defined + let packageType = appPackage.getPackageType(); + switch(packageType){ + case PackageType.war: + core.debug("Initiated deployment via kudu service for webapp war package : "+ webPackage); + this.actionParams.type = "war"; + break; + + case PackageType.jar: + core.debug("Initiated deployment via kudu service for webapp jar package : "+ webPackage); + this.actionParams.type = "jar"; + break; + + case PackageType.folder: + let tempPackagePath = utility.generateTemporaryFolderOrZipPath(`${process.env.RUNNER_TEMP}`, false); + webPackage = await zipUtility.archiveFolder(webPackage, "", tempPackagePath) as string; + core.debug("Compressed folder into zip " + webPackage); + core.debug("Initiated deployment via kudu service for webapp package : "+ webPackage); + this.actionParams.type = "zip"; + break; + + case PackageType.zip: + core.debug("Initiated deployment via kudu service for webapp zip package : "+ webPackage); + this.actionParams.type = "zip"; + break; + + default: + throw new Error('Invalid App Service package: ' + webPackage + ' or type provided: ' + this.actionParams.type); + } } this.deploymentID = await this.kuduServiceUtility.deployUsingOneDeploy(webPackage, { slotName: this.actionParams.slotName, commitMessage:this.actionParams.commitMessage },