Refactor scripts to enable pre-existing ext-phalcon

This commit is contained in:
Shivam Mathur 2020-01-21 17:58:09 +05:30
parent 898b6fa1f9
commit 63c4aea452
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
6 changed files with 153 additions and 34 deletions

View File

@ -52,6 +52,10 @@ describe('Extension tests', () => {
linux = await extensions.addExtension('xdebug', '7.2', 'fedora');
expect(linux).toContain('Platform fedora is not supported');
linux = await extensions.addExtension('phalcon3, phalcon4', '7.3', 'linux');
expect(linux).toContain('phalcon.sh phalcon3 7.3');
expect(linux).toContain('phalcon.sh phalcon4 7.3');
});
it('checking addExtensionOnDarwin', async () => {

9
dist/index.js vendored
View File

@ -2703,6 +2703,15 @@ function addExtensionLinux(extension_csv, version, pipe) {
version +
pipe;
break;
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script +=
'\nsh ' +
path.join(__dirname, '../src/scripts/ext/phalcon.sh') +
' ' +
extension +
' ' +
version;
return;
// match 7.0xdebug..7.4xdebug
case /^7\.[0-4]xdebug$/.test(version_extension):
script +=

View File

@ -128,6 +128,15 @@ export async function addExtensionLinux(
version +
pipe;
break;
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script +=
'\nsh ' +
path.join(__dirname, '../src/scripts/ext/phalcon.sh') +
' ' +
extension +
' ' +
version;
return;
// match 7.0xdebug..7.4xdebug
case /^7\.[0-4]xdebug$/.test(version_extension):
script +=

View File

@ -10,22 +10,46 @@ Param (
[string]
$version
)
Function Install-Phalcon() {
if ($extension_version -eq '4') {
Install-Phpextension phalcon -MinimumStability stable -Path $php_dir
} else {
$installed = Get-Php -Path $php_dir
$nts = if (!$installed.ThreadSafe) { "_nts" } else { "" }
$match = Invoke-WebRequest -UseBasicParsing -Uri $domain/phalcon/cphalcon/releases | Select-String -Pattern "href=`"(.*phalcon_x64_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`""
$zip_file = $match.Matches[0].Groups[1].Value
Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip > $null 2>&1
Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\phalcon.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\phalcon -Force > $null 2>&1
New-Item -ItemType SymbolicLink -Path $ext_dir\php_phalcon.dll -Target $ENV:RUNNER_TOOL_CACHE\phalcon\php_phalcon.dll > $null 2>&1
Enable-PhpExtension -Extension phalcon -Path $php_dir
}
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "32" $tick $extension "Installed and enabled"
}
$tick = ([char]8730)
$domain = 'https://github.com'
$php_dir = 'C:\tools\php'
$ext_dir = $php_dir + '\ext'
Install-Phpextension psr -MinimumStability stable -Path $php_dir
if($extension -eq "phalcon4") {
Install-Phpextension phalcon -MinimumStability stable -Path $php_dir
} else {
$installed = Get-Php -Path $php_dir
$extension_version = $extension.substring($extension.Length - 1)
$nts = if(! $installed.ThreadSafe ) { "_nts" } else { "" }
$match = Invoke-WebRequest -UseBasicParsing -Uri $domain/phalcon/cphalcon/releases | Select-String -Pattern "href=`"(.*phalcon_x64_.*_php${version}_${extension_version}.*[0-9]${nts}.zip)`""
$zip_file = $match.Matches[0].Groups[1].Value
Invoke-WebRequest -UseBasicParsing -Uri $domain/$zip_file -OutFile $ENV:RUNNER_TOOL_CACHE\phalcon.zip >$null 2>&1
Expand-Archive -Path $ENV:RUNNER_TOOL_CACHE\phalcon.zip -DestinationPath $ENV:RUNNER_TOOL_CACHE\phalcon -Force >$null 2>&1
New-Item -ItemType SymbolicLink -Path $ext_dir\php_phalcon.dll -Target $ENV:RUNNER_TOOL_CACHE\phalcon\php_phalcon.dll >$null 2>&1
Enable-PhpExtension -Extension phalcon -Path $php_dir
$extension_version = $extension.substring($extension.Length - 1)
if($extension_version -eq '4') {
if (Test-Path $ext_dir\php_psr.dll) {
Enable-PhpExtension -Extension psr -Path $php_dir
} else {
Install-Phpextension psr -MinimumStability stable -Path $php_dir
}
}
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "32" $tick $extension "Installed and enabled"
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
printf "\033[%s;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" "32" $tick $extension "Enabled"
} else {
Remove-Item $ext_dir\php_phalcon.dll
Install-Phalcon
}
} else {
Install-Phalcon
}

View File

@ -1,22 +1,78 @@
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
find /etc/apt/sources.list.d -type f -name 'ondrej-ubuntu-php*.list' -exec sudo DEBIAN_FRONTEND=noninteractive apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1
curl -s https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh | sudo bash
sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$2"-psr
add_log() {
mark=$1
subject=$2
message=$3
if [ "$mark" = "$tick" ]; then
printf "\033[32;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
else
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s\033[0m\n" "$mark" "$subject" "$message"
fi
}
if [ ! "$(apt-cache search php"$2"-psr)" ]; then
sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y php"$2"-dev
for tool in php-config phpize; do
if [ -e "/usr/bin/$tool$2" ]; then
sudo update-alternatives --set $tool /usr/bin/"$tool$2"
update_ppa() {
if [ "$ppa_updated" = "false" ]; then
find /etc/apt/sources.list.d -type f -name 'ondrej-ubuntu-php*.list' -exec sudo DEBIAN_FRONTEND=noninteractive apt-get update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1
ppa_updated="true"
fi
}
install_phalcon() {
extension=$1
version=$2
(sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "php$version-$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
(update_ppa && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "php$version-$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") ||
add_log "$cross" "$extension" "Could not install $extension on PHP $semver"
}
remove_extension() {
extension=$1
sudo sed -i "/$extension/d" "$ini_file"
rm -rf "$ext_dir/$extension.so"
}
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
extension_major_version=$(echo "$1" | grep -i -Po '\d')
ppa_updated="false"
tick="✓"
cross="✗"
if [ "$extension_major_version" = "4" ]; then
if [ -e "$ext_dir/psr.so" ]; then
echo "extension=psr" >>"$ini_file"
fi
if [ -e "$ext_dir/phalcon.so" ]; then
if php -m | grep -i -q -w psr; then
echo "extension=phalcon" >>"$ini_file"
phalcon_version=$(php -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major_version" ]; then
remove_extension "psr" >/dev/null 2>&1
remove_extension "phalcon" >/dev/null 2>&1
install_phalcon "$1" "$2"
else
add_log "$tick" "$1" "Enabled"
fi
else
install_phalcon "$1" "$2"
fi
done
cd ~ && git clone --depth=1 https://github.com/jbboehr/php-psr.git
cd php-psr && sudo /usr/bin/phpize"$2"
./configure --with-php-config=/usr/bin/php-config"$2"
make -j2 && sudo make -j2 install
echo "extension=psr.so" >> "$ini_file"
else
install_phalcon "$1" "$2"
fi
fi
extension_major_version=$(echo "$1" | grep -i -Po '\d')
extension_version=$(apt-cache policy -- *phalcon | grep -i -Po "$extension_major_version\.\d\.\d.*php$2" | head -n 1)
sudo DEBIAN_FRONTEND=noninteractive apt-fast -o Dpkg::Options::="--force-overwrite" install -y php"$2"-phalcon="$extension_version"
if [ "$extension_major_version" = "3" ]; then
if [ -e "$ext_dir/phalcon.so" ]; then
echo "extension=phalcon" >>"$ini_file"
phalcon_version=$(php -r "echo phpversion('phalcon');" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major_version" ]; then
remove_extension "phalcon" >/dev/null 2>&1
install_phalcon "$1" "$2"
else
add_log "$tick" "$1" "Enabled"
fi
else
install_phalcon "$1" "$2"
fi
fi

View File

@ -1,5 +1,22 @@
extension=$1
extension_major=${extension: -1}
php_version=$2
brew tap shivammathur/homebrew-phalcon
brew install phalcon@"$php_version"_"$extension_major"
ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||")
if [ -e "$ext_dir/psr.so" ] && [ -e "$ext_dir/phalcon.so" ]; then
echo "extension=psr" >>"$ini_file"
echo "extension=phalcon" >>"$ini_file"
phalcon_semver=$(php -r "echo phpversion('phalcon');")
phalcon_version=$(echo "$phalcon_semver" | cut -d'.' -f 1)
if [ "$phalcon_version" != "$extension_major" ]; then
sudo sed -i '' "/psr/d" "$ini_file"
sudo sed -i '' "/phalcon/d" "$ini_file"
rm -rf "$ext_dir"/psr.so
rm -rf "$ext_dir"/phalcon.so
brew tap shivammathur/homebrew-phalcon
brew install phalcon@"$php_version"_"$extension_major"
fi
else
brew tap shivammathur/homebrew-phalcon
brew install phalcon@"$php_version"_"$extension_major"
fi