Skip to content

Commit

Permalink
enhance tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
amancevice committed Jan 23, 2024
1 parent 3be47fc commit fde89cc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 43 deletions.
70 changes: 32 additions & 38 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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'
4 changes: 2 additions & 2 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 3 additions & 2 deletions spec/config/bootstrap.sql
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion spec/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fde89cc

Please sign in to comment.