Skip to content

Commit

Permalink
Add support for update and extension versions
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Feb 14, 2020
1 parent ca33d01 commit 17241e2
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 106 deletions.
9 changes: 6 additions & 3 deletions __tests__/extensions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ 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'
);
expect(win32).toContain('Add-Extension xdebug');
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',
Expand All @@ -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'
);
Expand All @@ -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'
);
Expand Down Expand Up @@ -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');
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down
19 changes: 17 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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 +=
Expand Down Expand Up @@ -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 =
Expand Down
14 changes: 14 additions & 0 deletions src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 +=
Expand Down Expand Up @@ -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 =
Expand Down
6 changes: 4 additions & 2 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down
79 changes: 0 additions & 79 deletions src/scripts/ext/extensions.sh

This file was deleted.

38 changes: 22 additions & 16 deletions src/scripts/linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
if [ "$update" = "true" ]; then
$apt_install php"$version" >/dev/null 2>&1
status="Updated to"
else
semver=$(php -v | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '-')
status="Found"
fi
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"
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"
15 changes: 11 additions & 4 deletions src/scripts/win32.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"
}
}
Expand Down Expand Up @@ -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"
}
}
Expand Down

0 comments on commit 17241e2

Please sign in to comment.