mirror of
				https://github.com/shivammathur/setup-php.git
				synced 2025-10-31 07:16:22 +07:00 
			
		
		
		
	Improve extension support
Add support for xdebug2 coverage
This commit is contained in:
		| @ -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 | ||||
|   ); | ||||
| } | ||||
|  | ||||
| /** | ||||
|  | ||||
| @ -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<string> { | ||||
|   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: | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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" | ||||
|  | ||||
| @ -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/" | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -243,14 +243,11 @@ export async function CSVArray(values_csv: string): Promise<Array<string>> { | ||||
|  * @param extension | ||||
|  */ | ||||
| export async function getExtensionPrefix(extension: string): Promise<string> { | ||||
|   const zend: Array<string> = ['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'; | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Shivam Mathur
					Shivam Mathur