Add PECL support on linux

This commit is contained in:
Shivam Mathur 2019-11-07 11:11:35 +05:30
parent 24ecbee4ea
commit e14155415a
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
9 changed files with 73 additions and 28 deletions

View File

@ -60,8 +60,9 @@ Setup PHP with required extensions, php.ini configuration and composer in [GitHu
|macOS X Catalina 10.15|`macOS-latest` or `macOS-10.15`| |macOS X Catalina 10.15|`macOS-latest` or `macOS-10.15`|
## :wrench: PHP Extension Support ## :wrench: PHP Extension Support
- On `ubuntu` extensions which have the package in apt are installed. - On `ubuntu` extensions which have the package in `APT` are installed. If extension is not in `APT`, you can use `PECL` to install the extension as fallback by specifying `pecl: true`.
- On `windows` and `macOS` PECL extensions are installed. - 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 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. - Extensions which cannot be installed gracefully leave an error message in the logs, the action is not interrupted.
@ -119,6 +120,7 @@ Inputs supported by this GitHub Action.
- extension-csv `optional` - extension-csv `optional`
- ini-values-csv `optional` - ini-values-csv `optional`
- coverage `optional` - coverage `optional`
- pecl `optional`
See [action.yml](action.yml "Metadata for this GitHub Action") and usage below for more info. See [action.yml](action.yml "Metadata for this GitHub Action") and usage below for more info.
@ -132,9 +134,10 @@ steps:
uses: shivammathur/setup-php@master uses: shivammathur/setup-php@master
with: with:
php-version: '7.3' php-version: '7.3'
extension-csv: mbstring, xdebug #optional extension-csv: mbstring, xdebug #optional, setup extensions
ini-values-csv: post_max_size=256M, short_open_tag=On #optional ini-values-csv: post_max_size=256M, short_open_tag=On #optional, setup php.ini configuration
coverage: xdebug #optional coverage: xdebug #optional, setup coverage driver
pecl: true #optional, setup PECL
- name: Check PHP Version - name: Check PHP Version
run: php -v run: php -v
- name: Check Composer Version - name: Check Composer Version
@ -161,10 +164,10 @@ jobs:
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@master uses: shivammathur/setup-php@master
with: with:
php-version: ${{ matrix.php-versions }} extension-csv: mbstring, xdebug #optional, setup extensions
extension-csv: mbstring, xdebug #optional ini-values-csv: post_max_size=256M, short_open_tag=On #optional, setup php.ini configuration
ini-values-csv: post_max_size=256M, short_open_tag=On #optional coverage: xdebug #optional, setup coverage driver
coverage: xdebug #optional pecl: true #optional, setup PECL
- name: Check PHP Version - name: Check PHP Version
run: php -v run: php -v
- name: Check Composer Version - name: Check Composer Version

View File

@ -40,11 +40,13 @@ describe('Extension tests', () => {
'linux' 'linux'
); );
expect(linux).toContain( expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt install -y php7.2-xdebug' 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.2-xdebug'
); );
expect(linux).toContain('pecl install xdebug');
expect(linux).toContain( expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt install -y php7.2-pcov' 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.2-pcov'
); );
expect(linux).toContain('pecl install pcov');
linux = await extensions.addExtension('xdebug, pcov', '7.4', 'linux'); linux = await extensions.addExtension('xdebug, pcov', '7.4', 'linux');
expect(linux).toContain('xdebug.sh'); expect(linux).toContain('xdebug.sh');

View File

