Add support for update and extension versions

This commit is contained in:
Shivam Mathur 2020-02-13 22:39:00 +05:30
parent ca33d01e9f
commit 17241e2689
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
8 changed files with 79 additions and 108 deletions

View File

@ -3,7 +3,7 @@ import * as extensions from '../src/extensions';
describe('Extension tests', () => {
it('checking addExtensionOnWindows', async () => {
let win32: string = await extensions.addExtension(
'xdebug, pcov, phalcon4, ast-beta',
'xdebug, pcov, phalcon4, ast-beta, grpc-1.2.3',
'7.4',
'win32'
);
@ -11,6 +11,7 @@ describe('Extension tests', () => {
expect(win32).toContain('Add-Extension pcov');
expect(win32).toContain('phalcon.ps1 phalcon4');
expect(win32).toContain('Add-Extension ast beta');
expect(win32).toContain('Add-Extension grpc stable 1.2.3');
win32 = await extensions.addExtension(
'phalcon3, does_not_exist',
@ -27,7 +28,7 @@ describe('Extension tests', () => {
it('checking addExtensionOnLinux', async () => {
let linux: string = await extensions.addExtension(
'xdebug, pcov, ast-beta, xdebug-alpha',
'xdebug, pcov, ast-beta, xdebug-alpha, grpc-1.2.3',
'7.4',
'linux'
);
@ -36,6 +37,7 @@ describe('Extension tests', () => {
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-pcov'
);
expect(linux).toContain('add_unstable_extension ast beta extension');
expect(linux).toContain('add_pecl_extension grpc 1.2.3');
expect(linux).toContain(
'add_unstable_extension xdebug alpha zend_extension'
);
@ -64,13 +66,14 @@ describe('Extension tests', () => {
it('checking addExtensionOnDarwin', async () => {
let darwin: string = await extensions.addExtension(
'xdebug, pcov, ast-beta',
'xdebug, pcov, ast-beta, grpc-1.2.3',
'7.2',
'darwin'
);
expect(darwin).toContain('sudo pecl install -f xdebug');
expect(darwin).toContain('sudo pecl install -f pcov');
expect(darwin).toContain('add_unstable_extension ast beta extension');
expect(darwin).toContain('sudo pecl install -f grpc-1.2.3');
darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin');
expect(darwin).toContain('phalcon_darwin.sh phalcon3 7.0');

View File

@ -20,6 +20,9 @@ inputs:
tools:
description: 'Setup popular tools globally.'
required: false
update:
description: 'Update PHP if already installed.'
required: false
# Deprecated options, do not use. Will not be supported in v2 which will be released around February 1, 2020.
extension-csv:
description: 'Deprecated! Use extensions instead.'

19
dist/index.js vendored
View File

@ -2368,7 +2368,8 @@ function build(filename, version, os_version) {
const pecl = yield utils.getInput('pecl', false);
let tools_csv = yield utils.getInput('tools', false);
if (pecl == 'true' ||
/.*-(beta|alpha|devel|snapshot).*/.test(extension_csv)) {
/.*-(beta|alpha|devel|snapshot).*/.test(extension_csv) ||
/.*-(\d+\.\d+\.\d+).*/.test(extension_csv)) {
tools_csv = 'pecl, ' + tools_csv;
}
let script = yield utils.readScript(filename, version, os_version);
@ -2392,9 +2393,9 @@ exports.build = build;
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const os_version = process.platform;
let version = yield utils.getInput('php-version', true);
version = version.length > 1 ? version.slice(0, 3) : version + '.0';
const os_version = process.platform;
// check the os version and run the respective script
let script_path = '';
switch (os_version) {
@ -2761,6 +2762,16 @@ function addExtensionWindows(extension_csv, version, pipe) {
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
script += '\nAdd-Extension ' + extension_name + ' ' + stability;
break;
// match exact versions
case /.*-\d+\.\d+\.\d+/.test(version_extension):
script +=
'\nAdd-Extension ' +
extension_name +
' ' +
'stable' +
' ' +
stability;
return;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script +=
@ -2811,6 +2822,10 @@ function addExtensionLinux(extension_csv, version, pipe) {
' ' +
prefix;
return;
// match exact versions
case /.*-\d+\.\d+\.\d+/.test(version_extension):
script += '\nadd_pecl_extension ' + extension_name + ' ' + stability;
return;
// match 5.6gearman..7.4gearman
case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
install_command =

View File

@ -102,6 +102,16 @@ export async function addExtensionWindows(
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
script += '\nAdd-Extension ' + extension_name + ' ' + stability;
break;
// match exact versions
case /.*-\d+\.\d+\.\d+/.test(version_extension):
script +=
'\nAdd-Extension ' +
extension_name +
' ' +
'stable' +
' ' +
stability;
return;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script +=
@ -152,6 +162,10 @@ export async function addExtensionLinux(
' ' +
prefix;
return;
// match exact versions
case /.*-\d+\.\d+\.\d+/.test(version_extension):
script += '\nadd_pecl_extension ' + extension_name + ' ' + stability;
return;
// match 5.6gearman..7.4gearman
case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
install_command =

View File

@ -32,7 +32,8 @@ export async function build(
let tools_csv: string = await utils.getInput('tools', false);
if (
pecl == 'true' ||
/.*-(beta|alpha|devel|snapshot).*/.test(extension_csv)
/.*-(beta|alpha|devel|snapshot).*/.test(extension_csv) ||
/.*-(\d+\.\d+\.\d+).*/.test(extension_csv)
) {
tools_csv = 'pecl, ' + tools_csv;
}
@ -58,9 +59,10 @@ export async function build(
*/
export async function run(): Promise<void> {
try {
const os_version: string = process.platform;
let version: string = await utils.getInput('php-version', true);
version = version.length > 1 ? version.slice(0, 3) : version + '.0';
const os_version: string = process.platform;
// check the os version and run the respective script
let script_path = '';
switch (os_version) {

View File

@ -1,79 +0,0 @@
linux_extension_dir() {
apiv=$1
if [ "$version" = "5.3" ]; then
echo "/home/runner/php/5.3.29/lib/php/extensions/no-debug-non-zts-$apiv"
elif [[ "$version" =~ $old_versions_linux ]]; then
echo "/usr/lib/php5/$apiv"
elif [ "$version" = "8.0" ]; then
echo "/home/runner/php/8.0/lib/php/extensions/no-debug-non-zts-$apiv"
else
echo "/usr/lib/php/$apiv"
fi
}
darwin_extension_dir() {
apiv=$1
if [[ "$version" =~ $old_versions_darwin ]]; then
echo "/opt/local/lib/php${version/./}/extensions/no-debug-non-zts-$apiv"
else
echo "/usr/local/lib/php/pecl/$apiv"
fi
}
get_apiv() {
case $version in
5.3)
echo "20090626"
;;
5.4)
echo "20100525"
;;
5.5)
echo "20121212"
;;
5.6)
echo "20131226"
;;
7.0)
echo "20151012"
;;
7.1)
echo "20160303"
;;
7.2)
echo "20170718"
;;
7.3)
echo "20180731"
;;
*)
if [ "$version" = "8.0" ]; then
php_h="https://raw.githubusercontent.com/php/php-src/master/main/php.h"
else
semver=$(curl -sSL --retry 5 https://github.com/php/php-src/releases | grep "$flags" "(php-$version.[0-9]+)".zip | head -n 1 | grep "$flags" '[0-9]+\.[0-9]+\.[0-9]+')
php_h="https://raw.githubusercontent.com/php/php-src/PHP-$semver/main/php.h"
fi
curl -sSL --retry 5 "$php_h" | grep "PHP_API_VERSION" | cut -d' ' -f 3
;;
esac
}
version=$2
old_versions_linux="5.[4-5]"
old_versions_darwin="5.[3-5]"
os=$(uname -s)
if [ "$os" = "Linux" ]; then
flags='-Po'
apiv=$(get_apiv)
dir=$(linux_extension_dir "$apiv")
sudo mkdir -p "$dir" && sudo chown -R "$USER":"$(id -g -n)" $(dirname "$dir")
elif [ "$os" = "Darwin" ]; then
flags='-Eo'
apiv=$(get_apiv)
dir=$(darwin_extension_dir "$apiv")
else
dir='C:\\tools\\php\\ext'
fi
hash=$(echo -n "$1" | openssl dgst -sha256 | cut -d ' ' -f 2)
echo "::set-output name=ext_dir::$dir"
echo "::set-output name=ext_hash::$hash"

View File

@ -24,11 +24,12 @@ update_ppa() {
else
ppa="ondrej-ubuntu-php*.list"
fi
find /etc/apt/sources.list.d -type f -name "$ppa" -exec sudo DEBIAN_FRONTEND=noninteractive apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1
find /etc/apt/sources.list.d -type f -name "$ppa" -exec sudo "$debconf_fix" apt-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1
echo "true"
fi
}
# Function to configure PECL
configure_pecl() {
if [ "$pecl_config" = "false" ] && [ -e /usr/bin/pecl ]; then
for tool in pear pecl; do
@ -247,7 +248,8 @@ ppa_updated="false"
pecl_config="false"
version=$1
old_versions="5.[4-5]"
apt_install="sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y"
debconf_fix="DEBIAN_FRONTEND=noninteractive"
apt_install="sudo $debconf_fix apt-fast install -y"
existing_version=$(php-config --version | cut -c 1-3)
# Setup PHP
@ -267,33 +269,37 @@ if [ "$existing_version" != "$version" ]; then
fi
$apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml >/dev/null 2>&1
fi
status="installed"
status="Installed"
else
status="switched"
if [ "$update" = "true" ]; then
$apt_install php"$version" >/dev/null 2>&1
status="Updated to"
else
status="Switched to"
fi
fi
# PHP 5.3 is switched by install script, for rest switch_version
if [ "$version" != "5.3" ]; then
switch_version
fi
if [ "$version" = "8.0" ]; then
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
else
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
fi
if [ "$status" != "switched" ]; then
status="Installed PHP $semver"
else
status="Switched to PHP $semver"
fi
else
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
status="PHP $semver Found"
if [ "$update" = "true" ]; then
$apt_install php"$version" >/dev/null 2>&1
status="Updated to"
else
status="Found"
fi
fi
semver=$(php -v | head -n 1 | cut -f 2 -d ' ')
if [ ! "$version" = "8.0" ]; then
semver=$(echo "$semver" | cut -f 1 -d '-')
fi
ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g")
ext_dir=$(php -i | grep "extension_dir => /" | sed -e "s|.*=> s*||")
scan_dir=$(php --ini | grep additional | sed -e "s|.*: s*||")
sudo chmod 777 "$ini_file"
add_log "$tick" "PHP" "$status"
add_log "$tick" "PHP" "$status PHP $semver"

View File

@ -31,7 +31,12 @@ Function Add-Extension {
[ValidateNotNull()]
[ValidateSet('stable', 'beta', 'alpha', 'devel', 'snapshot')]
[string]
$mininum_stability = 'stable'
$mininum_stability = 'stable',
[Parameter(Position = 2, Mandatory = $false)]
[ValidateNotNull()]
[ValidatePattern('^\d+(\.\d+){0,2}$')]
[string]
$extension_version = ''
)
try {
$extension_info = Get-PhpExtension -Path $php_dir | Where-Object { $_.Name -eq $extension -or $_.Handle -eq $extension }
@ -50,7 +55,7 @@ Function Add-Extension {
}
}
else {
Install-PhpExtension -Extension $extension -MinimumStability $mininum_stability -Path $php_dir
Install-PhpExtension -Extension $extension -MinimumStability $mininum_stability -Version $extension_version -Path $php_dir
Add-Log $tick $extension "Installed and enabled"
}
}
@ -192,8 +197,10 @@ if ($null -eq $installed -or -not("$($installed.Version).".StartsWith(($version
Install-Php -Version $version -Architecture $arch -ThreadSafe $ts -InstallVC -Path $php_dir -TimeZone UTC -InitialPhpIni Production -Force >$null 2>&1
} else {
$updated = Update-Php $php_dir >$null 2>&1
if($updated -eq $False) {
if((Test-Path env:update) -and $env:update -eq 'true') {
Update-Php $php_dir > $null 2>&1
$status = "Updated to"
} else {
$status = "Found"
}
}