From 685a5c42d3f1b3892fe81885c3d7b66ee4b09e57 Mon Sep 17 00:00:00 2001 From: hkim Date: Mon, 6 Feb 2023 15:31:29 -0600 Subject: [PATCH 1/2] remove travis, add github actions --- .github/workflows/ci.yml | 37 ++++++++++++++++++++++++++++++++++++ .travis.yml | 41 ---------------------------------------- 2 files changed, 37 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d4c8c32 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: CI + +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: [2.6, 2.7, 3.0] + redis-version: [4, 5, 6] + + steps: + - name: Checkout project + uses: actions/checkout@v3 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + + - name: Start Redis + uses: supercharge/redis-github-action@1.4.0 + with: + redis-version: ${{ matrix.redis-version }} + + - name: Run tests + run: bundle exec rake diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a738f6f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -language: ruby -cache: bundler - -rvm: - - 2.5.8 - - 2.7.2 - -env: - matrix: - - PG_VERSION=11 - -before_install: - - git config --global user.name "Prodder In Travis-CI" - - git config --global user.email "prodder@example.com" - # install postgres - - sudo apt-get install postgresql-client-$PG_VERSION postgresql-server-dev-$PG_VERSION - # setup pg_dump - - ls -al /usr/lib/postgresql/ - - sudo ln -sfn /usr/lib/postgresql/$PG_VERSION/bin/pg_dump /usr/bin/pg_dump - # start up the specific version of PG - - sudo -E sh -c 'service postgresql stop' - - sleep 5s - - sudo -E sh -c 'service postgresql start $PG_VERSION' - - psql -U postgres -d postgres -c 'select setting from pg_settings where name = $m$server_version$m$;' - -script: - - psql --version - - pg_lsclusters - - psql -U postgres -d postgres -c 'select 1;' - - ls -al `which pg_dump` - - bundle exec rake spec - - bundle exec rake cucumber - -deploy: - provider: rubygems - api_key: - secure: "UhUkPFhEuI1dLPa4skTUdOBcGY2SEkRP3N9jLDQad04DflV+GutcjrfN1iQxWk59gVt3zqird5FS8SdwCFuOn8DAU9ACtg73xiPPWRRTdzma4Qw+4thuOHcdwPBz3762YFTRyH7IbRTAlxaD6qPz6US3BnYAkJU7C8c30rHLX6cZutjLV4FsvWonkzxcjyEUViVEdBM0kzI+tdBnQovpcM67a9AfxxBZITJLIfIcah1qc/RANpLkUFJCwNyH9oARWsGIvpIKcQEJBhsl04tvbNRLpiMCk1e1RS1bjMdbbx/rVm3C7dvAjUznbr3ON9abgoe6QDDYr6kXPJbylmxFUzA7ftBWjz2nNruRncsohx08LaM4ADRJWKB3XbP5BXkwUgE672Fi20+Z78LwWfjrr3iRVm7u9Mt9pZHG6Ih8Jy64Uq3647kdVZu9APPfn1NZETFG7vLAMZUtPXv7HBkujlq23XdYXax1XYYbYsM0LOlnG6ol2y6OrBrxWIqC+E8UmLXf/+/MS4j3v2RAe7jXh6fFlw+5MjLr3HXqZ12CrAChp22NRPp1OY4Hac4zzRwGeVOgewknpOK7qQfVFFaQoQksU6VaenSx+TxcYOZYuQdrQjfbO6c+Q/vvZ1RoPOEwH0AelkrW2eGqQTNVWIbH5vvfhys68SA8ov8gNnIzMtU=" - gem: prodder - on: - tags: true - repo: enova/prodder From 336cc07520aa179242b4a374db122a955e294a5b Mon Sep 17 00:00:00 2001 From: hkim Date: Fri, 10 Feb 2023 15:15:11 -0600 Subject: [PATCH 2/2] remove deprecated methods, fix ci --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++-------- config/database.yml.github-actions | 8 +++++++ lib/prodder/prodder.rake | 23 +++++++++--------- lib/prodder/version.rb | 2 +- 4 files changed, 48 insertions(+), 23 deletions(-) create mode 100644 config/database.yml.github-actions diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4c8c32..00a3072 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,22 +16,40 @@ jobs: strategy: matrix: ruby-version: [2.6, 2.7, 3.0] - redis-version: [4, 5, 6] - + services: + postgres: + image: postgres:12.1-alpine + ports: + - 5432:5432 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - - name: Checkout project + - name: Checkout Project uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true # runs 'bundle install' and caches installed gems automatically + bundler-cache: true - - name: Start Redis - uses: supercharge/redis-github-action@1.4.0 - with: - redis-version: ${{ matrix.redis-version }} + - name: Install Library Dependencies + run: sudo apt-get install libpq-dev + + - name: Setup Database + run: | + cp config/database.yml.github-actions config/database.yml + env: + RAILS_ENV: test + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres - - name: Run tests - run: bundle exec rake + - name: Test with RSpec + env: + RAILS_ENV: "test" + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + run: | + bundle exec rspec diff --git a/config/database.yml.github-actions b/config/database.yml.github-actions new file mode 100644 index 0000000..0724691 --- /dev/null +++ b/config/database.yml.github-actions @@ -0,0 +1,8 @@ +test: + adapter: postgresql + host: localhost + encoding: unicode + database: github-actions + pool: 20 + username: <%= ENV["POSTGRES_USER"] %> + password: <%= ENV["POSTGRES_PASSWORD"] %> diff --git a/lib/prodder/prodder.rake b/lib/prodder/prodder.rake index c547ed1..5760af3 100644 --- a/lib/prodder/prodder.rake +++ b/lib/prodder/prodder.rake @@ -169,7 +169,7 @@ namespace :db do end as("superuser", in: environments) do ActiveRecord::Tasks::DatabaseTasks.create_current - ActiveRecord::Base.configurations.each do |env, config| + Rails.configuration.database_configuration.each do |env, config| if environments.include?(env) && config["migration_user"] && config['database'] set_psql_env config `psql --no-psqlrc --command "ALTER DATABASE #{config['database']} OWNER TO #{config['migration_user']}" #{Shellwords.escape(config['database'])}` @@ -182,7 +182,7 @@ namespace :db do task :all => dependencies do as("superuser") do ActiveRecord::Tasks::DatabaseTasks.create_all - ActiveRecord::Base.configurations.each do |env, config| + Rails.configuration.database_configuration.each do |env, config| if config["migration_user"] && config['database'] set_psql_env config `psql --no-psqlrc --command "ALTER DATABASE #{config['database']} OWNER TO #{config['migration_user']}" #{Shellwords.escape(config['database'])}` @@ -204,7 +204,7 @@ namespace :db do desc "Load db/structure.sql into the current environment's database" task :load => dependencies do as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do - config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] + config = Rails.configuration.database_configuration[ENV['RAILS_ENV'] || Rails.env] set_psql_env config puts "Loading db/structure.sql into database '#{config['database']}'" `psql --no-psqlrc -f db/structure.sql #{Shellwords.escape(config['database'])}` @@ -217,7 +217,7 @@ namespace :db do task :seed => dependencies do if File.exist?('db/seeds.sql') as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do - config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] + config = Rails.configuration.database_configuration[ENV['RAILS_ENV'] || Rails.env] set_psql_env config puts "Loading db/seeds.sql into database '#{config['database']}'" `psql --no-psqlrc -f db/seeds.sql #{Shellwords.escape(config['database'])}` @@ -232,7 +232,7 @@ namespace :db do task :quality_check => dependencies do if File.exist?('db/quality_checks.sql') as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do - config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] + config = Rails.configuration.database_configuration[ENV['RAILS_ENV'] || Rails.env] set_psql_env config puts "Loading db/quality_checks.sql into database '#{config['database']}'" `psql --no-psqlrc -f db/quality_checks.sql #{Shellwords.escape(config['database'])}` @@ -247,7 +247,7 @@ namespace :db do task :permission => dependencies do if File.exist?('db/permissions.sql') as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do - config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] + config = Rails.configuration.database_configuration[ENV['RAILS_ENV'] || Rails.env] set_psql_env config puts "Loading db/permissions.sql into database '#{config['database']}'" result = ActiveRecord::Base.connection.execute(<<-SQL).first @@ -268,7 +268,7 @@ namespace :db do task :settings => dependencies do if File.exist?('db/settings.sql') as("superuser", in: ENV['RAILS_ENV'] || Rails.env) do - config = ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env] + config = Rails.configuration.database_configuration[ENV['RAILS_ENV'] || Rails.env] set_psql_env config puts "Loading db/settings.sql into database '#{config['database']}'" result = ActiveRecord::Base.connection.execute(<<-SQL).first @@ -362,20 +362,19 @@ namespace :db do def as(user, opts = {}, &block) if File.exist?('db/permissions.sql') - # `ActiveRecord::Base.configurations` in Rails 6 now returns an object instead of a hash - config, config_was = ActiveRecord::Base.configurations.deep_dup.to_h, ActiveRecord::Base.configurations.deep_dup + config, config_was = Rails.configuration.database_configuration.deep_dup.to_h, Rails.configuration.database_configuration.deep_dup in_env = Array(opts[:in]) || config.keys if config.all? { |env, config_hash| in_env.include?(env) ? config_hash[user] : true } disconnect config.each { |env, config_hash| config_hash["username"] = config_hash[user] if in_env.include?(env) } - ActiveRecord::Base.configurations = config + Rails.configuration.database_configuration = config end else puts "No permissions file (db/permissions.sql) found, running everything in context of user" end yield ensure - ActiveRecord::Base.configurations = config_was if config_was + Rails.configuration.database_configuration = config_was if config_was in_env.each { |env| ActiveRecord::Base.establish_connection(env.intern) } if in_env end @@ -394,5 +393,5 @@ end # Yes, I really want migrations to run against the test DB. Rake::Task['db:migrate'].actions.unshift(proc { - ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ENV['RAILS_ENV'] || Rails.env]) + ActiveRecord::Base.establish_connection(Rails.configuration.database_configuration[(ENV['RAILS_ENV'] || Rails.env).to_sym]) }) diff --git a/lib/prodder/version.rb b/lib/prodder/version.rb index e3b5a74..e7acde0 100644 --- a/lib/prodder/version.rb +++ b/lib/prodder/version.rb @@ -1,3 +1,3 @@ module Prodder - VERSION = "1.7.7" + VERSION = "1.8.0" end