Skip to content

Commit

Permalink
Merge pull request shivammathur#54 from shivammathur/develop
Browse files Browse the repository at this point in the history
Add option to disable coverage drivers
  • Loading branch information
shivammathur authored Oct 5, 2019
2 parents f866c88 + 754ab95 commit 7e81c05
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 14 deletions.
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

## :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
with:
php-version: 7.3
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` needs `PHPUnit >= 8.0` and `PHP >= 7.1`, `PHPUnit` needs `PHP >= 7.2`. So use `PHP >= 7.2` with `PCOV`

### 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
with:
Expand All @@ -67,6 +73,15 @@ with:
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

Inputs supported by this GitHub Action.
Expand Down
14 changes: 14 additions & 0 deletions __tests__/features.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ describe('Features tests', () => {
win32 = await features.addCoverage('pcov', '5.6', 'win32');
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');
expect(win32).toEqual('');
});
Expand All @@ -191,6 +195,12 @@ describe('Features tests', () => {
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
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');
expect(linux).toEqual('');
});
Expand All @@ -205,6 +215,10 @@ describe('Features tests', () => {
darwin = await features.addCoverage('pcov', '7.4', 'darwin');
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');
expect(darwin).toEqual('');
});
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inputs:
description: '(Optional) Custom values you want to set in php.ini'
required: false
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
runs:
using: 'node12'
Expand Down
31 changes: 28 additions & 3 deletions lib/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ function addINIValuesWindows(ini_values_csv) {
exports.addINIValuesWindows = addINIValuesWindows;
function addCoverage(coverage, version, os_version) {
return __awaiter(this, void 0, void 0, function* () {
let script = '';
script += '\n';
let script = '\n';
coverage = coverage.toLowerCase();
// pcov
switch (coverage) {
Expand Down Expand Up @@ -340,7 +339,33 @@ function addCoverage(coverage, version, os_version) {
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');
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:
script = '';
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "setup-php",
"version": "1.3.8",
"version": "1.3.9",
"private": false,
"description": "Setup php action",
"main": "lib/setup-php.js",
Expand Down
36 changes: 33 additions & 3 deletions src/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ export async function addCoverage(
version: string,
os_version: string
): Promise<string> {
let script: string = '';
script += '\n';
let script: string = '\n';
coverage = coverage.toLowerCase();
// pcov
switch (coverage) {
Expand Down Expand Up @@ -434,7 +433,38 @@ export async function addCoverage(
'Set Coverage Driver'
);
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:
script = '';
}
Expand Down

0 comments on commit 7e81c05

Please sign in to comment.