Skip to content

Commit c5fa553

Browse files
authored
Add GitHub Actions. (#1154)
Remove the CI cases on Travis migrated to GitHub Actions.
1 parent ad94a79 commit c5fa553

File tree

6 files changed

+141
-36
lines changed

6 files changed

+141
-36
lines changed

.github/workflows/test.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Test
2+
on: [push, pull_request]
3+
jobs:
4+
build:
5+
name: >-
6+
${{ matrix.os }} ruby ${{ matrix.ruby }} ${{ matrix.db }}
7+
# Run all the tests on the new environment as much as possible.
8+
# https://docs.github.com/en/free-pro-team@latest/actions/reference/specifications-for-github-hosted-runners
9+
runs-on: ${{ matrix.os }}
10+
continue-on-error: ${{ matrix.allow-failure }}
11+
strategy:
12+
matrix:
13+
os:
14+
# Use ubuntu-18.04 instead of ubuntu-20.04 temporarily, due to a failing test on mysql 8.0.
15+
# https://github.com/brianmario/mysql2/issues/1165
16+
# - ubuntu-20.04 # focal
17+
- ubuntu-18.04 # bionic
18+
# - ubuntu-16.04 # xenial
19+
ruby:
20+
- '3.0'
21+
- 2.7
22+
- 2.6
23+
- 2.5
24+
- 2.4
25+
- 2.3
26+
- 2.2
27+
- 2.1
28+
db: ['']
29+
allow-failure: [false]
30+
include:
31+
# Allow failure due to Mysql2::Error: Unknown system variable 'session_track_system_variables'.
32+
- {os: ubuntu-16.04, ruby: 2.4, db: mariadb10.0, allow-failure: true}
33+
# Comment out due to .travis_setup.sh stucking.
34+
# - {os: ubuntu-18.04, ruby: 2.4, db: mariadb10.1, allow-failure: false}
35+
# Allow failure due to the issue #1165.
36+
- {os: ubuntu-20.04, ruby: 2.4, db: mariadb10.3, allow-failure: true}
37+
- {os: ubuntu-18.04, ruby: 2.4, db: mysql57, allow-failure: false}
38+
# `service mysql restart` fails.
39+
- {os: ubuntu-20.04, ruby: 2.4, db: mysql80, allow-failure: true}
40+
- {os: ubuntu-18.04, ruby: 'head', db: '', allow-failure: true}
41+
# On the fail-fast: true, it cancels all in-progress jobs
42+
# if any matrix job fails unlike Travis fast_finish.
43+
fail-fast: false
44+
steps:
45+
- uses: actions/checkout@v2
46+
# https://github.com/ruby/setup-ruby
47+
- uses: ruby/setup-ruby@v1
48+
with:
49+
ruby-version: ${{ matrix.ruby }}
50+
- run: ruby -v
51+
- run: bundle install --without benchmarks development
52+
- if: matrix.db != ''
53+
run: echo 'DB=${{ matrix.db }}' >> $GITHUB_ENV
54+
- run: sudo echo "127.0.0.1 mysql2gem.example.com" | sudo tee -a /etc/hosts
55+
- run: bash .travis_setup.sh
56+
- run: bundle exec rake

.travis.yml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,9 @@ addons:
1818
- mysql-server-5.6
1919
- mysql-client-core-5.6
2020
- mysql-client-5.6
21-
rvm:
22-
- 2.7
23-
- 2.6
24-
- 2.5
25-
- 2.4
26-
- 2.3
27-
- 2.2
28-
- 2.1
29-
- 2.0.0
30-
- ruby-head
3121
matrix:
3222
include:
23+
- rvm: 2.0.0
3324
- rvm: 2.4
3425
env: DB=mariadb10.0
3526
addons:
@@ -59,18 +50,6 @@ matrix:
5950
addons:
6051
hosts:
6152
- mysql2gem.example.com
62-
- rvm: 2.4
63-
env: DB=mysql57
64-
dist: xenial
65-
addons:
66-
hosts:
67-
- mysql2gem.example.com
68-
- rvm: 2.4
69-
env: DB=mysql80
70-
dist: xenial
71-
addons:
72-
hosts:
73-
- mysql2gem.example.com
7453
- os: osx
7554
rvm: 2.4
7655
env: DB=mysql56
@@ -84,7 +63,6 @@ matrix:
8463
script: docker run --add-host=mysql2gem.example.com:127.0.0.1 -t mysql2
8564
fast_finish: true
8665
allow_failures:
87-
- rvm: ruby-head
8866
- os: osx
8967
rvm: 2.4
9068
env: DB=mysql56

.travis_mysql57.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ apt-get purge -qq '^mysql*' '^libmysql*'
66
rm -fr /etc/mysql
77
rm -fr /var/lib/mysql
88
apt-key add support/5072E1F5.asc
9+
# Verify the repository as add-apt-repository does not.
10+
wget -q --spider http://repo.mysql.com/apt/ubuntu/dists/$(lsb_release -cs)/mysql-5.7
911
add-apt-repository 'http://repo.mysql.com/apt/ubuntu mysql-5.7'
1012
apt-get update -qq
1113
apt-get install -qq mysql-server libmysqlclient-dev
12-
13-
# https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
14-
mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''"

.travis_mysql80.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ apt-get purge -qq '^mysql*' '^libmysql*'
66
rm -fr /etc/mysql
77
rm -fr /var/lib/mysql
88
apt-key add support/5072E1F5.asc
9+
# Verify the repository as add-apt-repository does not.
10+
wget -q --spider http://repo.mysql.com/apt/ubuntu/dists/$(lsb_release -cs)/mysql-8.0
911
add-apt-repository 'http://repo.mysql.com/apt/ubuntu mysql-8.0'
1012
apt-get update -qq
1113
apt-get install -qq mysql-server libmysqlclient-dev
12-
13-
# https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
14-
mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY ''"

.travis_setup.sh

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
set -eux
44

5+
CHANGED_PWD=false
6+
# Change the password recreating the root user on mariadb < 10.2
7+
# where ALTER USER is not available.
8+
# https://stackoverflow.com/questions/56052177/
9+
CHANGED_PWD_BY_RECREATE=false
10+
11+
# Install the default used DB if DB is not set.
12+
if [[ -n ${GITHUB_ACTION-} && -z ${DB-} ]]; then
13+
if command -v lsb_release > /dev/null; then
14+
case "$(lsb_release -cs)" in
15+
xenial | bionic)
16+
sudo apt-get install -qq mysql-server-5.7 mysql-client-core-5.7 mysql-client-5.7
17+
CHANGED_PWD=true
18+
;;
19+
focal)
20+
sudo apt-get install -qq mysql-server-8.0 mysql-client-core-8.0 mysql-client-8.0
21+
CHANGED_PWD=true
22+
;;
23+
*)
24+
;;
25+
esac
26+
fi
27+
fi
28+
529
# Install MySQL 5.5 if DB=mysql55
630
if [[ -n ${DB-} && x$DB =~ ^xmysql55 ]]; then
731
sudo bash .travis_mysql55.sh
@@ -10,21 +34,33 @@ fi
1034
# Install MySQL 5.7 if DB=mysql57
1135
if [[ -n ${DB-} && x$DB =~ ^xmysql57 ]]; then
1236
sudo bash .travis_mysql57.sh
37+
CHANGED_PWD=true
1338
fi
1439

