diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 9d53287..3b25e50 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -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 diff --git a/activerecord_where_assoc.gemspec b/activerecord_where_assoc.gemspec index 8d84b23..fd54fc4 100644 --- a/activerecord_where_assoc.gemspec +++ b/activerecord_where_assoc.gemspec @@ -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 diff --git a/test/support/database_setup.rb b/test/support/database_setup.rb index 0fd4345..f84bf25 100644 --- a/test/support/database_setup.rb +++ b/test/support/database_setup.rb @@ -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