Skip to content

Commit

Permalink
Add tools support
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Dec 27, 2019
1 parent 273096b commit de32d8b
Show file tree
Hide file tree
Showing 13 changed files with 556 additions and 112 deletions.
41 changes: 33 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Setup PHP with required extensions, php.ini configuration, code-coverage support

- [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 @@ -60,13 +61,36 @@ 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 following tools can be setup globally using the `tools` input

- `php-cs-fixer`
- `phpcs`
- `phpcbf`
- `phpcpd`
- `phpstan`
- `phpmd`
- `codeception`
- `phpunit`
- `deployer`
- `prestissimo`
- `pecl`

```yml
uses: shivammathur/setup-php@v1
with:
php-version: '7.4'
tools: php-cs-fixer, phpunit
```
## :signal_strength: Coverage support
### Xdebug
Expand Down Expand Up @@ -121,7 +145,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 +165,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 +192,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 @@ -191,7 +215,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,7 +233,7 @@ 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 }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
Expand Down
45 changes: 26 additions & 19 deletions __tests__/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ jest.mock('../src/install', () => ({
const extension_csv: string = process.env['extensions'] || '';
const ini_values_csv: string = process.env['ini-values'] || '';
const coverage_driver: string = process.env['coverage'] || '';
let tools_csv: string = process.env['tools'] || '';
const pecl: string = process.env['pecl'] || '';
if (pecl == 'true') {
tools_csv = 'pecl, ' + tools_csv;
}

let script = 'initial script ' + filename + version + os_version;
if (extension_csv) {
Expand All @@ -24,6 +29,9 @@ jest.mock('../src/install', () => ({
if (coverage_driver) {
script += 'set coverage driver';
}
if (tools_csv) {
script += 'add_tool';
}

return script;
}
Expand All @@ -36,15 +44,10 @@ jest.mock('../src/install', () => ({
let script = '';
switch (os_version) {
case 'darwin':
case 'linux':
script = await install.build(os_version + '.sh', version, os_version);
script += 'sh script.sh ' + version + ' ' + __dirname;
break;
case 'linux': {
const pecl: string = process.env['pecl'] || '';
script = await install.build(os_version + '.sh', version, os_version);
script += 'sh script.sh ' + version + ' ' + pecl + ' ' + __dirname;
break;
}
case 'win32':
script = await install.build(os_version + '.sh', version, os_version);
script += 'pwsh script.ps1 ' + version + ' ' + __dirname;
Expand Down Expand Up @@ -73,31 +76,33 @@ function setEnv(
extension_csv: string,
ini_values_csv: string,
coverage_driver: string,
tools: string,
pecl: string
): void {
process.env['php-version'] = version.toString();
process.env['RUNNER_OS'] = os;
process.env['extensions'] = extension_csv;
process.env['ini-values'] = ini_values_csv;
process.env['coverage'] = coverage_driver;
process.env['tools'] = tools;
process.env['pecl'] = pecl;
}

describe('Install', () => {
it('Test install on windows', async () => {
setEnv('7.0', 'win32', '', '', '', '');
setEnv('7.0', 'win32', '', '', '', '', '');
// @ts-ignore
let script: string = await install.run();
expect(script).toContain('initial script');
expect(script).toContain('pwsh script.ps1 7.0 ' + __dirname);

setEnv('7.3', 'win32', '', '', '', '');
setEnv('7.3', 'win32', '', '', '', '', '');
// @ts-ignore
script = await install.run();
expect(script).toContain('initial script');
expect(script).toContain('pwsh script.ps1 7.3 ' + __dirname);

setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', '');
setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', '', '');
// @ts-ignore
script = await install.run();
expect(script).toContain('initial script');
Expand All @@ -108,39 +113,41 @@ describe('Install', () => {
});

it('Test install on linux', async () => {
setEnv('7.3', 'linux', '', '', '', '');
setEnv('7.3', 'linux', '', '', '', '', '');
// @ts-ignore
let script: string = await install.run();
expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 7.3 ');

setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'true');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', 'true');
// @ts-ignore
script = await install.run();
expect(script).toContain('initial script');
expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver');
expect(script).toContain('sh script.sh 7.3 true');
expect(script).toContain('sh script.sh 7.3');
expect(script).toContain('add_tool');

setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'true');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', '');
// @ts-ignore
script = await install.run();
expect(script).toContain('initial script');
expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver');
expect(script).toContain('sh script.sh 7.3 true');
expect(script).toContain('sh script.sh 7.3');
expect(script).toContain('add_tool');
});

it('Test install on darwin', async () => {
setEnv('7.3', 'darwin', '', '', '', '');
setEnv('7.3', 'darwin', '', '', '', '', '');
// @ts-ignore
let script: string = await install.run();
expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 7.3 ' + __dirname);

setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '');
setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '', '');
// @ts-ignore
script = await install.run();
expect(script).toContain('initial script');
Expand All @@ -151,19 +158,19 @@ describe('Install', () => {
});

it('Test malformed version inputs', async () => {
setEnv('7.4.1', 'darwin', '', '', '', '');
setEnv('7.4.1', 'darwin', '', '', '', '', '');
// @ts-ignore
let script: string = await install.run();
expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 7.4 ' + __dirname);

setEnv(8.0, 'darwin', '', '', '', '');
setEnv(8.0, 'darwin', '', '', '', '', '');
// @ts-ignore
script = await install.run();
expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 8.0 ' + __dirname);

setEnv(8, 'darwin', '', '', '', '');
setEnv(8, 'darwin', '', '', '', '', '');
// @ts-ignore
script = await install.run();
expect(script).toContain('initial script');
Expand Down
61 changes: 61 additions & 0 deletions __tests__/tools.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as tools from '../src/tools';

describe('Tools tests', () => {
it('checking getToolCommand', async () => {
expect(await tools.getToolCommand('linux')).toBe('add_tool ');
expect(await tools.getToolCommand('darwin')).toBe('add_tool ');
expect(await tools.getToolCommand('win32')).toBe('Add-Tool ');
expect(await tools.getToolCommand('fedora')).toContain(
'Platform fedora is not supported'
);
});

it('checking getPECLCommand', async () => {
expect(await tools.getPECLCommand('linux')).toBe('add_pecl ');
expect(await tools.getPECLCommand('darwin')).toBe('add_pecl ');
expect(await tools.getPECLCommand('win32')).toBe('Add-PECL ');
expect(await tools.getPECLCommand('fedora')).toContain(
'Platform fedora is not supported'
);
});

it('checking addTools', async () => {
let script: string = await tools.addTools(
'php-cs-fixer, phpstan, phpunit, pecl',
'linux'
);
expect(script).toContain('add_tool https://getcomposer.org/composer.phar');
expect(script).toContain(
'add_tool https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/latest/download/php-cs-fixer.phar'
);
expect(script).toContain(
'add_tool https://github.com/phpstan/phpstan/releases/latest/download/phpstan.phar'
);
expect(script).toContain('add_tool https://phar.phpunit.de/phpunit.phar');
expect(script).toContain('add_pecl');

script = await tools.addTools('phpcs, phpcbf, phpcpd, phpmd', 'darwin');
expect(script).toContain('add_tool https://getcomposer.org/composer.phar');
expect(script).toContain(
'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcs.phar'
);
expect(script).toContain(
'add_tool https://github.com/squizlabs/PHP_CodeSniffer/releases/latest/download/phpcbf.phar'
);
expect(script).toContain(
'add_tool https://github.com/sebastianbergmann/phpcpd/releases/latest/download/phpcpd.phar'
);
expect(script).toContain(
'add_tool https://github.com/phpmd/phpmd/releases/latest/download/phpmd.phar'
);

script = await tools.addTools(
'codeception, deployer, prestissimo, phpmd, does_not_exit',
'win32'
);
expect(script).toContain('Add-Tool https://getcomposer.org/composer.phar');
expect(script).toContain('Add-Tool https://deployer.org/deployer.phar');
expect(script).toContain('composer global require hirak/prestissimo');
expect(script).toContain('Tool does_not_exit is not supported');
});
});
6 changes: 3 additions & 3 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ describe('Utils tests', () => {
});

it('checking INIArray', async () => {
expect(await utils.INIArray('a=1, b=2, c=3')).toEqual([
expect(await utils.CSVArray('a=1, b=2, c=3')).toEqual([
'a=1',
'b=2',
'c=3'
]);
expect(await utils.INIArray('')).toEqual([]);
expect(await utils.INIArray(' ')).toEqual([]);
expect(await utils.CSVArray('')).toEqual([]);
expect(await utils.CSVArray(' ')).toEqual([]);
});

it('checking log', async () => {
Expand Down
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ inputs:
coverage:
description: 'Setup code coverage driver.'
required: false
pecl:
description: 'Setup PECL on ubuntu'
tools:
description: 'Setup popular tools globally.'
required: false
# Deprecated options, do not use. Will not be supported after February 1, 2020.
extension-csv:
Expand All @@ -29,6 +29,10 @@ inputs:
description: 'Deprecated! Use ini-values instead.'
deprecationMessage: 'The ini-values-csv property will not be supported after February 1, 2020. Use ini-values instead.'
required: false
pecl:
description: 'Deprecated! Use tools instead to setup PECL.'
deprecationMessage: 'The pecl property will not be supported after February 1, 2020. Specify pecl in tools instead.'
required: false
runs:
using: 'node12'
main: 'dist/index.js'
Loading

0 comments on commit de32d8b

Please sign in to comment.