From fff036a06e4050b64ae9ef06892152fa484507a2 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Sun, 5 May 2024 22:38:36 +0200 Subject: [PATCH] Test against multiple PostgreSQL versions 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. --- .github/workflows/ruby.yml | 36 +++++++++++++++++++----------------- spec/aruba/rake_task_spec.rb | 7 +++++++ spec/config.github.yml | 2 +- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 1623f56c..3a7d4012 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -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: @@ -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: diff --git a/spec/aruba/rake_task_spec.rb b/spec/aruba/rake_task_spec.rb index 034357d1..5748f139 100644 --- a/spec/aruba/rake_task_spec.rb +++ b/spec/aruba/rake_task_spec.rb @@ -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 } diff --git a/spec/config.github.yml b/spec/config.github.yml index ce27bc19..88b585d7 100644 --- a/spec/config.github.yml +++ b/spec/config.github.yml @@ -1,5 +1,5 @@ host: localhost -username: postgres +username: runner password: "" database: chronomodel pool: 11