Skip to content

Commit 62beed2

Browse files
authored
Merge pull request #59 from shivammathur/develop
Release 1.4.2
2 parents 3087ceb + fce9311 commit 62beed2

36 files changed

+800
-548
lines changed

README.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
</a>
55
</p>
66

7-
# Setup PHP in GitHub Actions
7+
<h1 align="center">Setup PHP in GitHub Actions</h1>
88

9-
<p align="left">
9+
<p align="center">
1010
<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>
1111
<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>
1212
<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>
@@ -64,8 +64,9 @@ with:
6464
6565
Specify `coverage: pcov` to use `PCOV`.
6666
It is much faster than `Xdebug`.
67+
`PCOV` needs `PHP >= 7.1`
6768
If your source code directory is other than `src`, `lib` or, `app`, specify `pcov.directory` using the `ini-values-csv` input.
68-
`PCOV` needs `PHPUnit >= 8.0` and `PHP >= 7.1`, `PHPUnit` needs `PHP >= 7.2`. So use `PHP >= 7.2` with `PCOV`
69+
6970

7071
```yaml
7172
uses: shivammathur/setup-php@master
@@ -149,8 +150,7 @@ jobs:
149150
- name: Check Composer Version
150151
run: composer -V
151152
- name: Check PHP Extensions
152-
run: php -m
153-
153+
run: php -m
154154
```
155155

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

181186
## :sparkling_heart: Support this project
182187

183-
- Please star the project and share it among your developer friends.
188+
- Please star the project and share it.
184189
- 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>.
185190

186191
## :bookmark: This action uses the following works

__tests__/config.test.ts

