Skip to content

Commit

Permalink
Fix zephir_parser on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Dec 28, 2024
1 parent 5bb2eed commit eebef15
Showing 1 changed file with 1 addition and 60 deletions.
61 changes: 1 addition & 60 deletions src/scripts/extensions/zephir_parser.ps1
Original file line number Diff line number Diff line change
@@ -1,62 +1,3 @@
# 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"
$nts = if (!$installed.ThreadSafe) { "nts" } else { "ts" }
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}-$nts-windows.*.zip)"
} catch {
$match = (Get-File -Url "$zp_releases/expanded_assets/$extension_version").Links.href | Select-String -Pattern "(zephir_parser-php-${version}-$nts-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 (Get-File -Url $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) {
Get-File -Url $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 (
Expand All @@ -71,7 +12,7 @@ Function Add-ZephirParser() {
Enable-PhpExtension -Extension zephir_parser -Path $php_dir
} else {
$status = 'Installed and enabled'
Add-ZephirParserFromGitHub $extension
Add-Extension zephir_parser $extension >$null 2>&1
}
Add-ExtensionLog zephir_parser $status
} catch {
Expand Down

0 comments on commit eebef15

Please sign in to comment.