CI: cleanup the gitlab-ci yml file and test MySQL and PostgreSQL migrations

This commit splits the `test` job into three separate jobs:
- test
- lint
- db:migrate

It also factorise some code, and remove useless use of git checkout
This commit is contained in:
PaulR 2019-04-19 14:32:56 +02:00 committed by Thomas Citharel
parent d87ca39693
commit c26fef6b39
6 changed files with 97 additions and 17 deletions

View File

@ -1,21 +1,91 @@
image: framasoft/framadate-ci variables:
TESTING_IMAGE: framasoft/framadate-ci:php-7.2
image: ${TESTING_IMAGE}
cache:
key: "${TESTING_IMAGE}:${CI_PROJECT_ID}"
paths:
- vendor/
before_script:
- composer install -o --no-interaction --no-progress --prefer-dist
stages: stages:
- test - test
- deploy - deploy
- beta - beta
- funky - funky
# Run php-cs-fixer and phpunit on all branches # Run phpunit on all branches
test: test:
stage: test stage: test
script: script:
- composer install -o --no-interaction --no-progress --prefer-dist
- php vendor/bin/php-cs-fixer fix --verbose --dry-run
- APP_ENV=test bin/doctrine migrations:migrate --no-interaction -vvv
- vendor/bin/phpunit --bootstrap app/tests/bootstrap.php --debug app/tests - vendor/bin/phpunit --bootstrap app/tests/bootstrap.php --debug app/tests
cache:
paths: # Run php-cs-fixer on all branches
- vendor/ lint:
stage: test
script:
- php vendor/bin/php-cs-fixer fix --verbose --dry-run
# Run doctrine migrations with MySQL
.db:migration:mysql:
stage: test
variables:
APP_ENV: "test"
MYSQL_DATABASE: "fd_test"
MYSQL_ROOT_PASSWORD: "coucou"
FRAMADATE_DB_DRIVER: 'pdo_mysql'
FRAMADATE_DB_HOST: "mysql"
FRAMADATE_DB_NAME: "${MYSQL_DATABASE}"
FRAMADATE_DB_USER: "root"
FRAMADATE_DB_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
script:
- docker-php-ext-install "${FRAMADATE_DB_DRIVER}"
- bin/doctrine migrations:status -vvv
- bin/doctrine migrations:migrate --no-interaction -vvv
- bin/doctrine migrations:status -vvv
db:migration:mysql:5.6:
extends: .db:migration:mysql
services:
- 'mysql:5.6'
db:migration:mysql:5.7:
extends: .db:migration:mysql
services:
- 'mysql:5.7'
db:migration:mysql:8:
extends: .db:migration:mysql
services:
- name: 'mysql:8'
command: ['--default-authentication-plugin=mysql_native_password']
# Run doctrine migrations with PostgreSQL
.db:migration:postgresql:
stage: test
variables:
APP_ENV: "test"
POSTGRES_DB: "fd_test"
POSTGRES_USER: "marmotte"
POSTGRES_PASSWORD: "sleeping"
FRAMADATE_DB_DRIVER: 'pdo_pgsql'
FRAMADATE_DB_HOST: "postgres"
FRAMADATE_DB_NAME: "${POSTGRES_DB}"
FRAMADATE_DB_USER: "${POSTGRES_USER}"
FRAMADATE_DB_PASSWORD: "${POSTGRES_PASSWORD}"
script:
- docker-php-ext-install "${FRAMADATE_DB_DRIVER}"
- bin/doctrine migrations:status -vvv
- bin/doctrine migrations:migrate --no-interaction -vvv
- bin/doctrine migrations:status -vvv
db:migration:postgresql:9.6:
extends: .db:migration:postgresql
services:
- 'postgres:9.6'
check:missing:trads: check:missing:trads:
stage: test stage: test
@ -65,7 +135,6 @@ pages:
beta: beta:
stage: beta stage: beta
script: script:
- git checkout develop
- composer install -o --no-interaction --no-progress --prefer-dist --no-dev - composer install -o --no-interaction --no-progress --prefer-dist --no-dev
- composer dump-autoload --optimize --no-dev --classmap-authoritative - composer dump-autoload --optimize --no-dev --classmap-authoritative
# - if [ ! -z ${ZANATA_CONFIG_FRAMABOT+x} ]; then mkdir -p ${HOME}/.config; echo -e "${ZANATA_CONFIG_FRAMABOT}" > ${HOME}/.config/zanata.ini; fi # - if [ ! -z ${ZANATA_CONFIG_FRAMABOT+x} ]; then mkdir -p ${HOME}/.config; echo -e "${ZANATA_CONFIG_FRAMABOT}" > ${HOME}/.config/zanata.ini; fi
@ -87,7 +156,6 @@ beta:
funky: funky:
stage: funky stage: funky
script: script:
- git checkout funky
- composer install - composer install
- mkdir tpl_c - mkdir tpl_c
- mkdir .public - mkdir .public

