Skip to content

Commit 6e194e9

Browse files
authored
Merge pull request #1170 from junaruga/wip/ci-macos
GitHub Actions: Add macOS cases.
2 parents 557bd5f + 6bc631b commit 6e194e9

File tree

4 files changed

+59
-51
lines changed

4 files changed

+59
-51
lines changed

.github/workflows/ubuntu.yml renamed to .github/workflows/build.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Ubuntu
1+
name: Build
22
on: [push, pull_request]
33
jobs:
44
build:
@@ -38,6 +38,16 @@ jobs:
3838
# `service mysql restart` fails.
3939
- {os: ubuntu-20.04, ruby: 2.4, db: mysql80, allow-failure: true}
4040
- {os: ubuntu-18.04, ruby: 'head', db: '', allow-failure: true}
41+
# db: A DB's brew package name in macOS case.
42+
# Set a name "db: '[email protected]'" when using an old version.
43+
# MariaDB lastet version
44+
# Allow failure due to the following test failures.
45+
# https://github.com/brianmario/mysql2/issues/965
46+
# https://github.com/brianmario/mysql2/issues/1152
47+
- {os: macos-latest, ruby: 2.4, db: mariadb, allow-failure: true}
48+
# MySQL latest version
49+
# Allow failure due to the issue #1165.
50+
- {os: macos-latest, ruby: 2.4, db: mysql, allow-failure: true}
4151
# On the fail-fast: true, it cancels all in-progress jobs
4252
# if any matrix job fails unlike Travis fast_finish.
4353
fail-fast: false

.travis.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,5 @@ matrix:
4949
addons:
5050
hosts:
5151
- mysql2gem.example.com
52-
- os: osx
53-
rvm: 2.4
54-
env: DB=mysql56
55-
addons:
56-
hosts:
57-
- mysql2gem.example.com
5852
fast_finish: true
5953
allow_failures:
60-
- os: osx
61-
rvm: 2.4
62-
env: DB=mysql56

.travis_setup.sh

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22

33
set -eux
44

5-
CHANGED_PWD=false
6-
# Change the password recreating the root user on mariadb < 10.2
5+
# Change the password to be empty.
6+
CHANGED_PASSWORD=false
7+
# Change the password to be empty, recreating the root user on mariadb < 10.2
78
# where ALTER USER is not available.
89
# https://stackoverflow.com/questions/56052177/
9-
CHANGED_PWD_BY_RECREATE=false
10+
CHANGED_PASSWORD_BY_RECREATE=false
1011

1112
# Install the default used DB if DB is not set.
12-
if [[ -n ${GITHUB_ACTION-} && -z ${DB-} ]]; then
13+
if [[ -n ${GITHUB_ACTIONS-} && -z ${DB-} ]]; then
1314
if command -v lsb_release > /dev/null; then
1415
case "$(lsb_release -cs)" in
1516
xenial | bionic)
1617
sudo apt-get install -qq mysql-server-5.7 mysql-client-core-5.7 mysql-client-5.7
17-
CHANGED_PWD=true
18+
CHANGED_PASSWORD=true
1819
;;
1920
focal)
2021
sudo apt-get install -qq mysql-server-8.0 mysql-client-core-8.0 mysql-client-8.0
21-
CHANGED_PWD=true
22+
CHANGED_PASSWORD=true
2223
;;
2324
*)
2425
;;
@@ -34,30 +35,30 @@ fi
3435
# Install MySQL 5.7 if DB=mysql57
3536
if [[ -n ${DB-} && x$DB =~ ^xmysql57 ]]; then
3637
sudo bash .travis_mysql57.sh
37-
CHANGED_PWD=true
38+
CHANGED_PASSWORD=true
3839
fi
3940

4041
# Install MySQL 8.0 if DB=mysql80
4142
if [[ -n ${DB-} && x$DB =~ ^xmysql80 ]]; then
4243
sudo bash .travis_mysql80.sh
43-
CHANGED_PWD=true
44+
CHANGED_PASSWORD=true
4445
fi
4546

4647
# Install MariaDB client headers after Travis CI fix for MariaDB 10.2 broke earlier 10.x
4748
if [[ -n ${DB-} && x$DB =~ ^xmariadb10.0 ]]; then
48-
if [[ -n ${GITHUB_ACTION-} ]]; then
49+
if [[ -n ${GITHUB_ACTIONS-} ]]; then
4950
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.0 libmariadb2
50-
CHANGED_PWD_BY_RECREATE=true
51+
CHANGED_PASSWORD_BY_RECREATE=true
5152
else
5253
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' libmariadbclient-dev
5354
fi
5455
fi
5556

