From 422a17d8dca41786a03a6bc294b9e20a88d1448d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B5nis=20Ormisson?= Date: Thu, 17 Feb 2022 14:45:34 +0200 Subject: [PATCH] Use GitHub actions (#447) * init github actions * init github actions: test run on feature branch * github actions: remove alternative mysql port * github actions: expose mysql port * github actions: install & try migrations * github actions: adjust test db configuration for github actions * github actions: run tests * github actions: fix codeception db connection add actions badge * github actions: try only php8 * github actions: add php 7.4 * github actions: dont fail fast * github actions: save test-outputs as artifacts * github actions: save test-outputs only on fail * github actions: save runtime folder in artifacts on failed build * github actions: save runtime folder in artifacts on failed build * github actions: save error logs for tests * github actions: log error if unable to send email on new user creation * github actions: change log conf * github actions: add tests yii2:transaction=false to pass tests on php < 8 * github actions: add tests yii2:transaction=false to pass tests on php < 8 * github actions: remove travis * github actions: add changelog --- .github/workflows/php.yml | 79 ++++++++++++++++++++++++++ .travis.yml | 65 --------------------- CHANGELOG.md | 1 + README.md | 3 +- codeception.dist.yml | 5 +- src/User/Service/UserCreateService.php | 1 + tests/_app/config/db.php | 4 +- 7 files changed, 88 insertions(+), 70 deletions(-) create mode 100644 .github/workflows/php.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..98da305 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,79 @@ +name: Build + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + operating-system: ['ubuntu-latest'] + php-versions: ['8.1', '8.0','7.4','7.3', '7.2','7.1','7.0', '5.6'] + + services: + mariadb: + image: mariadb:latest + ports: + - 3306:3306 + env: + MYSQL_USER: user + MYSQL_PASSWORD: password + MYSQL_DATABASE: yii2-usuario-test + MYSQL_ROOT_PASSWORD: password + options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 + + steps: + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, intl, gd + ini-values: post_max_size=256M, max_execution_time=180 + coverage: xdebug + + - uses: actions/checkout@v2 + + + - name: Verify MariaDB connection + run: | + while ! mysqladmin ping -h"127.0.0.1" --silent; do + sleep 1 + done + + - name: Validate PHP version + run: php -v + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + + - name: Verify db connection & databases + run: mysql -e "SHOW DATABASES;" -h127.0.0.1 -uroot -ppassword + + - name: Install + run: composer install --prefer-dist --no-interaction + + - name: Run migrations + run: php tests/_app/yii.php migrate/up --interactive=0 --migrationPath=@yii/rbac/migrations + + - name: Run tests + run: XDEBUG_MODE=coverage php vendor/bin/codecept run --coverage --coverage-xml + + - name: Archive failed tests artifacts - test output & log + uses: actions/upload-artifact@v2 + if: failure() + with: + name: test-outputs-php-${{ matrix.php-versions }} + path: tests/_output + + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2996e05..0000000 --- a/.travis.yml +++ /dev/null @@ -1,65 +0,0 @@ - -# faster builds on new travis setup not using sudo -sudo: false - -language: php - -php: - - 5.6 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - nightly - -services: - - mysql - -matrix: - fast_finish: true - allow_failures: - - php: nightly - -# cache vendor dirs -# cache: -# directories: -# - vendor -# - $HOME/.composer/cache - -install: - - | - if [[ $TRAVIS_PHP_VERSION != '7.1' && $TRAVIS_PHP_VERSION != '7.2' && $TRAVIS_PHP_VERSION != hhv* ]]; then - # disable xdebug for performance reasons when code coverage is not needed - # note: xdebug on hhvm is disabled by default - phpenv config-rm xdebug.ini || echo "xdebug is not installed" - fi - - travis_retry composer self-update && composer --version - - export PATH="$HOME/.composer/vendor/bin:$PATH" - - COMPOSER_MEMORY_LIMIT=-1 travis_retry composer install --prefer-dist --no-interaction - -before_script: - - php -r "echo INTL_ICU_VERSION . \"\n\";" - - php -r "echo INTL_ICU_DATA_VERSION . \"\n\";" - - mysql --version - - # initialize database - - mysql -e 'CREATE DATABASE `yii2-usuario-test`;'; - - php tests/_app/yii.php migrate/up --interactive=0 - - php tests/_app/yii.php migrate/up --interactive=0 --migrationPath=@yii/rbac/migrations - - # enable code coverage on PHP 7.2, only one PHP version needs to generate coverage data - - | - if [ $TRAVIS_PHP_VERSION = '7.2' ]; then - CODECEPTION_FLAGS="--coverage-xml" - fi - -script: - - composer validate --no-check-lock - - vendor/bin/codecept run $CODECEPTION_FLAGS - -after_script: - - | - if [ $TRAVIS_PHP_VERSION = '7.2' ]; then - travis_retry wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover tests/_output/coverage.xml - fi diff --git a/CHANGELOG.md b/CHANGELOG.md index be6a4df..0007c1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # CHANGELOG ## work in progress + - Fix replace non-working travis build with working github actions build (TonisOrmisson) - Fix user login events not triggered on ajax requests (TonisOrmisson) - Enh: Added minimum requirements when a new password is automatically generated (MatteoF96) - Fix #380: Avoid rewriting AccessRule::matchRole (maxxer) diff --git a/README.md b/README.md index 3bdb3db..17aa983 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ Yii 2 Usuario Extension [![Packagist Version](https://img.shields.io/packagist/v/2amigos/yii2-usuario.svg?style=flat-square)](https://packagist.org/packages/2amigos/yii2-usuario) [![Latest Stable Version](https://poser.pugx.org/2amigos/yii2-usuario/version)](https://packagist.org/packages/2amigos/yii2-usuario) [![Total Downloads](https://poser.pugx.org/2amigos/yii2-usuario/downloads)](https://packagist.org/packages/2amigos/yii2-usuario) -[![Build Status](https://travis-ci.org/2amigos/yii2-usuario.svg?branch=master)](https://travis-ci.org/2amigos/yii2-usuario) +[![Build Status](https://github.com/2amigos/yii2-usuario/actions/workflows/php.yml/badge.svg)](https://github.com/2amigos/yii2-usuario/actions/) + [![Latest Unstable Version](https://poser.pugx.org/2amigos/yii2-usuario/v/unstable)](//packagist.org/packages/2amigos/yii2-usuario) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/2amigos/yii2-usuario/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/2amigos/yii2-usuario/?branch=master) diff --git a/codeception.dist.yml b/codeception.dist.yml index f90b32a..b9a5a10 100644 --- a/codeception.dist.yml +++ b/codeception.dist.yml @@ -4,8 +4,8 @@ paths: log: tests/_output data: tests/_data helpers: tests/_support +bootstrap: _bootstrap.php settings: - bootstrap: _bootstrap.php colors: true memory_limit: 1024M modules: @@ -13,11 +13,12 @@ modules: Db: dsn: 'mysql:host=127.0.0.1;dbname=yii2-usuario-test' user: 'root' - password: '' + password: 'password' dump: tests/_data/schema.sql Yii2: configFile: 'tests/_app/config/test.php' cleanup: false + transaction: false coverage: enabled: true whitelist: diff --git a/src/User/Service/UserCreateService.php b/src/User/Service/UserCreateService.php index 5f7622d..a631d5e 100644 --- a/src/User/Service/UserCreateService.php +++ b/src/User/Service/UserCreateService.php @@ -87,6 +87,7 @@ class UserCreateService implements ServiceInterface $model->addError('username', $error_msg); } $transaction->rollBack(); + Yii::error($error_msg, 'usuario'); return false; } $transaction->commit(); diff --git a/tests/_app/config/db.php b/tests/_app/config/db.php index ef85450..db1c386 100644 --- a/tests/_app/config/db.php +++ b/tests/_app/config/db.php @@ -2,9 +2,9 @@ $db = [ 'class' => 'yii\db\Connection', - 'dsn' => 'mysql:host=localhost;dbname=yii2-usuario-test', + 'dsn' => 'mysql:host=127.0.0.1;dbname=yii2-usuario-test', 'username' => 'root', - 'password' => '', + 'password' => 'password', 'charset' => 'utf8', ];