Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.7.0 #133

Merged
merged 11 commits into from
Dec 31, 2019
Merged

1.7.0 #133

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
46 changes: 35 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
<a href="#tada-php-support" title="PHP Versions Supported"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg"></a>
</p>

Setup PHP with required extensions, php.ini configuration, code-coverage support and composer in [GitHub Actions](https://github.com/features/actions "GitHub Actions"). This action gives you a cross platform interface to setup the PHP environment you need to test your application. Refer to [Usage](#memo-usage "How to use this") section and [examples](#examples "Examples of use") to see how to use this.
Setup PHP with required extensions, php.ini configuration, code-coverage support and tools like composer in [GitHub Actions](https://github.com/features/actions "GitHub Actions"). This action gives you a cross platform interface to setup the PHP environment you need to test your application. Refer to [Usage](#memo-usage "How to use this") section and [examples](#examples "Examples of use") to see how to use this.

## Contents

- [PHP Support](#tada-php-support)
- [OS/Platform Support](#cloud-osplatform-support)
- [PHP Extension Support](#wrench-php-extension-support)
- [PHP Extension Support](#heavy_plus_sign-php-extension-support)
- [Tools Support](#wrench-tools-support)
- [Coverage support](#signal_strength-coverage-support)
- [Xdebug](#xdebug)
- [PCOV](#pcov)
Expand Down Expand Up @@ -49,7 +50,7 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support
|7.4|`Stable`|`Active`|
|8.0|`Experimental`|`In development`|

**Note:** Specifying `8.0` in `php-version` input installs a nightly build of `PHP 8.0.0-dev` with `PHP JIT` support. See [experimental setup](#experimental-setup) for more information.
**Note:** Specifying `8.0` in `php-version` input installs a nightly build of `PHP 8.0.0-dev` with `PHP JIT`, `Union Types v2` and other [new features](https://wiki.php.net/rfc#php_80 "New features implemented in PHP 8"). See [experimental setup](#experimental-setup) for more information.

## :cloud: OS/Platform Support

Expand All @@ -60,13 +61,28 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support
|Ubuntu 16.04|`ubuntu-16.04`|
|macOS X Catalina 10.15|`macOS-latest` or `macOS-10.15`|

## :wrench: PHP Extension Support
- On `ubuntu` by default extensions which are available as a package can be installed. If the extension is not available as a package but it is on `PECL`, it can be installed by specifying `pecl: true`.
## :heavy_plus_sign: PHP Extension Support
- On `ubuntu` by default extensions which are available as a package can be installed. If the extension is not available as a package but it is on `PECL`, it can be installed by specifying `pecl` in the tools input.
- On `windows` extensions which have `windows` binary on `PECL` can be installed.
- On `macOS` extensions which are on `PECL` can be installed.
- Extensions which are installed along with PHP if specified are enabled.
- Extensions which cannot be installed gracefully leave an error message in the logs, the action is not interrupted.

## :wrench: Tools Support

The latest version of the following tools can be setup globally using the `tools` input

`composer`, `codeception`, `deployer`, `pecl`, `phinx`, `phpcbf`, `phpcpd`, `php-cs-fixer`, `phpcs`, `phpmd`, `phpstan`, `phpunit`, `prestissimo`, `psalm`

```yml
uses: shivammathur/setup-php@v1
with:
php-version: '7.4'
tools: php-cs-fixer, phpunit
```

**Note:** `composer` is setup by default, so that is not required to be specified.

## :signal_strength: Coverage support

### Xdebug
Expand Down Expand Up @@ -103,7 +119,7 @@ Specify `coverage: none` to disable both `Xdebug` and `PCOV`.
Consider disabling the coverage using this PHP action for these reasons.

- You are not generating coverage reports while testing.
- It will disable `Xdebug`, which will have a positive impact on PHP performance.
- It will remove `Xdebug`, which will have a positive impact on PHP performance.
- You are using `phpdbg` for running your tests.

```yaml
Expand All @@ -121,7 +137,7 @@ Inputs supported by this GitHub Action.
- extensions `optional`
- ini-values `optional`
- coverage `optional`
- pecl `optional`
- tools `optional`

See [action.yml](action.yml "Metadata for this GitHub Action") and usage below for more info.

Expand All @@ -141,7 +157,7 @@ steps:
extensions: mbstring, intl #optional, setup extensions
ini-values: post_max_size=256M, short_open_tag=On #optional, setup php.ini configuration
coverage: xdebug #optional, setup coverage driver
pecl: false #optional, setup PECL
tools: php-cs-fixer, phpunit #optional, setup tools globally
```

### Matrix Setup
Expand All @@ -168,7 +184,7 @@ jobs:
extensions: mbstring, intl #optional, setup extensions
ini-values: post_max_size=256M, short_open_tag=On #optional, setup php.ini configuration
coverage: xdebug #optional, setup coverage driver
pecl: false #optional, setup PECL
tools: php-cs-fixer, phpunit #optional, setup tools globally
```

### Experimental Setup
Expand All @@ -179,6 +195,7 @@ jobs:
- `PECL` is installed by default with this version on `ubuntu`.
- Some extensions might not support this version currently.
- Refer to this [RFC](https://wiki.php.net/rfc/jit "PHP JIT RFC configuration") for configuring `PHP JIT` on this version.
- Refer to this [list of RFCs](https://wiki.php.net/rfc#php_80 "List of RFCs implemented in PHP8") implemented in this version.

```yaml
steps:
Expand All @@ -191,7 +208,8 @@ steps:
php-version: '8.0'
extensions: mbstring #optional, setup extensions
ini-values: opcache.jit_buffer_size=256M, opcache.jit=1235, pcre.jit=1 #optional, setup php.ini configuration
coverage: pcov #optional, setup PCOV, Xdebug does not support this version yet.
coverage: pcov #optional, setup PCOV, Xdebug does not support this version yet.
tools: php-cs-fixer, phpunit #optional, setup tools globally
```

### Cache dependencies
Expand All @@ -208,14 +226,20 @@ You can persist composer's internal cache directory using the [`action/cache`](h
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
path: ${{ steps.composer-cache.outputs.dir }}
shivammathur marked this conversation as resolved.
Show resolved Hide resolved
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Dependencies
run: composer install --prefer-dist
```

In the above example, if you support a range of `composer` dependencies and do not commit `composer.lock`, you can use the hash of `composer.json` as the key for your cache.

```yml
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
```

### Problem Matchers

You can setup problem matchers for your `PHPUnit` output. This will scan the errors in your tests and surface that information prominently in the GitHub Actions UI by creating annotations and log file decorations.
Expand Down
55 changes: 16 additions & 39 deletions __tests__/coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ import * as coverage from '../src/coverage';

jest.mock('../src/extensions', () => ({
addExtension: jest.fn().mockImplementation(extension => {
return 'addExtension ' + extension + '\n';
return 'add_extension ' + extension + '\n';
})
}));

describe('Config tests', () => {
it('checking addCoverage with PCOV on windows', async () => {
let win32: string = await coverage.addCoverage('pcov', '7.4', 'win32');
expect(win32).toContain('addExtension pcov');
expect(win32).toContain(
'if(php -m | findstr -i xdebug) { Disable-PhpExtension xdebug $php_dir'
);
expect(win32).toContain(
'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }'
);
expect(win32).toContain('add_extension pcov');
expect(win32).toContain('Remove-Extension xdebug');

win32 = await coverage.addCoverage('pcov', '7.0', 'win32');
expect(win32).toContain('PHP 7.1 or newer is required');
Expand All @@ -26,24 +21,19 @@ describe('Config tests', () => {

it('checking addCoverage with PCOV on linux', async () => {
const linux: string = await coverage.addCoverage('pcov', '7.4', 'linux');
expect(linux).toContain('addExtension pcov');
expect(linux).toContain('sudo sed -i "/xdebug/d" "$ini_file"');
expect(linux).toContain('sudo phpdismod -v 7.4 xdebug');
expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug'
);
expect(linux).toContain('add_extension pcov');
expect(linux).toContain('remove_extension xdebug');
});

it('checking addCoverage with PCOV on darwin', async () => {
const darwin: string = await coverage.addCoverage('pcov', '7.4', 'darwin');
expect(darwin).toContain('addExtension pcov');
expect(darwin).toContain('sudo sed -i \'\' "/xdebug/d" "$ini_file"');
expect(darwin).toContain('sudo rm -rf "$ext_dir"/xdebug.so');
expect(darwin).toContain('add_extension pcov');
expect(darwin).toContain('remove_extension xdebug');
});

it('checking addCoverage with Xdebug on windows', async () => {
const win32: string = await coverage.addCoverage('xdebug', '7.4', 'win32');
expect(win32).toContain('addExtension xdebug');
expect(win32).toContain('add_extension xdebug');
});

it('checking addCoverage with Xdebug on windows', async () => {
Expand All @@ -53,7 +43,7 @@ describe('Config tests', () => {

it('checking addCoverage with Xdebug on linux', async () => {
const linux: string = await coverage.addCoverage('xdebug', '7.4', 'linux');
expect(linux).toContain('addExtension xdebug');
expect(linux).toContain('add_extension xdebug');
});

it('checking addCoverage with Xdebug on linux', async () => {
Expand All @@ -67,7 +57,7 @@ describe('Config tests', () => {
'7.4',
'darwin'
);
expect(darwin).toContain('addExtension xdebug');
expect(darwin).toContain('add_extension xdebug');
});

it('checking addCoverage with Xdebug on darwin', async () => {
Expand All @@ -81,33 +71,20 @@ describe('Config tests', () => {

it('checking disableCoverage windows', async () => {
const win32 = await coverage.addCoverage('none', '7.4', 'win32');
expect(win32).toContain('Disable-PhpExtension xdebug');
expect(win32).toContain('Disable-PhpExtension pcov');
expect(win32).toContain(
'if (Test-Path $ext_dir\\php_xdebug.dll) { Remove-Item $ext_dir\\php_xdebug.dll }'
);
expect(win32).toContain(
'if (Test-Path $ext_dir\\php_pcov.dll) { Remove-Item $ext_dir\\php_pcov.dll }'
);
expect(win32).toContain('Remove-Extension xdebug');
expect(win32).toContain('Remove-Extension pcov');
});

it('checking disableCoverage on linux', async () => {
const linux: string = await coverage.addCoverage('none', '7.4', 'linux');
expect(linux).toContain('sudo phpdismod -v 7.4 xdebug');
expect(linux).toContain('sudo phpdismod -v 7.4 pcov');
expect(linux).toContain('sudo sed -i "/xdebug/d" "$ini_file"');
expect(linux).toContain('sudo sed -i "/pcov/d" "$ini_file"');
expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt-fast remove php-xdebug php-pcov'
);
expect(linux).toContain('remove_extension xdebug');
expect(linux).toContain('remove_extension pcov');
});

it('checking disableCoverage on darwin', async () => {
const darwin: string = await coverage.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"');
expect(darwin).toContain('sudo rm -rf "$ext_dir"/xdebug.so');
expect(darwin).toContain('sudo rm -rf "$ext_dir"/pcov.so');
expect(darwin).toContain('remove_extension xdebug');
expect(darwin).toContain('remove_extension pcov');
});

it('checking no or invalid coverage driver', async () => {
Expand Down
28 changes: 16 additions & 12 deletions __tests__/extensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import * as extensions from '../src/extensions';
describe('Extension tests', () => {
it('checking addExtensionOnWindows', async () => {
let win32: string = await extensions.addExtension(
'xdebug, pcov, redis',
'xdebug, pcov, phalcon4',
'7.4',
'win32'
);
expect(win32).toContain('Add-Extension xdebug');
expect(win32).toContain('Add-Extension pcov');
expect(win32).toContain('Add-Extension redis beta');
expect(win32).toContain('phalcon.ps1 phalcon4');

win32 = await extensions.addExtension(
'does_not_exist',
'phalcon3, does_not_exist',
'7.2',
'win32',
true
);
expect(win32).toContain('phalcon.ps1 phalcon3');
expect(win32).toContain('Add-Extension does_not_exist');

win32 = await extensions.addExtension('xdebug', '7.2', 'fedora');
Expand All @@ -25,7 +26,7 @@ describe('Extension tests', () => {

it('checking addExtensionOnLinux', async () => {
let linux: string = await extensions.addExtension(
'xdebug, pcov, redis',
'xdebug, pcov',
'7.4',
'linux'
);
Expand All @@ -37,9 +38,6 @@ describe('Extension tests', () => {
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-pcov'
);
expect(linux).toContain('pecl install pcov');
expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-igbinary php7.4-redis'
);

linux = await extensions.addExtension('gearman', '7.0', 'linux');
expect(linux).toContain('gearman.sh 7.0');
Expand All @@ -51,21 +49,21 @@ describe('Extension tests', () => {
'7.2',
'linux'
);
expect(linux).toContain('phalcon.sh 3.4.x 7.2');
expect(linux).toContain('phalcon.sh master 7.2');
expect(linux).toContain('phalcon.sh phalcon3 7.2');
expect(linux).toContain('phalcon.sh phalcon4 7.2');
expect(linux).toContain('gearman.sh 7.2');

linux = await extensions.addExtension(
'phalcon3, phalcon4, gearman',
'7.3',
'linux'
);
expect(linux).toContain('phalcon.sh 3.4.x 7.3');
expect(linux).toContain('phalcon.sh master 7.3');
expect(linux).toContain('phalcon.sh phalcon3 7.3');
expect(linux).toContain('phalcon.sh phalcon4 7.3');
expect(linux).toContain('gearman.sh 7.3');

linux = await extensions.addExtension('phalcon4, gearman', '7.4', 'linux');
expect(linux).toContain('phalcon.sh master 7.4');
expect(linux).toContain('phalcon.sh phalcon4 7.4');
expect(linux).toContain('gearman.sh 7.4');

linux = await extensions.addExtension('xdebug', '7.2', 'fedora');
Expand All @@ -81,6 +79,12 @@ describe('Extension tests', () => {
expect(darwin).toContain('sudo pecl install xdebug');
expect(darwin).toContain('sudo pecl install pcov');

darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin');
expect(darwin).toContain('phalcon_darwin.sh phalcon3 7.0');

darwin = await extensions.addExtension('phalcon4', '7.3', 'darwin');
expect(darwin).toContain('phalcon_darwin.sh phalcon4 7.3');

darwin = await extensions.addExtension('pcov', '5.6', 'darwin');
expect(darwin).toContain('sudo pecl install pcov');

Expand Down
Loading