5657
# Install MariaDB client headers after Travis CI fix for MariaDB 10.2 broke earlier 10.x
5758
if [[ -n ${DB-} && x$DB =~ ^xmariadb10.1 ]]; then
58-
if [[ -n ${GITHUB_ACTION-} ]]; then
59+
if [[ -n ${GITHUB_ACTIONS-} ]]; then
5960
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.1 libmariadb-dev
60-
CHANGED_PWD_BY_RECREATE=true
61+
CHANGED_PASSWORD_BY_RECREATE=true
6162
else
6263
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' libmariadbclient-dev
6364
fi
@@ -70,16 +71,29 @@ if [[ -n ${DB-} && x$DB =~ ^xmariadb10.2 ]]; then
7071
fi
7172

7273
# Install MariaDB 10.3 if DB=mariadb10.3
73-
if [[ -n ${GITHUB_ACTION-} && -n ${DB-} && x$DB =~ ^xmariadb10.3 ]]; then
74+
if [[ -n ${GITHUB_ACTIONS-} && -n ${DB-} && x$DB =~ ^xmariadb10.3 ]]; then
7475
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.3 libmariadb-dev
75-
CHANGED_PWD=true
76+
CHANGED_PASSWORD=true
7677
fi
7778

78-
# Install MySQL if OS=darwin
79+
# Install MySQL/MariaDB if OS=darwin
7980
if [[ x$OSTYPE =~ ^xdarwin ]]; then
80-
brew update
81-
brew install "$DB" mariadb-connector-c
82-
$(brew --prefix "$DB")/bin/mysql.server start
81+
brew update > /dev/null
82+
83+
# Check available packages.
84+
for KEYWORD in mysql mariadb; do
85+
brew search "${KEYWORD}"
86+
done
87+
88+
brew info "$DB"
89+
brew install "$DB"
90+
DB_PREFIX="$(brew --prefix "${DB}")"
91+
export PATH="${DB_PREFIX}/bin:${PATH}"
92+
export LDFLAGS="-L${DB_PREFIX}/lib"
93+
export CPPFLAGS="-I${DB_PREFIX}/include"
94+
95+
mysql.server start
96+
CHANGED_PASSWORD_BY_RECREATE=true
8397
fi
8498

8599
# TODO: get SSL working on OS X in Travis
@@ -88,14 +102,12 @@ if ! [[ x$OSTYPE =~ ^xdarwin ]]; then
88102
sudo service mysql restart
89103
fi
90104

91-
# Print the MySQL version and create the test DB
92-
if [[ x$OSTYPE =~ ^xdarwin ]]; then
93-
$(brew --prefix "$DB")/bin/mysqld --version
94-
$(brew --prefix "$DB")/bin/mysql -u root -e 'CREATE DATABASE IF NOT EXISTS test'
95-
else
96-
mysqld --version
105+
mysqld --version
97106

98-
if [[ -n ${GITHUB_ACTION-} && -f /etc/mysql/debian.cnf ]]; then
107+
MYSQL_OPTS=''
108+
DB_SYS_USER=root
109+
if ! [[ x$OSTYPE =~ ^xdarwin ]]; then
110+
if [[ -n ${GITHUB_ACTIONS-} && -f /etc/mysql/debian.cnf ]]; then
99111
MYSQL_OPTS='--defaults-extra-file=/etc/mysql/debian.cnf'
100112
# Install from packages in OS official packages.
101113
if sudo grep -q debian-sys-maint /etc/mysql/debian.cnf; then
@@ -105,25 +117,20 @@ else
105117
# xenial
106118
DB_SYS_USER=root
107119
fi
108-
else
109-
# Install from official mysql packages.
110-
MYSQL_OPTS=''
111-
DB_SYS_USER=root
112120
fi
121+
fi
113122

114-
if [ "${CHANGED_PWD}" = true ]; then
115-
# https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
116-
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" \
117-
-e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''"
118-
elif [ "${CHANGED_PWD_BY_RECREATE}" = true ]; then
119-
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" <<SQL
123+
if [ "${CHANGED_PASSWORD}" = true ]; then
124+
# https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
125+
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" \
126+
-e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''"
127+
elif [ "${CHANGED_PASSWORD_BY_RECREATE}" = true ]; then
128+
sudo mysql ${MYSQL_OPTS} -u "${DB_SYS_USER}" <<SQL
120129
DROP USER 'root'@'localhost';
121130
CREATE USER 'root'@'localhost' IDENTIFIED BY '';
122131
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
123132
FLUSH PRIVILEGES;
124133
SQL
125-
fi
126-
127-
# IF NOT EXISTS is mariadb-10+ only - https://mariadb.com/kb/en/mariadb/comment-syntax/
128-
mysql -u root -e 'CREATE DATABASE /*M!50701 IF NOT EXISTS */ test'
129134
fi
135+
136+
mysql -u root -e 'CREATE DATABASE IF NOT EXISTS test'

spec/mysql2/client_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ def run_gc
629629
end
630630

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

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

713713
expect(values).to match_array(threads.map(&:object_id))
714714
end

0 commit comments

Comments
 (0)