language: perl
perl:
  - "5.24"

os: linux
dist: focal

services:
  - docker

env:
  - DB=mariadb:5.5
  - DB=mariadb:10.2
  - DB=mariadb:10.3
  - DB=mariadb:10.4
  - DB=mariadb:10.5
  - DB=mysql:5.5
  - DB=mysql:5.7
  - DB=mysql:8.0
  - DB=percona:5.6
  - DB=percona:5.7
  - DB=percona:8.0

install:
  - cpanm --quiet --notest Data::Dumper
  - cpanm --quiet --notest JSON
  - cpanm --quiet --notest Perl::Critic
  - cpanm --quiet --notest Text::Template

before_script:
  - mysql --version
  - mysqladmin --version
  - docker run -it --name=mysqltestinstance -d -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -p 3306:3306 ${DB}
  - echo -e "[client]\nuser=root\npassword=\"\"\nhost=127.0.0.1" > ~/.my.cnf
  - chmod 600 ~/.my.cnf
  - git clone https://github.com/datacharmer/test_db.git
  - cd test_db
  - count=10
  - while ! mysql -e 'select version()' && [ $count -gt 0 ]; do echo $count seconds to go; sleep 1; count=$(( $count - 1 )); done
  - if [[ $DB =~ .*:8.0 ]] ; then
      for file in public_key.pem ca.pem server-cert.pem client-key.pem client-cert.pem ; do
        docker cp mysqltestinstance:/var/lib/mysql/$file "${HOME}" ;
      done ;
    fi
  - "cat employees.sql | grep -v 'storage_engine' | mysql"
  - cd ..

script:
  - ./mysqltuner.pl --verbose --tbstat 2>stderr.txt | tee -a "stdout.txt"

after_script:
  - docker stop mysqltestinstance
  - echo "Standard Output: $(cat stdout.txt)"
  - echo "Standard Error : $(cat stderr.txt)"
