diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 1ffe93a5..a1a8f738 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -3,13 +3,14 @@ import * as extensions from '../src/extensions'; describe('Extension tests', () => { it('checking addExtensionOnWindows', async () => { let win32: string = await extensions.addExtension( - 'xdebug, pcov, phalcon4', + 'xdebug, pcov, phalcon4, ast-beta', '7.4', 'win32' ); expect(win32).toContain('Add-Extension xdebug'); expect(win32).toContain('Add-Extension pcov'); expect(win32).toContain('phalcon.ps1 phalcon4'); + expect(win32).toContain('Add-Extension ast beta'); win32 = await extensions.addExtension( 'phalcon3, does_not_exist', @@ -26,7 +27,7 @@ describe('Extension tests', () => { it('checking addExtensionOnLinux', async () => { let linux: string = await extensions.addExtension( - 'xdebug, pcov', + 'xdebug, pcov, ast-beta', '7.4', 'linux' ); @@ -34,7 +35,8 @@ describe('Extension tests', () => { expect(linux).toContain( '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'); expect(linux).toContain('gearman.sh 7.0'); @@ -60,12 +62,13 @@ describe('Extension tests', () => { it('checking addExtensionOnDarwin', async () => { let darwin: string = await extensions.addExtension( - 'xdebug, pcov', + 'xdebug, pcov, ast-beta', '7.2', 'darwin' ); - expect(darwin).toContain('sudo pecl install xdebug'); - expect(darwin).toContain('sudo pecl install pcov'); + expect(darwin).toContain('sudo pecl install -f xdebug'); + expect(darwin).toContain('sudo pecl install -f pcov'); + expect(darwin).toContain('install_extension ast-beta'); darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin'); 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'); 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'); - expect(darwin).toContain('sudo pecl install pcov'); + expect(darwin).toContain('sudo pecl install -f pcov'); 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'); - 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'); - expect(darwin).toContain('sudo pecl install xdebug'); + expect(darwin).toContain('sudo pecl install -f xdebug'); 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'); - expect(darwin).toContain('sudo pecl install redis'); + expect(darwin).toContain('sudo pecl install -f redis'); darwin = await extensions.addExtension('imagick', '5.6', 'darwin'); 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'); 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( 'does_not_exist', diff --git a/dist/index.js b/dist/index.js index bdfc545e..f1681f78 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2284,7 +2284,8 @@ function build(filename, version, os_version) { const coverage_driver = yield utils.getInput('coverage', false); const pecl = yield utils.getInput('pecl', 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; } 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* () { extension = extension.toLowerCase(); const version_extension = version + extension; - // add script to enable extension is already installed along with php let install_command = ''; 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): - install_command = 'sudo pecl install xdebug-2.5.5' + pipe; + install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe; break; 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; 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; case /[5-9]\.\dimagick/.test(version_extension): install_command = 'brew install pkg-config imagemagick' + pipe + - ' && sudo pecl install imagick' + + ' && sudo pecl install -f imagick' + pipe; break; case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): @@ -2623,7 +2627,7 @@ function addExtensionDarwin(extension_csv, version, pipe) { pipe; break; default: - install_command = 'sudo pecl install ' + extension + pipe; + install_command = 'sudo pecl install -f ' + extension + pipe; break; } script += @@ -2652,9 +2656,14 @@ function addExtensionWindows(extension_csv, version, pipe) { let script = '\n'; yield utils.asyncForEach(extensions, function (extension) { 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; 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 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): script += @@ -2690,10 +2699,13 @@ function addExtensionLinux(extension_csv, version, pipe) { yield utils.asyncForEach(extensions, function (extension) { return __awaiter(this, void 0, void 0, function* () { extension = extension.toLowerCase(); - // add script to enable extension is already installed along with php const version_extension = version + extension; let install_command = ''; 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 case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): install_command = @@ -2728,7 +2740,7 @@ function addExtensionLinux(extension_csv, version, pipe) { '-' + extension.replace('pdo_', '').replace('pdo-', '') + pipe + - ' || sudo pecl install ' + + ' || sudo pecl install -f ' + extension + pipe; break; diff --git a/src/extensions.ts b/src/extensions.ts index 28b3bedb..96c7fa60 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -18,23 +18,26 @@ export async function addExtensionDarwin( await utils.asyncForEach(extensions, async function(extension: string) { extension = extension.toLowerCase(); const version_extension: string = version + extension; - // add script to enable extension is already installed along with php let install_command = ''; 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): - install_command = 'sudo pecl install xdebug-2.5.5' + pipe; + install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe; break; 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; 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; case /[5-9]\.\dimagick/.test(version_extension): install_command = 'brew install pkg-config imagemagick' + pipe + - ' && sudo pecl install imagick' + + ' && sudo pecl install -f imagick' + pipe; break; case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): @@ -48,7 +51,7 @@ export async function addExtensionDarwin( pipe; break; default: - install_command = 'sudo pecl install ' + extension + pipe; + install_command = 'sudo pecl install -f ' + extension + pipe; break; } script += @@ -77,9 +80,14 @@ export async function addExtensionWindows( const extensions: Array = await utils.extensionArray(extension_csv); let script = '\n'; 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; 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 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): script += @@ -115,10 +123,13 @@ export async function addExtensionLinux( let script = '\n'; await utils.asyncForEach(extensions, async function(extension: string) { extension = extension.toLowerCase(); - // add script to enable extension is already installed along with php const version_extension: string = version + extension; let install_command = ''; 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 case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): install_command = @@ -153,7 +164,7 @@ export async function addExtensionLinux( '-' + extension.replace('pdo_', '').replace('pdo-', '') + pipe + - ' || sudo pecl install ' + + ' || sudo pecl install -f ' + extension + pipe; break; diff --git a/src/install.ts b/src/install.ts index ba2b68ad..1bd8cf79 100644 --- a/src/install.ts +++ b/src/install.ts @@ -29,7 +29,10 @@ export async function build( const coverage_driver: string = await utils.getInput('coverage', false); const pecl: string = await utils.getInput('pecl', 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; } diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index c584da3a..7a060163 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -26,20 +26,21 @@ add_extension() { elif php -m | grep -i -q -w "$extension"; then add_log "$tick" "$extension" "Enabled" 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) - if [ "$exists" = "200" ] || [[ "$extension" == "phalcon"* ]]; then - ( - 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 + (eval "$install_command" && add_log "$tick" "$extension" "Installed and enabled") || + add_log "$cross" "$extension" "Could not install $extension on PHP $semver" 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 remove_extension() { extension=$1 @@ -79,13 +80,17 @@ add_composer_tool() { release=$2 prefix=$3 ( - composer global require "$prefix$release" >/dev/null 2>&1 && \ - sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" && \ - add_log "$tick" "$tool" "Added" + composer global require "$prefix$release" >/dev/null 2>&1 && \ + sudo ln -sf "$(composer -q global config home)"/vendor/bin/"$tool" /usr/local/bin/"$tool" && \ + add_log "$tick" "$tool" "Added" ) || add_log "$cross" "$tool" "Could not setup $tool" } 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" } @@ -106,7 +111,7 @@ version=$1 step_log "Setup PHP" setup_php_and_composer 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*||") sudo chmod 777 "$ini_file" mkdir -p "$(pecl config-get ext_dir)" diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index fe2d2815..54c7bf80 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -40,6 +40,16 @@ add_extension() { 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 remove_extension() { extension=$1 @@ -125,14 +135,12 @@ setup_master() { # Function to setup PECL add_pecl() { - update_ppa add_devtools - 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 rm -rf install-pear-nozlib.phar >/dev/null 2>&1 + $apt_install php-pear >/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 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" } diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 19772ade..06624013 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -35,7 +35,7 @@ Function Add-Extension { ) try { $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) { 'Builtin' { Add-Log $tick $extension "Enabled" @@ -51,7 +51,11 @@ Function Add-Extension { } else { 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 { @@ -151,7 +155,7 @@ Function Add-Composer-Tool() { } 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