129 lines
4.5 KiB
PowerShell
Raw Normal View History

# Function to get the url of the phalcon release asset.
Function Get-PhalconReleaseAssetUrl() {
2022-07-19 14:26:08 +05:30
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[string]
$Semver
)
2022-10-24 11:17:28 +05:30
$domain = 'https://api.github.com/repos'
$releases = 'phalcon/cphalcon/releases'
2024-03-25 06:33:54 +05:30
$match = $null
2022-12-25 21:52:32 +05:30
if($extension_version -match '[3-4]') {
$nts = if (!$installed.ThreadSafe) { "_nts" } else { "" }
try {
$match = (Invoke-RestMethod -Uri "$domain/$releases/tags/v$Semver").assets | Select-String -Pattern "browser_download_url=.*(phalcon_${arch}_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)"
2024-03-25 06:33:54 +05:30
} catch { }
if($null -eq $match) {
try {
$match = (Get-File -Url "$github/$releases/expanded_assets/v$Semver").Links.href | Select-String -Pattern "(phalcon_${arch}_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)"
} catch { }
2022-12-25 21:52:32 +05:30
}
} else {
2022-07-19 14:26:08 +05:30
$nts = if (!$installed.ThreadSafe) { "-nts" } else { "-ts" }
2022-12-25 21:52:32 +05:30
try {
2024-03-25 06:33:54 +05:30
$match = (Invoke-RestMethod -Uri "$domain/$releases/tags/v$Semver").assets | Select-String -Pattern "browser_download_url=.*(php_phalcon-php${version}${nts}-windows.*-x64.zip)"
} catch { }
if($null -eq $match) {
try {
$match = (Get-File -Url "$github/$releases/expanded_assets/v$Semver").Links.href | Select-String -Pattern "(php_phalcon-php${version}${nts}-windows.*-x64.zip)"
} catch { }
}
if($null -eq $match) {
try {
$match = (Invoke-RestMethod -Uri "$domain/$releases/tags/v$Semver").assets | Select-String -Pattern "browser_download_url=.*(phalcon-php${version}${nts}-windows.*-x64.zip)"
} catch { }
}
if($null -eq $match) {
try {
$match = (Get-File -Url "$github/$releases/expanded_assets/v$Semver").Links.href | Select-String -Pattern "(phalcon-php${version}${nts}-windows.*-x64.zip)"
} catch { }
2022-12-25 21:52:32 +05:30
}
2022-07-19 14:26:08 +05:30
}
if($NULL -ne $match) {
return "$github/$releases/download/v$Semver/$($match.Matches[0].Groups[1].Value)"
}
return false;
}
# Function to add phalcon using GitHub releases.
Function Add-PhalconFromGitHub() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[string]
$Semver
)
$zip_url = Get-PhalconReleaseAssetUrl $Semver
if($zip_url) {
Get-File -Url $zip_url -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip > $null 2>&1
2020-07-26 15:48:19 +05:30
Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\phalcon.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\phalcon -Force > $null 2>&1
Copy-Item -Path "$ENV:RUNNER_TOOL_CACHE\phalcon\php_phalcon.dll" -Destination "$ext_dir\php_phalcon.dll"
Enable-PhpExtension -Extension phalcon -Path $php_dir
2022-07-19 14:26:08 +05:30
} else {
throw "Unable to get Phalcon release from the GitHub release"
}
}
2022-10-24 11:17:28 +05:30
# Function to get phalcon semver.
Function Get-PhalconSemver() {
if($extension_version -eq '3') {
return '3.4.5'
} elseif (($extension_version -eq '4') -and ($version -eq '7.2')) {
return '4.1.0'
2024-03-25 06:33:54 +05:30
} elseif (($extension_version -eq '5') -and ($version -eq '7.4')) {
return '5.4.0'
2022-10-24 11:17:28 +05:30
}
return Get-PeclPackageVersion phalcon $extension_version stable stable | Select-Object -First 1
}
2022-07-19 14:26:08 +05:30
# Function to install phalcon
Function Add-PhalconHelper() {
2022-10-24 11:17:28 +05:30
$semver = Get-PhalconSemver
if (($extension_version -eq '3') -or ($extension_version -eq '5')) {
Add-PhalconFromGitHub $semver
} elseif ($extension_version -eq '4') {
Add-Extension -Extension phalcon -Stability stable -Extension_version $semver
2020-07-26 15:48:19 +05:30
}
}
2022-10-24 11:17:28 +05:30
# Function to add phalcon
2020-07-26 15:48:19 +05:30
Function Add-Phalcon() {
Param (
2019-12-26 18:31:18 +05:30
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
2022-07-19 14:26:08 +05:30
[ValidateSet('phalcon3', 'phalcon4', 'phalcon5')]
2019-12-26 18:31:18 +05:30
[string]
2020-07-26 15:48:19 +05:30
$extension
)
try {
$status = 'Enabled'
$extension_version = $extension.substring($extension.Length - 1)
2020-07-26 15:48:19 +05:30
if($extension_version -eq '4') {
if (Test-Path $ext_dir\php_psr.dll) {
Enable-PhpExtension -Extension psr -Path $php_dir
2020-07-26 15:48:19 +05:30
} else {
Install-Phpextension -Extension psr -MinimumStability stable -Path $php_dir
2020-07-26 15:48:19 +05:30
}
}
2020-07-26 15:48:19 +05:30
if(Test-Path $ext_dir\php_phalcon.dll) {
$phalcon = Get-PhpExtension $ext_dir\php_phalcon.dll
if($phalcon.Version[0] -eq $extension_version) {
Enable-PhpExtension -Extension phalcon -Path $php_dir
2020-07-26 15:48:19 +05:30
} else {
$status = 'Installed and enabled'
Remove-Item $ext_dir\php_phalcon.dll
2020-07-26 15:48:19 +05:30
Add-PhalconHelper
}
} else {
$status = 'Installed and enabled'
Add-PhalconHelper
}
2020-07-26 15:48:19 +05:30
Add-Log $tick $extension $status
} catch [Exception] {
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
}
}