Skip to content

Commit

Permalink
Test against multiple PostgreSQL versions
Browse files Browse the repository at this point in the history
This commit introduces an improvement in our testing strategy to ensure
broader compatibility across various PostgreSQL versions.

The primary focus remains on the latest stable release of PostgreSQL,
acknowledging the significance of maintaining support for older versions
to accommodate the longevity of applications.

To facilitate this, tests have been added to verify the application's
functionality against PostgreSQL 12.

Since `setup-postgres` action does not allow to create multiple
databases, consider a refactoring if ankane/setup-postgres#9 will be
merged.
  • Loading branch information
tagliala committed May 5, 2024
1 parent 3654a98 commit fff036a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
36 changes: 19 additions & 17 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,43 @@ jobs:
name: Ruby specs
runs-on: ubuntu-latest

services:
db:
image: postgres:12
ports: ['5432:5432']
env:
POSTGRES_HOST_AUTH_METHOD: trust

options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
ruby-version: ['3.0', '3.1', '3.2', '3.3']
gemfile: [rails_7.0, rails_7.1]
postgres-version: ['16']
channel: ['stable']

include:
# Test minimum required Ruby and Rails against PostgreSQL 12
- ruby-version: '3.0'
gemfile: rails_7.0
postgres-version: '12'
channel: 'stable'

- ruby-version: '3.1'
gemfile: rails_edge
postgres-version: '16'
channel: 'experimental'
- ruby-version: '3.2'
gemfile: rails_edge
postgres-version: '16'
channel: 'experimental'
- ruby-version: '3.3'
gemfile: rails_edge
postgres-version: '16'
channel: 'experimental'
- ruby-version: 'head'
gemfile: rails_7.0
postgres-version: '16'
channel: 'experimental'
- ruby-version: 'head'
gemfile: rails_7.1
postgres-version: '16'
channel: 'experimental'
- ruby-version: 'head'
gemfile: rails_edge
postgres-version: '16'
channel: 'experimental'

env:
Expand All @@ -61,11 +61,13 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Database
- uses: ankane/setup-postgres@v1
with:
postgres-version: ${{ matrix.postgres-version }}
database: chronomodel
- name: Create Rails app database # FIXME: refactor when ankane/setup-postgres#9 will be merged
run: |
psql -c "CREATE ROLE runner SUPERUSER LOGIN CREATEDB;" -U postgres -h localhost
psql -c "CREATE DATABASE chronomodel;" -U postgres -h localhost
psql -c "CREATE DATABASE chronomodel_railsapp;" -U postgres -h localhost
createdb chronomodel_railsapp
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
7 changes: 7 additions & 0 deletions spec/aruba/rake_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@
contents.sub('username: postgres', "username: #{Etc.getlogin}")
end
end

# Hande GitHub Actions
if ENV['CI']
file_mangle!('config/database.yml') do |contents|
contents.sub('username: postgres', 'username: runner')
end
end
end

it { expect(last_command).to be_successfully_executed }
Expand Down
2 changes: 1 addition & 1 deletion spec/config.github.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
host: localhost
username: postgres
username: runner
password: ""
database: chronomodel
pool: 11

0 comments on commit fff036a

Please sign in to comment.