@ -35,10 +35,14 @@ jest.mock('../src/install', () => ({
let script: string = ''; let script: string = '';
switch (os_version) { switch (os_version) {
case 'darwin': case 'darwin':
case 'linux':
script = await install.build(os_version + '.sh', version, os_version); script = await install.build(os_version + '.sh', version, os_version);
script += 'sh script.sh ' + version + ' ' + __dirname; script += 'sh script.sh ' + version + ' ' + __dirname;
break; break;
case 'linux':
let 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': case 'win32':
script = await install.build(os_version + '.sh', version, os_version); script = await install.build(os_version + '.sh', version, os_version);
script += script +=
@ -67,24 +71,26 @@ function setEnv(
os: string, os: string,
extension_csv: string, extension_csv: string,
ini_values_csv: string, ini_values_csv: string,
coverage_driver: string coverage_driver: string,
pecl: any
): void { ): void {
process.env['php-version'] = version; process.env['php-version'] = version;
process.env['RUNNER_OS'] = os; process.env['RUNNER_OS'] = os;
process.env['extension-csv'] = extension_csv; process.env['extension-csv'] = extension_csv;
process.env['ini-values-csv'] = ini_values_csv; process.env['ini-values-csv'] = ini_values_csv;
process.env['coverage'] = coverage_driver; process.env['coverage'] = coverage_driver;
process.env['pecl'] = pecl;
} }
describe('Install', () => { describe('Install', () => {
it('Test install on windows', async () => { it('Test install on windows', async () => {
setEnv('7.3', 'win32', '', '', ''); setEnv('7.3', 'win32', '', '', '', '');
// @ts-ignore // @ts-ignore
let script: string = await install.run(); let script: string = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('pwsh script.ps1 -version 7.3 -dir ' + __dirname); expect(script).toContain('pwsh script.ps1 -version 7.3 -dir ' + __dirname);
setEnv('7.3', 'win32', 'a, b', 'a=b', 'x'); setEnv('7.3', 'win32', 'a, b', 'a=b', 'x', '');
// @ts-ignore // @ts-ignore
script = await install.run(); script = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
@ -95,30 +101,39 @@ describe('Install', () => {
}); });
it('Test install on linux', async () => { it('Test install on linux', async () => {
setEnv('7.3', 'linux', '', '', ''); setEnv('7.3', 'linux', '', '', '', '');
// @ts-ignore // @ts-ignore
let script: string = await install.run(); let script: string = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 7.3 ' + __dirname); expect(script).toContain('sh script.sh 7.3 ');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x'); setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'true');
// @ts-ignore // @ts-ignore
script = await install.run(); script = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('install extensions'); expect(script).toContain('install extensions');
expect(script).toContain('edit php.ini'); expect(script).toContain('edit php.ini');
expect(script).toContain('set coverage driver'); expect(script).toContain('set coverage driver');
expect(script).toContain('sh script.sh 7.3 ' + __dirname); expect(script).toContain('sh script.sh 7.3 true');
setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 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');
}); });
it('Test install on darwin', async () => { it('Test install on darwin', async () => {
setEnv('7.3', 'darwin', '', '', ''); setEnv('7.3', 'darwin', '', '', '', '');
// @ts-ignore // @ts-ignore
let script: string = await install.run(); let script: string = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');
expect(script).toContain('sh script.sh 7.3 ' + __dirname); 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 // @ts-ignore
script = await install.run(); script = await install.run();
expect(script).toContain('initial script'); expect(script).toContain('initial script');

View File

@ -16,6 +16,9 @@ inputs:
coverage: coverage:
description: '(Optional) Code coverage driver you want to install. (Accepts: xdebug, pcov and none)' description: '(Optional) Code coverage driver you want to install. (Accepts: xdebug, pcov and none)'
required: false required: false
pecl:
description: '(Optional) Setup PECL on ubuntu'
required: false
runs: runs:
using: 'node12' using: 'node12'
main: 'lib/install.js' main: 'lib/install.js'

View File

@ -192,10 +192,12 @@ function addExtensionLinux(extension_csv, version) {
break; break;
default: default:
install_command = install_command =
'sudo DEBIAN_FRONTEND=noninteractive apt install -y php' + 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php' +
version + version +
'-' + '-' +
extension + extension +
' >/dev/null 2>&1 || sudo pecl install ' +
extension +
' >/dev/null 2>&1'; ' >/dev/null 2>&1';
break; break;
} }

View File

@ -61,10 +61,14 @@ function run() {
let script_path = ''; let script_path = '';
switch (os_version) { switch (os_version) {
case 'darwin': case 'darwin':
case 'linux':
script_path = yield build(os_version + '.sh', version, os_version); script_path = yield build(os_version + '.sh', version, os_version);
yield exec_1.exec('sh ' + script_path + ' ' + version + ' ' + __dirname); yield exec_1.exec('sh ' + script_path + ' ' + version + ' ' + __dirname);
break; break;
case 'linux':
let pecl = yield utils.getInput('pecl', false);
script_path = yield build(os_version + '.sh', version, os_version);
yield exec_1.exec('sh ' + script_path + ' ' + version + ' ' + pecl);
break;
case 'win32': case 'win32':
script_path = yield build('win32.ps1', version, os_version); script_path = yield build('win32.ps1', version, os_version);
yield exec_1.exec('pwsh ' + script_path + ' -version ' + version + ' -dir ' + __dirname); yield exec_1.exec('pwsh ' + script_path + ' -version ' + version + ' -dir ' + __dirname);

View File

@ -185,10 +185,12 @@ export async function addExtensionLinux(
break; break;
default: default:
install_command = install_command =
'sudo DEBIAN_FRONTEND=noninteractive apt install -y php' + 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php' +
version + version +
'-' + '-' +
extension + extension +
' >/dev/null 2>&1 || sudo pecl install ' +
extension +
' >/dev/null 2>&1'; ' >/dev/null 2>&1';
break; break;
} }

View File

@ -47,10 +47,14 @@ export async function run() {
let script_path: string = ''; let script_path: string = '';
switch (os_version) { switch (os_version) {
case 'darwin': case 'darwin':
case 'linux':
script_path = await build(os_version + '.sh', version, os_version); script_path = await build(os_version + '.sh', version, os_version);
await exec('sh ' + script_path + ' ' + version + ' ' + __dirname); await exec('sh ' + script_path + ' ' + version + ' ' + __dirname);
break; break;
case 'linux':
let pecl: string = await utils.getInput('pecl', false);
script_path = await build(os_version + '.sh', version, os_version);
await exec('sh ' + script_path + ' ' + version + ' ' + pecl);
break;
case 'win32': case 'win32':
script_path = await build('win32.ps1', version, os_version); script_path = await build('win32.ps1', version, os_version);
await exec( await exec(

View File

@ -26,12 +26,11 @@ if [ "$existing_version" != "$1" ]; then
if [ "$1" != "7.4" ]; then if [ "$1" != "7.4" ]; then
sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$1" curl php"$1"-curl >/dev/null 2>&1 sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$1" curl php"$1"-curl >/dev/null 2>&1
else else
sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$1" php"$1"-dev curl php"$1"-curl >/dev/null 2>&1 sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$1" php"$1"-dev php"$1"-xml curl php"$1"-curl >/dev/null 2>&1
fi fi
status="Installed PHP$version" status="Installed PHP$version"
fi fi
for tool in php phar phar.phar php-cgi php-config phpize; do for tool in php phar phar.phar php-cgi php-config phpize; do
if [ -e "/usr/bin/$tool$1" ]; then if [ -e "/usr/bin/$tool$1" ]; then
sudo update-alternatives --set $tool /usr/bin/"$tool$1" >/dev/null 2>&1 sudo update-alternatives --set $tool /usr/bin/"$tool$1" >/dev/null 2>&1
@ -44,6 +43,17 @@ ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
sudo chmod 777 "$ini_file" sudo chmod 777 "$ini_file"
sudo mkdir -p /run/php sudo mkdir -p /run/php
add_log "$tick" "PHP" "$status" add_log "$tick" "PHP" "$status"
if [ "$2" = "true" ]; then
if [ "$1" != "7.4" ]; then
sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$1"-dev php"$1"-xml >/dev/null 2>&1
fi
sudo update-alternatives --set php-config /usr/bin/php-config"$1" >/dev/null 2>&1
sudo update-alternatives --set phpize /usr/bin/phpize"$1" >/dev/null 2>&1
wget https://github.com/pear/pearweb_phars/raw/master/install-pear-nozlib.phar >/dev/null 2>&1
sudo php install-pear-nozlib.phar >/dev/null 2>&1
sudo pear config-set php_ini "$ini_file" >/dev/null 2>&1
add_log "$tick" "PECL" "Installed"
fi
if [ ! -e "/usr/bin/composer" ]; then if [ ! -e "/usr/bin/composer" ]; then
curl -s -L https://getcomposer.org/installer > composer-setup.php curl -s -L https://getcomposer.org/installer > composer-setup.php
@ -71,6 +81,6 @@ add_extension()
( (
eval "$install_command" && \ eval "$install_command" && \
add_log "$tick" "$extension" "Installed and enabled" add_log "$tick" "$extension" "Installed and enabled"
) || add_log "$cross" "$extension" "Could not find php$version-$extension" ) || add_log "$cross" "$extension" "Could not install $extension on php$version"
fi fi
} }