From ca33d01e9f8ae2c8d24af2bd31935bdd4df1fd53 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sun, 9 Feb 2020 04:08:48 +0530 Subject: [PATCH] Add support for old PHP versions on linux --- __tests__/extensions.test.ts | 2 +- __tests__/install.test.ts | 18 +- __tests__/tools.test.ts | 73 ++-- builds | 607 ++++++++++++++++++++++++++++++++++ dist/index.js | 70 ++-- src/coverage.ts | 6 +- src/extensions.ts | 2 +- src/install.ts | 2 +- src/scripts/darwin.sh | 9 +- src/scripts/ext/extensions.sh | 76 ++++- src/scripts/linux.sh | 68 +++- src/tools.ts | 60 +++- update.zip | Bin 2879 -> 0 bytes 13 files changed, 893 insertions(+), 100 deletions(-) create mode 100644 builds delete mode 100644 update.zip diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index e1191c0b..03491255 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -31,7 +31,7 @@ describe('Extension tests', () => { '7.4', 'linux' ); - expect(linux).toContain('update_extension xdebug 2.9.0'); + expect(linux).toContain('update_extension xdebug 2.9.1'); expect(linux).toContain( 'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-pcov' ); diff --git a/__tests__/install.test.ts b/__tests__/install.test.ts index 45119282..f48dcd2b 100644 --- a/__tests__/install.test.ts +++ b/__tests__/install.test.ts @@ -46,7 +46,7 @@ jest.mock('../src/install', () => ({ case 'darwin': case 'linux': script = await install.build(os_version + '.sh', version, os_version); - script += 'sh script.sh ' + version + ' ' + __dirname; + script += 'bash script.sh ' + version + ' ' + __dirname; break; case 'win32': script = await install.build(os_version + '.sh', version, os_version); @@ -117,7 +117,7 @@ describe('Install', () => { // @ts-ignore let script: string = await install.run(); expect(script).toContain('initial script'); - expect(script).toContain('sh script.sh 7.3 '); + expect(script).toContain('bash script.sh 7.3 '); setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', 'true'); // @ts-ignore @@ -126,7 +126,7 @@ describe('Install', () => { expect(script).toContain('install extensions'); expect(script).toContain('edit php.ini'); expect(script).toContain('set coverage driver'); - expect(script).toContain('sh script.sh 7.3'); + expect(script).toContain('bash script.sh 7.3'); expect(script).toContain('add_tool'); setEnv('7.3', 'linux', 'a, b', 'a=b', 'x', 'phpunit', ''); @@ -136,7 +136,7 @@ describe('Install', () => { expect(script).toContain('install extensions'); expect(script).toContain('edit php.ini'); expect(script).toContain('set coverage driver'); - expect(script).toContain('sh script.sh 7.3'); + expect(script).toContain('bash script.sh 7.3'); expect(script).toContain('add_tool'); }); @@ -145,7 +145,7 @@ describe('Install', () => { // @ts-ignore let script: string = await install.run(); expect(script).toContain('initial script'); - expect(script).toContain('sh script.sh 7.3 ' + __dirname); + expect(script).toContain('bash script.sh 7.3 ' + __dirname); setEnv('7.3', 'darwin', 'a, b', 'a=b', 'x', '', ''); // @ts-ignore @@ -154,7 +154,7 @@ describe('Install', () => { expect(script).toContain('install extensions'); expect(script).toContain('edit php.ini'); expect(script).toContain('set coverage driver'); - expect(script).toContain('sh script.sh 7.3 ' + __dirname); + expect(script).toContain('bash script.sh 7.3 ' + __dirname); }); it('Test malformed version inputs', async () => { @@ -162,18 +162,18 @@ describe('Install', () => { // @ts-ignore let script: string = await install.run(); expect(script).toContain('initial script'); - expect(script).toContain('sh script.sh 7.4 ' + __dirname); + expect(script).toContain('bash script.sh 7.4 ' + __dirname); setEnv(8.0, 'darwin', '', '', '', '', ''); // @ts-ignore script = await install.run(); expect(script).toContain('initial script'); - expect(script).toContain('sh script.sh 8.0 ' + __dirname); + expect(script).toContain('bash script.sh 8.0 ' + __dirname); setEnv(8, 'darwin', '', '', '', '', ''); // @ts-ignore script = await install.run(); expect(script).toContain('initial script'); - expect(script).toContain('sh script.sh 8.0 ' + __dirname); + expect(script).toContain('bash script.sh 8.0 ' + __dirname); }); }); diff --git a/__tests__/tools.test.ts b/__tests__/tools.test.ts index 6c7394dd..c6aadaa1 100644 --- a/__tests__/tools.test.ts +++ b/__tests__/tools.test.ts @@ -107,22 +107,13 @@ describe('Tools tests', () => { }); it('checking getCodeceptionUriBuilder', async () => { - expect(await tools.getCodeceptionUriBuilder('3.2.1', '5.6', 'php56')).toBe( + expect(await tools.getCodeceptionUriBuilder('3.2.1', 'php56')).toBe( 'releases/3.2.1/php56/codecept.phar' ); - expect(await tools.getCodeceptionUriBuilder('3.2.1', '7.0', 'php54')).toBe( + expect(await tools.getCodeceptionUriBuilder('3.2.1', 'php54')).toBe( 'releases/3.2.1/php54/codecept.phar' ); - expect(await tools.getCodeceptionUriBuilder('3.2.1', '7.1', 'php56')).toBe( - 'releases/3.2.1/php56/codecept.phar' - ); - expect(await tools.getCodeceptionUriBuilder('3.2.1', '7.2', 'php56')).toBe( - 'releases/3.2.1/codecept.phar' - ); - expect(await tools.getCodeceptionUriBuilder('3.2.1', '7.3', 'php56')).toBe( - 'releases/3.2.1/codecept.phar' - ); - expect(await tools.getCodeceptionUriBuilder('3.2.1', '7.4', 'php56')).toBe( + expect(await tools.getCodeceptionUriBuilder('3.2.1', '')).toBe( 'releases/3.2.1/codecept.phar' ); }); @@ -146,17 +137,59 @@ describe('Tools tests', () => { expect(await tools.getCodeceptionUri('latest', '7.4')).toBe( 'codecept.phar' ); - expect(await tools.getCodeceptionUri('3.2.1', '5.6')).toBe( - 'releases/3.2.1/php54/codecept.phar' + expect(await tools.getCodeceptionUri('4.0.0', '7.4')).toBe( + 'releases/4.0.0/codecept.phar' ); - expect(await tools.getCodeceptionUri('4.3.2', '5.6')).toBe( - 'releases/4.3.2/php56/codecept.phar' + expect(await tools.getCodeceptionUri('4.0.0', '5.6')).toBe( + 'releases/4.0.0/php56/codecept.phar' ); - expect(await tools.getCodeceptionUri('3.2.1', '7.4')).toBe( - 'releases/3.2.1/codecept.phar' + expect(await tools.getCodeceptionUri('4.0.0', '7.1')).toBe( + 'releases/4.0.0/php56/codecept.phar' ); - expect(await tools.getCodeceptionUri('4.3.2', '7.4')).toBe( - 'releases/4.3.2/codecept.phar' + expect(await tools.getCodeceptionUri('3.1.0', '7.4')).toBe( + 'releases/3.1.0/codecept.phar' + ); + expect(await tools.getCodeceptionUri('3.1.0', '5.6')).toBe( + 'releases/3.1.0/php54/codecept.phar' + ); + expect(await tools.getCodeceptionUri('2.5.4', '7.4')).toBe( + 'releases/2.5.4/codecept.phar' + ); + expect(await tools.getCodeceptionUri('2.5.4', '5.6')).toBe( + 'releases/2.5.4/php54/codecept.phar' + ); + expect(await tools.getCodeceptionUri('2.3.4', '7.4')).toBe( + 'releases/2.3.4/codecept.phar' + ); + expect(await tools.getCodeceptionUri('2.3.4', '5.4')).toBe( + 'releases/2.3.4/php54/codecept.phar' + ); + expect(await tools.getCodeceptionUri('2.2.4', '5.6')).toBe( + 'releases/2.2.4/codecept.phar' + ); + expect(await tools.getCodeceptionUri('2.2.4', '7.4')).toBe( + 'releases/2.2.4/codecept.phar' + ); + expect(await tools.getCodeceptionUri('2.2.4', '5.4')).toBe( + 'releases/2.2.4/php54/codecept.phar' + ); + expect(await tools.getCodeceptionUri('2.1.7', '5.6')).toBe( + 'releases/2.1.7/codecept.phar' + ); + expect(await tools.getCodeceptionUri('2.1.7', '5.4')).toBe( + 'releases/2.1.7/php54/codecept.phar' + ); + expect(await tools.getCodeceptionUri('2.1.5', '5.4')).toBe( + 'releases/2.1.5/codecept.phar' + ); + expect(await tools.getCodeceptionUri('2.1.5', '7.4')).toBe( + 'releases/2.1.5/codecept.phar' + ); + expect(await tools.getCodeceptionUri('1.6.9', '7.4')).toBe( + 'releases/1.6.9/codecept.phar' + ); + expect(await tools.getCodeceptionUri('1.5.0', '7.4')).toBe( + 'releases/1.5.0/codecept.phar' ); }); diff --git a/builds b/builds new file mode 100644 index 00000000..00771115 --- /dev/null +++ b/builds @@ -0,0 +1,607 @@ + + + + + + Codeception Builds + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+

4.0

+

Requires: PHP 5.6 and higher + CURL

+ + + +

3.1

+

Requires: PHP 5.6 and higher + CURL

+ + + +

3.0

+

Requires: PHP 5.6 and higher + CURL

+ + + +

2.5

+

Requires: PHP 5.6 and higher + CURL

+ + + +

2.4

+

Requires: PHP 5.6 and higher + CURL

+ + + +

2.3

+

Requires: PHP 5.4 and higher + CURL

+ + + +

2.2

+

Requires: PHP 5.4 and higher + CURL

+ + + +

2.1

+

Requires: PHP 5.4 and higher + CURL

+ + + +

2.0

+

Requires: PHP 5.4 and higher + CURL

+ + + +

1.8

+

Requires: PHP 5.3 and higher + CURL

+ + + +

1.7

+

Requires: PHP 5.3 and higher + CURL

+ + + +

1.6

+

Requires: PHP 5.3 and higher + CURL

+ + + +
+
+ +
+ + + +
+ Quick Start → +


Write and execute a test for an existing app + in less than a 5 mins! +

+
+ + + + +
+
+ + +
+ +
+ +
+ + + + + + + + + +
+ + + +
+ + + + + + + + + + + + + diff --git a/dist/index.js b/dist/index.js index dc3d507f..91a39e1e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1703,20 +1703,13 @@ exports.getUri = getUri; * Helper function to get the codeception url * * @param version - * @param php_version * @param suffix */ -function getCodeceptionUriBuilder(version, php_version, suffix) { +function getCodeceptionUriBuilder(version, suffix) { return __awaiter(this, void 0, void 0, function* () { - switch (true) { - case /^5\.6$|^7\.[0|1]$/.test(php_version): - return ['releases', version, suffix, 'codecept.phar'] - .filter(Boolean) - .join('/'); - case /^7\.[2-4]$/.test(php_version): - default: - return ['releases', version, 'codecept.phar'].filter(Boolean).join('/'); - } + return ['releases', version, suffix, 'codecept.phar'] + .filter(Boolean) + .join('/'); }); } exports.getCodeceptionUriBuilder = getCodeceptionUriBuilder; @@ -1728,19 +1721,55 @@ exports.getCodeceptionUriBuilder = getCodeceptionUriBuilder; */ function getCodeceptionUri(version, php_version) { return __awaiter(this, void 0, void 0, function* () { + const codecept = yield getCodeceptionUriBuilder(version, ''); + const codecept54 = yield getCodeceptionUriBuilder(version, 'php54'); + const codecept56 = yield getCodeceptionUriBuilder(version, 'php56'); + // Refer to https://codeception.com/builds switch (true) { case /latest/.test(version): switch (true) { - case /^5\.6$|^7\.[0|1]$/.test(php_version): + case /5\.6|7\.[0|1]/.test(php_version): return 'php56/codecept.phar'; - case /^7\.[2-4]$/.test(php_version): + case /7\.[2-4]/.test(php_version): default: return 'codecept.phar'; } - case /([4-9]|\d{2,})\..*/.test(version): - return yield getCodeceptionUriBuilder(version, php_version, 'php56'); + case /(^[4-9]|\d{2,})\..*/.test(version): + switch (true) { + case /5\.6|7\.[0|1]/.test(php_version): + return codecept56; + case /7\.[2-4]/.test(php_version): + default: + return codecept; + } + case /(^2\.[4-5]\.\d+|^3\.[0-1]\.\d+).*/.test(version): + switch (true) { + case /5\.6/.test(php_version): + return codecept54; + case /7\.[0-4]/.test(php_version): + default: + return codecept; + } + case /^2\.3\.\d+.*/.test(version): + switch (true) { + case /5\.[4-6]/.test(php_version): + return codecept54; + case /^7\.[0-4]$/.test(php_version): + default: + return codecept; + } + case /(^2\.(1\.([6-9]|\d{2,}))|^2\.2\.\d+).*/.test(version): + switch (true) { + case /5\.[4-5]/.test(php_version): + return codecept54; + case /5.6|7\.[0-4]/.test(php_version): + default: + return codecept; + } + case /(^2\.(1\.[0-5]|0\.\d+)|^1\.[6-8]\.\d+).*/.test(version): + return codecept; default: - return yield getCodeceptionUriBuilder(version, php_version, 'php54'); + return yield codecept; } }); } @@ -2104,7 +2133,7 @@ exports.addCoverageXdebug = addCoverageXdebug; function addCoveragePCOV(version, os_version, pipe) { return __awaiter(this, void 0, void 0, function* () { let script = '\n'; - switch (version) { + switch (true) { default: script += (yield extensions.addExtension('pcov', version, os_version, true)) + @@ -2126,8 +2155,7 @@ function addCoveragePCOV(version, os_version, pipe) { script += yield utils.addLog('$tick', 'coverage: pcov', 'PCOV enabled as coverage driver', os_version); // version is not supported break; - case '5.6': - case '7.0': + case /5\.[3-6]|7\.0/.test(version): script += yield utils.addLog('$cross', 'pcov', 'PHP 7.1 or newer is required', os_version); break; } @@ -2373,7 +2401,7 @@ function run() { case 'darwin': case 'linux': script_path = yield build(os_version + '.sh', version, os_version); - yield exec_1.exec('sh ' + script_path + ' ' + version + ' ' + __dirname); + yield exec_1.exec('bash ' + script_path + ' ' + version + ' ' + __dirname); break; case 'win32': script_path = yield build('win32.ps1', version, os_version); @@ -2805,7 +2833,7 @@ function addExtensionLinux(extension_csv, version, pipe) { // match 7.0xdebug..7.4xdebug case /^7\.[0-4]xdebug$/.test(version_extension): script += - '\nupdate_extension xdebug 2.9.0' + + '\nupdate_extension xdebug 2.9.1' + pipe + '\n' + (yield utils.addLog('$tick', 'xdebug', 'Enabled', 'linux')); diff --git a/src/coverage.ts b/src/coverage.ts index 74bc5ab8..f4fdb1af 100644 --- a/src/coverage.ts +++ b/src/coverage.ts @@ -54,7 +54,7 @@ export async function addCoveragePCOV( pipe: string ): Promise { let script = '\n'; - switch (version) { + switch (true) { default: script += (await extensions.addExtension('pcov', version, os_version, true)) + @@ -83,8 +83,8 @@ export async function addCoveragePCOV( ); // version is not supported break; - case '5.6': - case '7.0': + + case /5\.[3-6]|7\.0/.test(version): script += await utils.addLog( '$cross', 'pcov', diff --git a/src/extensions.ts b/src/extensions.ts index 246c8f82..3248b6f9 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -174,7 +174,7 @@ export async function addExtensionLinux( // match 7.0xdebug..7.4xdebug case /^7\.[0-4]xdebug$/.test(version_extension): script += - '\nupdate_extension xdebug 2.9.0' + + '\nupdate_extension xdebug 2.9.1' + pipe + '\n' + (await utils.addLog('$tick', 'xdebug', 'Enabled', 'linux')); diff --git a/src/install.ts b/src/install.ts index c908b8ec..a5bd54a6 100644 --- a/src/install.ts +++ b/src/install.ts @@ -67,7 +67,7 @@ export async function run(): Promise { case 'darwin': case 'linux': script_path = await build(os_version + '.sh', version, os_version); - await exec('sh ' + script_path + ' ' + version + ' ' + __dirname); + await exec('bash ' + script_path + ' ' + version + ' ' + __dirname); break; case 'win32': script_path = await build('win32.ps1', version, os_version); diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 9f88a97b..106a78b9 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -34,8 +34,8 @@ add_extension() { add_log "$tick" "$extension" "Enabled" elif ! php -m | grep -i -q -w "$extension"; then if [[ "$version" =~ $old_versions ]]; then - (eval "$install_command" >/dev/null 2>&1 && echo "$prefix=$ext_dir/$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Installed and enabled") || (sudo port install php"$nodot_version"-"$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || + (eval "$install_command" >/dev/null 2>&1 && echo "$prefix=$ext_dir/$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Installed and enabled") || add_log "$cross" "$extension" "Could not install $extension on PHP $semver" else (eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || @@ -102,12 +102,13 @@ add_tool() { if [ "$status_code" = "200" ]; then sudo chmod a+x "$tool_path" if [ "$tool" = "phive" ]; then - add_extension curl >/dev/null 2>&1 - add_extension mbstring >/dev/null 2>&1 - add_extension xml >/dev/null 2>&1 + add_extension curl "sudo pecl install -f curl" extension >/dev/null 2>&1 + add_extension mbstring "sudo pecl install -f mbstring" extension >/dev/null 2>&1 + add_extension xml "sudo pecl install -f xml" extension >/dev/null 2>&1 elif [ "$tool" = "cs2pr" ]; then sudo sed -i '' 's/exit(9)/exit(0)/' "$tool_path" tr -d '\r' < "$tool_path" | sudo tee "$tool_path.tmp" >/dev/null 2>&1 && sudo mv "$tool_path.tmp" "$tool_path" + sudo chmod a+x "$tool_path" fi add_log "$tick" "$tool" "Added" else diff --git a/src/scripts/ext/extensions.sh b/src/scripts/ext/extensions.sh index af88bcae..9dc8d260 100644 --- a/src/scripts/ext/extensions.sh +++ b/src/scripts/ext/extensions.sh @@ -1,12 +1,76 @@ -php_h="https://raw.githubusercontent.com/php/php-src/PHP-$2/main/php.h" +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 - apiv=$(curl -sSL --retry 5 "$php_h" | grep "PHP_API_VERSION" | cut -d' ' -f 3) - dir="/usr/lib/php/$apiv" - sudo mkdir -p "$dir" && sudo chown -R "$USER":"$(id -g -n)" /usr/lib/php + 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 - apiv=$(curl -sSL --retry 5 "$php_h" | grep "PHP_API_VERSION" | cut -d' ' -f 3) - dir="/usr/local/lib/php/pecl/$apiv" + flags='-Eo' + apiv=$(get_apiv) + dir=$(darwin_extension_dir "$apiv") else dir='C:\\tools\\php\\ext' fi diff --git a/src/scripts/linux.sh b/src/scripts/linux.sh index e75e88f5..f42cc8db 100644 --- a/src/scripts/linux.sh +++ b/src/scripts/linux.sh @@ -19,8 +19,13 @@ add_log() { # Function to update php ppa 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-fast update -o Dir::Etc::sourcelist="{}" ';' >/dev/null 2>&1 - ppa_updated="true" + if [[ "$version" =~ $old_versions ]]; then + ppa="dotdeb-ubuntu-php*.list" + 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 + echo "true" fi } @@ -53,15 +58,18 @@ add_extension() { extension=$1 install_command=$2 prefix=$3 + if [[ "$version" =~ $old_versions ]]; then + install_command="ppa_updated=$(update_ppa) && ${install_command/5\.[4-5]-$extension/5-$extension=$release_version}" + fi if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then # shellcheck disable=SC2046 - $apt_install $(apt-cache depends php"$version"-"$extension" | awk '/Depends:/{print$2}') >/dev/null 2>&1 - echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" + $apt_install $(apt-cache depends php"$version"-"$extension" 2>/dev/null | awk '/Depends:/{print$2}') >/dev/null 2>&1 + echo "$prefix=$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" elif php -m | grep -i -q -w "$extension"; then add_log "$tick" "$extension" "Enabled" elif ! php -m | grep -i -q -w "$extension"; then - (eval "$install_command" && add_log "$tick" "$extension" "Installed and enabled") || - (update_ppa && eval "$install_command" && add_log "$tick" "$extension" "Installed and enabled") || + (eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || + (ppa_updated=$(update_ppa) && eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || (sudo pecl install -f "$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || add_log "$cross" "$extension" "Could not install $extension on PHP $semver" fi @@ -72,7 +80,7 @@ add_extension() { delete_extension() { extension=$1 sudo sed -i "/$extension/d" "$ini_file" - sudo rm -rf /etc/php/"$version"/cli/conf.d/*"$extension"* >/dev/null 2>&1 + sudo rm -rf "$scan_dir"/*"$extension"* >/dev/null 2>&1 sudo rm -rf "$ext_dir"/"$extension".so >/dev/null 2>&1 } @@ -103,7 +111,7 @@ add_unstable_extension() { if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then extension_version=$(php -d="$prefix=$extension" -r "echo phpversion('$extension');") if [ "$extension_version" = "$pecl_version" ]; then - echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" + echo "$prefix=$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" else delete_extension "$extension" add_pecl_extension "$extension" "$pecl_version" @@ -130,7 +138,7 @@ update_extension() { if [ "$final_version" != "$current_version" ]; then version_exists=$(apt-cache policy -- *"$extension" | grep "$final_version") if [ -z "$version_exists" ]; then - update_ppa + ppa_updated=$(update_ppa) fi $apt_install php"$version"-"$extension" fi @@ -152,9 +160,9 @@ add_tool() { elif [ "$tool" = "cs2pr" ]; then sudo sed -i 's/\r$//; s/exit(9)/exit(0)/' "$tool_path" elif [ "$tool" = "phive" ]; then - add_extension curl >/dev/null 2>&1 - add_extension mbstring >/dev/null 2>&1 - add_extension xml >/dev/null 2>&1 + add_extension curl "$apt_install php$version-curl" extension >/dev/null 2>&1 + add_extension mbstring "$apt_install php$version-mbstring" extension >/dev/null 2>&1 + add_extension xml "$apt_install php$version-xml" extension >/dev/null 2>&1 fi add_log "$tick" "$tool" "Added" else @@ -190,13 +198,29 @@ setup_master() { install_dir=~/php/"$version" sudo mkdir -m 777 -p ~/php $apt_install libicu-dev >/dev/null 2>&1 - curl -o "$tar_file" -L https://bintray.com/shivammathur/php/download_file?file_path="$tar_file" >/dev/null 2>&1 + curl -SLO https://dl.bintray.com/shivammathur/php/"$tar_file" >/dev/null 2>&1 sudo tar xf "$tar_file" -C ~/php >/dev/null 2>&1 rm -rf "$tar_file" sudo ln -sf -S "$version" "$install_dir"/bin/* /usr/bin/ sudo ln -sf "$install_dir"/etc/php.ini /etc/php.ini } +# Function to setup PHP 5.3, PHP 5.4 and PHP 5.5 +setup_old_versions() { + ( + cd /tmp || exit + curl -SLO https://dl.bintray.com/shivammathur/php/php-"$version".tar.xz >/dev/null 2>&1 + sudo tar xf php-"$version".tar.xz >/dev/null 2>&1 + cd php-"$version" || exit + sudo chmod a+x ./*.sh + ./install.sh >/dev/null 2>&1 + ./post-install.sh >/dev/null 2>&1 + ) + sudo rm -rf /tmp/php-"$version" + configure_pecl + release_version=$(php -v | head -n 1 | cut -d' ' -f 2) +} + # Function to setup PECL add_pecl() { add_devtools @@ -222,20 +246,25 @@ cross="✗" ppa_updated="false" pecl_config="false" version=$1 +old_versions="5.[4-5]" apt_install="sudo DEBIAN_FRONTEND=noninteractive apt-fast install -y" existing_version=$(php-config --version | cut -c 1-3) # Setup PHP step_log "Setup PHP" -sudo mkdir -p /var/run -sudo mkdir -p /run/php +sudo mkdir -p /var/run /run/php if [ "$existing_version" != "$version" ]; then if [ ! -e "/usr/bin/php$version" ]; then - update_ppa if [ "$version" = "8.0" ]; then setup_master + elif [[ "$version" =~ $old_versions ]] || [ "$version" = "5.3" ]; then + setup_old_versions else + version_exists=$(apt-cache policy -- php"$version" | grep "$version") + if [ -z "$version_exists" ]; then + ppa_updated=$(update_ppa) + fi $apt_install php"$version" php"$version"-curl php"$version"-mbstring php"$version"-xml >/dev/null 2>&1 fi status="installed" @@ -243,7 +272,9 @@ if [ "$existing_version" != "$version" ]; then status="switched" fi - 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 ' ') @@ -262,6 +293,7 @@ else fi 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*||") +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" diff --git a/src/tools.ts b/src/tools.ts index 0b816983..69b0fcff 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -138,23 +138,15 @@ export async function getUri( * Helper function to get the codeception url * * @param version - * @param php_version * @param suffix */ export async function getCodeceptionUriBuilder( version: string, - php_version: string, suffix: string ): Promise { - switch (true) { - case /^5\.6$|^7\.[0|1]$/.test(php_version): - return ['releases', version, suffix, 'codecept.phar'] - .filter(Boolean) - .join('/'); - case /^7\.[2-4]$/.test(php_version): - default: - return ['releases', version, 'codecept.phar'].filter(Boolean).join('/'); - } + return ['releases', version, suffix, 'codecept.phar'] + .filter(Boolean) + .join('/'); } /** @@ -167,19 +159,55 @@ export async function getCodeceptionUri( version: string, php_version: string ): Promise { + const codecept: string = await getCodeceptionUriBuilder(version, ''); + const codecept54: string = await getCodeceptionUriBuilder(version, 'php54'); + const codecept56: string = await getCodeceptionUriBuilder(version, 'php56'); + // Refer to https://codeception.com/builds switch (true) { case /latest/.test(version): switch (true) { - case /^5\.6$|^7\.[0|1]$/.test(php_version): + case /5\.6|7\.[0|1]/.test(php_version): return 'php56/codecept.phar'; - case /^7\.[2-4]$/.test(php_version): + case /7\.[2-4]/.test(php_version): default: return 'codecept.phar'; } - case /([4-9]|\d{2,})\..*/.test(version): - return await getCodeceptionUriBuilder(version, php_version, 'php56'); + case /(^[4-9]|\d{2,})\..*/.test(version): + switch (true) { + case /5\.6|7\.[0|1]/.test(php_version): + return codecept56; + case /7\.[2-4]/.test(php_version): + default: + return codecept; + } + case /(^2\.[4-5]\.\d+|^3\.[0-1]\.\d+).*/.test(version): + switch (true) { + case /5\.6/.test(php_version): + return codecept54; + case /7\.[0-4]/.test(php_version): + default: + return codecept; + } + case /^2\.3\.\d+.*/.test(version): + switch (true) { + case /5\.[4-6]/.test(php_version): + return codecept54; + case /^7\.[0-4]$/.test(php_version): + default: + return codecept; + } + case /(^2\.(1\.([6-9]|\d{2,}))|^2\.2\.\d+).*/.test(version): + switch (true) { + case /5\.[4-5]/.test(php_version): + return codecept54; + case /5.6|7\.[0-4]/.test(php_version): + default: + return codecept; + } + case /(^2\.(1\.[0-5]|0\.\d+)|^1\.[6-8]\.\d+).*/.test(version): + return codecept; default: - return await getCodeceptionUriBuilder(version, php_version, 'php54'); + return await codecept; } } diff --git a/update.zip b/update.zip deleted file mode 100644 index f4bdf08b816208cb1f1bda937d628e267182638b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2879 zcma);c{o&k8^>qHSW=jJVhoxP*~idWvt?dSVw5IIVPqLbA~U0G*|J61WgTNn2qQ@` zNVZb8NR2%vTXqqZ@bc92)Z3f)dVl9S=eqy+eLv^Ee%Jjy=WA@p0_Fs4ErXl7#(x#x zA7H=^0GVVfZ)(B{05;H-amL$j-SvGd*_Pz!>PG&5B#>Vucn`P#mT~;m)DTtbv@r_+ zAg}`f5d4kIm0*3*_L2+2m8|ejuhpi`mzaM-)*~DIlIV}?kJ++E=FOZWc3K+Dii(3- z5o>^^M@b^MM%-%E6w2|1-(2Baf89Zo{Ppv14$H5$w3PC&B;11(dT~v_c$T2jn8G7s z70eia1d3;f5~gETC2g2c`DLMrwI*noMa2sH2HRS8v4LtT29ce4H{6<1E*B@QyhKmF4AJj4NRH z2F00pz#zOpD7Hk{Ka1v7q(~j(^Nuzz)bwatTwpaTP#+LI-2G{vKv!a?k#>O)k=Gc` zx~vA(z|?2j9D=)E<{8o037H0-(n>1XUrDBp^d$HPG<@v02ksm1s%_6(5;=@M{7Lfd}9e(xE3Do7C0RW8p1zTW2l|s??jw1YYT9%~f{45lbPj{i)`1 zJgxm${8LhYiaIRwjl^eq)|qGB(0uidou!PLNekbZ74O8^2_~~ebKT=>j*1j#m;Nvd zSGXk4oK}@{QQPc5qubf(sIc+HzHoTEL#dwx#R6$G4sG!F*&`0u0%b+{_2zP-n+CI2 z`K>+nw`KWzJ6QC`=Mms3o`1AH+0#sk?KzNOk?qA+ce?uk*X}P=Lfy(;bNtFf`EHtb z{6<5AN*Tbm^WvjtmqsoX%|`@HXT$8ZXR>FiS6W*&t^GTE9ip!i=j@HXJW(y89pvIh z1|F8!gD3-x&RX7kN^OsQUtIGbRSd&QB-9Mc@HV#%4=bJVRVPeJACW{crDob0o>gG}@UG6A zJ8Sv`JYj>!=jpxT@2A0@-f zUar2+Ux1vc3AnGpCk-NX&VG#a9ysFg0eh|Ifkck8`>SQT^Tk`oqSZKw7j>VS*rQQ< zPKecTl`JwK+2y#(e8yy15pTi`S-Wtwa+`3oS@r4Jqvf>jvIm)X6L?5S^>ynVPSbiN z9JTMH=gsbDB=dPb!OMi@TnN^AZTeIMB;6epm>P~8hdxl136hp%&ha0GO4f`3l@&3= zYx6U;sr4P}xly6%p`mj=F`QyM@&4~ms0njuj^Di-V537>Sw-_Mt%{dF?vP-pfcpb> zdgGdMsgki^x_95c=8Y^wdR|p|Vv(7CBT_@KRP3d}gOC^{6Uu^NV{n78OtVybb6O1k zom8V~^b#k>{gLj1yhG1~r-EyjmAiK*7f@tZ;{rcm;h_3RVr`qNQ3^6O`7593%QI`^ zJqVjXjawwmPnPGzM6SEV^fCG8-Is1l*BgH{^|u&H?p4JuX=Di?V! zbLFm)bG`Y*4Qr2gk~hh39Vd=tDYOh}jKiYU;Az)|9-(P|Jir_HO=YcC{2HF3}aJnLEi95KM zfMLL66k8j?_ylB;ZsX?5293)IXrtHjgFr&%Ltr>9WZ}7@idBFwOOVx-pbN{1*Og-Q zd$DafJiruNDZ21d36P6HrMCj}&+*gc7^wSaYfai`r3C_@>pr*BX=9xCmUV8eNgPi! zLEP}mGJkF*I(<@8xU2oepe>7r^>pwkMg?gWJ90&k_Hhn0vy$7xAtV!;UE{LD3n1*dX5s2LT zIBs5BLr}CYR(FhO2#vGUoP5rYeP-LGW7w-0!Q60ZKA+mh{Z!EBZLx3hP^g|`P^@f9 zC@?a&aO{#n>BJQBEFjG<^vEgY9`27gB9u)xyb!{BpTHE(P>ZIRV+!*YP93v55#p&G60|SE!Ysk7 ziXIqHBVgq;NAhL)E>GM;58Nm25(36k{yfJ%;fn0-W) zMUg&=7Hol^X{90AN6Lq-^QTi%E;vjU?Q?)&n81i!!?!-K&gDkN@e_cH`B4+zaTBs( zPq_LRnm!v=mOz}+$%WEWiI{Y_Yx(CBWMgf127~fxpiG4`2cN zw!q)G!PtWtnJiP?G@~mkhV59_J@!PDyTzv6dtKyvss{! NwkYdEb}Du%{|2n_qH_QM