From 5b5c99333541e14245ae67878f32fa24e9a816aa Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Tue, 24 Sep 2019 16:29:19 +0200 Subject: [PATCH] Add mariadb tests --- .drone.yml | 328 ++++++++++++++++++++++++++++++++++------------------ autotest.sh | 131 +++++++++++++++------ 2 files changed, 312 insertions(+), 147 deletions(-) diff --git a/.drone.yml b/.drone.yml index 53df6dabad..6e77ffd6b0 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,13 +1,13 @@ kind: pipeline -name: mysql-php7.1 +name: mysql8.0-php7.1 steps: -- name: mysql-php7.1 +- name: mysql8.0-php7.1 image: friendicaci/php7.1:php7.1.32 commands: - phpenmod xdebug - sleep 20 - - ./autotest.sh + - ./autotest.sh mysql - wget https://codecov.io/bash -O codecov.sh - sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" - sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" @@ -39,13 +39,13 @@ services: # - push --- kind: pipeline -name: mysql-php7.2 +name: mysql8.0-php7.2 steps: - - name: mysql-php7.2 + - name: mysql8.0-php7.2 image: friendicaci/php7.2:php7.2.22 commands: - - NOCOVERAGE=true ./autotest.sh + - NOCOVERAGE=true ./autotest.sh mysql environment: MYSQL_USERNAME: friendica MYSQL_PASSWORD: friendica @@ -74,30 +74,132 @@ services: # - push --- kind: pipeline -name: mysql-php7.3 +name: mysql8.0-php7.3 steps: - - name: mysql-php7.3 - image: friendicaci/php7.3:php7.3.9 - commands: - - NOCOVERAGE=true ./autotest.sh - environment: - MYSQL_USERNAME: friendica - MYSQL_PASSWORD: friendica - MYSQL_DATABASE: friendica - MYSQL_HOST: mysql +- name: mysql8.0-php7.3 + image: friendicaci/php7.3:php7.3.9 + commands: + - NOCOVERAGE=true ./autotest.sh mysql + environment: + MYSQL_USERNAME: friendica + MYSQL_PASSWORD: friendica + MYSQL_DATABASE: friendica + MYSQL_HOST: mysql services: - - name: mysql - image: mysql:8.0 - command: [ "--default-authentication-plugin=mysql_native_password" ] - environment: - MYSQL_ROOT_PASSWORD: friendica - MYSQL_USER: friendica - MYSQL_PASSWORD: friendica - MYSQL_DATABASE: friendica - tmpfs: - - /var/lib/mysql +- name: mysql + image: mysql:8.0 + command: [ "--default-authentication-plugin=mysql_native_password" ] + environment: + MYSQL_ROOT_PASSWORD: friendica + MYSQL_USER: friendica + MYSQL_PASSWORD: friendica + MYSQL_DATABASE: friendica + tmpfs: + - /var/lib/mysql + +#trigger: +# branch: +# - master +# - develop +# - "*-rc" +# event: +# - pull_request +# - push +--- +kind: pipeline +name: mariadb10.1-php7.1 + +steps: +- name: mariadb10.1-php7.1 + image: friendicaci/php7.1:php7.1.32 + commands: + - NOCOVERAGE=true ./autotest.sh mariadb + environment: + MYSQL_USER: friendica + MYSQL_PASSWORD: friendica + MYSQL_DATABASE: friendica + MYSQL_HOST: mariadb + +services: +- name: mariadb + image: mariadb:10.1 + environment: + MYSQL_ROOT_PASSWORD: friendica + MYSQL_USER: friendica + MYSQL_PASSWORD: friendica + MYSQL_DATABASE: friendica + tmpfs: + - /var/lib/mysql + +#trigger: +# branch: +# - master +# - develop +# - "*-rc" +# event: +# - pull_request +# - push +--- +kind: pipeline +name: mariadb10.1-php7.2 + +steps: +- name: mariadb10.1-php7.2 + image: friendicaci/php7.2:php7.2.22 + commands: + - NOCOVERAGE=true ./autotest.sh mariadb + environment: + MYSQL_USER: friendica + MYSQL_PASSWORD: friendica + MYSQL_DATABASE: friendica + MYSQL_HOST: mariadb + +services: +- name: mariadb + image: mariadb:10.1 + environment: + MYSQL_ROOT_PASSWORD: friendica + MYSQL_USER: friendica + MYSQL_PASSWORD: friendica + MYSQL_DATABASE: friendica + tmpfs: + - /var/lib/mysql + +#trigger: +# branch: +# - master +# - develop +# - "*-rc" +# event: +# - pull_request +# - push +--- +kind: pipeline +name: mariadb10.1-php7.3 + +steps: +- name: mariadb10.1-php7.3 + image: friendicaci/php7.3:php7.3.9 + commands: + - NOCOVERAGE=true ./autotest.sh mariadb + environment: + MYSQL_USER: friendica + MYSQL_PASSWORD: friendica + MYSQL_DATABASE: friendica + MYSQL_HOST: mariadb + +services: +- name: mariadb + image: mariadb:10.1 + environment: + MYSQL_ROOT_PASSWORD: friendica + MYSQL_USER: friendica + MYSQL_PASSWORD: friendica + MYSQL_DATABASE: friendica + tmpfs: + - /var/lib/mysql #trigger: # branch: @@ -112,21 +214,21 @@ kind: pipeline name: redis-php7.1 steps: - - name: redis-php7.1 - image: friendicaci/php7.1:php7.1.32 - commands: - - phpenmod xdebug - - sleep 20 - - NOINSTALL=true TEST_SELECTION=REDIS ./autotest.sh - - wget https://codecov.io/bash -O codecov.sh - - sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" - - sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" - environment: - REDIS_HOST: redis +- name: redis-php7.1 + image: friendicaci/php7.1:php7.1.32 + commands: + - phpenmod xdebug + - sleep 20 + - NOINSTALL=true TEST_SELECTION=REDIS ./autotest.sh mysql + - wget https://codecov.io/bash -O codecov.sh + - sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" + - sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" + environment: + REDIS_HOST: redis services: - - name: redis - image: redis +- name: redis + image: redis #trigger: # branch: @@ -141,16 +243,16 @@ kind: pipeline name: redis-php7.2 steps: - - name: redis-php7.2 - image: friendicaci/php7.2:php7.2.22 - commands: - - NOCOVERAGE=true NOINSTALL=true TEST_SELECTION=REDIS ./autotest.sh - environment: - REDIS_HOST: redis +- name: redis-php7.2 + image: friendicaci/php7.2:php7.2.22 + commands: + - NOCOVERAGE=true NOINSTALL=true TEST_SELECTION=REDIS ./autotest.sh mysql + environment: + REDIS_HOST: redis services: - - name: redis - image: redis +- name: redis + image: redis #trigger: # branch: @@ -165,16 +267,16 @@ kind: pipeline name: redis-php7.3 steps: - - name: redis-php7.3 - image: friendicaci/php7.3:php7.3.9 - commands: - - NOCOVERAGE=true NOINSTALL=true TEST_SELECTION=REDIS ./autotest.sh - environment: - REDIS_HOST: redis +- name: redis-php7.3 + image: friendicaci/php7.3:php7.3.9 + commands: + - NOCOVERAGE=true NOINSTALL=true TEST_SELECTION=REDIS ./autotest.sh mysql + environment: + REDIS_HOST: redis services: - - name: redis - image: redis +- name: redis + image: redis #trigger: # branch: @@ -190,21 +292,21 @@ kind: pipeline name: memcache-php7.1 steps: - - name: memcache-php7.1 - image: friendicaci/php7.1:php7.1.32 - commands: - - phpenmod xdebug - - sleep 20 - - NOINSTALL=true TEST_SELECTION=MEMCACHE ./autotest.sh - - wget https://codecov.io/bash -O codecov.sh - - sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" - - sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" - environment: - MEMCACHE_HOST: memcached +- name: memcache-php7.1 + image: friendicaci/php7.1:php7.1.32 + commands: + - phpenmod xdebug + - sleep 20 + - NOINSTALL=true TEST_SELECTION=MEMCACHE ./autotest.sh mysql + - wget https://codecov.io/bash -O codecov.sh + - sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" + - sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" + environment: + MEMCACHE_HOST: memcached services: - - name: memcached - image: memcached +- name: memcached + image: memcached #trigger: # branch: @@ -219,16 +321,16 @@ kind: pipeline name: memcache-php7.2 steps: - - name: memcache-php7.2 - image: friendicaci/php7.2:php7.2.22 - commands: - - NOCOVERAGE=true NOINSTALL=true TEST_SELECTION=MEMCACHE ./autotest.sh - environment: - MEMCACHE_HOST: memcached +- name: memcache-php7.2 + image: friendicaci/php7.2:php7.2.22 + commands: + - NOCOVERAGE=true NOINSTALL=true TEST_SELECTION=MEMCACHE ./autotest.sh mysql + environment: + MEMCACHE_HOST: memcached services: - - name: memcached - image: memcached +- name: memcached + image: memcached #trigger: # branch: @@ -243,16 +345,16 @@ kind: pipeline name: memcache-php7.3 steps: - - name: memcache-php7.3 - image: friendicaci/php7.3:php7.3.9 - commands: - - NOCOVERAGE=true NOINSTALL=true TEST_SELECTION=MEMCACHE ./autotest.sh - environment: - MEMCACHE_HOST: memcached +- name: memcache-php7.3 + image: friendicaci/php7.3:php7.3.9 + commands: + - NOCOVERAGE=true NOINSTALL=true TEST_SELECTION=MEMCACHE ./autotest.sh mysql + environment: + MEMCACHE_HOST: memcached services: - - name: memcached - image: memcached +- name: memcached + image: memcached #trigger: # branch: @@ -269,21 +371,21 @@ kind: pipeline name: memcached-php7.1 steps: - - name: memcached-php7.1 - image: friendicaci/php7.1:php7.1.32 - commands: - - phpenmod xdebug - - sleep 20 - - NOINSTALL=true TEST_SELECTION=MEMCACHED ./autotest.sh - - wget https://codecov.io/bash -O codecov.sh - - sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" - - sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" - environment: - MEMCACHED_HOST: memcached +- name: memcached-php7.1 + image: friendicaci/php7.1:php7.1.32 + commands: + - phpenmod xdebug + - sleep 20 + - NOINSTALL=true TEST_SELECTION=MEMCACHED ./autotest.sh mysql + - wget https://codecov.io/bash -O codecov.sh + - sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" + - sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 2f4b253b-ca17-41d7-96e3-81623581c97d -f tests/autotest-clover.xml; fi" + environment: + MEMCACHED_HOST: memcached services: - - name: memcached - image: memcached +- name: memcached + image: memcached #trigger: # branch: @@ -298,16 +400,16 @@ kind: pipeline name: memcached-php7.2 steps: - - name: memcached-php7.2 - image: friendicaci/php7.2:php7.2.22 - commands: - - NOCOVERAGE=true NOINSTALL=true TEST_SELECTION=MEMCACHED ./autotest.sh - environment: - MEMCACHED_HOST: memcached +- name: memcached-php7.2 + image: friendicaci/php7.2:php7.2.22 + commands: + - NOCOVERAGE=true NOINSTALL=true TEST_SELECTION=MEMCACHED ./autotest.sh mysql + environment: + MEMCACHED_HOST: memcached services: - - name: memcached - image: memcached +- name: memcached + image: memcached #trigger: # branch: @@ -322,16 +424,16 @@ kind: pipeline name: memcached-php7.3 steps: - - name: memcached-php7.3 - image: friendicaci/php7.3:php7.3.9 - commands: - - NOCOVERAGE=true NOINSTALL=true TEST_SELECTION=MEMCACHED ./autotest.sh - environment: - MEMCACHED_HOST: memcached +- name: memcached-php7.3 + image: friendicaci/php7.3:php7.3.9 + commands: + - NOCOVERAGE=true NOINSTALL=true TEST_SELECTION=MEMCACHED ./autotest.sh mysql + environment: + MEMCACHED_HOST: memcached services: - - name: memcached - image: memcached +- name: memcached + image: memcached #trigger: # branch: diff --git a/autotest.sh b/autotest.sh index 2235c041e1..ee5675b9b5 100755 --- a/autotest.sh +++ b/autotest.sh @@ -5,6 +5,8 @@ DATABASEUSER=${MYSQL_USERNAME:-friendica} DATABASEHOST=${MYSQL_HOST:-localhost} BASEDIR=$PWD +DBCONFIGS="mysql mariadb" + export MYSQL_DATABASE="$DATABASENAME" export MYSQL_USERNAME="$DATABASEUSER" export MYSQL_PASSWORD="friendica" @@ -45,6 +47,20 @@ if ! [ \( -w config -a ! -f config/local.config.php \) -o \( -f config/local.con exit 1 fi +if [ "$1" ]; then + FOUND=0 + for DBCONFIG in $DBCONFIGS; do + if [ "$1" = "$DBCONFIG" ]; then + FOUND=1 + break + fi + done + if [ $FOUND = 0 ]; then + echo -e "Unknown database config name \"$1\"\n" >&2 + exit 2 + fi +fi + # Back up existing (dev) config if one exists and backup not already there if [ -f config/local.config.php ] && [ ! -f config/local.config-autotest-backup.php ]; then mv config/local.config.php config/local.config-autotest-backup.php @@ -70,7 +86,8 @@ function cleanup_config { trap cleanup_config EXIT function execute_tests { - echo "Setup environment for MariaDB testing ..." + DB=$1 + echo "Setup environment for $DB testing ..." # back to root folder cd "$BASEDIR" @@ -80,33 +97,72 @@ function execute_tests { fi if [ -z "$NOINSTALL" ]; then - if [ -n "$USEDOCKER" ]; then - echo "Fire up the mysql docker" - DOCKER_CONTAINER_ID=$(docker run \ - -e MYSQL_ROOT_PASSWORD=friendica \ - -e MYSQL_USER="$DATABASEUSER" \ - -e MYSQL_PASSWORD=friendica \ - -e MYSQL_DATABASE="$DATABASENAME" \ - -d mysql) - DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID") - else - if [ -z "$DRONE" ]; then # no need to drop the DB when we are on CI - if [ "mysql" != "$(mysql --version | grep -o mysql)" ]; then - echo "Your mysql binary is not provided by mysql" - echo "To use the docker container set the USEDOCKER environment variable" - exit 3 - fi - mysql -u "$DATABASEUSER" -pfriendica -e "DROP DATABASE IF EXISTS $DATABASENAME" - mysql -u "$DATABASEUSER" -pfriendica -e "CREATE DATABASE $DATABASENAME DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" - else - DATABASEHOST=mysql - fi - fi + #drop database + if [ "$DB" == "mysql" ]; then + if [ -n "$USEDOCKER" ]; then + echo "Fire up the mysql docker" + DOCKER_CONTAINER_ID=$(docker run \ + -e MYSQL_ROOT_PASSWORD=friendica \ + -e MYSQL_USER="$DATABASEUSER" \ + -e MYSQL_PASSWORD=friendica \ + -e MYSQL_DATABASE="$DATABASENAME" \ + -d mysql) + DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID") - echo "Waiting for MySQL $DATABASEHOST initialization..." - if ! bin/wait-for-connection $DATABASEHOST 3306 300; then - echo "[ERROR] Waited 300 seconds, no response" >&2 - exit 1 + else + if [ -z "$DRONE" ]; then # no need to drop the DB when we are on CI + if [ "mysql" != "$(mysql --version | grep -o mysql)" ]; then + echo "Your mysql binary is not provided by mysql" + echo "To use the docker container set the USEDOCKER environment variable" + exit 3 + fi + mysql -u "$DATABASEUSER" -pfriendica -e "DROP DATABASE IF EXISTS $DATABASENAME" -h $DATABASEHOST || true + mysql -u "$DATABASEUSER" -pfriendica -e "CREATE DATABASE $DATABASENAME DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" -h $DATABASEHOST + else + DATABASEHOST=mysql + fi + fi + + echo "Waiting for MySQL $DATABASEHOST initialization..." + if ! bin/wait-for-connection $DATABASEHOST 3306 300; then + echo "[ERROR] Waited 300 seconds, no response" >&2 + exit 1 + fi + + echo "MySQL is up." + fi + if [ "$DB" == "mariadb" ]; then + if [ -n "$USEDOCKER" ]; then + echo "Fire up the mariadb docker" + DOCKER_CONTAINER_ID=$(docker run \ + -e MYSQL_ROOT_PASSWORD=friendica \ + -e MYSQL_USER="$DATABASEUSER" \ + -e MYSQL_PASSWORD=friendica \ + -e MYSQL_DATABASE="$DATABASENAME" \ + -d mariadb) + DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID") + + else + if [ -z "$DRONE" ]; then # no need to drop the DB when we are on CI + if [ "MariaDB" != "$(mysql --version | grep -o MariaDB)" ]; then + echo "Your mysql binary is not provided by mysql" + echo "To use the docker container set the USEDOCKER environment variable" + exit 3 + fi + mysql -u "$DATABASEUSER" -pfriendica -e "DROP DATABASE IF EXISTS $DATABASENAME" -h $DATABASEHOST || true + mysql -u "$DATABASEUSER" -pfriendica -e "CREATE DATABASE $DATABASENAME DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" -h $DATABASEHOST + else + DATABASEHOST=mariadb + fi + fi + + echo "Waiting for MariaDB $DATABASEHOST initialization..." + if ! bin/wait-for-connection $DATABASEHOST 3306 300; then + echo "[ERROR] Waited 300 seconds, no response" >&2 + exit 1 + fi + + echo "MariaDB is up." fi if [ -n "$USEDOCKER" ]; then @@ -155,12 +211,12 @@ function execute_tests { fi INPUT="$BASEDIR/tests" - if [ -n "$1" ]; then - INPUT="$INPUT/$1" + if [ -n "$2" ]; then + INPUT="$INPUT/$2" fi - echo "${PHPUNIT[@]}" --configuration tests/phpunit.xml $GROUP $COVER --log-junit "autotest-results.xml" "$INPUT" "$2" - "${PHPUNIT[@]}" --configuration tests/phpunit.xml $GROUP $COVER --log-junit "autotest-results.xml" "$INPUT" "$2" + echo "${PHPUNIT[@]}" --configuration tests/phpunit.xml $GROUP $COVER --log-junit "autotest-results.xml" "$INPUT" "$3" + "${PHPUNIT[@]}" --configuration tests/phpunit.xml $GROUP $COVER --log-junit "autotest-results.xml" "$INPUT" "$3" RESULT=$? if [ -n "$DOCKER_CONTAINER_ID" ]; then @@ -174,8 +230,15 @@ function execute_tests { # # Start the test execution # -if [ -n "$1" ] && [ ! -f "tests/$FILENAME" ] && [ "${FILENAME:0:2}" != "--" ]; then - execute_tests "$FILENAME" "$2" +if [ -z "$1" ] && [ -n "$TEST_SELECTION" ]; then + # run all known database configs + for DBCONFIG in $DBCONFIGS; do + execute_tests "$DBCONFIG" + done else - execute_tests + FILENAME="$2" + if [ -n "$2" ] && [ ! -f "tests/$FILENAME" ] && [ "${FILENAME:0:2}" != "--" ]; then + FILENAME="../$FILENAME" + fi + execute_tests "$1" "$FILENAME" "$3" fi