+7-13
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ describe('Config tests', () => {
77
'win32'
88
);
99
expect(win32).toContain(
10-
'Add-Content C:\\tools\\php\\php.ini "post_max_size=256M"'
11-
);
12-
expect(win32).toContain(
13-
'Add-Content C:\\tools\\php\\php.ini "short_open_tag=On"'
14-
);
15-
expect(win32).toContain(
16-
'Add-Content C:\\tools\\php\\php.ini "date.timezone=Asia/Kolkata"'
10+
'Add-Content C:\\tools\\php\\php.ini "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata"'
1711
);
1812

1913
win32 = await config.addINIValues(
@@ -28,9 +22,9 @@ describe('Config tests', () => {
2822
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
2923
'linux'
3024
);
31-
expect(linux).toContain('echo "post_max_size=256M" >> $ini_file');
32-
expect(linux).toContain('echo "short_open_tag=On" >> $ini_file');
33-
expect(linux).toContain('echo "date.timezone=Asia/Kolkata" >> $ini_file');
25+
expect(linux).toContain(
26+
'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata" >> $ini_file'
27+
);
3428

3529
linux = await config.addINIValues(
3630
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
@@ -44,9 +38,9 @@ describe('Config tests', () => {
4438
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',
4539
'darwin'
4640
);
47-
expect(darwin).toContain('echo "post_max_size=256M" >> $ini_file');
48-
expect(darwin).toContain('echo "short_open_tag=On" >> $ini_file');
49-
expect(darwin).toContain('echo "date.timezone=Asia/Kolkata" >> $ini_file');
41+
expect(darwin).toContain(
42+
'echo "post_max_size=256M\nshort_open_tag=On\ndate.timezone=Asia/Kolkata" >> $ini_file'
43+
);
5044

5145
darwin = await config.addINIValues(
5246
'post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata',

__tests__/coverage.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Config tests', () => {
2727
let linux: string = await coverage.addCoverage('pcov', '7.4', 'linux');
2828
expect(linux).toContain('addExtension pcov');
2929
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
30-
expect(linux).toContain('sudo phpdismod xdebug');
30+
expect(linux).toContain('sudo phpdismod -v 7.4 xdebug');
3131
});
3232

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

5959
it('checking disableCoverage on linux', async () => {
6060
let linux: string = await coverage.addCoverage('none', '7.4', 'linux');
61-
expect(linux).toContain('sudo phpdismod xdebug');
62-
expect(linux).toContain('sudo phpdismod pcov');
61+
expect(linux).toContain('sudo phpdismod -v 7.4 xdebug');
62+
expect(linux).toContain('sudo phpdismod -v 7.4 pcov');
6363
expect(linux).toContain('sudo sed -i "/xdebug/d" $ini_file');
6464
expect(linux).toContain('sudo sed -i "/pcov/d" $ini_file');
6565
});

__tests__/extensions.test.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
import * as extensions from '../src/extensions';
22

3-
let valid_extensions = ['xdebug', 'pcov'];
4-
jest.mock('../src/pecl', () => ({
5-
checkPECLExtension: jest.fn().mockImplementation(extension => {
6-
return valid_extensions.indexOf(extension) !== -1;
7-
})
8-
}));
9-
103
describe('Extension tests', () => {
114
it('checking addExtensionOnWindows', async () => {
125
let win32: string = await extensions.addExtension(
@@ -27,7 +20,9 @@ describe('Extension tests', () => {
2720
expect(win32).toContain('Install-PhpExtension pcov');
2821

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

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

48+
linux = await extensions.addExtension('phalcon3, phalcon4', '7.2', 'linux');
49+
expect(linux).toContain('./phalcon.sh master 7.2');
50+
expect(linux).toContain('./phalcon.sh 4.0.x 7.2');
51+
52+
linux = await extensions.addExtension('phalcon3, phalcon4', '7.3', 'linux');
53+
expect(linux).toContain('./phalcon.sh master 7.3');
54+
expect(linux).toContain('./phalcon.sh 4.0.x 7.3');
55+
5356
linux = await extensions.addExtension('xdebug', '7.2', 'fedora');
5457
expect(linux).toContain('Platform fedora is not supported');
5558
});
@@ -82,9 +85,7 @@ describe('Extension tests', () => {
8285
expect(darwin).toContain('sudo pecl install xdebug');
8386

8487
darwin = await extensions.addExtension('does_not_exist', '7.2', 'darwin');
85-
expect(darwin).toContain(
86-
'Could not find does_not_exist for PHP7.2 on PECL'
87-
);
88+
expect(darwin).toContain('add_extension does_not_exist');
8889

8990
darwin = await extensions.addExtension('xdebug', '7.2', 'fedora');
9091
expect(darwin).toContain('Platform fedora is not supported');

__tests__/pecl.test.ts

-15
This file was deleted.

action.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
name: 'Setup PHP Action'
22
author: shivammathur
3-
description: 'Setup a PHP environment with composer and add it to the PATH'
3+
description: 'GitHub action to setup PHP with required extensions, php.ini configuration, code-coverage support and composer'
44
branding:
55
icon: 'activity'
66
color: 'purple'
77
inputs:
88
php-version:
9-
description: 'PHP version to be installed.'
9+
description: 'PHP version you want to install.'
1010
required: true
1111
extension-csv:
12-
description: '(Optional) Comma seperated list of PHP extensions to be installed.'
12+
description: '(Optional) PHP extensions you want to install.'
1313
required: false
1414
ini-values-csv:
15-
description: '(Optional) Custom values you want to set in php.ini'
15+
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, pcov and none)'
18+
description: '(Optional) Code coverage driver you want to install. (Accepts: xdebug, pcov and none)'
1919
required: false
2020
runs:
2121
using: 'node12'

examples/laravel-mysql.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ jobs:
55
laravel:
66
name: Laravel (PHP ${{ matrix.php-versions }})
77
runs-on: ubuntu-latest
8-
env:
8+
env:
9+
DB_DATABASE: laravel
10+
DB_USERNAME: root
911
DB_PASSWORD: password
1012
BROADCAST_DRIVER: log
1113
CACHE_DRIVER: redis

examples/lumen-mysql.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# GitHub Action for Lumen with MySQL and Redis
2+
name: Testing Lumen with MySQL
3+
on: [push, pull_request]
4+
jobs:
5+
lumen:
6+
name: Lumen (PHP ${{ matrix.php-versions }})
7+
runs-on: ubuntu-latest
8+
env:
9+
DB_DATABASE: lumen
10+
DB_USERNAME: root
11+
DB_PASSWORD: password
12+
BROADCAST_DRIVER: log
13+
CACHE_DRIVER: redis
14+
QUEUE_CONNECTION: redis
15+
SESSION_DRIVER: redis
16+
services:
17+
mysql:
18+
image: mysql:5.7
19+
env:
20+
MYSQL_ALLOW_EMPTY_PASSWORD: false
21+
MYSQL_ROOT_PASSWORD: password
22+
MYSQL_DATABASE: lumen
23+
ports:
24+
- 3306
25+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
26+
redis:
27+
image: redis
28+
ports:
29+
- 6379/tcp
30+
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
31+
strategy:
32+
fail-fast: false
33+
max-parallel: 3
34+
matrix:
35+
php-versions: ['7.2', '7.3']
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v1
39+
- name: Setup PHP, with composer and extensions
40+
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
41+
with:
42+
php-version: ${{ matrix.php-versions }}
43+
extension-csv: mbstring, dom, fileinfo, mysql
44+
coverage: xdebug #optional
45+
- name: Install Composer dependencies
46+
run: |
47+
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
48+
composer require predis/predis illuminate/redis
49+
- name: Prepare the application
50+
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
51+
- name: Register Redis as service provider
52+
run: sed -i '$i\$app->register(Illuminate\\Redis\\RedisServiceProvider::class);' bootstrap/app.php
53+
- name: Run Migration
54+
run: php artisan migrate -v
55+
env:
56+
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
57+
- name: Test with phpunit
58+
run: vendor/bin/phpunit --coverage-text
59+
env:
60+
DB_PORT: ${{ job.services.mysql.ports['3306'] }}

examples/lumen-postgres.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# GitHub Action for Lumen with PostgreSQL and Redis
2+
name: Testing Lumen with PostgreSQL
3+
on: [push, pull_request]
4+
jobs:
5+
laravel:
6+
name: Lumen (PHP ${{ matrix.php-versions }})
7+
runs-on: ubuntu-latest
8+
env:
9+
BROADCAST_DRIVER: log
10+
CACHE_DRIVER: redis
11+
QUEUE_CONNECTION: redis
12+
SESSION_DRIVER: redis
13+
DB_CONNECTION: pgsql
14+
DB_HOST: localhost
15+
DB_PASSWORD: postgres
16+
DB_USERNAME: postgres
17+
DB_DATABASE: postgres
18+
services:
19+
postgres:
20+
image: postgres:10.8
21+
env:
22+
POSTGRES_USER: postgres
23+
POSTGRES_PASSWORD: postgres
24+
POSTGRES_DB: postgres
25+
ports:
26+
- 5432/tcp
27+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
28+
redis:
29+
image: redis
30+
ports:
31+
- 6379/tcp
32+
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
33+
strategy:
34+
fail-fast: false
35+
max-parallel: 3
36+
matrix:
37+
php-versions: ['7.2', '7.3']
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v1
41+
- name: Setup PHP, with composer and extensions
42+
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
43+
with:
44+
php-version: ${{ matrix.php-versions }}
45+
extension-csv: mbstring, dom, fileinfo, pgsql
46+
coverage: xdebug #optional
47+
- name: Install Composer dependencies
48+
run: |
49+
composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
50+
composer require predis/predis illuminate/redis
51+
- name: Prepare the application
52+
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
53+
- name: Register Redis as service provider
54+
run: sed -i '$i\$app->register(Illuminate\\Redis\\RedisServiceProvider::class);' bootstrap/app.php
55+
- name: Run Migration
56+
run: php artisan migrate -v
57+
env:
58+
DB_PORT: ${{ job.services.postgres.ports[5432] }}
59+
- name: Test with phpunit
60+
run: vendor/bin/phpunit --coverage-text
61+
env:
62+
DB_PORT: ${{ job.services.postgres.ports[5432] }}

examples/lumen.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# GitHub Action for Lumen
2+
name: Unit Testing Lumen
3+
on: [push, pull_request]
4+
jobs:
5+
lumen:
6+
name: Lumen (PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }})
7+
runs-on: ${{ matrix.operating-system }}
8+
strategy:
9+
fail-fast: false
10+
max-parallel: 9
11+
matrix:
12+
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
13+
php-versions: ['7.2', '7.3']
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v1
17+
- name: Setup PHP, with composer and extensions
18+
uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php
19+
with:
20+
php-version: ${{ matrix.php-versions }}
21+
extension-csv: mbstring, dom, fileinfo, mysql
22+
coverage: xdebug #optional
23+
- name: Install Composer dependencies
24+
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
25+
- name: Prepare the application
26+
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
27+
- name: Test with phpunit
28+
run: vendor/bin/phpunit --coverage-text
29+
shell: pwsh

0 commit comments

Comments
 (0)