-
-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom support for zephir parser
- Loading branch information
1 parent
dd01156
commit 7abee8e
Showing
6 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Function to get the url of the phalcon release asset. | ||
Function Get-ZephirParserReleaseAssetUrl() { | ||
Param ( | ||
[Parameter(Position = 0, Mandatory = $true)] | ||
[ValidateNotNull()] | ||
[string] | ||
$extension_version | ||
) | ||
$repo = 'zephir-lang/php-zephir-parser' | ||
$zp_releases = "$github/$repo/releases" | ||
try { | ||
$match = (Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/tags/$extension_version").assets | Select-String -Pattern "browser_download_url=.*(zephir_parser-php-${version}.*windows.*.zip)" | ||
} catch { | ||
$match = (Invoke-WebRequest -Uri "$zp_releases/expanded_assets/$extension_version").Links.href | Select-String -Pattern "(zephir_parser-php-${version}.*windows.*.zip)" | ||
} | ||
if($NULL -ne $match) { | ||
return "$zp_releases/download/$extension_version/$($match.Matches[0].Groups[1].Value)" | ||
} | ||
return false; | ||
} | ||
|
||
# Function to get zephir parser version using GitHub releases. | ||
Function Get-ZephirParserVersion() { | ||
Param ( | ||
[Parameter(Position = 0, Mandatory = $true)] | ||
[ValidateNotNull()] | ||
[string] | ||
$extension | ||
) | ||
$repo = 'zephir-lang/php-zephir-parser' | ||
$zp_releases = "$github/$repo/releases" | ||
if($extension -eq 'zephir_parser') { | ||
return (Invoke-WebRequest -UseBasicParsing -Uri $zp_releases/latest).BaseResponse.RequestMessage.RequestUri.Segments[-1] | ||
} else { | ||
return 'v' + ($extension.split('-')[1] -replace 'v') | ||
} | ||
} | ||
|
||
# Function to add zephir parser using GitHub releases. | ||
Function Add-ZephirParserFromGitHub() { | ||
Param ( | ||
[Parameter(Position = 0, Mandatory = $true)] | ||
[ValidateNotNull()] | ||
[string] | ||
$extension | ||
) | ||
$extension_version = Get-ZephirParserVersion $extension | ||
$zip_url = Get-ZephirParserReleaseAssetUrl $extension_version | ||
if($zip_url) { | ||
Invoke-WebRequest -Uri $zip_url -OutFile $ENV:RUNNER_TOOL_CACHE\zp.zip > $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)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |