Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 6 additions & 37 deletions lib/DeploymentProvider/Providers/WebAppDeploymentProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider_1.BaseWebApp
break;
case packageUtility_1.PackageType.folder:
let tempPackagePath = utility.generateTemporaryFolderOrZipPath(`${process.env.RUNNER_TEMP}`, false);
// excluding release.zip while creating zip for deployment if it's a Linux PHP app
yield this.deleteReleaseZipForLinuxPhpApps(webPackage);
// Excluding release.zip while creating zip for deployment if it's a Linux app
yield this.deleteReleaseZipForLinuxApps(webPackage);
webPackage = (yield zipUtility.archiveFolder(webPackage, "", tempPackagePath));
core.debug("Compressed folder into zip " + webPackage);
core.debug("Initiated deployment via kudu service for webapp package : " + webPackage);
Expand Down Expand Up @@ -119,58 +119,27 @@ class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider_1.BaseWebApp
core.setOutput('webapp-url', this.applicationURL);
});
}
deleteReleaseZipForLinuxPhpApps(webPackage) {
deleteReleaseZipForLinuxApps(webPackage) {
return __awaiter(this, void 0, void 0, function* () {
// Ignore if the app is not a Linux app or if release.zip does not exist
// Ignore if the app is not a Linux app
if (!this.actionParams.isLinux) {
core.debug(`It's not a Linux app, skipping deletion of release.zip`);
return;
}
const releaseZipPath = path_1.default.join(webPackage, 'release.zip');
// Check if release.zip exists
if (!fs_1.default.existsSync(releaseZipPath)) {
core.debug(`release.zip does not exist, skipping deletion: ${releaseZipPath}`);
return;
}
let isPhpApp = yield this.checkIfTheAppIsPhpApp(webPackage);
// No need to delete release.zip for non-PHP apps
if (!isPhpApp) {
core.debug(`Not a PHP app, skipping deletion of release.zip: ${releaseZipPath}`);
return;
}
// Delete release.zip if it exists
try {
yield fs_1.default.promises.unlink(releaseZipPath);
core.debug(`Deleted release.zip`);
}
catch (error) {
core.debug(`Error while deleting release.zip for Linux PHP app: ${error}`);
}
});
}
checkIfTheAppIsPhpApp(webPackage) {
return __awaiter(this, void 0, void 0, function* () {
try {
// Check if the webPackage folder contains a composer.json file
const composerFile = 'composer.json';
if (fs_1.default.existsSync(path_1.default.join(webPackage, composerFile))) {
core.debug(`Detected PHP app by presence of ${composerFile}`);
return true;
}
// Check if the webPackage folder contains a .php file
core.debug(`Checking for .php files in the web package directory: ${webPackage}`);
const hasPhpFiles = fs_1.default.readdirSync(webPackage, { withFileTypes: true, recursive: true }).some(file => file.isFile() && file.name.endsWith('.php'));
if (hasPhpFiles) {
core.debug(`Detected PHP app by presence of .php files`);
}
else {
core.debug(`No .php files found in the web package directory.`);
}
return hasPhpFiles;
}
catch (error) {
core.debug(`Error while checking if the app is PHP: ${error}`);
core.debug(`Error while deleting release.zip for Linux app: ${error}`);
}
return false;
});
}
}
Expand Down
48 changes: 6 additions & 42 deletions src/DeploymentProvider/Providers/WebAppDeploymentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider {
case PackageType.folder:
let tempPackagePath = utility.generateTemporaryFolderOrZipPath(`${process.env.RUNNER_TEMP}`, false);

// excluding release.zip while creating zip for deployment if it's a Linux PHP app
await this.deleteReleaseZipForLinuxPhpApps(webPackage);
// Excluding release.zip while creating zip for deployment if it's a Linux app
await this.deleteReleaseZipForLinuxApps(webPackage);

webPackage = await zipUtility.archiveFolder(webPackage, "", tempPackagePath) as string;
core.debug("Compressed folder into zip " + webPackage);
Expand Down Expand Up @@ -85,64 +85,28 @@ export class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider {
core.setOutput('webapp-url', this.applicationURL);
}

private async deleteReleaseZipForLinuxPhpApps(webPackage: string): Promise<void> {
private async deleteReleaseZipForLinuxApps(webPackage: string): Promise<void> {

// Ignore if the app is not a Linux app or if release.zip does not exist
// Ignore if the app is not a Linux app
if (!this.actionParams.isLinux) {
core.debug(`It's not a Linux app, skipping deletion of release.zip`);
return;
}

const releaseZipPath = path.join(webPackage, 'release.zip');

// Check if release.zip exists
if (!fs.existsSync(releaseZipPath)) {
core.debug(`release.zip does not exist, skipping deletion: ${releaseZipPath}`);
return;
}

let isPhpApp = await this.checkIfTheAppIsPhpApp(webPackage);

// No need to delete release.zip for non-PHP apps
if (!isPhpApp) {
core.debug(`Not a PHP app, skipping deletion of release.zip: ${releaseZipPath}`);
return;
}

// Delete release.zip if it exists
try {
await fs.promises.unlink(releaseZipPath);
core.debug(`Deleted release.zip`);
} catch (error) {
core.debug(`Error while deleting release.zip for Linux PHP app: ${error}`);
core.debug(`Error while deleting release.zip for Linux app: ${error}`);
}
}

private async checkIfTheAppIsPhpApp(webPackage: string): Promise<boolean> {

try {
// Check if the webPackage folder contains a composer.json file
const composerFile = 'composer.json';
if (fs.existsSync(path.join(webPackage, composerFile))) {
core.debug(`Detected PHP app by presence of ${composerFile}`);
return true;
}

// Check if the webPackage folder contains a .php file
core.debug(`Checking for .php files in the web package directory: ${webPackage}`);
const hasPhpFiles = fs.readdirSync(webPackage, {withFileTypes: true, recursive: true}).some(file => file.isFile() && file.name.endsWith('.php'));

if (hasPhpFiles) {
core.debug(`Detected PHP app by presence of .php files`);
} else {
core.debug(`No .php files found in the web package directory.`);
}

return hasPhpFiles;
} catch (error) {
core.debug(`Error while checking if the app is PHP: ${error}`);
}

return false;
}

}
Loading