Skip to content

Commit 2545bea

Browse files
authored
Releases/v2 recurisive file check (#477)
* checking php files recursively * checking php files recursively * adding a comment * adding logs
1 parent eec1459 commit 2545bea

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

lib/DeploymentProvider/Providers/WebAppDeploymentProvider.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,26 @@ class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider_1.BaseWebApp
121121
}
122122
deleteReleaseZipForLinuxPhpApps(webPackage) {
123123
return __awaiter(this, void 0, void 0, function* () {
124-
const releaseZipPath = path_1.default.join(webPackage, 'release.zip');
125124
// Ignore if the app is not a Linux app or if release.zip does not exist
126-
if (!this.actionParams.isLinux || !fs_1.default.existsSync(releaseZipPath)) {
125+
if (!this.actionParams.isLinux) {
126+
core.info(`It's not a Linux app, skipping deletion of release.zip`);
127+
return;
128+
}
129+
const releaseZipPath = path_1.default.join(webPackage, 'release.zip');
130+
if (!fs_1.default.existsSync(releaseZipPath)) {
131+
core.info(`release.zip does not exist, skipping deletion: ${releaseZipPath}`);
127132
return;
128133
}
129134
let isPhpApp = yield this.checkIfTheAppIsPhpApp(webPackage);
130135
// No need to delete release.zip for non-PHP apps
131136
if (!isPhpApp) {
137+
core.info(`Not a PHP app, skipping deletion of release.zip: ${releaseZipPath}`);
132138
return;
133139
}
134140
// Delete release.zip if it exists
135141
try {
136142
yield fs_1.default.promises.unlink(releaseZipPath);
137-
core.debug(`Deleted release.zip`);
143+
core.info(`Deleted release.zip`);
138144
}
139145
catch (error) {
140146
core.debug(`Error while deleting release.zip for Linux PHP app: ${error}`);
@@ -147,14 +153,22 @@ class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider_1.BaseWebApp
147153
// Check if the webPackage folder contains a composer.json file
148154
const composerFile = 'composer.json';
149155
if (fs_1.default.existsSync(path_1.default.join(webPackage, composerFile))) {
156+
core.info(`Detected PHP app by presence of ${composerFile}`);
150157
return true;
151158
}
152159
// Check if the webPackage folder contains a .php file
153-
const hasPhpFiles = fs_1.default.readdirSync(webPackage).some(file => file.endsWith('.php'));
160+
core.info(`Checking for .php files in the web package directory: ${webPackage}`);
161+
const hasPhpFiles = fs_1.default.readdirSync(webPackage, { withFileTypes: true, recursive: true }).some(file => file.isFile() && file.name.endsWith('.php'));
162+
if (hasPhpFiles) {
163+
core.info(`Detected PHP app by presence of .php files`);
164+
}
165+
else {
166+
core.info(`No .php files found in the web package directory.`);
167+
}
154168
return hasPhpFiles;
155169
}
156170
catch (error) {
157-
core.debug(`Error while checking if the app is PHP: ${error}`);
171+
core.info(`Error while checking if the app is PHP: ${error}`);
158172
}
159173
return false;
160174
});

src/DeploymentProvider/Providers/WebAppDeploymentProvider.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { addAnnotation } from 'azure-actions-appservice-rest/Utilities/Annotatio
99

1010
import fs from 'fs';
1111
import path from 'path';
12+
import { dir } from 'console';
1213

1314
export class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider {
1415

@@ -86,25 +87,32 @@ export class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider {
8687
}
8788

8889
private async deleteReleaseZipForLinuxPhpApps(webPackage: string): Promise<void> {
89-
const releaseZipPath = path.join(webPackage, 'release.zip');
9090

9191
// Ignore if the app is not a Linux app or if release.zip does not exist
92-
if (!this.actionParams.isLinux || !fs.existsSync(releaseZipPath)) {
92+
if (!this.actionParams.isLinux) {
93+
core.info(`It's not a Linux app, skipping deletion of release.zip`);
94+
return;
95+
}
96+
97+
const releaseZipPath = path.join(webPackage, 'release.zip');
98+
99+
if (!fs.existsSync(releaseZipPath)) {
100+
core.info(`release.zip does not exist, skipping deletion: ${releaseZipPath}`);
93101
return;
94102
}
95103

96104
let isPhpApp = await this.checkIfTheAppIsPhpApp(webPackage);
97105

98106
// No need to delete release.zip for non-PHP apps
99107
if (!isPhpApp) {
108+
core.info(`Not a PHP app, skipping deletion of release.zip: ${releaseZipPath}`);
100109
return;
101110
}
102111

103112
// Delete release.zip if it exists
104-
105113
try {
106114
await fs.promises.unlink(releaseZipPath);
107-
core.debug(`Deleted release.zip`);
115+
core.info(`Deleted release.zip`);
108116
} catch (error) {
109117
core.debug(`Error while deleting release.zip for Linux PHP app: ${error}`);
110118
}
@@ -116,17 +124,26 @@ export class WebAppDeploymentProvider extends BaseWebAppDeploymentProvider {
116124
// Check if the webPackage folder contains a composer.json file
117125
const composerFile = 'composer.json';
118126
if (fs.existsSync(path.join(webPackage, composerFile))) {
127+
core.info(`Detected PHP app by presence of ${composerFile}`);
119128
return true;
120129
}
121130

122131
// Check if the webPackage folder contains a .php file
123-
const hasPhpFiles = fs.readdirSync(webPackage).some(file => file.endsWith('.php'));
132+
core.info(`Checking for .php files in the web package directory: ${webPackage}`);
133+
const hasPhpFiles = fs.readdirSync(webPackage, {withFileTypes: true, recursive: true}).some(file => file.isFile() && file.name.endsWith('.php'));
134+
135+
if (hasPhpFiles) {
136+
core.info(`Detected PHP app by presence of .php files`);
137+
} else {
138+
core.info(`No .php files found in the web package directory.`);
139+
}
124140

125141
return hasPhpFiles;
126142
} catch (error) {
127-
core.debug(`Error while checking if the app is PHP: ${error}`);
143+
core.info(`Error while checking if the app is PHP: ${error}`);
128144
}
129145

130146
return false;
131147
}
148+
132149
}

0 commit comments

Comments
 (0)