Skip to content

Commit

Permalink
Refactor logic for determining deployment type
Browse files Browse the repository at this point in the history
  • Loading branch information
dannysongg committed Sep 28, 2023
1 parent 0f57d77 commit 403feab
Showing 1 changed file with 35 additions and 34 deletions.
69 changes: 35 additions & 34 deletions src/DeploymentProvider/Providers/WebAppDeploymentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down

0 comments on commit 403feab

Please sign in to comment.