View File

@ -23,7 +23,7 @@ Follow the instructions on <https://framagit.org/framasoft/framadate/framadate/w
* PHP [PHP 5.6](http://php.net) * PHP [PHP 5.6](http://php.net)
* Templating [Smarty](http://www.smarty.net/), * Templating [Smarty](http://www.smarty.net/),
* I18N [o80-i18n](https://github.com/olivierperez/o80-i18n) * I18N [o80-i18n](https://github.com/olivierperez/o80-i18n)
* Database: PostgreSQL ou [MySQL 5.5](https://dev.mysql.com/downloads/mysql/5.5.html) * Database: PostgreSQL 9.6 or [MySQL 5.6+](https://dev.mysql.com/downloads/mysql/5.6.html)/[MariaDB 10.1+](https://www.debian.org/releases/stable/mips/release-notes/ch-whats-new.en.html#mariadb-replaces-mysql)
--- ---

View File

@ -53,6 +53,10 @@ class Version20151012082600 extends AbstractMigration
$this->skipIf($commentTable->hasColumn('date'), 'Column date in comment table already exists'); $this->skipIf($commentTable->hasColumn('date'), 'Column date in comment table already exists');
// The default for datetime types is only available for MySQL 5.6
// See the "Functionality Added or Changed" section,
// "Important Change: In MySQL, the TIMESTAMP data type" element, on
// https://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-6.html
$commentTable->addColumn('date', 'datetime', ['default' => 0]); $commentTable->addColumn('date', 'datetime', ['default' => 0]);
} }

View File

@ -32,22 +32,22 @@ const ADRESSEMAILADMIN = 'admin@app.tld';
const ADRESSEMAILREPONSEAUTO = 'no@reply'; const ADRESSEMAILREPONSEAUTO = 'no@reply';
// Database driver // Database driver
const DB_DRIVER = 'pdo_sqlite'; const DB_DRIVER = FRAMADATE_DB_DRIVER;
// Database name // Database name
const DB_NAME = 'framadate'; const DB_NAME = FRAMADATE_DB_NAME;
// Database host // Database host
const DB_HOST = ''; const DB_HOST = FRAMADATE_DB_HOST;
// Database port // Database port
const DB_PORT = ''; const DB_PORT = FRAMADATE_DB_PORT;
// Database user // Database user
const DB_USER = ''; const DB_USER = FRAMADATE_DB_USER;
// Database password // Database password
const DB_PASSWORD = ''; const DB_PASSWORD = FRAMADATE_DB_PASSWORD;
// Table name prefix // Table name prefix
const TABLENAME_PREFIX = 'fd_'; const TABLENAME_PREFIX = 'fd_';

View File

@ -40,6 +40,13 @@ define('ROOT_DIR', __DIR__ . '/../../');
$path = '/app/inc/config.php'; $path = '/app/inc/config.php';
if (getenv('APP_ENV') === 'test') { if (getenv('APP_ENV') === 'test') {
$path = '/app/inc/config.test.php'; $path = '/app/inc/config.test.php';
// Read DB connection params from Environment Variables if possible
define('FRAMADATE_DB_DRIVER', getenv('FRAMADATE_DB_DRIVER') ? getenv('FRAMADATE_DB_DRIVER') : 'pdo_sqlite');
define('FRAMADATE_DB_NAME', getenv('FRAMADATE_DB_NAME') ? getenv('FRAMADATE_DB_NAME') : 'framadate');
define('FRAMADATE_DB_HOST', getenv('FRAMADATE_DB_HOST') ? getenv('FRAMADATE_DB_HOST') : '');
define('FRAMADATE_DB_PORT', getenv('FRAMADATE_DB_PORT') ? getenv('FRAMADATE_DB_PORT') : '');
define('FRAMADATE_DB_USER', getenv('FRAMADATE_DB_USER') ? getenv('FRAMADATE_DB_USER') : '');
define('FRAMADATE_DB_PASSWORD', getenv('FRAMADATE_DB_PASSWORD') ? getenv('FRAMADATE_DB_PASSWORD') : '');
} }
define('CONF_FILENAME', ROOT_DIR . $path); define('CONF_FILENAME', ROOT_DIR . $path);

View File

@ -55,4 +55,5 @@ try {
$cli->run($input, $output); $cli->run($input, $output);
} catch (\Exception $e) { } catch (\Exception $e) {
$style->error($e->getMessage()); $style->error($e->getMessage());
exit(1);
} }