1540
# Install MySQL 8.0 if DB=mysql80
1641
if [[ -n ${DB-} && x$DB =~ ^xmysql80 ]]; then
1742
sudo bash .travis_mysql80.sh
43+
CHANGED_PWD=true
1844
fi
1945

2046
# Install MariaDB client headers after Travis CI fix for MariaDB 10.2 broke earlier 10.x
2147
if [[ -n ${DB-} && x$DB =~ ^xmariadb10.0 ]]; then
22-
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' libmariadbclient-dev
48+
if [[ -n ${GITHUB_ACTION-} ]]; then
49+
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.0 libmariadb2
50+
CHANGED_PWD_BY_RECREATE=true
51+
else
52+
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' libmariadbclient-dev
53+
fi
2354
fi
2455

2556
# Install MariaDB client headers after Travis CI fix for MariaDB 10.2 broke earlier 10.x
2657
if [[ -n ${DB-} && x$DB =~ ^xmariadb10.1 ]]; then
27-
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' libmariadbclient-dev
58+
if [[ -n ${GITHUB_ACTION-} ]]; then
59+
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+
else
62+
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' libmariadbclient-dev
63+
fi
2864
fi
2965

3066
# Install MariaDB 10.2 if DB=mariadb10.2
@@ -33,6 +69,12 @@ if [[ -n ${DB-} && x$DB =~ ^xmariadb10.2 ]]; then
3369
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.2 libmariadbclient18
3470
fi
3571

72+
# Install MariaDB 10.3 if DB=mariadb10.3
73+
if [[ -n ${GITHUB_ACTION-} && -n ${DB-} && x$DB =~ ^xmariadb10.3 ]]; then
74+
sudo apt-get install -y -o Dpkg::Options::='--force-confnew' mariadb-server mariadb-server-10.3 libmariadb-dev
75+
CHANGED_PWD=true
76+
fi
77+
3678
# Install MySQL if OS=darwin
3779
if [[ x$OSTYPE =~ ^xdarwin ]]; then
3880
brew update
@@ -52,6 +94,36 @@ if [[ x$OSTYPE =~ ^xdarwin ]]; then
5294
$(brew --prefix "$DB")/bin/mysql -u root -e 'CREATE DATABASE IF NOT EXISTS test'
5395
else
5496
mysqld --version
97+
98+
if [[ -n ${GITHUB_ACTION-} && -f /etc/mysql/debian.cnf ]]; then
99+
MYSQL_OPTS='--defaults-extra-file=/etc/mysql/debian.cnf'
100+
# Install from packages in OS official packages.
101+
if sudo grep -q debian-sys-maint /etc/mysql/debian.cnf; then
102+
# bionic, focal
103+
DB_SYS_USER=debian-sys-maint
104+
else
105+
# xenial
106+
DB_SYS_USER=root
107+
fi
108+
else
109+
# Install from official mysql packages.
110+
MYSQL_OPTS=''
111+
DB_SYS_USER=root
112+
fi
113+
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
120+
DROP USER 'root'@'localhost';
121+
CREATE USER 'root'@'localhost' IDENTIFIED BY '';
122+
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
123+
FLUSH PRIVILEGES;
124+
SQL
125+
fi
126+
55127
# IF NOT EXISTS is mariadb-10+ only - https://mariadb.com/kb/en/mariadb/comment-syntax/
56128
mysql -u root -e 'CREATE DATABASE /*M!50701 IF NOT EXISTS */ test'
57129
fi

Gemfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ group :development do
3333
gem 'rake-compiler-dock', '~> 0.7.0'
3434
end
3535

36-
platforms :rbx do
37-
gem 'rubysl-bigdecimal'
38-
gem 'rubysl-drb'
39-
gem 'rubysl-rake'
40-
end
36+
# On MRI Ruby >= 3.0, rubysl-rake causes the conflict on GitHub Actions.
37+
# platforms :rbx do
38+
# gem 'rubysl-bigdecimal'
39+
# gem 'rubysl-drb'
40+
# gem 'rubysl-rake'
41+
# end

0 commit comments

Comments
 (0)