Skip to content

Commit

Permalink
Merge pull request #3568 from cloudfoundry/backwards-compatibility-un…
Browse files Browse the repository at this point in the history
…it-tests

Add a github action to test db migrations backwards-compatibility
  • Loading branch information
FloThinksPi authored Dec 21, 2023
2 parents 36abd2f + 2b33ce9 commit 00206f5
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/docs_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ permissions:
jobs:
Test-Docs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: hmarr/debug-action@v2
- uses: actions/checkout@v4
- name: Prepare setup
run: cp -a .ruby-version docs/v3/.ruby-version
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/migration_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Backwards Compatibility Unit Tests
concurrency:
group: '${{ github.workflow }}-${{ github.new_cc_ref || github.run_id }}'
cancel-in-progress: true
on:
workflow_dispatch:
description: "This action tests backwards compatibility when db migrations are introduced. It tests database schema at new code(old_cc_ref) with unittests running old code(new_cc_ref) "
old_cc_ref:
description: 'Old Version of CC_NG that the backwards compatibility should be checked against'
required: true
new_cc_ref:
description: 'Old Version of CC_NG that needs testing for backwards incompatible changes'
required: true
pull_request:
branches: [ main ]
paths:
- 'db/migrations/**'

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
Test-Postgres-Backwards-Compatibillity:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
max-parallel: 3
matrix:
image: ["postgres:10", "postgres:11", "postgres:16"]
version: ${{ github.event_name == 'workflow_dispatch' && [[github.event.inputs.new_cc_ref, github.event.inputs.old_cc_ref]]] || [[github.head_ref, github.event.pull_request.base.sha ]] }}
services:
postgres:
image: ${{ matrix.image }}
env:
POSTGRES_PASSWORD: rootpassword
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: hmarr/debug-action@v2
- name: Checkout code to run the db migration with
uses: actions/checkout@v4
with:
ref: ${{ matrix.version[0] }}
- uses: ./.github/workflows/composite/setup
- name: Migrate Database
run: DB=postgres POSTGRES_CONNECTION_PREFIX="postgres://postgres:rootpassword@localhost:5432" bundle exec rake db:parallel:recreate
- name: Checkout code to run the unit tests with
uses: actions/checkout@v4
with:
ref: ${{ matrix.version[1] }}
- name: Run Tests
run: DB=postgres POSTGRES_CONNECTION_PREFIX="postgres://postgres:rootpassword@localhost:5432" bundle exec rake spec:no_recreate

Test-Mysql-Backwards-Compatibillity:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
max-parallel: 3
matrix:
image: ["mysql:5.7", "mysql:8.0", "mysql:8.2"]
version: ${{ github.event_name == 'workflow_dispatch' && [[github.event.inputs.new_cc_ref, github.event.inputs.old_cc_ref]]] || [[github.head_ref, github.event.pull_request.base.sha ]] }}
services:
mysql:
image: ${{ matrix.image }}
env:
MYSQL_DATABASE: cc_test
MYSQL_ROOT_PASSWORD: password
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
ports:
- 3306:3306
steps:
- uses: hmarr/debug-action@v2
- name: Checkout code to run the db migration with
uses: actions/checkout@v4
with:
ref: ${{ matrix.version[0] }}
- uses: ./.github/workflows/composite/setup
- name: Migrate Database
run: DB=mysql MYSQL_CONNECTION_PREFIX="mysql2://root:[email protected]:3306" bundle exec rake db:parallel:recreate
- name: Checkout code to run the unit tests with
uses: actions/checkout@v4
with:
ref: ${{ matrix.version[1] }}
- name: Run tests
run: DB=mysql MYSQL_CONNECTION_PREFIX="mysql2://root:[email protected]:3306" bundle exec rake spec:no_recreate
5 changes: 5 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
Rubocop:
runs-on: ubuntu-latest
steps:
- uses: hmarr/debug-action@v2
- uses: actions/checkout@v4
- uses: ./.github/workflows/composite/setup
- name: Run Rubocop
Expand All @@ -38,6 +39,7 @@ jobs:

Test-Postgres:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
Expand All @@ -55,6 +57,7 @@ jobs:
ports:
- 5432:5432
steps:
- uses: hmarr/debug-action@v2
- uses: actions/checkout@v4
- uses: ./.github/workflows/composite/setup
- name: Run tests
Expand All @@ -69,6 +72,7 @@ jobs:

Test-Mysql:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
Expand All @@ -83,6 +87,7 @@ jobs:
ports:
- 3306:3306
steps:
- uses: hmarr/debug-action@v2
- uses: actions/checkout@v4
- uses: ./.github/workflows/composite/setup
- name: Run tests
Expand Down
9 changes: 9 additions & 0 deletions lib/tasks/spec.rake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ namespace :spec do
run_failed_specs
end

desc 'Run tests on a already migrated database'
task no_recreate: ['db:pick'] do
if ARGV[1]
run_specs(ARGV[1])
else
run_specs_parallel('spec')
end
end

def run_specs(path)
sh "bundle exec rspec #{path} --require rspec/instafail --format RSpec::Instafail --format progress"
end
Expand Down

0 comments on commit 00206f5

Please sign in to comment.