From 777bdbac28ade599c304f334a641622ee538917b Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Fri, 19 Jun 2020 04:09:13 +0530 Subject: [PATCH] Improve extension support --- .github/workflows/experimental-workflow.yml | 88 --------------------- .github/workflows/workflow.yml | 2 +- README.md | 2 +- __tests__/coverage.test.ts | 19 ----- __tests__/extensions.test.ts | 18 +++-- dist/index.js | 52 +++++++----- src/coverage.ts | 10 --- src/extensions.ts | 47 +++++++---- src/scripts/darwin.sh | 14 +++- src/scripts/win32.ps1 | 2 + 10 files changed, 91 insertions(+), 163 deletions(-) delete mode 100644 .github/workflows/experimental-workflow.yml diff --git a/.github/workflows/experimental-workflow.yml b/.github/workflows/experimental-workflow.yml deleted file mode 100644 index 001a8c6b..00000000 --- a/.github/workflows/experimental-workflow.yml +++ /dev/null @@ -1,88 +0,0 @@ -name: Experimental workflow -on: - pull_request: - branches: - - nightly - - master - - develop - - verbose - paths-ignore: - - '**.md' - - 'examples/**' - push: - branches: - - nightly - - master - - develop - - verbose - paths-ignore: - - '**.md' - - 'examples/**' -jobs: - run: - name: Run - runs-on: ${{ matrix.operating-system }} - strategy: - fail-fast: false - matrix: - operating-system: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, windows-latest, macos-latest] - php-versions: ['8.0'] - env: - extensions: xml, opcache, pcov - key: cache-v2 - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup cache environment - id: cache-env - uses: shivammathur/cache-extensions@develop - with: - php-version: ${{ matrix.php-versions }} - extensions: ${{ env.extensions }} - key: ${{ env.key }} - - - name: Cache extensions - uses: actions/cache@v2 - with: - path: ${{ steps.cache-env.outputs.dir }} - key: ${{ steps.cache-env.outputs.key }} - restore-keys: ${{ steps.cache-env.outputs.key }} - - - name: Setup PHP with extensions and custom config - run: node dist/index.js - env: - php-version: ${{ matrix.php-versions }} - extensions: ${{ env.extensions }} - ini-values: post_max_size=256M, short_open_tag=On, date.timezone=Asia/Kolkata - coverage: pcov - - - name: Testing PHP version - run: | - php -v - php -r "if(strpos(phpversion(), '${{ matrix.php-versions }}') === false) {throw new Exception('Wrong PHP version Installed');}" - - - name: Testing Composer version - run: | - composer -V - php -r "if(strpos(@exec('composer -V'), 'Composer version') === false) {throw new Exception('Composer not found');}" - - name: Testing Extensions - run: | - php -m - php -r "if(! extension_loaded('mbstring')) {throw new Exception('mbstring not found');}" - php -r "if(! extension_loaded('pcov')) {throw new Exception('PCOV not found');}" - - name: Testing ini values - run: | - php -r "if(ini_get('post_max_size')!='256M') {throw new Exception('post_max_size not added');}" - php -r "if(ini_get('short_open_tag')!=1) {throw new Exception('short_open_tag not added');}" - php -r "if(ini_get('date.timezone')!='Asia/Kolkata') {throw new Exception('date.timezone not added');}" - - name: Test JIT - run: | - php -r "if(! extension_loaded('Zend OPcache')) {throw new Exception('Zend OPcache not found');}" - php -r "if(ini_get('opcache.jit_buffer_size')!='256M') {throw new Exception('opcache.jit_buffer_size not set');}" - php -r "if(ini_get('opcache.jit')!=1235) {throw new Exception('opcache.jit not set');}" - php -r "if(ini_get('pcre.jit')!=1) {throw new Exception('pcre.jit not set');}" - - name: Benchmark JIT - run: | - curl -o bench.php https://raw.githubusercontent.com/php/php-src/master/Zend/bench.php - php bench.php \ No newline at end of file diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index e15b78d9..ba51afe6 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -24,7 +24,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, windows-latest, macos-latest] - php-versions: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] + php-versions: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0'] env: extensions: xml, opcache, xdebug, pcov key: cache-v2 diff --git a/README.md b/README.md index 31c45c46..88c2463a 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ with: ### Xdebug Specify `coverage: xdebug` to use `Xdebug`. -Runs on all [PHP versions supported](#tada-php-support "List of PHP versions supported on this GitHub Action") except `8.0`. +Runs on all [PHP versions supported](#tada-php-support "List of PHP versions supported on this GitHub Action"). ```yaml uses: shivammathur/setup-php@v2 diff --git a/__tests__/coverage.test.ts b/__tests__/coverage.test.ts index ad9a9bb6..30ab8ca1 100644 --- a/__tests__/coverage.test.ts +++ b/__tests__/coverage.test.ts @@ -36,21 +36,11 @@ describe('Config tests', () => { expect(win32).toContain('add_extension xdebug'); }); - it('checking addCoverage with Xdebug on windows', async () => { - const win32: string = await coverage.addCoverage('xdebug', '8.0', 'win32'); - expect(win32).toContain('Xdebug currently only supports PHP 7.4 or lower'); - }); - it('checking addCoverage with Xdebug on linux', async () => { const linux: string = await coverage.addCoverage('xdebug', '7.4', 'linux'); expect(linux).toContain('add_extension xdebug'); }); - it('checking addCoverage with Xdebug on linux', async () => { - const linux: string = await coverage.addCoverage('xdebug', '8.0', 'linux'); - expect(linux).toContain('Xdebug currently only supports PHP 7.4 or lower'); - }); - it('checking addCoverage with Xdebug on darwin', async () => { const darwin: string = await coverage.addCoverage( 'xdebug', @@ -60,15 +50,6 @@ describe('Config tests', () => { expect(darwin).toContain('add_extension xdebug'); }); - it('checking addCoverage with Xdebug on darwin', async () => { - const darwin: string = await coverage.addCoverage( - 'xdebug', - '8.0', - 'darwin' - ); - expect(darwin).toContain('Xdebug currently only supports PHP 7.4 or lower'); - }); - it('checking disableCoverage windows', async () => { const win32 = await coverage.addCoverage('none', '7.4', 'win32'); expect(win32).toContain('Remove-Extension xdebug'); diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 81734487..a32f3da7 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -1,6 +1,12 @@ import * as extensions from '../src/extensions'; describe('Extension tests', () => { + it('checking getXdebugVersion', async () => { + expect(await extensions.getXdebugVersion('5.3')).toContain('2.2.7'); + expect(await extensions.getXdebugVersion('5.4')).toContain('2.4.1'); + expect(await extensions.getXdebugVersion('5.5')).toContain('2.5.5'); + expect(await extensions.getXdebugVersion('5.6')).toContain('2.9.6'); + }); it('checking addExtensionOnWindows', async () => { let win32: string = await extensions.addExtension( 'Xdebug, pcov, sqlite, :intl, phalcon4, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2', @@ -104,8 +110,8 @@ describe('Extension tests', () => { '7.2', 'darwin' ); - expect(darwin).toContain('sudo pecl install -f xdebug'); - expect(darwin).toContain('sudo pecl install -f pcov'); + expect(darwin).toContain('add_brew_extension xdebug'); + expect(darwin).toContain('add_brew_extension pcov'); expect(darwin).toContain('sudo pecl install -f sqlite3'); expect(darwin).toContain('remove_extension intl'); expect(darwin).toContain('add_unstable_extension ast beta extension'); @@ -121,7 +127,7 @@ describe('Extension tests', () => { expect(darwin).toContain('sudo pecl install -f pcov'); darwin = await extensions.addExtension('pcov', '7.2', 'darwin'); - expect(darwin).toContain('sudo pecl install -f pcov'); + expect(darwin).toContain('add_brew_extension pcov'); darwin = await extensions.addExtension('xdebug', '5.3', 'darwin'); expect(darwin).toContain('sudo pecl install -f xdebug-2.2.7'); @@ -133,13 +139,13 @@ describe('Extension tests', () => { expect(darwin).toContain('sudo pecl install -f xdebug-2.5.5'); darwin = await extensions.addExtension('xdebug', '5.6', 'darwin'); - expect(darwin).toContain('sudo pecl install -f xdebug-2.5.5'); + expect(darwin).toContain('add_brew_extension xdebug'); darwin = await extensions.addExtension('xdebug', '7.0', 'darwin'); - expect(darwin).toContain('sudo pecl install -f xdebug-2.9.0'); + expect(darwin).toContain('add_brew_extension xdebug'); darwin = await extensions.addExtension('xdebug', '7.2', 'darwin'); - expect(darwin).toContain('sudo pecl install -f xdebug'); + expect(darwin).toContain('add_brew_extension xdebug'); darwin = await extensions.addExtension('redis', '5.6', 'darwin'); expect(darwin).toContain('sudo pecl install -f redis-2.2.8'); diff --git a/dist/index.js b/dist/index.js index 0e9af736..3bbbd003 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2148,9 +2148,6 @@ const config = __importStar(__webpack_require__(641)); */ async function addCoverageXdebug(version, os_version, pipe) { switch (version) { - case '8.0': - return ('\n' + - (await utils.addLog('$cross', 'xdebug', 'Xdebug currently only supports PHP 7.4 or lower', os_version))); case '7.4': default: return ((await extensions.addExtension('xdebug', version, os_version, true)) + @@ -2685,9 +2682,27 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.addExtension = exports.addExtensionLinux = exports.addExtensionWindows = exports.addExtensionDarwin = void 0; +exports.addExtension = exports.addExtensionLinux = exports.addExtensionWindows = exports.addExtensionDarwin = exports.getXdebugVersion = void 0; const path = __importStar(__webpack_require__(622)); const utils = __importStar(__webpack_require__(163)); +/** + * Function to get Xdebug version compatible with php versions + * + * @param version + */ +async function getXdebugVersion(version) { + switch (version) { + case '5.3': + return '2.2.7'; + case '5.4': + return '2.4.1'; + case '5.5': + return '2.5.5'; + default: + return '2.9.6'; + } +} +exports.getXdebugVersion = getXdebugVersion; /** * Install and enable extensions for darwin * @@ -2741,25 +2756,22 @@ async function addExtensionDarwin(extension_csv, version, pipe) { ' ' + ext_prefix; return; - // match 5.3xdebug - case /5\.3xdebug/.test(version_extension): - command = command_prefix + 'xdebug-2.2.7' + pipe; + // match 5.3xdebug...5.5xdebug + case /5\.[3-5]xdebug/.test(version_extension): + command = + command_prefix + 'xdebug-' + (await getXdebugVersion(version)); break; - // match 5.4xdebug - case /5\.4xdebug/.test(version_extension): - command = command_prefix + 'xdebug-2.4.1' + pipe; + // match 5.6xdebug, 7.0xdebug...7.4xdebug, 8.0xdebug + case /(5\.6|7\.[0-4]|8\.[0-9])xdebug/.test(version_extension): + command = 'add_brew_extension xdebug'; break; - // match 5.5xdebug and 5.6xdebug - case /5\.[5-6]xdebug/.test(version_extension): - command = command_prefix + 'xdebug-2.5.5' + pipe; - break; - // match 7.0redis - case /7\.0xdebug/.test(version_extension): - command = command_prefix + 'xdebug-2.9.0' + pipe; + // match 7.1pcov...7.4pcov, 8.0pcov + case /(7\.[1-4]|8\.[0-9])pcov/.test(version_extension): + command = 'add_brew_extension pcov'; break; // match 5.6redis case /5\.6redis/.test(version_extension): - command = command_prefix + 'redis-2.2.8' + pipe; + command = command_prefix + 'redis-2.2.8'; break; // match imagick case /^imagick$/.test(extension): @@ -2774,7 +2786,7 @@ async function addExtensionDarwin(extension_csv, version, pipe) { // match sqlite case /^sqlite$/.test(extension): extension = 'sqlite3'; - command = command_prefix + extension + pipe; + command = command_prefix + extension; break; // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): @@ -2787,7 +2799,7 @@ async function addExtensionDarwin(extension_csv, version, pipe) { version; return; default: - command = command_prefix + extension + pipe; + command = command_prefix + extension; break; } add_script += diff --git a/src/coverage.ts b/src/coverage.ts index f4fdb1af..d46c11fd 100644 --- a/src/coverage.ts +++ b/src/coverage.ts @@ -15,16 +15,6 @@ export async function addCoverageXdebug( pipe: string ): Promise { switch (version) { - case '8.0': - return ( - '\n' + - (await utils.addLog( - '$cross', - 'xdebug', - 'Xdebug currently only supports PHP 7.4 or lower', - os_version - )) - ); case '7.4': default: return ( diff --git a/src/extensions.ts b/src/extensions.ts index 1381cb79..49d30d04 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -1,6 +1,24 @@ import * as path from 'path'; import * as utils from './utils'; +/** + * Function to get Xdebug version compatible with php versions + * + * @param version + */ +export async function getXdebugVersion(version: string): Promise { + switch (version) { + case '5.3': + return '2.2.7'; + case '5.4': + return '2.4.1'; + case '5.5': + return '2.5.5'; + default: + return '2.9.6'; + } +} + /** * Install and enable extensions for darwin * @@ -60,25 +78,22 @@ export async function addExtensionDarwin( ' ' + ext_prefix; return; - // match 5.3xdebug - case /5\.3xdebug/.test(version_extension): - command = command_prefix + 'xdebug-2.2.7' + pipe; + // match 5.3xdebug...5.5xdebug + case /5\.[3-5]xdebug/.test(version_extension): + command = + command_prefix + 'xdebug-' + (await getXdebugVersion(version)); break; - // match 5.4xdebug - case /5\.4xdebug/.test(version_extension): - command = command_prefix + 'xdebug-2.4.1' + pipe; + // match 5.6xdebug, 7.0xdebug...7.4xdebug, 8.0xdebug + case /(5\.6|7\.[0-4]|8\.[0-9])xdebug/.test(version_extension): + command = 'add_brew_extension xdebug'; break; - // match 5.5xdebug and 5.6xdebug - case /5\.[5-6]xdebug/.test(version_extension): - command = command_prefix + 'xdebug-2.5.5' + pipe; - break; - // match 7.0redis - case /7\.0xdebug/.test(version_extension): - command = command_prefix + 'xdebug-2.9.0' + pipe; + // match 7.1pcov...7.4pcov, 8.0pcov + case /(7\.[1-4]|8\.[0-9])pcov/.test(version_extension): + command = 'add_brew_extension pcov'; break; // match 5.6redis case /5\.6redis/.test(version_extension): - command = command_prefix + 'redis-2.2.8' + pipe; + command = command_prefix + 'redis-2.2.8'; break; // match imagick case /^imagick$/.test(extension): @@ -93,7 +108,7 @@ export async function addExtensionDarwin( // match sqlite case /^sqlite$/.test(extension): extension = 'sqlite3'; - command = command_prefix + extension + pipe; + command = command_prefix + extension; break; // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): @@ -106,7 +121,7 @@ export async function addExtensionDarwin( version; return; default: - command = command_prefix + extension + pipe; + command = command_prefix + extension; break; } add_script += diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index 4e7a845c..c15bf516 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -91,6 +91,16 @@ add_pecl_extension() { fi } +# Function to install a php extension from shivammathur/extensions tap. +add_brew_extension() { + extension=$1 + if ! brew tap | grep shivammathur/extensions; then + brew tap --shallow shivammathur/extensions + fi + brew install "$extension@$version" + sudo cp "$(brew --prefix)/opt/$extension@$version/$extension.so" "$ext_dir" +} + # Function to setup extensions add_extension() { extension=$1 @@ -172,7 +182,7 @@ add_composertool() { add_blackfire() { sudo mkdir -p usr/local/var/run - brew tap blackfireio/homebrew-blackfire >/dev/null 2>&1 + brew tap --shallow blackfireio/homebrew-blackfire >/dev/null 2>&1 brew install blackfire-agent >/dev/null 2>&1 if [[ -n $BLACKFIRE_SERVER_ID ]] && [[ -n $BLACKFIRE_SERVER_TOKEN ]]; then sudo blackfire-agent --register --server-id="$BLACKFIRE_SERVER_ID" --server-token="$BLACKFIRE_SERVER_TOKEN" >/dev/null 2>&1 @@ -212,7 +222,7 @@ update_formulae() { setup_php() { action=$1 export HOMEBREW_NO_INSTALL_CLEANUP=TRUE - brew tap shivammathur/homebrew-php + brew tap --shallow shivammathur/homebrew-php if brew list php@"$version" 2>/dev/null | grep -q "Error" && [ "$action" != "upgrade" ]; then brew unlink php@"$version" else diff --git a/src/scripts/win32.ps1 b/src/scripts/win32.ps1 index fe0982b3..9809bf96 100644 --- a/src/scripts/win32.ps1 +++ b/src/scripts/win32.ps1 @@ -362,6 +362,8 @@ if($version -lt "5.5") { } Update-PhpCAInfo -Path $php_dir -Source $cert_source if ($version -eq 'master') { + Invoke-WebRequest -UseBasicParsing -Uri "https://github.com/shivammathur/php-extensions-windows/releases/download/latest/php_$env:PHPTS`_$arch`_pcov.dll" -OutFile $ext_dir"\php_pcov.dll" >$null 2>&1 + Invoke-WebRequest -UseBasicParsing -Uri "https://github.com/shivammathur/php-extensions-windows/releases/download/latest/php_$env:PHPTS`_$arch`_xdebug.dll" -OutFile $ext_dir"\php_xdebug.dll" >$null 2>&1 Copy-Item $dir"\..\src\bin\php_$env:PHPTS`_pcov.dll" -Destination $ext_dir"\php_pcov.dll" Set-PhpIniKey -Key 'opcache.jit_buffer_size' -Value '256M' -Path $php_dir Set-PhpIniKey -Key 'opcache.jit' -Value '1235' -Path $php_dir