diff --git a/__tests__/coverage.test.ts b/__tests__/coverage.test.ts index 3033d773..9b8d6b84 100644 --- a/__tests__/coverage.test.ts +++ b/__tests__/coverage.test.ts @@ -1,15 +1,9 @@ import * as coverage from '../src/coverage'; -jest.mock('../src/extensions', () => ({ - addExtension: jest.fn().mockImplementation(extension => { - return 'add_extension ' + extension + '\n'; - }) -})); - describe('Config tests', () => { it('checking addCoverage with PCOV on windows', async () => { let win32: string = await coverage.addCoverage('PCOV', '7.4', 'win32'); - expect(win32).toContain('add_extension pcov'); + expect(win32).toContain('Add-Extension pcov'); expect(win32).toContain('Remove-Extension xdebug'); win32 = await coverage.addCoverage('pcov', '7.0', 'win32'); @@ -27,24 +21,38 @@ describe('Config tests', () => { it('checking addCoverage with PCOV on darwin', async () => { const darwin: string = await coverage.addCoverage('pcov', '7.4', 'darwin'); - expect(darwin).toContain('add_extension pcov'); + expect(darwin).toContain('add_brew_extension pcov'); expect(darwin).toContain('remove_extension xdebug'); }); it('checking addCoverage with Xdebug on windows', async () => { const win32: string = await coverage.addCoverage('xdebug', '7.4', 'win32'); - expect(win32).toContain('add_extension xdebug'); + expect(win32).toContain('Add-Extension xdebug'); }); - it('checking addCoverage with Xdebug on linux', async () => { - const linux: string = await coverage.addCoverage('xdebug', '7.4', 'linux'); - expect(linux).toContain('add_extension xdebug'); + it('checking addCoverage with Xdebug3 on windows', async () => { + const win32: string = await coverage.addCoverage('xdebug3', '7.4', 'win32'); + expect(win32).toContain('Add-Extension xdebug'); + }); + + it('checking addCoverage with Xdebug2 on windows', async () => { + const win32: string = await coverage.addCoverage('xdebug2', '7.4', 'win32'); + expect(win32).toContain('Add-Extension xdebug stable 2.9.8'); }); it('checking addCoverage with Xdebug on linux', async () => { const linux: string = await coverage.addCoverage('xdebug', '8.0', 'linux'); expect(linux).toContain('add_extension xdebug'); - expect(linux).toContain('echo "xdebug.mode=coverage"'); + }); + + it('checking addCoverage with Xdebug3 on linux', async () => { + const linux: string = await coverage.addCoverage('xdebug3', '8.0', 'linux'); + expect(linux).toContain('add_extension xdebug'); + }); + + it('checking addCoverage with Xdebug2 on linux', async () => { + const linux: string = await coverage.addCoverage('xdebug2', '7.4', 'linux'); + expect(linux).toContain('add_pecl_extension xdebug 2.9.8 zend_extension'); }); it('checking addCoverage with Xdebug on darwin', async () => { @@ -53,7 +61,25 @@ describe('Config tests', () => { '7.4', 'darwin' ); - expect(darwin).toContain('add_extension xdebug'); + expect(darwin).toContain('add_brew_extension xdebug'); + }); + + it('checking addCoverage with Xdebug3 on darwin', async () => { + const darwin: string = await coverage.addCoverage( + 'xdebug3', + '7.4', + 'darwin' + ); + expect(darwin).toContain('add_brew_extension xdebug'); + }); + + it('checking addCoverage with Xdebug2 on darwin', async () => { + const darwin: string = await coverage.addCoverage( + 'xdebug2', + '7.4', + 'darwin' + ); + expect(darwin).toContain('add_brew_extension xdebug2'); }); it('checking disableCoverage windows', async () => { diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 450c3412..834af2d6 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -13,7 +13,7 @@ describe('Extension tests', () => { expect(win32).toContain('phalcon.ps1 phalcon4'); expect(win32).toContain('Add-Extension ast beta'); - win32 = await extensions.addExtension('xdebug', '7.2', 'win32'); + win32 = await extensions.addExtension('xdebug2', '7.2', 'win32'); expect(win32).toContain('Add-Extension xdebug stable 2.9.8'); win32 = await extensions.addExtension('mysql', '7.4', 'win32'); @@ -71,7 +71,7 @@ describe('Extension tests', () => { linux = await extensions.addExtension('gearman', '7.4', 'linux'); expect(linux).toContain('gearman.sh 7.4'); - linux = await extensions.addExtension('xdebug', '7.2', 'linux'); + linux = await extensions.addExtension('xdebug2', '7.2', 'linux'); expect(linux).toContain('add_pecl_extension xdebug 2.9.8 zend_extension'); linux = await extensions.addExtension('xdebug', '7.2', 'openbsd'); @@ -119,12 +119,6 @@ describe('Extension tests', () => { darwin = await extensions.addExtension('xdebug', '7.2', 'darwin'); expect(darwin).toContain('add_brew_extension xdebug'); - darwin = await extensions.addExtension('redis', '5.6', 'darwin'); - expect(darwin).toContain('pecl_install redis-2.2.8'); - - darwin = await extensions.addExtension('redis', '7.2', 'darwin'); - expect(darwin).toContain('pecl_install redis'); - darwin = await extensions.addExtension( 'does_not_exist', '7.2', diff --git a/dist/index.js b/dist/index.js index d6b01187..bfaeda9f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1256,14 +1256,11 @@ exports.CSVArray = CSVArray; * @param extension */ async function getExtensionPrefix(extension) { - const zend = ['xdebug', 'opcache', 'ioncube', 'eaccelerator']; - switch (zend.indexOf(extension)) { - case 0: - case 1: - return 'zend_extension'; - case -1: + switch (true) { default: return 'extension'; + case /xdebug([2-3])?$|opcache|ioncube|eaccelerator/.test(extension): + return 'zend_extension'; } } exports.getExtensionPrefix = getExtensionPrefix; @@ -2141,18 +2138,11 @@ exports.addCoverage = exports.disableCoverage = exports.addCoveragePCOV = export const utils = __importStar(__webpack_require__(163)); const extensions = __importStar(__webpack_require__(911)); const config = __importStar(__webpack_require__(641)); -/** - * Function to setup Xdebug - * - * @param version - * @param os_version - * @param pipe - */ -async function addCoverageXdebug(version, os_version, pipe) { - const xdebug = (await extensions.addExtension('xdebug', version, os_version, true)) + pipe; - const ini = await config.addINIValues('xdebug.mode=coverage', os_version, true); - const log = await utils.addLog('$tick', 'xdebug', 'Xdebug enabled as coverage driver', os_version); - return xdebug + '\n' + ini + '\n' + log; +async function addCoverageXdebug(extension, version, os_version, pipe) { + const xdebug = (await extensions.addExtension(extension, version, os_version, true)) + + pipe; + const log = await utils.addLog('$tick', extension, 'Xdebug enabled as coverage driver', os_version); + return xdebug + '\n' + log; } exports.addCoverageXdebug = addCoverageXdebug; /** @@ -2233,7 +2223,10 @@ async function addCoverage(coverage_driver, version, os_version) { case 'pcov': return script + (await addCoveragePCOV(version, os_version, pipe)); case 'xdebug': - return script + (await addCoverageXdebug(version, os_version, pipe)); + case 'xdebug3': + return (script + (await addCoverageXdebug('xdebug', version, os_version, pipe))); + case 'xdebug2': + return (script + (await addCoverageXdebug('xdebug2', version, os_version, pipe))); case 'none': return script + (await disableCoverage(version, os_version, pipe)); default: @@ -2284,7 +2277,7 @@ async function addINIValuesUnix(ini_values_csv) { script += (await utils.addLog('$tick', line, 'Added to php.ini', 'linux')) + '\n'; }); - return 'echo "' + ini_values.join('\n') + '" >> $ini_file' + script; + return ('echo "' + ini_values.join('\n') + '" >> ${pecl_file:-$ini_file}' + script); } exports.addINIValuesUnix = addINIValuesUnix; /** @@ -2721,18 +2714,12 @@ async function addExtensionDarwin(extension_csv, version) { ' ' + ext_prefix; return; - // match 5.6xdebug to 8.0xdebug, 5.6igbinary to 8.0igbinary - // match 5.6grpc to 7.4grpc, 5.6imagick to 7.4imagick, 5.6protobuf to 7.4protobuf, 5.6swoole to 7.4swoole + // match 5.6 to 8.0 amqp, grpc, igbinary, imagick, imap, msgpack, pecl_http, propro, protobuf, raphf, redis, swoole, xdebug, xdebug2, zmq // match 7.1pcov to 8.0pcov - case /(5\.6|7\.[0-4]|8\.0)(xdebug|igbinary)/.test(version_extension): - case /(5\.6|7\.[0-4])(grpc|imagick|protobuf|swoole)/.test(version_extension): + case /(5\.6|7\.[0-4]|8.0)(amqp|grpc|igbinary|imagick|imap|msgpack|^(pecl_)?http$|propro|protobuf|raphf|redis|swoole|xdebug|xdebug2|zmq)/.test(version_extension): case /(7\.[1-4]|8\.0])pcov/.test(version_extension): command = 'add_brew_extension ' + extension_name; break; - // match 5.6redis - case /5\.6redis/.test(version_extension): - command = command_prefix + 'redis-2.2.8'; - break; // match sqlite case /^sqlite$/.test(extension): extension = 'sqlite3'; @@ -2786,7 +2773,7 @@ async function addExtensionWindows(extension_csv, version) { '\nAdd-Extension mysql\nAdd-Extension mysqli\nAdd-Extension mysqlnd'; break; // match 7.2xdebug - case /7\.2xdebug/.test(version_extension): + case /7\.[2-4]xdebug2/.test(version_extension): script += '\nAdd-Extension xdebug stable 2.9.8'; break; // match 7.0mysql..8.0mysql @@ -2866,7 +2853,7 @@ async function addExtensionLinux(extension_csv, version, pipe) { version; return; // match 7.2xdebug - case /^7\.2xdebug$/.test(version_extension): + case /^7\.[2-4]xdebug2$/.test(version_extension): script += '\nadd_pecl_extension xdebug 2.9.8 ' + ext_prefix; return; // match sqlite diff --git a/src/config.ts b/src/config.ts index b6fa736e..c92f3408 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,7 +14,9 @@ export async function addINIValuesUnix( script += (await utils.addLog('$tick', line, 'Added to php.ini', 'linux')) + '\n'; }); - return 'echo "' + ini_values.join('\n') + '" >> $ini_file' + script; + return ( + 'echo "' + ini_values.join('\n') + '" >> ${pecl_file:-$ini_file}' + script + ); } /** diff --git a/src/coverage.ts b/src/coverage.ts index 60a7043f..4c8456a2 100644 --- a/src/coverage.ts +++ b/src/coverage.ts @@ -2,32 +2,22 @@ import * as utils from './utils'; import * as extensions from './extensions'; import * as config from './config'; -/** - * Function to setup Xdebug - * - * @param version - * @param os_version - * @param pipe - */ export async function addCoverageXdebug( + extension: string, version: string, os_version: string, pipe: string ): Promise { const xdebug = - (await extensions.addExtension('xdebug', version, os_version, true)) + pipe; - const ini = await config.addINIValues( - 'xdebug.mode=coverage', - os_version, - true - ); + (await extensions.addExtension(extension, version, os_version, true)) + + pipe; const log = await utils.addLog( '$tick', - 'xdebug', + extension, 'Xdebug enabled as coverage driver', os_version ); - return xdebug + '\n' + ini + '\n' + log; + return xdebug + '\n' + log; } /** @@ -140,7 +130,14 @@ export async function addCoverage( case 'pcov': return script + (await addCoveragePCOV(version, os_version, pipe)); case 'xdebug': - return script + (await addCoverageXdebug(version, os_version, pipe)); + case 'xdebug3': + return ( + script + (await addCoverageXdebug('xdebug', version, os_version, pipe)) + ); + case 'xdebug2': + return ( + script + (await addCoverageXdebug('xdebug2', version, os_version, pipe)) + ); case 'none': return script + (await disableCoverage(version, os_version, pipe)); default: diff --git a/src/extensions.ts b/src/extensions.ts index 95d4e2ed..5ee65340 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -30,20 +30,14 @@ export async function addExtensionDarwin( ' ' + ext_prefix; return; - // match 5.6xdebug to 8.0xdebug, 5.6igbinary to 8.0igbinary - // match 5.6grpc to 7.4grpc, 5.6imagick to 7.4imagick, 5.6protobuf to 7.4protobuf, 5.6swoole to 7.4swoole + // match 5.6 to 8.0 amqp, grpc, igbinary, imagick, imap, msgpack, pecl_http, propro, protobuf, raphf, redis, swoole, xdebug, xdebug2, zmq // match 7.1pcov to 8.0pcov - case /(5\.6|7\.[0-4]|8\.0)(xdebug|igbinary)/.test(version_extension): - case /(5\.6|7\.[0-4])(grpc|imagick|protobuf|swoole)/.test( + case /(5\.6|7\.[0-4]|8.0)(amqp|grpc|igbinary|imagick|imap|msgpack|^(pecl_)?http$|propro|protobuf|raphf|redis|swoole|xdebug|xdebug2|zmq)/.test( version_extension ): case /(7\.[1-4]|8\.0])pcov/.test(version_extension): command = 'add_brew_extension ' + extension_name; break; - // match 5.6redis - case /5\.6redis/.test(version_extension): - command = command_prefix + 'redis-2.2.8'; - break; // match sqlite case /^sqlite$/.test(extension): extension = 'sqlite3'; @@ -100,7 +94,7 @@ export async function addExtensionWindows( '\nAdd-Extension mysql\nAdd-Extension mysqli\nAdd-Extension mysqlnd'; break; // match 7.2xdebug - case /7\.2xdebug/.test(version_extension): + case /7\.[2-4]xdebug2/.test(version_extension): script += '\nAdd-Extension xdebug stable 2.9.8'; break; // match 7.0mysql..8.0mysql @@ -184,7 +178,7 @@ export async function addExtensionLinux( version; return; // match 7.2xdebug - case /^7\.2xdebug$/.test(version_extension): + case /^7\.[2-4]xdebug2$/.test(version_extension): script += '\nadd_pecl_extension xdebug 2.9.8 ' + ext_prefix; return; // match sqlite diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 058d975c..c36aebd5 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -148,7 +148,7 @@ add_tool() { status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url") fi if [ "$status_code" != "200" ] && [[ "$url" =~ .*github.com.*releases.*latest.* ]]; then - url=$(echo $url | sed -e "s|releases/latest/download|releases/download/$(curl "${curl_opts[@]}" "$(echo "$url" | cut -d '/' -f '1-5')/releases" | grep -Eo -m 1 "([0-9]+\.[0-9]+\.[0-9]+)/$(echo "$url" | sed -e "s/.*\///")" | cut -d '/' -f 1)|") + url="${url//releases\/latest\/download/releases/download/$(curl "${curl_opts[@]}" "$(echo "$url" | cut -d '/' -f '1-5')/releases" | grep -Eo -m 1 "([0-9]+\.[0-9]+\.[0-9]+)/$(echo "$url" | sed -e "s/.*\///")" | cut -d '/' -f 1)}" status_code=$(sudo curl -w "%{http_code}" -o "$tool_path" "${curl_opts[@]}" "$url") fi if [ "$status_code" = "200" ]; then @@ -221,6 +221,15 @@ setup_php() { brew link --force --overwrite php@"$version" } +# Function to configure PHP +configure_php() { + ( + echo -e "date.timezone=UTC\nmemory_limit=-1" + [[ "$version" =~ 8.0 ]] && echo -e "opcache.enable=1\nopcache.jit_buffer_size=256M\nopcache.jit=1235" + [[ "$version" =~ 7.[2-4]|8.0 ]] && echo -e "xdebug.mode=coverage" + ) | sudo tee -a "$ini_file" >/dev/null +} + # Variables tick="✓" cross="✗" @@ -241,7 +250,7 @@ else fi ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") sudo chmod 777 "$ini_file" "$tool_path_dir" -echo -e "date.timezone=UTC\nmemory_limit=-1" >>"$ini_file" +configure_php ext_dir=$(php -i | grep -Ei "extension_dir => /" | sed -e "s|.*=> s*||") scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||") sudo mkdir -m 777 -p "$ext_dir" "$HOME/.composer" diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index 891dac39..a5b6018a 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -103,12 +103,8 @@ add_extension() { elif check_extension "$extension"; then add_log "$tick" "$extension" "Enabled" elif ! check_extension "$extension"; then - if [ "$version" = "8.0" ]; then - pecl_install "$extension" - else - eval "$install_command" >/dev/null 2>&1 || - (update_lists && eval "$install_command" >/dev/null 2>&1) || pecl_install "$extension" - fi + eval "$install_command" >/dev/null 2>&1 || + (update_lists && eval "$install_command" >/dev/null 2>&1) || pecl_install "$extension" (check_extension "$extension" && add_log "$tick" "$extension" "Installed and enabled") || add_log "$cross" "$extension" "Could not install $extension on PHP $semver" fi @@ -258,6 +254,15 @@ php_semver() { fi } +# Function to configure PHP +configure_php() { + ( + echo -e "date.timezone=UTC\nmemory_limit=-1" + [[ "$version" =~ 8.0 ]] && echo -e "opcache.enable=1\nopcache.jit_buffer_size=256M\nopcache.jit=1235" + [[ "$version" =~ 7.[2-4]|8.0 ]] && echo -e "xdebug.mode=coverage" + ) | sudo tee -a "$pecl_file" >/dev/null +} + # Variables tick="✓" cross="✗" @@ -308,6 +313,7 @@ ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||") pecl_file="$scan_dir"/99-pecl.ini echo '' | sudo tee "$pecl_file" >/dev/null 2>&1 +configure_php sudo rm -rf /usr/local/bin/phpunit >/dev/null 2>&1 sudo chmod 777 "$ini_file" "$pecl_file" "$tool_path_dir" sudo cp "$dist"/../src/configs/*.json "$RUNNER_TOOL_CACHE/" diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index 60fd091e..7e5d4b93 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -300,8 +300,11 @@ if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version } $installed = Get-Php -Path $php_dir -Set-PhpIniKey -Key 'date.timezone' -Value 'UTC' -Path $php_dir -Set-PhpIniKey -Key 'memory_limit' -Value '-1' -Path $php_dir +('date.timezone=UTC', 'memory_limit=-1', 'xdebug.mode=coverage') | ForEach-Object { $p=$_.split('='); Set-PhpIniKey -Key $p[0] -Value $p[1] -Path $php_dir } +# Patch till there is a pcov DLL for PHP 8.0 on pecl +if ($version -eq '8.0') { + Invoke-WebRequest -Uri "https://github.com/shivammathur/php-extensions-windows/releases/latest/download/php$version`_$env:PHPTS`_$arch`_pcov.dll" -OutFile $php_dir"\ext\php`_pcov.dll" +} Enable-PhpExtension -Extension openssl, curl, opcache, mbstring -Path $php_dir Update-PhpCAInfo -Path $php_dir -Source CurrentUser Copy-Item -Path $dist\..\src\configs\*.json -Destination $env:RUNNER_TOOL_CACHE diff --git a/src/utils.ts b/src/utils.ts index e119abd0..4312734a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -243,14 +243,11 @@ export async function CSVArray(values_csv: string): Promise> { * @param extension */ export async function getExtensionPrefix(extension: string): Promise { - const zend: Array = ['xdebug', 'opcache', 'ioncube', 'eaccelerator']; - switch (zend.indexOf(extension)) { - case 0: - case 1: - return 'zend_extension'; - case -1: + switch (true) { default: return 'extension'; + case /xdebug([2-3])?$|opcache|ioncube|eaccelerator/.test(extension): + return 'zend_extension'; } }