diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8c9c0b9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d5cfbf8..0000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -language: ruby - -cache: - bundler: true - -rvm: - - 2.3.8 - - 2.4.6 - - 2.5.5 - - 2.6.2 - - jruby-9.1.17.0 - - jruby-9.2.6.0 -before_script: - - psql -c 'create database sequel_bitemporal_test;' -U postgres -env: - - SQLITE=1 SEQUEL='~> 4.0' - - SQLITE=1 SEQUEL='~> 5.0' - - PG=1 SEQUEL='~> 4.0' - - PG=1 SEQUEL='~> 5.0' -gemfile: - - ci/sequel.gemfile -matrix: - allow_failures: - - rvm: jruby-9.1.17.0 - env: PG=1 SEQUEL='~> 4.0' - - rvm: jruby-9.1.17.0 - env: PG=1 SEQUEL='~> 5.0' - - rvm: jruby-9.2.6.0 - env: PG=1 SEQUEL='~> 4.0' - - rvm: jruby-9.2.6.0 - env: PG=1 SEQUEL='~> 5.0' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1f4b49a..aebcfcb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/support/db.rb b/spec/support/db.rb index 42a5d9a..40f3a58 100644 --- a/spec/support/db.rb +++ b/spec/support/db.rb @@ -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)