Skip to content

Commit

Permalink
Switch CI from TravisCI to Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanTron committed Feb 12, 2024
1 parent 3a7be17 commit c952f31
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 37 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: ['**']

jobs:
tests:
services:
postgres:
image: postgres:13
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby:
- "2.7"
- "3.0"
- "3.1"
- "3.2"
- "3.3"
name: Ruby ${{ matrix.ruby }}

env:
SEQUEL: "~> 5.0"
BUNDLE_GEMFILE: "ci/sequel.gemfile"
steps:
- uses: actions/checkout@v3
- name: Install db dependencies and check connections
run: |
env PGPASSWORD=postgres psql -h localhost -p ${{ job.services.postgres.ports[5432] }} -U postgres -l
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Create databases
run: |
env PGPASSWORD=postgres psql -c 'create database sequel_bitemporal_test;' -U postgres -h localhost -p ${{ job.services.postgres.ports[5432] }}
- name: Run PostgreSQL tests
run: bundle exec rake spec
env:
TEST_ADAPTER: postgresql
TEST_DATABASE: sequel_bitemporal_test
TEST_DATABASE_HOST: localhost
TEST_DATABASE_PORT: ${{ job.services.postgres.ports[5432] }}
TEST_USERNAME: postgres
TEST_PASSWORD: postgres
- name: Run SQLite tests
run: bundle exec rake spec
env:
TEST_ADAPTER: sqlite
31 changes: 0 additions & 31 deletions .travis.yml

This file was deleted.

6 changes: 1 addition & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
DB = if DbHelpers.pg?
`createdb sequel_bitemporal_test`
Sequel.extension :pg_range, :pg_range_ops
if ::Sequel::Plugins::Bitemporal.jruby?
Sequel.connect "jdbc:postgresql://localhost/sequel_bitemporal_test"
else
Sequel.postgres "sequel_bitemporal_test"
end
Sequel.connect DbHelpers.pg_ruby_connect_uri
else
if Sequel::Plugins::Bitemporal.jruby?
rspec_exclusions[:skip_jdbc_sqlite] = true
Expand Down
15 changes: 14 additions & 1 deletion spec/support/db.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
module DbHelpers

def self.pg?
ENV.has_key? "PG"
!ENV.has_key?("TEST_ADAPTER") || ENV["TEST_ADAPTER"]=="postgresql"
end

def self.jruby?
(defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby') || defined?(JRUBY_VERSION)
end

def self.pg_ruby_connect_uri
username = ENV.fetch("TEST_USERNAME", nil)
password = ENV.fetch("TEST_PASSWORD", nil)
auth = [username, password].compact.join(":")

uri = "postgresql://#{"#{auth}@" unless auth.empty?}#{ENV.fetch("TEST_DATABASE_HOST", "127.0.0.1")}:#{ENV.fetch("TEST_DATABASE_PORT", "5432")}/#{ENV.fetch("TEST_DATABASE", "sequel_bitemporal_test")}"
if jruby?
"jdbc:#{uri}"
else
uri
end
end

def db_setup(opts={})
use_time = opts[:use_time]
DB.drop_table(:room_versions) if DB.table_exists?(:room_versions)
Expand Down

0 comments on commit c952f31

Please sign in to comment.