Skip to content

Commit 7e81c05

Browse files
authored
Merge pull request #54 from shivammathur/develop
Add option to disable coverage drivers
2 parents f866c88 + 754ab95 commit 7e81c05

File tree

7 files changed

+98
-14
lines changed

7 files changed

+98
-14
lines changed

README.md

+20-5
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,23 @@ Setup PHP with required extensions, php.ini configuration and composer in [GitHu
4848
- Extensions which cannot be installed gracefully leave an error message in the logs, the action is not interrupted.
4949

5050
## :signal_strength: Coverage support
51-
- Specify `coverage: xdebug` to use `Xdebug`.
52-
- Runs on all [PHP versions supported](#tada-php-support)
51+
52+
### Xdebug
53+
54+
Specify `coverage: xdebug` to use `Xdebug`.
55+
Runs on all [PHP versions supported](#tada-php-support)
5356
```
5457
uses: shivammathur/setup-php@master
5558
with:
5659
php-version: 7.3
5760
coverage: xdebug
5861
```
59-
- Specify `coverage: pcov` to use `PCOV`. `PCOV` is way faster than `Xdebug`
60-
- For `pcov.directory` to be other than `src`, `lib` or, `app`, specify it using the `ini-values-csv` input.
61-
- `PCOV` needs `PHPUnit >= 8.0` and `PHP >= 7.1`, `PHPUnit` needs `PHP >= 7.2`. So use `PHP >= 7.2` with `PCOV`
62+
63+
### PCOV
64+
65+
Specify `coverage: pcov` to use `PCOV`. `PCOV` is way faster than `Xdebug`.
66+
For `pcov.directory` to be other than `src`, `lib` or, `app`, specify it using the `ini-values-csv` input.
67+
`PCOV` needs `PHPUnit >= 8.0` and `PHP >= 7.1`, `PHPUnit` needs `PHP >= 7.2`. So use `PHP >= 7.2` with `PCOV`
6268
```
6369
uses: shivammathur/setup-php@master
6470
with:
@@ -67,6 +73,15 @@ with:
6773
coverage: pcov
6874
```
6975

76+
### Disable coverage
77+
Specify `coverage: none` to disable both `Xdebug` and `PCOV`.
78+
```
79+
uses: shivammathur/setup-php@master
80+
with:
81+
php-version: 7.3
82+
coverage: none
83+
```
84+
7085
## :memo: Usage
7186

7287
Inputs supported by this GitHub Action.

__tests__/features.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ describe('Features tests', () => {
178178
win32 = await features.addCoverage('pcov', '5.6', 'win32');
179179
expect(win32).toContain('PCOV requires PHP 7.1 or newer');
180180

181+
win32 = await features.addCoverage('none', '7.4', 'win32');
182+
expect(win32).toContain('Disable-PhpExtension xdebug');
183+
expect(win32).toContain('Disable-PhpExtension pcov');
184+
181185
win32 = await features.addCoverage('', '7.4', 'win32');
182186
expect(win32).toEqual('');
183187
});
@@ -191,6 +195,12 @@ describe('Features tests', () => {
191195
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
192196
expect(linux).toContain('sudo phpdismod xdebug');
193197

198+
linux = await features.addCoverage('none', '7.4', 'linux');
199+
expect(linux).toContain('sudo phpdismod xdebug');
200+
expect(linux).toContain('sudo phpdismod pcov');
201+
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
202+
expect(linux).toContain('sudo sed -i "/pcov/d" $ini_file');
203+
194204
linux = await features.addCoverage('', '7.4', 'linux');
195205
expect(linux).toEqual('');
196206
});
@@ -205,6 +215,10 @@ describe('Features tests', () => {
205215
darwin = await features.addCoverage('pcov', '7.4', 'darwin');
206216
expect(darwin).toContain('sh ./pcov.sh');
207217

218+
darwin = await features.addCoverage('none', '7.4', 'darwin');
219+
expect(darwin).toContain('sudo sed -i \'\' "/xdebug/d" $ini_file');
220+
expect(darwin).toContain('sudo sed -i \'\' "/pcov/d" $ini_file');
221+
208222
darwin = await features.addCoverage('', '7.4', 'win32');
209223
expect(darwin).toEqual('');
210224
});

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ inputs:
1515
description: '(Optional) Custom values you want to set in php.ini'
1616
required: false
1717
coverage:
18-
description: '(Optional) Driver to calculate code coverage (Accepts: xdebug and pcov)'
18+
description: '(Optional) Driver to calculate code coverage (Accepts: xdebug, pcov and none)'
1919
required: false
2020
runs:
2121
using: 'node12'

lib/features.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ function addINIValuesWindows(ini_values_csv) {
297297
exports.addINIValuesWindows = addINIValuesWindows;
298298
function addCoverage(coverage, version, os_version) {
299299
return __awaiter(this, void 0, void 0, function* () {
300-
let script = '';
301-
script += '\n';
300+
let script = '\n';
302301
coverage = coverage.toLowerCase();
303302
// pcov
304303
switch (coverage) {
@@ -340,7 +339,33 @@ function addCoverage(coverage, version, os_version) {
340339
script += yield addExtension('xdebug', version, os_version, 'Set Coverage Driver');
341340
script += yield utils.log('Xdebug enabled as coverage driver', os_version, 'success', 'Set Coverage Driver');
342341
break;
343-
// unknown coverage driver
342+
case 'none':
343+
switch (os_version) {
344+
case 'linux':
345+
script +=
346+
'if [ -e /etc/php/' +
347+
version +
348+
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
349+
script +=
350+
'if [ -e /etc/php/' +
351+
version +
352+
'/mods-available/pcov.ini ]; then sudo phpdismod pcov; fi\n';
353+
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
354+
script += 'sudo sed -i "/pcov/d" $ini_file\n';
355+
break;
356+
case 'darwin':
357+
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
358+
script += 'sudo sed -i \'\' "/pcov/d" $ini_file\n';
359+
break;
360+
case 'win32':
361+
script +=
362+
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
363+
script +=
364+
'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov C:\\tools\\php }\n';
365+
break;
366+
}
367+
script += yield utils.log('Disabled Xdebug and PCOV', os_version, 'success', 'Set Coverage Driver');
368+
break;
344369
default:
345370
script = '';
346371
}

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "setup-php",
3-
"version": "1.3.8",
3+
"version": "1.3.9",
44
"private": false,
55
"description": "Setup php action",
66
"main": "lib/setup-php.js",

src/features.ts

+33-3
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ export async function addCoverage(
364364
version: string,
365365
os_version: string
366366
): Promise<string> {
367-
let script: string = '';
368-
script += '\n';
367+
let script: string = '\n';
369368
coverage = coverage.toLowerCase();
370369
// pcov
371370
switch (coverage) {
@@ -434,7 +433,38 @@ export async function addCoverage(
434433
'Set Coverage Driver'
435434
);
436435
break;
437-
// unknown coverage driver
436+
case 'none':
437+
switch (os_version) {
438+
case 'linux':
439+
script +=
440+
'if [ -e /etc/php/' +
441+
version +
442+
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
443+
script +=
444+
'if [ -e /etc/php/' +
445+
version +
446+
'/mods-available/pcov.ini ]; then sudo phpdismod pcov; fi\n';
447+
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
448+
script += 'sudo sed -i "/pcov/d" $ini_file\n';
449+
break;
450+
case 'darwin':
451+
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
452+
script += 'sudo sed -i \'\' "/pcov/d" $ini_file\n';
453+
break;
454+
case 'win32':
455+
script +=
456+
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
457+
script +=
458+
'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov C:\\tools\\php }\n';
459+
break;
460+
}
461+
script += await utils.log(
462+
'Disabled Xdebug and PCOV',
463+
os_version,
464+
'success',
465+
'Set Coverage Driver'
466+
);
467+
break;
438468
default:
439469
script = '';
440470
}

0 commit comments

Comments
 (0)