Skip to content

Commit

Permalink
Merge pull request shivammathur#59 from shivammathur/develop
Browse files Browse the repository at this point in the history
Release 1.4.2
  • Loading branch information
shivammathur authored Oct 14, 2019
2 parents 3087ceb + fce9311 commit 62beed2
Show file tree
Hide file tree
Showing 36 changed files with 800 additions and 548 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
</a>
</p>

# Setup PHP in GitHub Actions
<h1 align="center">Setup PHP in GitHub Actions</h1>

<p align="left">
<p align="center">
<a href="https://github.com/shivammathur/setup-php" title="GitHub action to setup PHP"><img alt="GitHub Actions status" src="https://github.com/shivammathur/setup-php/workflows/Main%20workflow/badge.svg"></a>
<a href="https://codecov.io/gh/shivammathur/setup-php" title="Code coverage"><img alt="Codecov Code Coverage" src="https://codecov.io/gh/shivammathur/setup-php/branch/master/graph/badge.svg"></a>
<a href="https://github.com/shivammathur/setup-php/blob/master/LICENSE" title="license"><img alt="LICENSE" src="https://img.shields.io/badge/license-MIT-428f7e.svg"></a>
Expand Down Expand Up @@ -64,8 +64,9 @@ with:
Specify `coverage: pcov` to use `PCOV`.
It is much faster than `Xdebug`.
`PCOV` needs `PHP >= 7.1`
If your source code directory is other than `src`, `lib` or, `app`, specify `pcov.directory` 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`


```yaml
uses: shivammathur/setup-php@master
Expand Down Expand Up @@ -149,8 +150,7 @@ jobs:
- name: Check Composer Version
run: composer -V
- name: Check PHP Extensions
run: php -m
run: php -m
```

### Examples
Expand All @@ -163,6 +163,11 @@ Examples for setting up this GitHub Action with different PHP Frameworks/Package
|Laravel with `MySQL` and `Redis`|`ubuntu`|[laravel-mysql.yml](./examples/laravel-mysql.yml "GitHub Action for Laravel with MySQL and Redis")|
|Laravel with `PostgreSQL` and `Redis`|`ubuntu`|[laravel-postgres.yml](./examples/laravel-postgres.yml "GitHub Action for Laravel with PostgreSQL and Redis")|
|Laravel without services|`macOS`, `ubuntu` and `windows`|[laravel.yml](./examples/laravel.yml "GitHub Action for Laravel without services")|
|Lumen with `MySQL` and `Redis`|`ubuntu`|[lumen-mysql.yml](./examples/lumen-mysql.yml "GitHub Action for Lumen with MySQL and Redis")|
|Lumen with `PostgreSQL` and `Redis`|`ubuntu`|[lumen-postgres.yml](./examples/lumen-postgres.yml "GitHub Action for Lumen with PostgreSQL and Redis")|
|Lumen without services|`macOS`, `ubuntu` and `windows`|[lumen.yml](./examples/lumen.yml "GitHub Action for Lumen without services")|
|Phalcon with `MySQL`|`ubuntu`|[phalcon-mysql.yml](./examples/phalcon-mysql.yml "GitHub Action for Phalcon with MySQL")|
|Phalcon with `PostgreSQL`|`ubuntu`|[phalcon-postgres.yml](./examples/phalcon-postgres.yml "GitHub Action for Phalcon with PostgreSQL")|
|Slim Framework|`macOS`, `ubuntu` and `windows`|[slim-framework.yml](./examples/slim-framework.yml "GitHub Action for Slim Framework")|
|Symfony with `MySQL`|`ubuntu`|[symfony-mysql.yml](./examples/symfony-mysql.yml "GitHub Action for Symfony with MySQL")|
|Symfony with `PostgreSQL`|`ubuntu`|[symfony-postgres.yml](./examples/symfony-postgres.yml "GitHub Action for Symfony with PostgreSQL")|
Expand All @@ -180,7 +185,7 @@ Contributions are welcome! See [Contributor's Guide](.github/CONTRIBUTING.md "sh

## :sparkling_heart: Support this project

- Please star the project and share it among your developer friends.
- Please star the project and share it.
- Consider supporting on <a href="https://www.patreon.com/shivammathur"><img alt="Support me on Patreon" src="https://shivammathur.com/badges/patreon.svg"></a> and <a href="https://www.paypal.me/shivammathur"><img alt="Support me on Paypal" src="https://shivammathur.com/badges/paypal.svg"></a>.

## :bookmark: This action uses the following works
Expand Down
20 changes: 7 additions & 13 deletions __tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ describe('Config tests', () => {
'win32'
);
expect(win32).toContain(
'Add-Content C:\\tools\\php\\php.ini "post_max_size=256M"'
);
expect(win32).toContain(
'Add-Content C:\\tools\\php\\php.ini "short_open_tag=On"'
);
expect(win32).toContain(
'Add-Content C:\\tools\\php\\php.ini "date.timezone=Asia/Kolkata"'
'Add-Content C:\\tools\\php\\php.ini "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata"'
);

win32 = await config.addINIValues(
Expand All @@ -28,9 +22,9 @@ describe('Config tests', () => {
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'linux'
);
expect(linux).toContain('echo "post_max_size=256M" >> $ini_file');
expect(linux).toContain('echo "short_open_tag=On" >> $ini_file');
expect(linux).toContain('echo "date.timezone=Asia/Kolkata" >> $ini_file');
expect(linux).toContain(
'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata" >> $ini_file'
);

linux = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
Expand All @@ -44,9 +38,9 @@ describe('Config tests', () => {
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
'darwin'
);
expect(darwin).toContain('echo "post_max_size=256M" >> $ini_file');
expect(darwin).toContain('echo "short_open_tag=On" >> $ini_file');
expect(darwin).toContain('echo "date.timezone=Asia/Kolkata" >> $ini_file');
expect(darwin).toContain(
'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata" >> $ini_file'
);

darwin = await config.addINIValues(
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
Expand Down
6 changes: 3 additions & 3 deletions __tests__/coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Config tests', () => {
let 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 xdebug');
expect(linux).toContain('sudo phpdismod -v 7.4 xdebug');
});

it('checking addCoverage with PCOV on darwin', async () => {
Expand Down Expand Up @@ -58,8 +58,8 @@ describe('Config tests', () => {

it('checking disableCoverage on linux', async () => {
let linux: string = await coverage.addCoverage('none', '7.4', 'linux');
expect(linux).toContain('sudo phpdismod xdebug');
expect(linux).toContain('sudo phpdismod pcov');
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');
});
Expand Down
23 changes: 12 additions & 11 deletions __tests__/extensions.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import * as extensions from '../src/extensions';

let valid_extensions = ['xdebug', 'pcov'];
jest.mock('../src/pecl', () => ({
checkPECLExtension: jest.fn().mockImplementation(extension => {
return valid_extensions.indexOf(extension) !== -1;
})
}));

describe('Extension tests', () => {
it('checking addExtensionOnWindows', async () => {
let win32: string = await extensions.addExtension(
Expand All @@ -27,7 +20,9 @@ describe('Extension tests', () => {
expect(win32).toContain('Install-PhpExtension pcov');

win32 = await extensions.addExtension('does_not_exist', '7.2', 'win32');
expect(win32).toContain('Could not find does_not_exist for PHP7.2 on PECL');
expect(win32).toContain(
'Add-Extension does_not_exist "Install-PhpExtension does_not_exist" extension "Add Extension"'
);

win32 = await extensions.addExtension('xdebug', '7.2', 'fedora');
expect(win32).toContain('Platform fedora is not supported');
Expand All @@ -50,6 +45,14 @@ describe('Extension tests', () => {
expect(linux).toContain('./xdebug.sh');
expect(linux).toContain('./pcov.sh');

linux = await extensions.addExtension('phalcon3, phalcon4', '7.2', 'linux');
expect(linux).toContain('./phalcon.sh master 7.2');
expect(linux).toContain('./phalcon.sh 4.0.x 7.2');

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

linux = await extensions.addExtension('xdebug', '7.2', 'fedora');
expect(linux).toContain('Platform fedora is not supported');
});
Expand Down Expand Up @@ -82,9 +85,7 @@ describe('Extension tests', () => {
expect(darwin).toContain('sudo pecl install xdebug');

darwin = await extensions.addExtension('does_not_exist', '7.2', 'darwin');
expect(darwin).toContain(
'Could not find does_not_exist for PHP7.2 on PECL'
);
expect(darwin).toContain('add_extension does_not_exist');

darwin = await extensions.addExtension('xdebug', '7.2', 'fedora');
expect(darwin).toContain('Platform fedora is not supported');
Expand Down
15 changes: 0 additions & 15 deletions __tests__/pecl.test.ts

This file was deleted.

10 changes: 5 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: 'Setup PHP Action'
author: shivammathur
description: 'Setup a PHP environment with composer and add it to the PATH'
description: 'GitHub action to setup PHP with required extensions, php.ini configuration, code-coverage support and composer'
branding:
icon: 'activity'
color: 'purple'
inputs:
php-version:
description: 'PHP version to be installed.'
description: 'PHP version you want to install.'
required: true
extension-csv:
description: '(Optional) Comma seperated list of PHP extensions to be installed.'
description: '(Optional) PHP extensions you want to install.'
required: false
ini-values-csv:
description: '(Optional) Custom values you want to set in php.ini'
description: '(Optional) Custom values you want to set in php.ini.'
required: false
coverage:
description: '(Optional) Driver to calculate code coverage (Accepts: xdebug, pcov and none)'
description: '(Optional) Code coverage driver you want to install. (Accepts: xdebug, pcov and none)'
required: false
runs:
using: 'node12'
Expand Down
4 changes: 3 additions & 1 deletion examples/laravel-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ jobs:
laravel:
name: Laravel (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
env:
env:
DB_DATABASE: laravel
DB_USERNAME: root
DB_PASSWORD: password
BROADCAST_DRIVER: log
CACHE_DRIVER: redis
Expand Down
60 changes: 60 additions & 0 deletions examples/lumen-mysql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# GitHub Action for Lumen with MySQL and Redis
name: Testing Lumen with MySQL
on: [push, pull_request]
jobs:
lumen:
name: Lumen (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
env:
DB_DATABASE: lumen
DB_USERNAME: root
DB_PASSWORD: password
BROADCAST_DRIVER: log
CACHE_DRIVER: redis
QUEUE_CONNECTION: redis
SESSION_DRIVER: redis
services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: lumen
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
redis:
image: redis
ports:
- 6379/tcp
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
max-parallel: 3
matrix:
php-versions: ['7.2', '7.3']
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring, dom, fileinfo, mysql
coverage: xdebug #optional
- name: Install Composer dependencies
run: |
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
composer require predis/predis illuminate/redis
- name: Prepare the application
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Register Redis as service provider
run: sed -i '$i\$app->register(Illuminate\\Redis\\RedisServiceProvider::class);' bootstrap/app.php
- name: Run Migration
run: php artisan migrate -v
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
- name: Test with phpunit
run: vendor/bin/phpunit --coverage-text
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
62 changes: 62 additions & 0 deletions examples/lumen-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# GitHub Action for Lumen with PostgreSQL and Redis
name: Testing Lumen with PostgreSQL
on: [push, pull_request]
jobs:
laravel:
name: Lumen (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
env:
BROADCAST_DRIVER: log
CACHE_DRIVER: redis
QUEUE_CONNECTION: redis
SESSION_DRIVER: redis
DB_CONNECTION: pgsql
DB_HOST: localhost
DB_PASSWORD: postgres
DB_USERNAME: postgres
DB_DATABASE: postgres
services:
postgres:
image: postgres:10.8
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432/tcp
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
redis:
image: redis
ports:
- 6379/tcp
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: false
max-parallel: 3
matrix:
php-versions: ['7.2', '7.3']
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring, dom, fileinfo, pgsql
coverage: xdebug #optional
- name: Install Composer dependencies
run: |
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
composer require predis/predis illuminate/redis
- name: Prepare the application
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Register Redis as service provider
run: sed -i '$i\$app->register(Illuminate\\Redis\\RedisServiceProvider::class);' bootstrap/app.php
- name: Run Migration
run: php artisan migrate -v
env:
DB_PORT: ${{ job.services.postgres.ports[5432] }}
- name: Test with phpunit
run: vendor/bin/phpunit --coverage-text
env:
DB_PORT: ${{ job.services.postgres.ports[5432] }}
29 changes: 29 additions & 0 deletions examples/lumen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# GitHub Action for Lumen
name: Unit Testing Lumen
on: [push, pull_request]
jobs:
lumen:
name: Lumen (PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }})
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
max-parallel: 9
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: ['7.2', '7.3']
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
extension-csv: mbstring, dom, fileinfo, mysql
coverage: xdebug #optional
- name: Install Composer dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Prepare the application
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Test with phpunit
run: vendor/bin/phpunit --coverage-text
shell: pwsh
Loading

0 comments on commit 62beed2

Please sign in to comment.