Add support for pre-release pecl extensions

This commit is contained in:
Shivam Mathur 2020-01-26 01:04:09 +05:30
parent e01b2f0bf7
commit b44b7344e0
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
7 changed files with 103 additions and 57 deletions

View File

@ -3,13 +3,14 @@ import * as extensions from '../src/extensions';
describe('Extension tests', () => { describe('Extension tests', () => {
it('checking addExtensionOnWindows', async () => { it('checking addExtensionOnWindows', async () => {
let win32: string = await extensions.addExtension( let win32: string = await extensions.addExtension(
'xdebug, pcov, phalcon4', 'xdebug, pcov, phalcon4, ast-beta',
'7.4', '7.4',
'win32' 'win32'
); );
expect(win32).toContain('Add-Extension xdebug'); expect(win32).toContain('Add-Extension xdebug');
expect(win32).toContain('Add-Extension pcov'); expect(win32).toContain('Add-Extension pcov');
expect(win32).toContain('phalcon.ps1 phalcon4'); expect(win32).toContain('phalcon.ps1 phalcon4');
expect(win32).toContain('Add-Extension ast beta');
win32 = await extensions.addExtension( win32 = await extensions.addExtension(
'phalcon3, does_not_exist', 'phalcon3, does_not_exist',
@ -26,7 +27,7 @@ describe('Extension tests', () => {
it('checking addExtensionOnLinux', async () => { it('checking addExtensionOnLinux', async () => {
let linux: string = await extensions.addExtension( let linux: string = await extensions.addExtension(
'xdebug, pcov', 'xdebug, pcov, ast-beta',
'7.4', '7.4',
'linux' 'linux'
); );
@ -34,7 +35,8 @@ describe('Extension tests', () => {
expect(linux).toContain( expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-pcov' 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-pcov'
); );
expect(linux).toContain('pecl install pcov'); expect(linux).toContain('pecl install -f pcov');
expect(linux).toContain('install_extension ast-beta');
linux = await extensions.addExtension('gearman', '7.0', 'linux'); linux = await extensions.addExtension('gearman', '7.0', 'linux');
expect(linux).toContain('gearman.sh 7.0'); expect(linux).toContain('gearman.sh 7.0');
@ -60,12 +62,13 @@ describe('Extension tests', () => {
it('checking addExtensionOnDarwin', async () => { it('checking addExtensionOnDarwin', async () => {
let darwin: string = await extensions.addExtension( let darwin: string = await extensions.addExtension(
'xdebug, pcov', 'xdebug, pcov, ast-beta',
'7.2', '7.2',
'darwin' 'darwin'
); );
expect(darwin).toContain('sudo pecl install xdebug'); expect(darwin).toContain('sudo pecl install -f xdebug');
expect(darwin).toContain('sudo pecl install pcov'); expect(darwin).toContain('sudo pecl install -f pcov');
expect(darwin).toContain('install_extension ast-beta');
darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin'); darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin');
expect(darwin).toContain('phalcon_darwin.sh phalcon3 7.0'); expect(darwin).toContain('phalcon_darwin.sh phalcon3 7.0');
@ -74,33 +77,33 @@ describe('Extension tests', () => {
expect(darwin).toContain('phalcon_darwin.sh phalcon4 7.3'); expect(darwin).toContain('phalcon_darwin.sh phalcon4 7.3');
darwin = await extensions.addExtension('pcov', '5.6', 'darwin'); darwin = await extensions.addExtension('pcov', '5.6', 'darwin');
expect(darwin).toContain('sudo pecl install pcov'); expect(darwin).toContain('sudo pecl install -f pcov');
darwin = await extensions.addExtension('pcov', '7.2', 'darwin'); darwin = await extensions.addExtension('pcov', '7.2', 'darwin');
expect(darwin).toContain('sudo pecl install pcov'); expect(darwin).toContain('sudo pecl install -f pcov');
darwin = await extensions.addExtension('xdebug', '5.6', 'darwin'); darwin = await extensions.addExtension('xdebug', '5.6', 'darwin');
expect(darwin).toContain('sudo pecl install xdebug-2.5.5'); expect(darwin).toContain('sudo pecl install -f xdebug-2.5.5');
darwin = await extensions.addExtension('xdebug', '7.0', 'darwin'); darwin = await extensions.addExtension('xdebug', '7.0', 'darwin');
expect(darwin).toContain('sudo pecl install xdebug-2.9.0'); expect(darwin).toContain('sudo pecl install -f xdebug-2.9.0');
darwin = await extensions.addExtension('xdebug', '7.2', 'darwin'); darwin = await extensions.addExtension('xdebug', '7.2', 'darwin');
expect(darwin).toContain('sudo pecl install xdebug'); expect(darwin).toContain('sudo pecl install -f xdebug');
darwin = await extensions.addExtension('redis', '5.6', 'darwin'); darwin = await extensions.addExtension('redis', '5.6', 'darwin');
expect(darwin).toContain('sudo pecl install redis-2.2.8'); expect(darwin).toContain('sudo pecl install -f redis-2.2.8');
darwin = await extensions.addExtension('redis', '7.2', 'darwin'); darwin = await extensions.addExtension('redis', '7.2', 'darwin');
expect(darwin).toContain('sudo pecl install redis'); expect(darwin).toContain('sudo pecl install -f redis');
darwin = await extensions.addExtension('imagick', '5.6', 'darwin'); darwin = await extensions.addExtension('imagick', '5.6', 'darwin');
expect(darwin).toContain('brew install pkg-config imagemagick'); expect(darwin).toContain('brew install pkg-config imagemagick');
expect(darwin).toContain('sudo pecl install imagick'); expect(darwin).toContain('sudo pecl install -f imagick');
darwin = await extensions.addExtension('imagick', '7.4', 'darwin'); darwin = await extensions.addExtension('imagick', '7.4', 'darwin');
expect(darwin).toContain('brew install pkg-config imagemagick'); expect(darwin).toContain('brew install pkg-config imagemagick');
expect(darwin).toContain('sudo pecl install imagick'); expect(darwin).toContain('sudo pecl install -f imagick');
darwin = await extensions.addExtension( darwin = await extensions.addExtension(
'does_not_exist', 'does_not_exist',

32
dist/index.js vendored
View File

@ -2284,7 +2284,8 @@ function build(filename, version, os_version) {
const coverage_driver = yield utils.getInput('coverage', false); const coverage_driver = yield utils.getInput('coverage', false);
const pecl = yield utils.getInput('pecl', false); const pecl = yield utils.getInput('pecl', false);
let tools_csv = yield utils.getInput('tools', false); let tools_csv = yield utils.getInput('tools', false);
if (pecl == 'true') { if (pecl == 'true' ||
/.*-(beta|alpha|devel|snapshot).*/.test(extension_csv)) {
tools_csv = 'pecl, ' + tools_csv; tools_csv = 'pecl, ' + tools_csv;
} }
let script = yield utils.readScript(filename, version, os_version); let script = yield utils.readScript(filename, version, os_version);
@ -2593,23 +2594,26 @@ function addExtensionDarwin(extension_csv, version, pipe) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
const version_extension = version + extension; const version_extension = version + extension;
// add script to enable extension is already installed along with php
let install_command = ''; let install_command = '';
switch (true) { switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
install_command = 'install_extension ' + extension + pipe;
break;
case /5\.6xdebug/.test(version_extension): case /5\.6xdebug/.test(version_extension):
install_command = 'sudo pecl install xdebug-2.5.5' + pipe; install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe;
break; break;
case /7\.0xdebug/.test(version_extension): case /7\.0xdebug/.test(version_extension):
install_command = 'sudo pecl install xdebug-2.9.0' + pipe; install_command = 'sudo pecl install -f xdebug-2.9.0' + pipe;
break; break;
case /5\.6redis/.test(version_extension): case /5\.6redis/.test(version_extension):
install_command = 'sudo pecl install redis-2.2.8' + pipe; install_command = 'sudo pecl install -f redis-2.2.8' + pipe;
break; break;
case /[5-9]\.\dimagick/.test(version_extension): case /[5-9]\.\dimagick/.test(version_extension):
install_command = install_command =
'brew install pkg-config imagemagick' + 'brew install pkg-config imagemagick' +
pipe + pipe +
' && sudo pecl install imagick' + ' && sudo pecl install -f imagick' +
pipe; pipe;
break; break;
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
@ -2623,7 +2627,7 @@ function addExtensionDarwin(extension_csv, version, pipe) {
pipe; pipe;
break; break;
default: default:
install_command = 'sudo pecl install ' + extension + pipe; install_command = 'sudo pecl install -f ' + extension + pipe;
break; break;
} }
script += script +=
@ -2652,9 +2656,14 @@ function addExtensionWindows(extension_csv, version, pipe) {
let script = '\n'; let script = '\n';
yield utils.asyncForEach(extensions, function (extension) { yield utils.asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// add script to enable extension is already installed along with php extension = extension.toLowerCase();
const [extension_name, stability] = extension.split('-');
const version_extension = version + extension; const version_extension = version + extension;
switch (true) { switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
script += '\nAdd-Extension ' + extension_name + ' ' + stability;
break;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script += script +=
@ -2690,10 +2699,13 @@ function addExtensionLinux(extension_csv, version, pipe) {
yield utils.asyncForEach(extensions, function (extension) { yield utils.asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
// add script to enable extension is already installed along with php
const version_extension = version + extension; const version_extension = version + extension;
let install_command = ''; let install_command = '';
switch (true) { switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
install_command = 'install_extension ' + extension + pipe;
break;
// match 5.6gearman..7.4gearman // match 5.6gearman..7.4gearman
case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
install_command = install_command =
@ -2728,7 +2740,7 @@ function addExtensionLinux(extension_csv, version, pipe) {
'-' + '-' +
extension.replace('pdo_', '').replace('pdo-', '') + extension.replace('pdo_', '').replace('pdo-', '') +
pipe + pipe +
' || sudo pecl install ' + ' || sudo pecl install -f ' +
extension + extension +
pipe; pipe;
break; break;

View File

@ -18,23 +18,26 @@ export async function addExtensionDarwin(
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
const version_extension: string = version + extension; const version_extension: string = version + extension;
// add script to enable extension is already installed along with php
let install_command = ''; let install_command = '';
switch (true) { switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
install_command = 'install_extension ' + extension + pipe;
break;
case /5\.6xdebug/.test(version_extension): case /5\.6xdebug/.test(version_extension):
install_command = 'sudo pecl install xdebug-2.5.5' + pipe; install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe;
break; break;
case /7\.0xdebug/.test(version_extension): case /7\.0xdebug/.test(version_extension):
install_command = 'sudo pecl install xdebug-2.9.0' + pipe; install_command = 'sudo pecl install -f xdebug-2.9.0' + pipe;
break; break;
case /5\.6redis/.test(version_extension): case /5\.6redis/.test(version_extension):
install_command = 'sudo pecl install redis-2.2.8' + pipe; install_command = 'sudo pecl install -f redis-2.2.8' + pipe;
break; break;
case /[5-9]\.\dimagick/.test(version_extension): case /[5-9]\.\dimagick/.test(version_extension):
install_command = install_command =
'brew install pkg-config imagemagick' + 'brew install pkg-config imagemagick' +
pipe + pipe +
' && sudo pecl install imagick' + ' && sudo pecl install -f imagick' +
pipe; pipe;
break; break;
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
@ -48,7 +51,7 @@ export async function addExtensionDarwin(
pipe; pipe;
break; break;
default: default:
install_command = 'sudo pecl install ' + extension + pipe; install_command = 'sudo pecl install -f ' + extension + pipe;
break; break;
} }
script += script +=
@ -77,9 +80,14 @@ export async function addExtensionWindows(
const extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.extensionArray(extension_csv);
let script = '\n'; let script = '\n';
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
// add script to enable extension is already installed along with php extension = extension.toLowerCase();
const [extension_name, stability]: string[] = extension.split('-');
const version_extension: string = version + extension; const version_extension: string = version + extension;
switch (true) { switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
script += '\nAdd-Extension ' + extension_name + ' ' + stability;
break;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script += script +=
@ -115,10 +123,13 @@ export async function addExtensionLinux(
let script = '\n'; let script = '\n';
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase(); extension = extension.toLowerCase();
// add script to enable extension is already installed along with php
const version_extension: string = version + extension; const version_extension: string = version + extension;
let install_command = ''; let install_command = '';
switch (true) { switch (true) {
// match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
install_command = 'install_extension ' + extension + pipe;
break;
// match 5.6gearman..7.4gearman // match 5.6gearman..7.4gearman
case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
install_command = install_command =
@ -153,7 +164,7 @@ export async function addExtensionLinux(
'-' + '-' +
extension.replace('pdo_', '').replace('pdo-', '') + extension.replace('pdo_', '').replace('pdo-', '') +
pipe + pipe +
' || sudo pecl install ' + ' || sudo pecl install -f ' +
extension + extension +
pipe; pipe;
break; break;

View File

@ -29,7 +29,10 @@ export async function build(
const coverage_driver: string = await utils.getInput('coverage', false); const coverage_driver: string = await utils.getInput('coverage', false);
const pecl: string = await utils.getInput('pecl', false); const pecl: string = await utils.getInput('pecl', false);
let tools_csv: string = await utils.getInput('tools', false); let tools_csv: string = await utils.getInput('tools', false);
if (pecl == 'true') { if (
pecl == 'true' ||
/.*-(beta|alpha|devel|snapshot).*/.test(extension_csv)
) {
tools_csv = 'pecl, ' + tools_csv; tools_csv = 'pecl, ' + tools_csv;
} }

View File

@ -26,20 +26,21 @@ add_extension() {
elif php -m | grep -i -q -w "$extension"; then elif php -m | grep -i -q -w "$extension"; then
add_log "$tick" "$extension" "Enabled" add_log "$tick" "$extension" "Enabled"
elif ! php -m | grep -i -q -w "$extension"; then elif ! php -m | grep -i -q -w "$extension"; then
exists=$(curl -sL https://pecl.php.net/json.php?package="$extension" -w "%{http_code}" -o /dev/null) (eval "$install_command" && add_log "$tick" "$extension" "Installed and enabled") ||
if [ "$exists" = "200" ] || [[ "$extension" == "phalcon"* ]]; then add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
(
eval "$install_command" && \
add_log "$tick" "$extension" "Installed and enabled"
) || add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
else
if ! php -m | grep -i -q -w "$extension"; then
add_log "$cross" "$extension" "Could not find $extension for PHP $semver on PECL"
fi
fi
fi fi
} }
# Function to force install extensions using PECL
install_extension() {
extension=$1
extension_name="$(echo "$extension" | cut -d'-' -f 1)"
sudo sed -i "/$extension_name/d" "$ini_file"
sudo rm -rf /etc/php/"$version"/cli/conf.d/*"$extension_name"* >/dev/null 2>&1
sudo rm -rf "$ext_dir"/"$extension_name".so >/dev/null 2>&1
sudo pecl install -f "$extension" >/dev/null 2>&1
}
# Function to remove extensions # Function to remove extensions
remove_extension() { remove_extension() {
extension=$1 extension=$1
@ -79,13 +80,17 @@ add_composer_tool() {
release=$2 release=$2
prefix=$3 prefix=$3
( (
composer global require "$prefix$release" >/dev/null 2>&1 && \ composer global require "$prefix$release" >/dev/null 2>&1 && \
sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" && \ sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" && \
add_log "$tick" "$tool" "Added" add_log "$tick" "$tool" "Added"
) || add_log "$cross" "$tool" "Could not setup $tool" ) || add_log "$cross" "$tool" "Could not setup $tool"
} }
add_pecl() { add_pecl() {
sudo pear config-set php_ini "$ini_file" >/dev/null 2>&1
sudo pear config-set auto_discover 1 >/dev/null 2>&1
sudo pear channel-update pear.php.net >/dev/null 2>&1
sudo pecl channel-update pecl.php.net >/dev/null 2>&1
add_log "$tick" "PECL" "Added" add_log "$tick" "PECL" "Added"
} }
@ -106,7 +111,7 @@ version=$1
step_log "Setup PHP" step_log "Setup PHP"
setup_php_and_composer setup_php_and_composer
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
echo "date.timezone=UTC" >> "$ini_file" echo "date.timezone=UTC" >>"$ini_file"
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||") ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
sudo chmod 777 "$ini_file" sudo chmod 777 "$ini_file"
mkdir -p "$(pecl config-get ext_dir)" mkdir -p "$(pecl config-get ext_dir)"

View File

@ -40,6 +40,16 @@ add_extension() {
fi fi
} }
# Function to force install extensions using PECL
install_extension() {
extension=$1
extension_name="$(echo "$extension" | cut -d'-' -f 1)"
sudo sed -i "/$extension_name/d" "$ini_file"
sudo rm -rf /etc/php/"$version"/cli/conf.d/*"$extension_name"* >/dev/null 2>&1
sudo rm -rf "$ext_dir"/"$extension_name".so >/dev/null 2>&1
sudo pecl install -f "$extension" >/dev/null 2>&1
}
# Function to remove extensions # Function to remove extensions
remove_extension() { remove_extension() {
extension=$1 extension=$1
@ -125,14 +135,12 @@ setup_master() {
# Function to setup PECL # Function to setup PECL
add_pecl() { add_pecl() {
update_ppa
add_devtools add_devtools
wget https://github.com/pear/pearweb_phars/raw/master/install-pear-nozlib.phar >/dev/null 2>&1 $apt_install php-pear >/dev/null 2>&1
sudo php install-pear-nozlib.phar >/dev/null 2>&1
sudo rm -rf install-pear-nozlib.phar >/dev/null 2>&1
sudo pear config-set php_ini "$ini_file" >/dev/null 2>&1 sudo pear config-set php_ini "$ini_file" >/dev/null 2>&1
sudo pear config-set auto_discover 1 >/dev/null 2>&1 sudo pear config-set auto_discover 1 >/dev/null 2>&1
sudo pear channel-update pear.php.net >/dev/null 2>&1 sudo pear channel-update pear.php.net >/dev/null 2>&1
sudo pecl channel-update pecl.php.net >/dev/null 2>&1
add_log "$tick" "PECL" "Added" add_log "$tick" "PECL" "Added"
} }

View File

@ -35,7 +35,7 @@ Function Add-Extension {
) )
try { try {
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension } $extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
if ($null -ne $extension_info) { if ($null -ne $extension_info -and $mininum_stability -eq 'stable') {
switch ($extension_info.State) { switch ($extension_info.State) {
'Builtin' { 'Builtin' {
Add-Log $tick $extension "Enabled" Add-Log $tick $extension "Enabled"
@ -51,7 +51,11 @@ Function Add-Extension {
} }
else { else {
Install-PhpExtension -Extension $extension -MinimumStability $mininum_stability -Path $php_dir Install-PhpExtension -Extension $extension -MinimumStability $mininum_stability -Path $php_dir
Add-Log $tick $extension "Installed and enabled" if($mininum_stability -ne 'stable') {
Add-Log $tick "$extension-$mininum_stability" "Installed and enabled"
} else {
Add-Log $tick $extension "Installed and enabled"
}
} }
} }
catch { catch {
@ -151,7 +155,7 @@ Function Add-Composer-Tool() {
} }
Function Add-PECL() { Function Add-PECL() {
Add-Log $tick "PECL" "Use extensions input or Install-PhpExtension to setup PECL extensions on windows" Add-Log $tick "PECL" "Use extensions input to setup PECL extensions on windows"
} }
# Variables # Variables