Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Actions: Add macOS cases. #1170

Merged
merged 4 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/ubuntu.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ubuntu
name: Build
on: [push, pull_request]
jobs:
build:
Expand Down Expand Up @@ -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: '[email protected]'" 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
Expand Down
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
85 changes: 46 additions & 39 deletions .travis_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I renamed CHANGED_PWD to CHANGED_PASSWORD, because PWD makes me imagine pwd (print working directory) command. Sorry it was my typo.


# Install the default used DB if DB is not set.
if [[ -n ${GITHUB_ACTION-} && -z ${DB-} ]]; then
if [[ -n ${GITHUB_ACTIONS-} && -z ${DB-} ]]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
;;
*)
;;
Expand All @@ -34,30 +35,30 @@ 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
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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}" <<SQL
if [ "${CHANGED_PASSWORD}" = 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_PASSWORD_BY_RECREATE}" = true ]; then
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" <<SQL
DROP USER 'root'@'localhost';
CREATE USER 'root'@'localhost' IDENTIFIED BY '';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
SQL
fi

# IF NOT EXISTS is mariadb-10+ only - https://mariadb.com/kb/en/mariadb/comment-syntax/
mysql -u root -e 'CREATE DATABASE /*M!50701 IF NOT EXISTS */ test'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new macOS db: '[email protected]' case showed the error when running mysql -u root -e 'CREATE DATABASE /*M!50701 IF NOT EXISTS */ test', because it was recognized as mysql -u root -e 'CREATE DATABASE test' and there was test database already. As every used database supports IF NOT EXISTS in CIs, I think we can remove the /*M!50701 ... */.

fi

mysql -u root -e 'CREATE DATABASE IF NOT EXISTS test'
4 changes: 2 additions & 2 deletions spec/mysql2/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def run_gc
end

# the query ran uninterrupted
expect(mark.fetch(:QUERY_END) - mark.fetch(:QUERY_START)).to be_within(0.1).of(query_time)
expect(mark.fetch(:QUERY_END) - mark.fetch(:QUERY_START)).to be_within(0.2).of(query_time)
# signals fired while the query was running
expect(mark.fetch(:USR1)).to be_between(mark.fetch(:QUERY_START), mark.fetch(:QUERY_END))
end
Expand Down Expand Up @@ -708,7 +708,7 @@ def run_gc

# This check demonstrates that the threads are sleeping concurrently:
# In the serial case, the difference would be a multiple of sleep time
expect(stop - start).to be_within(0.1).of(sleep_time)
expect(stop - start).to be_within(0.2).of(sleep_time)

expect(values).to match_array(threads.map(&:object_id))
end
Expand Down