Skip to content

Commit

Permalink
Adding github workflow for running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxLap committed Nov 6, 2020
1 parent a8965da commit dbd5ee3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
50 changes: 35 additions & 15 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,48 @@ on:
pull_request:
branches: [ master ]

env:
PGUSER: postgres
PGPASSWORD: postgres
MYSQL_USER: root
MYSQL_PASSWORD: root

jobs:
test:

runs-on: ubuntu-latest
services:
db:
image: postgres:11
ports: ['5432:5432']
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_USER: ${{env.PGUSER}}
POSTGRES_PASSWORD: ${{env.PGUSER}}

steps:
- uses: actions/checkout@v2
- run: sudo service mysql start
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Install dependencies
run: bundle install
- name: Run tests
run: bundle exec rake

- psql -c 'CREATE DATABASE activerecord_where_assoc' -U postgres
- mysql -e 'CREATE DATABASE activerecord_where_assoc'
- DB=mysql bundle exec rake test
- bundle exec rake test DB=pg
- bundle exec rake test DB=sqlite3
- bundle exec rake coveralls:push
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- run: psql --host=localhost --port=5432 -c 'CREATE DATABASE activerecord_where_assoc'
- run: mysql -h 127.0.0.1 -u "${{ env.MYSQL_USER }}" -p "${{ env.MYSQL_PASSWORD }}" -e 'CREATE DATABASE activerecord_where_assoc'
- run: DB=mysql bundle exec rake test
- run: DB=pg bundle exec rake test
- run: DB=sqlite3 bundle exec rake test
- run: bundle exec rake coveralls:push
4 changes: 2 additions & 2 deletions activerecord_where_assoc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ Gem::Specification.new do |spec|

# Travis-CI takes care of the other ones
# Using conditions because someone might not even be able to install the gems
spec.add_development_dependency "mysql2", "~> 0.4.0" if ENV["TRAVIS"] || ENV["ALL_DB"] || ENV["DB"] == "mysql"
spec.add_development_dependency "pg", "< 1.0.0" if ENV["TRAVIS"] || ENV["ALL_DB"] || ["pg", "postgres", "postgresql"].include?(ENV["DB"])
spec.add_development_dependency "mysql2", "~> 0.4.0" if ENV["TRAVIS"] || ENV["CI"] || ENV["ALL_DB"] || ENV["DB"] == "mysql"
spec.add_development_dependency "pg", "< 1.0.0" if ENV["TRAVIS"] || ENV["CI"] || ENV["ALL_DB"] || ["pg", "postgres", "postgresql"].include?(ENV["DB"])
end
8 changes: 7 additions & 1 deletion test/support/database_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,20 @@ def self.mysql_config
adapter: "mysql2",
database: database_name,
username: db_user_name,
password: db_password,
}
end

def self.db_user_name
# I don't know why, I get access denied on Travis-CI when using user travis, but root works...
return ENV["MYSQL_USER"] if ENV["MYSQL_USER"].present?
ENV["TRAVIS"] ? "root" : `whoami`
end

def self.db_password
return ENV["MYSQL_PASSWORD"] if ENV["MYSQL_PASSWORD"].present?
nil
end

def self.database_name
"activerecord_where_assoc"
end
Expand Down

0 comments on commit dbd5ee3

Please sign in to comment.