Skip to content
Open
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
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
pull-requests: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check_test_execution_conditions:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: xt0rted/block-autosquash-commits-action@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

rspec:
runs-on: ubuntu-latest
strategy:
matrix:
ruby:
- 3.0.6
- 3.1.4
mysql:
- 5.6
- 5.7
needs:
- check_test_execution_conditions
services:
mysql:
image: mysql:${{ matrix.mysql }}
env:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
options: >-
--health-cmd "mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- "3306:3306"
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run RSpec for ${{ matrix.mysql }}
run: bundle exec rake spec`echo ${{ matrix.mysql }} | awk -F. '{print $1"_"$2}'`
env:
MYSQL_HOST: 127.0.0.1
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ruby:3.1.6

WORKDIR /usr/src/app

RUN mkdir -p /usr/src/app/lib/gratan
COPY Gemfile gratan.gemspec /usr/src/app/
COPY lib/gratan/version.rb /usr/src/app/lib/gratan/
RUN bundle install

COPY . .

ENTRYPOINT ["gratan"]
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,13 @@ end
## Run tests

```sh
bundle install
docker-compose up -d
bundle exec rake
# MYSQL57=1 bundle exec rake
docker compose build
# for MySQL 5.6 and 5.7
docker compose run --rm rake
# for MySQL 5.6
docker compose run --rm rake spec5_6
# for MySQL 5.7
docker compose run --rm rake spec5_7
```

## Similar tools
Expand Down
16 changes: 15 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@ require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new('spec')
task :default => :spec
task :default => :spec_all

suffixes = %w(5_6 5_7)
task :spec_all => suffixes.map { |s| "spec#{s}" }

suffixes.each do |suffix|
overwrite_host = ENV['MYSQL_HOST'].to_s.empty?
task "spec#{suffix}" do
if overwrite_host
ENV['MYSQL_HOST'] = "mysql#{suffix}"
end
ENV['MYSQL5_7'] = (suffix == '5_7' ? 1 : 0).to_s
Rake::Task['spec'].execute
end
end
44 changes: 32 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
mysql56:
image: "mysql:5.6"
ports:
- "14406:3306"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
mysql57:
image: "mysql:5.7"
ports:
- "14407:3306"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
services:
mysql5_6:
image: "mysql:5.6"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
healthcheck:
test: ["CMD", "mysql", "-h", "localhost", "-u", "root", "--execute", "SHOW DATABASES;"]
start_period: 30s
timeout: 5s
interval: 5s
retries: 5
mysql5_7:
image: "mysql:5.7"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
healthcheck:
test: ["CMD", "mysql", "-h", "localhost", "-u", "root", "--execute", "SHOW DATABASES;"]
start_period: 30s
timeout: 5s
interval: 5s
retries: 5
rake:
build: .
depends_on:
mysql5_6:
condition: service_healthy
mysql5_7:
condition: service_healthy
entrypoint: ["rake"]
volumes:
- .:/usr/src/app
working_dir: /usr/src/app
34 changes: 25 additions & 9 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,34 @@
end
end

def mysql57?
ENV['MYSQL57'] == '1'
def env_empty?(str)
str.nil? || str.empty? || str == '0'
end

MYSQL_PORT = mysql57? ? 14407 : 14406
def mysql5_7?
!env_empty?(ENV['MYSQL5_7'])
end

MYSQL_PORT = if ENV['MYSQL_PORT'].blank?
3306
else
ENV['MYSQL_PORT'].to_i
end

MYSQL_HOST = if ENV['MYSQL_HOST'].blank?
'127.0.0.1'
else
ENV['MYSQL_HOST']
end

MYSQL_USER = 'root'

def mysql
client = nil
retval = nil

begin
client = Mysql2::Client.new(host: '127.0.0.1', username: 'root', port: MYSQL_PORT)
client = Mysql2::Client.new(host: MYSQL_HOST, username: MYSQL_USER, port: MYSQL_PORT)
retval = yield(client)
ensure
client.close if client
Expand Down Expand Up @@ -127,7 +143,7 @@ def show_grants
end
end

if mysql57?
if mysql5_7?
grants.each do |grant|
end
end
Expand All @@ -141,14 +157,14 @@ def client(user_options = {})
end

options = {
host: '127.0.0.1',
username: 'root',
host: MYSQL_HOST,
username: MYSQL_USER,
port: MYSQL_PORT,
ignore_user: IGNORE_USER,
logger: Logger.new('/dev/null'),
}

if mysql57?
if mysql5_7?
options.update(
override_sql_mode: true,
use_show_create_user: true,
Expand Down Expand Up @@ -189,7 +205,7 @@ def apply(cli = client)

class Array
def normalize
if mysql57?
if mysql5_7?
self.map do |i|
i.sub(/ IDENTIFIED BY PASSWORD '[^']+'/, '')
.sub(/ REQUIRE \w+\b/, '')
Expand Down