From e3b6a01416ff73f12e9ccb1accea0ad7015be031 Mon Sep 17 00:00:00 2001 From: Anton Rieder <1301152+aried3r@users.noreply.github.com> Date: Fri, 7 May 2021 16:14:08 +0200 Subject: [PATCH] Implement GitHub Actions for CI --- .github/workflows/test.yml | 102 ++++++++++++++++++++++++++++ .rubocop.yml | 1 - .travis.yml | 65 ------------------ README.md | 2 +- spec/functional/retry_spec.rb | 2 +- spec/spec_helper.rb | 2 +- spec/support/active_record_setup.rb | 7 +- spec/support/config/database.yml | 8 +-- spec/support/simplecov_helper.rb | 2 +- 9 files changed, 114 insertions(+), 77 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..bd4506cfb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,102 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake +# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby + +name: RPush Test + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +env: + POSTGRES_USER: postgres + POSTGRES_HOST: localhost + POSTGRES_PORT: 5432 + POSTGRES_DB: rpush_test + PGPASSWORD: postgres # https://www.postgresql.org/docs/13/libpq-envars.html + +jobs: + test: + runs-on: ubuntu-20.04 + + services: + postgres: + image: postgres:13 + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 + + redis: + image: redis + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps port 6379 on service container to the host + - 6379:6379 + + strategy: + matrix: + gemfile: ['rails_5.2', 'rails_6.0', 'rails_6.1'] + + ruby: ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0'] + + client: ['active_record', 'redis'] + + exclude: + # Rails 5.2 requires Ruby < 3.0 + # https://github.com/rails/rails/issues/40938 + - ruby: '3.0' + gemfile: 'rails_5.2' + # Rails >= 6 need Ruby >= 2.5 + - ruby: '2.3' + gemfile: 'rails_6.0' + - ruby: '2.4' + gemfile: 'rails_6.0' + - ruby: '2.3' + gemfile: 'rails_6.1' + - ruby: '2.4' + gemfile: 'rails_6.1' + + env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps + BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile + + steps: + - uses: actions/checkout@v2 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + + - name: Create PostgreSQL database + run: | + createdb \ + --host=$POSTGRES_HOST \ + --port=$POSTGRES_PORT \ + --username=$POSTGRES_USER \ + $POSTGRES_DB + + - name: Run tests + run: bundle exec rake + env: + # The hostname used to communicate with the PostgreSQL service container + POSTGRES_HOST: localhost + # The default PostgreSQL port + POSTGRES_PORT: 5432 + CLIENT: ${{ matrix.client }} diff --git a/.rubocop.yml b/.rubocop.yml index 36a31a6d4..0abee38e4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,6 @@ require: rubocop-performance AllCops: Exclude: - - gemfiles/vendor/bundle/**/* # This dir only shows up on Travis - lib/generators/**/* - vendor/bundle/**/* TargetRubyVersion: 2.3 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b9df40d7f..000000000 --- a/.travis.yml +++ /dev/null @@ -1,65 +0,0 @@ -language: ruby - -dist: xenial - -cache: bundler - -compiler: clang - -rvm: - - 2.3 - - 2.4 - - 2.5 - - 2.6 - - 2.7 - - 3.0 - -# Build only commits on master for the "Build pushed branches" feature. This -# prevents building twice on PRs originating from our repo ("Build pushed pull -# requests)". See: -# - https://github.com/travis-ci/travis-ci/issues/1147 -# - https://docs.travis-ci.com/user/pull-requests/#double-builds-on-pull-requests -branches: - only: - - master - -gemfile: - - gemfiles/rails_5.2.gemfile - - gemfiles/rails_6.0.gemfile - - gemfiles/rails_6.1.gemfile - -services: - - postgresql - - redis-server - -before_script: psql -c 'create database rpush_test;' -U postgres >/dev/null -before_install: - # https://github.com/rubygems/rubygems/issues/3036 - # https://github.com/rubygems/rubygems/issues/3036#issuecomment-566132226 - - yes | gem update --system - - gem install bundler - -env: - matrix: - - CLIENT=active_record - - CLIENT=redis - -matrix: - fast_finish: true - exclude: - - gemfile: gemfiles/rails_5.2.gemfile - rvm: 3.0 - - gemfile: gemfiles/rails_6.0.gemfile - rvm: 2.3 - - gemfile: gemfiles/rails_6.0.gemfile - rvm: 2.4 - - gemfile: gemfiles/rails_6.1.gemfile - rvm: 2.3 - - gemfile: gemfiles/rails_6.1.gemfile - rvm: 2.4 - -jobs: - include: - - stage: Lint - rvm: 2.6 - script: bundle exec rake rubocop diff --git a/README.md b/README.md index d061672ac..2914c66fa 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Gem Version](https://badge.fury.io/rb/rpush.svg)](http://badge.fury.io/rb/rpush) -[![Build Status](https://travis-ci.org/rpush/rpush.svg?branch=master)](https://travis-ci.org/rpush/rpush) +[![RPush Test](https://github.com/rpush/rpush/actions/workflows/test.yml/badge.svg)](https://github.com/rpush/rpush/actions/workflows/test.yml) [![Test Coverage](https://codeclimate.com/github/rpush/rpush/badges/coverage.svg)](https://codeclimate.com/github/rpush/rpush) [![Code Climate](https://codeclimate.com/github/rpush/rpush/badges/gpa.svg)](https://codeclimate.com/github/rpush/rpush) [![Join the chat at https://gitter.im/rpush/rpush](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rpush/rpush?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) diff --git a/spec/functional/retry_spec.rb b/spec/functional/retry_spec.rb index 3e27f6e21..6a1ad038e 100644 --- a/spec/functional/retry_spec.rb +++ b/spec/functional/retry_spec.rb @@ -39,4 +39,4 @@ notification.reload expect(notification.delivered).to eq(false) end -end +end if redis? diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7984e4353..ece44cce1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,7 @@ def client (ENV['CLIENT'] || :active_record).to_sym end -if !ENV['TRAVIS'] || (ENV['TRAVIS'] && ENV['QUALITY'] == 'true') +if !ENV['CI'] || (ENV['CI'] && ENV['QUALITY'] == 'true') begin require './spec/support/simplecov_helper' include SimpleCovHelper diff --git a/spec/support/active_record_setup.rb b/spec/support/active_record_setup.rb index 43db5afae..94027835e 100644 --- a/spec/support/active_record_setup.rb +++ b/spec/support/active_record_setup.rb @@ -6,14 +6,15 @@ SPEC_ADAPTER = 'jdbc' + SPEC_ADAPTER if jruby require 'yaml' -db_config = YAML.load_file(File.expand_path("config/database.yml", File.dirname(__FILE__))) +db_config_path = File.expand_path("config/database.yml", File.dirname(__FILE__)) +db_config = YAML.load(ERB.new(File.read(db_config_path)).result) if db_config[SPEC_ADAPTER].nil? puts "No such adapter '#{SPEC_ADAPTER}'. Valid adapters are #{db_config.keys.join(', ')}." exit 1 end -if ENV['TRAVIS'] +if ENV['CI'] db_config[SPEC_ADAPTER]['username'] = 'postgres' else require 'etc' @@ -62,7 +63,7 @@ Rpush420Updates ] -unless ENV['TRAVIS'] +unless ENV['CI'] migrations.reverse_each do |m| begin m.down diff --git a/spec/support/config/database.yml b/spec/support/config/database.yml index 051db6b71..4107f689d 100644 --- a/spec/support/config/database.yml +++ b/spec/support/config/database.yml @@ -2,10 +2,10 @@ postgresql: adapter: postgresql - database: rpush_test - host: localhost - username: postgres - password: "" + database: <%= ENV.fetch('POSTGRES_DB', 'rpush_test') %> + host: <%= ENV.fetch('POSTGRES_HOST', 'localhost') %> + username: <%= ENV.fetch('POSTGRES_USER', 'postgres') %> + password: <%= ENV.fetch('PGPASSWORD', '') %> jdbcpostgresql: adapter: jdbcpostgresql diff --git a/spec/support/simplecov_helper.rb b/spec/support/simplecov_helper.rb index fb1ebdc3f..4e078dd55 100644 --- a/spec/support/simplecov_helper.rb +++ b/spec/support/simplecov_helper.rb @@ -10,7 +10,7 @@ def start_simple_cov(name) formatters = [SimpleCov::Formatter::QualityFormatter] - if ENV['TRAVIS'] + if ENV['CI'] require 'codeclimate-test-reporter' if CodeClimate::TestReporter.run?