diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/build.yml similarity index 79% rename from .github/workflows/ubuntu.yml rename to .github/workflows/build.yml index cd90bbeac..1e57afa5a 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Ubuntu +name: Build on: [push, pull_request] jobs: build: @@ -38,6 +38,16 @@ jobs: # `service mysql restart` fails. - {os: ubuntu-20.04, ruby: 2.4, db: mysql80, allow-failure: true} - {os: ubuntu-18.04, ruby: 'head', db: '', allow-failure: true} + # db: A DB's brew package name in macOS case. + # Set a name "db: 'name@X.Y'" when using an old version. + # MariaDB lastet version + # Allow failure due to the following test failures. + # https://github.com/brianmario/mysql2/issues/965 + # https://github.com/brianmario/mysql2/issues/1152 + - {os: macos-latest, ruby: 2.4, db: mariadb, allow-failure: true} + # MySQL latest version + # Allow failure due to the issue #1165. + - {os: macos-latest, ruby: 2.4, db: mysql, allow-failure: true} # On the fail-fast: true, it cancels all in-progress jobs # if any matrix job fails unlike Travis fast_finish. fail-fast: false diff --git a/.travis.yml b/.travis.yml index dfcee6e0c..03129303b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,14 +49,5 @@ matrix: addons: hosts: - mysql2gem.example.com - - os: osx - rvm: 2.4 - env: DB=mysql56 - addons: - hosts: - - mysql2gem.example.com fast_finish: true allow_failures: - - os: osx - rvm: 2.4 - env: DB=mysql56 diff --git a/.travis_setup.sh b/.travis_setup.sh index 50ecd5e48..09f25a1d2 100644 --- a/.travis_setup.sh +++ b/.travis_setup.sh @@ -2,23 +2,24 @@ set -eux -CHANGED_PWD=false -# Change the password recreating the root user on mariadb < 10.2 +# Change the password to be empty. +CHANGED_PASSWORD=false +# Change the password to be empty, recreating the root user on mariadb < 10.2 # where ALTER USER is not available. # https://stackoverflow.com/questions/56052177/ -CHANGED_PWD_BY_RECREATE=false +CHANGED_PASSWORD_BY_RECREATE=false # Install the default used DB if DB is not set. -if [[ -n ${GITHUB_ACTION-} && -z ${DB-} ]]; then +if [[ -n ${GITHUB_ACTIONS-} && -z ${DB-} ]]; then if command -v lsb_release > /dev/null; then case "$(lsb_release -cs)" in xenial | bionic) sudo apt-get install -qq mysql-server-5.7 mysql-client-core-5.7 mysql-client-5.7 - CHANGED_PWD=true + CHANGED_PASSWORD=true ;; focal) sudo apt-get install -qq mysql-server-8.0 mysql-client-core-8.0 mysql-client-8.0 - CHANGED_PWD=true + CHANGED_PASSWORD=true ;; *) ;; @@ -34,20 +35,20 @@ fi # Install MySQL 5.7 if DB=mysql57 if [[ -n ${DB-} && x$DB =~ ^xmysql57 ]]; then sudo bash .travis_mysql57.sh - CHANGED_PWD=true + CHANGED_PASSWORD=true fi # Install MySQL 8.0 if DB=mysql80 if [[ -n ${DB-} && x$DB =~ ^xmysql80 ]]; then sudo bash .travis_mysql80.sh - CHANGED_PWD=true + CHANGED_PASSWORD=true fi # Install MariaDB client headers after Travis CI fix for MariaDB 10.2 broke earlier 10.x if [[ -n ${DB-} && x$DB =~ ^xmariadb10.0 ]]; then - if [[ -n ${GITHUB_ACTION-} ]]; then + if [[ -n ${GITHUB_ACTIONS-} ]]; then sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.0 libmariadb2 - CHANGED_PWD_BY_RECREATE=true + CHANGED_PASSWORD_BY_RECREATE=true else sudo apt-get install -y -o Dpkg::Options::='--force-confnew' libmariadbclient-dev fi @@ -55,9 +56,9 @@ fi # Install MariaDB client headers after Travis CI fix for MariaDB 10.2 broke earlier 10.x if [[ -n ${DB-} && x$DB =~ ^xmariadb10.1 ]]; then - if [[ -n ${GITHUB_ACTION-} ]]; then + if [[ -n ${GITHUB_ACTIONS-} ]]; then sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.1 libmariadb-dev - CHANGED_PWD_BY_RECREATE=true + CHANGED_PASSWORD_BY_RECREATE=true else sudo apt-get install -y -o Dpkg::Options::='--force-confnew' libmariadbclient-dev fi @@ -70,16 +71,29 @@ if [[ -n ${DB-} && x$DB =~ ^xmariadb10.2 ]]; then fi # Install MariaDB 10.3 if DB=mariadb10.3 -if [[ -n ${GITHUB_ACTION-} && -n ${DB-} && x$DB =~ ^xmariadb10.3 ]]; then +if [[ -n ${GITHUB_ACTIONS-} && -n ${DB-} && x$DB =~ ^xmariadb10.3 ]]; then sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.3 libmariadb-dev - CHANGED_PWD=true + CHANGED_PASSWORD=true fi -# Install MySQL if OS=darwin +# Install MySQL/MariaDB if OS=darwin if [[ x$OSTYPE =~ ^xdarwin ]]; then - brew update - brew install "$DB" mariadb-connector-c - $(brew --prefix "$DB")/bin/mysql.server start + brew update > /dev/null + + # Check available packages. + for KEYWORD in mysql mariadb; do + brew search "${KEYWORD}" + done + + brew info "$DB" + brew install "$DB" + DB_PREFIX="$(brew --prefix "${DB}")" + export PATH="${DB_PREFIX}/bin:${PATH}" + export LDFLAGS="-L${DB_PREFIX}/lib" + export CPPFLAGS="-I${DB_PREFIX}/include" + + mysql.server start + CHANGED_PASSWORD_BY_RECREATE=true fi # TODO: get SSL working on OS X in Travis @@ -88,14 +102,12 @@ if ! [[ x$OSTYPE =~ ^xdarwin ]]; then sudo service mysql restart fi -# Print the MySQL version and create the test DB -if [[ x$OSTYPE =~ ^xdarwin ]]; then - $(brew --prefix "$DB")/bin/mysqld --version - $(brew --prefix "$DB")/bin/mysql -u root -e 'CREATE DATABASE IF NOT EXISTS test' -else - mysqld --version +mysqld --version - if [[ -n ${GITHUB_ACTION-} && -f /etc/mysql/debian.cnf ]]; then +MYSQL_OPTS='' +DB_SYS_USER=root +if ! [[ x$OSTYPE =~ ^xdarwin ]]; then + if [[ -n ${GITHUB_ACTIONS-} && -f /etc/mysql/debian.cnf ]]; then MYSQL_OPTS='--defaults-extra-file=/etc/mysql/debian.cnf' # Install from packages in OS official packages. if sudo grep -q debian-sys-maint /etc/mysql/debian.cnf; then @@ -105,25 +117,20 @@ else # xenial DB_SYS_USER=root fi - else - # Install from official mysql packages. - MYSQL_OPTS='' - DB_SYS_USER=root fi +fi - if [ "${CHANGED_PWD}" = true ]; then - # https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/ - sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" \ - -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''" - elif [ "${CHANGED_PWD_BY_RECREATE}" = true ]; then - sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" <