Add option to disable coverage drivers

This commit is contained in:
Shivam Mathur 2019-10-05 15:00:00 +05:30
parent f866c880c2
commit 754ab9515b
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
7 changed files with 98 additions and 14 deletions

View File

@ -48,17 +48,23 @@ Setup PHP with required extensions, php.ini configuration and composer in [GitHu
- Extensions which cannot be installed gracefully leave an error message in the logs, the action is not interrupted. - Extensions which cannot be installed gracefully leave an error message in the logs, the action is not interrupted.
## :signal_strength: Coverage support ## :signal_strength: Coverage support
- Specify `coverage: xdebug` to use `Xdebug`.
- Runs on all [PHP versions supported](#tada-php-support) ### Xdebug
Specify `coverage: xdebug` to use `Xdebug`.
Runs on all [PHP versions supported](#tada-php-support)
``` ```
uses: shivammathur/setup-php@master uses: shivammathur/setup-php@master
with: with:
php-version: 7.3 php-version: 7.3
coverage: xdebug coverage: xdebug
``` ```
- Specify `coverage: pcov` to use `PCOV`. `PCOV` is way faster than `Xdebug`
- For `pcov.directory` to be other than `src`, `lib` or, `app`, specify it using the `ini-values-csv` input. ### PCOV
- `PCOV` needs `PHPUnit >= 8.0` and `PHP >= 7.1`, `PHPUnit` needs `PHP >= 7.2`. So use `PHP >= 7.2` with `PCOV`
Specify `coverage: pcov` to use `PCOV`. `PCOV` is way faster than `Xdebug`.
For `pcov.directory` to be other than `src`, `lib` or, `app`, specify it using the `ini-values-csv` input.
`PCOV` needs `PHPUnit >= 8.0` and `PHP >= 7.1`, `PHPUnit` needs `PHP >= 7.2`. So use `PHP >= 7.2` with `PCOV`
``` ```
uses: shivammathur/setup-php@master uses: shivammathur/setup-php@master
with: with:
@ -67,6 +73,15 @@ with:
coverage: pcov coverage: pcov
``` ```
### Disable coverage
Specify `coverage: none` to disable both `Xdebug` and `PCOV`.
```
uses: shivammathur/setup-php@master
with:
php-version: 7.3
coverage: none
```
## :memo: Usage ## :memo: Usage
Inputs supported by this GitHub Action. Inputs supported by this GitHub Action.

View File

@ -178,6 +178,10 @@ describe('Features tests', () => {
win32 = await features.addCoverage('pcov', '5.6', 'win32'); win32 = await features.addCoverage('pcov', '5.6', 'win32');
expect(win32).toContain('PCOV requires PHP 7.1 or newer'); expect(win32).toContain('PCOV requires PHP 7.1 or newer');
win32 = await features.addCoverage('none', '7.4', 'win32');
expect(win32).toContain('Disable-PhpExtension xdebug');
expect(win32).toContain('Disable-PhpExtension pcov');
win32 = await features.addCoverage('', '7.4', 'win32'); win32 = await features.addCoverage('', '7.4', 'win32');
expect(win32).toEqual(''); expect(win32).toEqual('');
}); });
@ -191,6 +195,12 @@ describe('Features tests', () => {
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file'); expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
expect(linux).toContain('sudo phpdismod xdebug'); expect(linux).toContain('sudo phpdismod xdebug');
linux = await features.addCoverage('none', '7.4', 'linux');
expect(linux).toContain('sudo phpdismod xdebug');
expect(linux).toContain('sudo phpdismod pcov');
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
expect(linux).toContain('sudo sed -i "/pcov/d" $ini_file');
linux = await features.addCoverage('', '7.4', 'linux'); linux = await features.addCoverage('', '7.4', 'linux');
expect(linux).toEqual(''); expect(linux).toEqual('');
}); });
@ -205,6 +215,10 @@ describe('Features tests', () => {
darwin = await features.addCoverage('pcov', '7.4', 'darwin'); darwin = await features.addCoverage('pcov', '7.4', 'darwin');
expect(darwin).toContain('sh ./pcov.sh'); expect(darwin).toContain('sh ./pcov.sh');
darwin = await features.addCoverage('none', '7.4', 'darwin');
expect(darwin).toContain('sudo sed -i \'\' "/xdebug/d" $ini_file');
expect(darwin).toContain('sudo sed -i \'\' "/pcov/d" $ini_file');
darwin = await features.addCoverage('', '7.4', 'win32'); darwin = await features.addCoverage('', '7.4', 'win32');
expect(darwin).toEqual(''); expect(darwin).toEqual('');
}); });

