From bf850fa0439d1a5a9e135e0f5434ed6e04fc2f46 Mon Sep 17 00:00:00 2001 From: Pedro Paiva Date: Mon, 25 Jan 2021 18:57:22 -0300 Subject: [PATCH] Add GitHub Action to replace Travis (#1397) --- .github/workflows/ci.yml | 66 +++++++++++++++++++ .travis.yml | 43 ------------ .../acceptance/helpers/step_helpers.rb | 19 +++--- .../database_adapters/config/postgresql.yml | 19 ++++++ .../database_adapters/config/sqlite3.yml | 16 +++++ spec/support/tests/database_configuration.rb | 11 +--- spec/support/unit/rails_application.rb | 6 +- 7 files changed, 116 insertions(+), 64 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml create mode 100644 spec/support/tests/database_adapters/config/postgresql.yml create mode 100644 spec/support/tests/database_adapters/config/sqlite3.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..176949a61 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,66 @@ +name: Test + +on: + push: + branches: + - master + paths-ignore: + - '**.md' + pull_request: + types: + - opened + - synchronize + paths-ignore: + - '**.md' + +jobs: + build: + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres + ports: [ '5432:5432' ] + options: --health-cmd pg_isready --health-interval 2s --health-timeout 1s --health-retries 10 + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: + - 2.7.2 + - 2.6.6 + - 2.5.8 + - 2.4.10 + appraisal: + - rails_6_0 + - rails_5_2 + - rails_5_1 + - rails_5_0 + - rails_4_2 + adapter: + - sqlite3 + - postgresql + exclude: + - { ruby: 2.7.2, appraisal: rails_4_2 } + - { ruby: 2.6.6, appraisal: rails_4_2 } + - { ruby: 2.4.10, appraisal: rails_6_0 } + env: + DATABASE_ADAPTER: ${{ matrix.adapter }} + BUNDLE_GEMFILE: gemfiles/${{ matrix.appraisal }}.gemfile + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + id: set-up-ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + - uses: actions/cache@v2 + with: + path: vendor/bundle + key: v1-rubygems-local-${{ runner.os }}-${{ matrix.ruby }}-${{ hashFiles(format('gemfiles/{0}.gemfile.lock', matrix.rails_appraisal)) }} + - name: Install dependencies + run: bundle install --jobs=3 --retry=3 + - name: Run Unit Tests + run: bundle exec rake spec:unit --trace + - name: Run Acceptance Tests + run: bundle exec rake spec:acceptance --trace diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0a913bba7..000000000 --- a/.travis.yml +++ /dev/null @@ -1,43 +0,0 @@ -language: ruby -dist: xenial -services: - - postgresql -env: - matrix: - - DATABASE_ADAPTER=sqlite3 - - DATABASE_ADAPTER=postgresql -rvm: - - 2.7.2 - - 2.6.6 - - 2.5.8 - - 2.4.10 -gemfile: - - gemfiles/rails_6_0.gemfile - - gemfiles/rails_5_2.gemfile - - gemfiles/rails_5_1.gemfile - - gemfiles/rails_5_0.gemfile - - gemfiles/rails_4_2.gemfile -matrix: - exclude: - - rvm: 2.7.2 - gemfile: gemfiles/rails_4_2.gemfile - - rvm: 2.6.6 - gemfile: gemfiles/rails_4_2.gemfile - - rvm: 2.4.10 - gemfile: gemfiles/rails_6_0.gemfile -cache: - directories: - - /home/travis/.rvm/gems/ruby-2.7.2 - - /home/travis/.rvm/gems/ruby-2.6.6 - - /home/travis/.rvm/gems/ruby-2.5.8 - - /home/travis/.rvm/gems/ruby-2.4.10 -# Source: -before_install: - - gem update --system --force --no-document - - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true - - gem install bundler -v '< 2' --no-document -install: "bundle install --jobs=3 --retry=3" -script: "bundle exec rake" -branches: - only: - - master diff --git a/spec/support/acceptance/helpers/step_helpers.rb b/spec/support/acceptance/helpers/step_helpers.rb index 49111244b..560f64a42 100644 --- a/spec/support/acceptance/helpers/step_helpers.rb +++ b/spec/support/acceptance/helpers/step_helpers.rb @@ -58,14 +58,8 @@ def run_n_unit_test_suite def create_rails_application fs.clean - command = - if rails_version =~ '~> 6.0' - "bundle exec rails new #{fs.project_directory} --skip-bundle --skip-javascript --no-rc" - else - "bundle exec rails new #{fs.project_directory} --skip-bundle --no-rc" - end - run_command!(command) do |runner| + run_command!(rails_new_command) do |runner| runner.directory = nil end @@ -76,11 +70,18 @@ def create_rails_application bundle.remove_gem 'debugger' bundle.remove_gem 'byebug' bundle.remove_gem 'web-console' - bundle.add_gem 'pg' end fs.open('config/database.yml', 'w') do |file| - YAML.dump(database.config.to_hash, file) + YAML.dump(database.config.load_file, file) + end + end + + def rails_new_command + if rails_version =~ '~> 6.0' + "bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --skip-javascript --no-rc" + else + "bundle exec rails new #{fs.project_directory} --database=#{database.adapter_name} --skip-bundle --no-rc" end end diff --git a/spec/support/tests/database_adapters/config/postgresql.yml b/spec/support/tests/database_adapters/config/postgresql.yml new file mode 100644 index 000000000..4c5c24182 --- /dev/null +++ b/spec/support/tests/database_adapters/config/postgresql.yml @@ -0,0 +1,19 @@ +default: &default + adapter: postgresql + encoding: unicode + pool: <%= ENV.fetch("RAILS_MAX_THREADS", 5) %> + host: <%= ENV.fetch("DB_HOST", "localhost") %> + username: <%= ENV.fetch("DB_USER", "postgres") %> + password: <%= ENV.fetch("DB_USER_PASSWORD", "postgres") %> + +development: + <<: *default + database: shoulda-matchers-test_development + +test: + <<: *default + database: shoulda-matchers-test_test + +production: + <<: *default + database: shoulda-matchers-test_production diff --git a/spec/support/tests/database_adapters/config/sqlite3.yml b/spec/support/tests/database_adapters/config/sqlite3.yml new file mode 100644 index 000000000..c52c94d72 --- /dev/null +++ b/spec/support/tests/database_adapters/config/sqlite3.yml @@ -0,0 +1,16 @@ +default: &default + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3 diff --git a/spec/support/tests/database_configuration.rb b/spec/support/tests/database_configuration.rb index df7aa13a2..71d4ed4fc 100644 --- a/spec/support/tests/database_configuration.rb +++ b/spec/support/tests/database_configuration.rb @@ -3,8 +3,6 @@ module Tests class DatabaseConfiguration < SimpleDelegator - ENVIRONMENTS = %w(development test production).freeze - attr_reader :adapter_class def self.for(database_name, adapter_name) @@ -18,13 +16,8 @@ def initialize(config) super(config) end - def to_hash - ENVIRONMENTS.each_with_object({}) do |env, config_as_hash| - config_as_hash[env] = { - 'adapter' => adapter.to_s, - 'database' => "#{database}_#{env}", - } - end + def load_file + YAML::load_file(File.join(__dir__, "database_adapters/config/#{adapter}.yml")) end end end diff --git a/spec/support/unit/rails_application.rb b/spec/support/unit/rails_application.rb index c0eba35d8..314309180 100644 --- a/spec/support/unit/rails_application.rb +++ b/spec/support/unit/rails_application.rb @@ -97,6 +97,7 @@ def rails_new_command 'rails', 'new', fs.project_directory.to_s, + "--database=#{database.adapter_name}", '--skip-bundle', '--no-rc', '--skip-webpack-install', @@ -106,6 +107,7 @@ def rails_new_command 'rails', 'new', fs.project_directory.to_s, + "--database=#{database.adapter_name}", '--skip-bundle', '--no-rc', ] @@ -135,7 +137,7 @@ def remove_bootsnap end def write_database_configuration - YAML.dump(database.config.to_hash, fs.open('config/database.yml', 'w')) + YAML.dump(database.config.load_file, fs.open('config/database.yml', 'w')) end def write_activerecord_model_with_different_connection @@ -201,8 +203,6 @@ def update_gems bundle.remove_gem 'debugger' bundle.remove_gem 'byebug' bundle.remove_gem 'web-console' - bundle.add_gem 'pg' - bundle.add_gem 'sqlite', '~> 1.3.6' end end