Skip to content

Commit

Permalink
Switch CI from TravisCI to GHA
Browse files Browse the repository at this point in the history
After years of generously donating their service, TravisCI
ends support for FOSS on 2020-12-31.
  • Loading branch information
jaredbeck committed Dec 22, 2020
1 parent 9650f9e commit d3e7a3a
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 62 deletions.
130 changes: 130 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: gha-workflow-authlogic-test
on: [push, pull_request]
jobs:

# Linting is a separate job, primary because it only needs to be done once,
# and secondarily because jobs are performed concurrently.
gha-job-authlogic-lint:
name: Lint
runs-on: ubuntu-18.04
steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Setup ruby
uses: actions/setup-ruby@v1
with:
# Set to `TargetRubyVersion` in `.rubocopy.yml`
ruby-version: 2.4
- name: Bundle
run: |
gem install bundler
bundle install --jobs 4 --retry 3
- name: Lint
run: bundle exec rubocop

# The test job is a matrix of ruby/rails versions.
gha-job-authlogic-test:
name: Ruby ${{ matrix.ruby }}, ${{ matrix.gemfile }}.rb
runs-on: ubuntu-18.04
services:
gha-service-authlogic-mysql:
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: authlogic
image: mysql:8.0
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 3306:3306
gha-service-authlogic-postgres:
env:
POSTGRES_PASSWORD: asdfasdf
image: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
strategy:
# Unlike TravisCI, the database will not be part of the matrix. Each
# sub-job in the matrix tests all three databases. Alternatively, we could
# have set this up with each database as a separate job, but then we'd be
# duplicating the matrix configuration three times.
matrix:
gemfile: [ 'rails_5.2', 'rails_6.0', 'rails_6.1' ]

# To keep matrix size down, only test highest and lowest rubies. In
# `.rubocopy.yml`, set `TargetRubyVersion`, to the lowest ruby version
# tested here.
ruby: [ '2.4', '2.7' ]

exclude:
# rails 6 requires ruby >= 2.5.0
- ruby: '2.4'
gemfile: 'rails_6.0'
- ruby: '2.4'
gemfile: 'rails_6.1'
steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Setup ruby
uses: actions/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Bundle
run: |
gem install bundler
bundle install --jobs 4 --retry 3
env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.rb

# MySQL db was created above, sqlite will be created during test suite,
# when migrations occur, so we only need to create the postgres db. I
# tried something like `cd .....dummy_app && ....db:create`, but couldn't
# get that to work.
- name: Create postgres database
run: |
createdb \
--host=$POSTGRES_HOST \
--port=$POSTGRES_PORT \
--username=postgres \
authlogic
env:
PGPASSWORD: asdfasdf
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432

# The following three steps finally run the tests.
# We run `rake test` instead of the default task, which includes rubocop,
# because rubocop is done (once!) in a separate job above.
- name: Test, sqlite
run: bundle exec rake test
env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.rb
DB: sqlite
- name: Test, mysql
run: bundle exec rake test
env:
BACKTRACE: 1
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.rb
DB: mysql
AUTHLOGIC_DB_NAME: authlogic
AUTHLOGIC_DB_USER: root
AUTHLOGIC_DB_HOST: 127.0.0.1
AUTHLOGIC_DB_PORT: 3306
- name: Test, postgres
run: bundle exec rake test
env:
BACKTRACE: 1
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.rb
DB: postgres
AUTHLOGIC_DB_NAME: authlogic
AUTHLOGIC_DB_USER: postgres
AUTHLOGIC_DB_HOST: 127.0.0.1
AUTHLOGIC_DB_PORT: 5432
AUTHLOGIC_DB_PASSWORD: asdfasdf
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ AllCops:
# file, we wouldn't have to specify this (https://bit.ly/2vNTsue), but we
# don't commit that file because that would interfere with testing multiple
# rubies on CI.
#
# Should be same as `ruby-version` in `.github/workflows/test.yml`
TargetRubyVersion: 2.4

# Avoid empty lines in methods, they are a sign the method is too big.
Expand Down
58 changes: 0 additions & 58 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions authlogic.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require "authlogic/version"
s.add_development_dependency "minitest-reporters", "~> 1.3"
s.add_development_dependency "mysql2", "~> 0.5.2"
s.add_development_dependency "pg", "~> 1.1.4"
s.add_development_dependency "rake", "~> 13.0"
s.add_development_dependency "rubocop", "~> 0.80.1"
s.add_development_dependency "rubocop-performance", "~> 1.1"
s.add_development_dependency "scrypt", ">= 1.2", "< 4.0"
Expand Down
16 changes: 12 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,24 @@

I18n.load_path << File.dirname(__FILE__) + "/i18n/lol.yml"

# https://docs.travis-ci.com/user/database-setup
case ENV["DB"]
when "mysql"
ActiveRecord::Base.establish_connection(
adapter: "mysql2",
database: "authlogic",
username: "root"
database: ENV.fetch("AUTHLOGIC_DB_NAME", "authlogic"),
host: ENV.fetch("AUTHLOGIC_DB_HOST", nil),
port: ENV.fetch("AUTHLOGIC_DB_PORT", nil),
username: ENV.fetch("AUTHLOGIC_DB_USER", "root")
)
when "postgres"
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "authlogic")
ActiveRecord::Base.establish_connection(
adapter: "postgresql",
database: ENV.fetch("AUTHLOGIC_DB_NAME", "authlogic"),
host: ENV.fetch("AUTHLOGIC_DB_HOST", nil),
password: ENV.fetch("AUTHLOGIC_DB_PASSWORD", nil),
port: ENV.fetch("AUTHLOGIC_DB_PORT", nil),
username: ENV.fetch("AUTHLOGIC_DB_USER", nil)
)
else
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
end
Expand Down

0 comments on commit d3e7a3a

Please sign in to comment.