View File

@ -15,7 +15,7 @@ inputs:
description: '(Optional) Custom values you want to set in php.ini' description: '(Optional) Custom values you want to set in php.ini'
required: false required: false
coverage: coverage:
description: '(Optional) Driver to calculate code coverage (Accepts: xdebug and pcov)' description: '(Optional) Driver to calculate code coverage (Accepts: xdebug, pcov and none)'
required: false required: false
runs: runs:
using: 'node12' using: 'node12'

View File

@ -297,8 +297,7 @@ function addINIValuesWindows(ini_values_csv) {
exports.addINIValuesWindows = addINIValuesWindows; exports.addINIValuesWindows = addINIValuesWindows;
function addCoverage(coverage, version, os_version) { function addCoverage(coverage, version, os_version) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let script = ''; let script = '\n';
script += '\n';
coverage = coverage.toLowerCase(); coverage = coverage.toLowerCase();
// pcov // pcov
switch (coverage) { switch (coverage) {
@ -340,7 +339,33 @@ function addCoverage(coverage, version, os_version) {
script += yield addExtension('xdebug', version, os_version, 'Set Coverage Driver'); script += yield addExtension('xdebug', version, os_version, 'Set Coverage Driver');
script += yield utils.log('Xdebug enabled as coverage driver', os_version, 'success', 'Set Coverage Driver'); script += yield utils.log('Xdebug enabled as coverage driver', os_version, 'success', 'Set Coverage Driver');
break; break;
// unknown coverage driver case 'none':
switch (os_version) {
case 'linux':
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/pcov.ini ]; then sudo phpdismod pcov; fi\n';
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
script += 'sudo sed -i "/pcov/d" $ini_file\n';
break;
case 'darwin':
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
script += 'sudo sed -i \'\' "/pcov/d" $ini_file\n';
break;
case 'win32':
script +=
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
script +=
'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov C:\\tools\\php }\n';
break;
}
script += yield utils.log('Disabled Xdebug and PCOV', os_version, 'success', 'Set Coverage Driver');
break;
default: default:
script = ''; script = '';
} }

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "setup-php", "name": "setup-php",
"version": "1.3.8", "version": "1.3.9",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "setup-php", "name": "setup-php",
"version": "1.3.8", "version": "1.3.9",
"private": false, "private": false,
"description": "Setup php action", "description": "Setup php action",
"main": "lib/setup-php.js", "main": "lib/setup-php.js",

View File

@ -364,8 +364,7 @@ export async function addCoverage(
version: string, version: string,
os_version: string os_version: string
): Promise<string> { ): Promise<string> {
let script: string = ''; let script: string = '\n';
script += '\n';
coverage = coverage.toLowerCase(); coverage = coverage.toLowerCase();
// pcov // pcov
switch (coverage) { switch (coverage) {
@ -434,7 +433,38 @@ export async function addCoverage(
'Set Coverage Driver' 'Set Coverage Driver'
); );
break; break;
// unknown coverage driver case 'none':
switch (os_version) {
case 'linux':
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/xdebug.ini ]; then sudo phpdismod xdebug; fi\n';
script +=
'if [ -e /etc/php/' +
version +
'/mods-available/pcov.ini ]; then sudo phpdismod pcov; fi\n';
script += 'sudo sed -i "/xdebug/d" $ini_file\n';
script += 'sudo sed -i "/pcov/d" $ini_file\n';
break;
case 'darwin':
script += 'sudo sed -i \'\' "/xdebug/d" $ini_file\n';
script += 'sudo sed -i \'\' "/pcov/d" $ini_file\n';
break;
case 'win32':
script +=
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug C:\\tools\\php }\n';
script +=
'if(php -m | findstr -i pcov) { Disable-PhpExtension pcov C:\\tools\\php }\n';
break;
}
script += await utils.log(
'Disabled Xdebug and PCOV',
os_version,
'success',
'Set Coverage Driver'
);
break;
default: default:
script = ''; script = '';
} }