From fce93115225eebc16a5cf1b483c04dbd0c3259e8 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Sun, 13 Oct 2019 09:48:29 +0530 Subject: [PATCH] Add support for phalcon --- README.md | 8 +++-- __tests__/extensions.test.ts | 8 +++++ examples/phalcon-mysql.yml | 60 ++++++++++++++++++++++++++++++++++ examples/phalcon-postgres.yml | 61 +++++++++++++++++++++++++++++++++++ lib/extensions.js | 8 +++++ lib/utils.js | 5 ++- src/extensions.ts | 8 +++++ src/scripts/phalcon.sh | 19 +++++++++++ src/utils.ts | 5 ++- 9 files changed, 177 insertions(+), 5 deletions(-) create mode 100644 examples/phalcon-mysql.yml create mode 100644 examples/phalcon-postgres.yml create mode 100644 src/scripts/phalcon.sh diff --git a/README.md b/README.md index f7437f19..cd3d49cb 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,9 @@ with: Specify `coverage: pcov` to use `PCOV`. It is much faster than `Xdebug`. +`PCOV` needs `PHP >= 7.1` If your source code directory is other than `src`, `lib` or, `app`, specify `pcov.directory` using the `ini-values-csv` input. -`PCOV` needs `PHPUnit >= 8.0` and `PHP >= 7.1`, `PHPUnit` needs `PHP >= 7.2`. So use `PHP >= 7.2` with `PCOV` + ```yaml uses: shivammathur/setup-php@master @@ -149,8 +150,7 @@ jobs: - name: Check Composer Version run: composer -V - name: Check PHP Extensions - run: php -m - + run: php -m ``` ### Examples @@ -166,6 +166,8 @@ Examples for setting up this GitHub Action with different PHP Frameworks/Package |Lumen with `MySQL` and `Redis`|`ubuntu`|[lumen-mysql.yml](./examples/lumen-mysql.yml "GitHub Action for Lumen with MySQL and Redis")| |Lumen with `PostgreSQL` and `Redis`|`ubuntu`|[lumen-postgres.yml](./examples/lumen-postgres.yml "GitHub Action for Lumen with PostgreSQL and Redis")| |Lumen without services|`macOS`, `ubuntu` and `windows`|[lumen.yml](./examples/lumen.yml "GitHub Action for Lumen without services")| +|Phalcon with `MySQL`|`ubuntu`|[phalcon-mysql.yml](./examples/phalcon-mysql.yml "GitHub Action for Phalcon with MySQL")| +|Phalcon with `PostgreSQL`|`ubuntu`|[phalcon-postgres.yml](./examples/phalcon-postgres.yml "GitHub Action for Phalcon with PostgreSQL")| |Slim Framework|`macOS`, `ubuntu` and `windows`|[slim-framework.yml](./examples/slim-framework.yml "GitHub Action for Slim Framework")| |Symfony with `MySQL`|`ubuntu`|[symfony-mysql.yml](./examples/symfony-mysql.yml "GitHub Action for Symfony with MySQL")| |Symfony with `PostgreSQL`|`ubuntu`|[symfony-postgres.yml](./examples/symfony-postgres.yml "GitHub Action for Symfony with PostgreSQL")| diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index c4840b7f..5f559653 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -45,6 +45,14 @@ describe('Extension tests', () => { expect(linux).toContain('./xdebug.sh'); expect(linux).toContain('./pcov.sh'); + linux = await extensions.addExtension('phalcon3, phalcon4', '7.2', 'linux'); + expect(linux).toContain('./phalcon.sh master 7.2'); + expect(linux).toContain('./phalcon.sh 4.0.x 7.2'); + + linux = await extensions.addExtension('phalcon3, phalcon4', '7.3', 'linux'); + expect(linux).toContain('./phalcon.sh master 7.3'); + expect(linux).toContain('./phalcon.sh 4.0.x 7.3'); + linux = await extensions.addExtension('xdebug', '7.2', 'fedora'); expect(linux).toContain('Platform fedora is not supported'); }); diff --git a/examples/phalcon-mysql.yml b/examples/phalcon-mysql.yml new file mode 100644 index 00000000..170cc6c4 --- /dev/null +++ b/examples/phalcon-mysql.yml @@ -0,0 +1,60 @@ +# GitHub Action for Phalcon with MySQL +## Notes +## Make sure you have .env.example or .env file in your project +## and you have loaded Dotenv (https://github.com/vlucas/phpdotenv) +name: Testing Phalcon with MySQL +on: [push, pull_request] +jobs: + phalcon: + name: Phalcon (PHP ${{ matrix.php-versions }}) + runs-on: ubuntu-latest + env: + DB_ADAPTER: mysql + DB_HOST: 127.0.0.1 + DB_NAME: phalcon + DB_USERNAME: root + DB_PASSWORD: password + CODECEPTION_URL: 127.0.0.1 + CODECEPTION_PORT: 8888 + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: false + MYSQL_ROOT_PASSWORD: password + MYSQL_DATABASE: phalcon + ports: + - 3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + strategy: + fail-fast: false + max-parallel: 3 + matrix: + php-versions: ['7.2', '7.3'] + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php + with: + php-version: ${{ matrix.php-versions }} + extension-csv: mbstring, phalcon4, mysql #use phalcon3 for the phalcon 3.x. + coverage: xdebug #optional + - name: Install Composer dependencies + run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + - name: Prepare the application + run: php -r "file_exists('.env') || copy('.env.example', '.env');" + - name: Run Migration + run: | + if [ ! -e phinx.yml ]; then vendor/bin/phinx init; fi + vendor/bin/phinx migrate + vendor/bin/phinx seed:run + env: + DB_PORT: ${{ job.services.mysql.ports['3306'] }} + - name: Run Tests + run: | + (cd public && nohup php -S $CODECEPTION_URL:$CODECEPTION_PORT > phalcon.log 2>&1 &) + vendor/bin/codecept build + vendor/bin/codecept run + env: + DB_PORT: ${{ job.services.mysql.ports['3306'] }} \ No newline at end of file diff --git a/examples/phalcon-postgres.yml b/examples/phalcon-postgres.yml new file mode 100644 index 00000000..5daf3a0b --- /dev/null +++ b/examples/phalcon-postgres.yml @@ -0,0 +1,61 @@ +# GitHub Action for Phalcon with PostgreSQL +## Notes +## Make sure you have .env.example or .env file in your project +## and you have loaded Dotenv (https://github.com/vlucas/phpdotenv) +name: Testing Phalcon with PostgreSQL +on: [push, pull_request] +jobs: + phalcon: + name: Phalcon (PHP ${{ matrix.php-versions }}) + runs-on: ubuntu-latest + env: + DB_ADAPTER: pgsql + DB_HOST: 127.0.0.1 + DB_NAME: postgres + DB_USERNAME: postgres + DB_PASSWORD: postgres + CODECEPTION_URL: 127.0.0.1 + CODECEPTION_PORT: 8888 + DB_CONNECTION: pgsql + services: + postgres: + image: postgres:10.8 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - 5432/tcp + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 + strategy: + fail-fast: false + max-parallel: 3 + matrix: + php-versions: ['7.2', '7.3'] + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@master #https://github.com/shivammathur/setup-php + with: + php-version: ${{ matrix.php-versions }} + extension-csv: mbstring, phalcon4, pgsql #use phalcon3 for the phalcon 3.x + coverage: xdebug #optional + - name: Install Composer dependencies + run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + - name: Prepare the application + run: php -r "file_exists('.env') || copy('.env.example', '.env');" + - name: Run Migration + run: | + if [ ! -e phinx.yml ]; then vendor/bin/phinx init; fi + vendor/bin/phinx migrate + vendor/bin/phinx seed:run + env: + DB_PORT: ${{ job.services.postgres.ports['5432'] }} + - name: Run Tests + run: | + (cd public && nohup php -S $CODECEPTION_URL:$CODECEPTION_PORT > phalcon.log 2>&1 &) + vendor/bin/codecept build + vendor/bin/codecept run + env: + DB_PORT: ${{ job.services.postgres.ports['5432'] }} \ No newline at end of file diff --git a/lib/extensions.js b/lib/extensions.js index 9f0c3f99..eacebf3c 100644 --- a/lib/extensions.js +++ b/lib/extensions.js @@ -156,6 +156,14 @@ function addExtensionLinux(extension_csv, version, log_prefix) { install_command = './pcov.sh >/dev/null 2>&1 && echo "extension=pcov.so" >> $ini_file'; break; + case '7.2phalcon3': + case '7.3phalcon3': + install_command = './phalcon.sh master ' + version + ' >/dev/null 2>&1'; + break; + case '7.2phalcon4': + case '7.3phalcon4': + install_command = './phalcon.sh 4.0.x ' + version + ' >/dev/null 2>&1'; + break; default: install_command = 'sudo DEBIAN_FRONTEND=noninteractive apt install -y php' + diff --git a/lib/utils.js b/lib/utils.js index 7d923847..4266f4a9 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -88,11 +88,14 @@ function readScript(filename, version, os_version) { } break; case 'linux': + let files = ['scripts/phalcon.sh']; + yield readFiles74(['scripts/phalcon.sh']); switch (version) { case '7.4': - yield readFiles74(['scripts/xdebug.sh', 'scripts/pcov.sh']); + files.concat(['scripts/xdebug.sh', 'scripts/pcov.sh']); break; } + yield readFiles74(files); break; case 'win32': switch (version) { diff --git a/src/extensions.ts b/src/extensions.ts index 68d7a202..069af4a8 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -152,6 +152,14 @@ export async function addExtensionLinux( install_command = './pcov.sh >/dev/null 2>&1 && echo "extension=pcov.so" >> $ini_file'; break; + case '7.2phalcon3': + case '7.3phalcon3': + install_command = './phalcon.sh master ' + version + ' >/dev/null 2>&1'; + break; + case '7.2phalcon4': + case '7.3phalcon4': + install_command = './phalcon.sh 4.0.x ' + version + ' >/dev/null 2>&1'; + break; default: install_command = 'sudo DEBIAN_FRONTEND=noninteractive apt install -y php' + diff --git a/src/scripts/phalcon.sh b/src/scripts/phalcon.sh new file mode 100644 index 00000000..b1ef2c4b --- /dev/null +++ b/src/scripts/phalcon.sh @@ -0,0 +1,19 @@ +ini_file=$(php --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") +sudo DEBIAN_FRONTEND=noninteractive apt install php"$2"-dev php-pear -y +for tool in php-config phpize; do + if [ -e "/usr/bin/$tool$2" ]; then + sudo update-alternatives --set $tool /usr/bin/"$tool$2" & + fi +done +sudo pecl config-set php_ini "$ini_file" +sudo pear config-set php_ini "$ini_file" +sudo pecl install psr +if [ "$1" = "master" ]; then + sudo DEBIAN_FRONTEND=noninteractive apt install php"$2"-phalcon -y +else + git clone --depth=1 -v https://github.com/phalcon/cphalcon.git -b "$1" + ( + cd cphalcon/build && sudo ./install --phpize /usr/bin/phpize"$2" --php-config /usr/bin/php-config"$2" + echo "extension=phalcon.so" >> "$ini_file" + ) +fi \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index 0b22f572..cdbf1da9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -79,11 +79,14 @@ export async function readScript( } break; case 'linux': + let files: Array = ['scripts/phalcon.sh']; + await readFiles74(['scripts/phalcon.sh']); switch (version) { case '7.4': - await readFiles74(['scripts/xdebug.sh', 'scripts/pcov.sh']); + files.concat(['scripts/xdebug.sh', 'scripts/pcov.sh']); break; } + await readFiles74(files); break; case 'win32': switch (version) {