diff --git a/Taskfile.yml b/Taskfile.yml index ee377d3..160cb8e 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -5,44 +5,33 @@ version: "3" dotenv: - .env -includes: - ruby: ~/.ksr/tasks/ruby.yml - mysql: ~/.ksr/tasks/mysql.yml - vars: - RUBY_VERSION: 2.7.5 + RUBY_VERSION: 3.2.2 tasks: init: desc: Initialize project + deps: + - up cmds: - - task: ruby:rbenv:install - - task: ruby:bundler:setup - - task: ruby:bundler:config - - task: ruby:bundle - - task: up + - rbenv install --skip-existing {{.RUBY_VERSION}} + - rbenv local {{.RUBY_VERSION}} + - bundle install - bundle exec rake bootstrap - ruby:bundler:config: - label: ruby:bundle:config - vars: - OPENSSL_PREFIX: { sh: brew --prefix openssl } - cmds: - - bundle config set --local build.mysql2 --with-opt-dir={{.OPENSSL_PREFIX}} - status: - - >- - grep -F 'BUNDLE_BUILD__MYSQL2: "--with-opt-dir={{.OPENSSL_PREFIX}}"' .bundle/config - - test: - desc: Test project + down: + desc: Stop local services cmds: - - bundle exec rake spec + - docker compose down release: desc: Publish gem with GitHub + preconditions: + - sh: git diff HEAD --quiet + msg: Refusing to release with local uncommitted changes vars: VERSION: - sh: bundle exec ruby -r replica_pools -e 'puts "v#{ReplicaPools::VERSION}"' + sh: bundle exec ruby -e 'puts "v#{ReplicaPools::VERSION}"' cmds: - gh release create {{.VERSION}} --generate-notes @@ -51,19 +40,22 @@ tasks: cmds: - bundle exec rake release + test: + desc: Run test suite + deps: + - up + cmds: + - bundle exec rake spec + up: desc: Start local services cmds: + # Bring up local MySQL - docker compose up --detach - - task: mysql:await - vars: - ENTRYPOINT: docker compose run --rm --entrypoint mysql mysql - HOST: mysql - - down: - desc: Stop local services - cmds: - - docker compose down - - clean: - desc: Clean project + # Wait for MySQL to be available + - silent: true + cmd: >- + gum spin --spinner minidot --title 'Waiting for MySQL...' -- bash -c + 'until docker compose run --rm mysql mysql --host mysql -e "select 1" mysql ; + do sleep 1 ; + done' diff --git a/compose.yml b/compose.yml index 66e3b25..360af20 100644 --- a/compose.yml +++ b/compose.yml @@ -2,8 +2,8 @@ version: "2.0" services: mysql: - image: mysql:5.7 + image: mysql:8.0 ports: - - 127.0.0.1:3309:3306 + - 3306 environment: MYSQL_ALLOW_EMPTY_PASSWORD: "true" diff --git a/spec/config/bootstrap.sql b/spec/config/bootstrap.sql index 48c8f82..2b4b1c7 100644 --- a/spec/config/bootstrap.sql +++ b/spec/config/bootstrap.sql @@ -1,3 +1,4 @@ -- Create MySQL db & user for running specs -create database IF NOT EXISTS test_db; -grant select on test_db.* to 'read_only' identified by 'readme'; +CREATE DATABASE IF NOT EXISTS test_db; +CREATE USER IF NOT EXISTS 'read_only' IDENTIFIED BY 'readme'; +GRANT SELECT ON test_db.* TO 'read_only'; diff --git a/spec/config/database.yml b/spec/config/database.yml index f213791..fcb3c25 100644 --- a/spec/config/database.yml +++ b/spec/config/database.yml @@ -3,7 +3,7 @@ test: &test username: root password: '' host: 127.0.0.1 - port: <%= ENV["MYSQL_PORT"] || 3309 %> + port: <%= ENV["MYSQL_PORT"] || 3306 %> encoding: utf8 read_timeout: 1 database: test_db diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ac919b8..68b8a4d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,8 @@ require 'bundler/setup' require 'logger' +ENV['MYSQL_PORT'] ||= %x(docker compose port mysql 3306)[/\d+$/] + module Rails def self.env ActiveSupport::StringInquirer.new("test")