From fde89cc2a99797d3bd5a7e2721b59de03b058eb6 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 23 Jan 2024 13:10:24 -0500 Subject: [PATCH] enhance tasks --- Taskfile.yml | 70 ++++++++++++++++++--------------------- compose.yml | 4 +-- spec/config/bootstrap.sql | 5 +-- spec/config/database.yml | 2 +- 4 files changed, 38 insertions(+), 43 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index ee377d3..c188c23 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -5,44 +5,32 @@ version: "3" dotenv: - .env -includes: - ruby: ~/.ksr/tasks/ruby.yml - mysql: ~/.ksr/tasks/mysql.yml - -vars: - RUBY_VERSION: 2.7.5 - tasks: init: desc: Initialize project - cmds: - - task: ruby:rbenv:install - - task: ruby:bundler:setup - - task: ruby:bundler:config - - task: ruby:bundle - - task: up - - bundle exec rake bootstrap - - ruby:bundler:config: - label: ruby:bundle:config + deps: + - up vars: - OPENSSL_PREFIX: { sh: brew --prefix openssl } + RUBY_VERSION: + sh: rbenv local 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 + - rbenv install --skip-existing {{.RUBY_VERSION}} + - bundle install + - bundle exec rake bootstrap - 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 +39,25 @@ tasks: cmds: - bundle exec rake release + test: + desc: Run test suite + env: + MYSQL_PORT: + sh: docker compose port mysql 3306 | sed 's/0.0.0.0://' + 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