From 7abee8e28c06b766cef0828e207a8279bc8f111e Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sun, 22 Jan 2023 02:04:12 +0530 Subject: [PATCH] Add custom support for zephir parser --- README.md | 2 +- __tests__/extensions.test.ts | 3 + dist/index.js | 3 + src/extensions.ts | 12 ++++ src/scripts/extensions/zephir_parser.ps1 | 79 ++++++++++++++++++++++++ src/scripts/extensions/zephir_parser.sh | 37 +++++++++++ 6 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 src/scripts/extensions/zephir_parser.ps1 create mode 100644 src/scripts/extensions/zephir_parser.sh diff --git a/README.md b/README.md index 5f308304..67deaaac 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,7 @@ PHP extensions can be set up using the `extensions` input. It accepts a `string` - These extensions have custom support: - `cubrid` and `pdo_cubrid` on `Ubuntu`. - `event`, `gearman`, `geos` and `relay` on `Ubuntu` and `macOS`. - - `blackfire`, `couchbase`, `ioncube`, `oci8`, `pdo_firebird`, `pdo_oci`, `pecl_http`, `phalcon3`, `phalcon4` and `phalcon5` on all supported OS. + - `blackfire`, `couchbase`, `ioncube`, `oci8`, `pdo_firebird`, `pdo_oci`, `pecl_http`, `phalcon3`, `phalcon4`, `phalcon5`, and `zephir_parser` on all supported OS. - By default, extensions which cannot be added or disabled gracefully leave an error message in the logs, the execution is not interrupted. To change this behaviour you can set `fail-fast` flag to `true`. diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 7800bf5b..019f41af 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -25,6 +25,7 @@ describe('Extension tests', () => { ${'sqlsrv-1.2.3preview1'} | ${'7.4'} | ${'Add-Extension sqlsrv devel 1.2.3'} ${'Xdebug'} | ${'7.4'} | ${'Add-Extension xdebug'} ${'xdebug2'} | ${'7.2'} | ${'Add-Extension xdebug stable 2.9.8'} + ${'zephir_parser'} | ${'7.2'} | ${'Add-ZephirParser zephir_parser'} `( 'checking addExtensionOnWindows for extension $extension on version $version', async ({extension, version, output}) => { @@ -66,6 +67,7 @@ describe('Extension tests', () => { ${'Xdebug'} | ${'7.4'} | ${'add_extension xdebug'} ${'xdebug-alpha'} | ${'7.4'} | ${'add_unstable_extension xdebug alpha zend_extension'} ${'xdebug2'} | ${'7.2'} | ${'add_pecl_extension xdebug 2.9.8 zend_extension'} + ${'zephir_parser-1.2.3'} | ${'7.2'} | ${'add_zephir_parser zephir_parser-1.2.3'} `( 'checking addExtensionOnLinux for extension $extension on version $version', async ({extension, version, output}) => { @@ -96,6 +98,7 @@ describe('Extension tests', () => { ${'pecl_http'} | ${'7.3'} | ${'add_http'} ${'relay-1.2.3'} | ${'7.4'} | ${'add_relay relay-1.2.3'} ${'sqlite'} | ${'7.2'} | ${'add_extension sqlite3'} + ${'zephir_parser-v1.2.3'} | ${'7.2'} | ${'add_zephir_parser zephir_parser-v1.2.3'} `( 'checking addExtensionOnDarwin for extension $extension on version $version', async ({extension, version, output}) => { diff --git a/dist/index.js b/dist/index.js index 875c7ed5..d99edb22 100644 --- a/dist/index.js +++ b/dist/index.js @@ -254,6 +254,7 @@ async function addExtensionDarwin(extension_csv, version) { case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension): case /(5\.6|7\.[0-3])phalcon3|7\.[2-4]phalcon4|(7\.4|8\.[0-2])phalcon5/.test(version_extension): case /(? $null 2>&1 + Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\zp.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\zp -Force > $null 2>&1 + Copy-Item -Path "$ENV:RUNNER_TOOL_CACHE\zp\php_zephir_parser.dll" -Destination "$ext_dir\php_zephir_parser.dll" + Enable-PhpExtension -Extension zephir_parser -Path $php_dir + } else { + throw "Unable to get zephir_parser release from the GitHub repo" + } +} + +# Function to add zephir parser. +Function Add-ZephirParser() { + Param ( + [Parameter(Position = 0, Mandatory = $true)] + [ValidateNotNull()] + [string] + $extension + ) + try { + $status = 'Enabled' + if (Test-Path $ext_dir\php_zephir_parser.dll) { + Enable-PhpExtension -Extension zephir_parser -Path $php_dir + } else { + $status = 'Installed and enabled' + Add-ZephirParserFromGitHub $extension + } + Add-ExtensionLog zephir_parser $status + } catch { + Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)" + } +} diff --git a/src/scripts/extensions/zephir_parser.sh b/src/scripts/extensions/zephir_parser.sh new file mode 100644 index 00000000..9ad6130e --- /dev/null +++ b/src/scripts/extensions/zephir_parser.sh @@ -0,0 +1,37 @@ +# Get zephir_parser version +get_zephir_parser_version() { + local ext=$1 + if [[ "$ext" =~ ^zephir_parser$ ]]; then + get -s -n "" "${zp_releases:?}"/latest 2<&1 | grep -m 1 -Eo "tag/(v?[0-9]+(\.[0-9]+)?(\.[0-9]+)?)" | head -n 1 | cut -d '/' -f 2 + else + zp_version="${ext##*-}" + echo "v${zp_version/v//}" + fi +} + +# Add zephir_parser helper +add_zephir_parser_helper() { + local ext=$1 + ext_version=$(get_zephir_parser_version "$ext") + [ "$(uname -s)" = "Linux" ] && os_suffix=ubuntu || os_suffix=macos + build_name=$(get -s -n "" https://api.github.com/repos/"$repo"/releases/tags/"$ext_version" | grep -Eo "zephir_parser-php-${version:?}.*$os_suffix-.*.zip" | head -n 1) + [ -z "$build_name" ] && build_name=$(get -s -n "" "$zp_releases"/expanded_assets/"$ext_version" | grep -Eo "zephir_parser-php-${version:?}.*$os_suffix-.*.zip" | head -n 1) + get -q -e "/tmp/zp.zip" "$zp_releases"/download/"$ext_version"/"$build_name" + sudo unzip -o "/tmp/zp.zip" -d "${ext_dir:?}" + enable_extension zephir_parser extension +} + +# Add zephir_parser +add_zephir_parser() { + ext=$1 + repo=zephir-lang/php-zephir-parser + zp_releases=https://github.com/"$repo"/releases + if ! shared_extension zephir_parser; then + message='Installed and enabled' + add_zephir_parser_helper "$ext" >/dev/null 2>&1 + else + message='Enabled' + enable_extension zephir_parser extension + fi + add_extension_log zephir_parser "$message" +} \ No newline at end of file