From ba42819555877f4870bda67dbb6eb79ffcdad530 Mon Sep 17 00:00:00 2001 From: Florian Braun <5863788+FloThinksPi@users.noreply.github.com> Date: Thu, 21 Dec 2023 13:34:55 +0100 Subject: [PATCH 1/3] Add a github action to test db migrations backwards-compatibility This action will test new schema with old unittests and thereby increases the likelyhood to notice incompatible changes where the old codes unittests would not run on the new schema. --- .github/workflows/migration_tests.yml | 88 +++++++++++++++++++++++++++ lib/tasks/spec.rake | 9 +++ 2 files changed, 97 insertions(+) create mode 100644 .github/workflows/migration_tests.yml diff --git a/.github/workflows/migration_tests.yml b/.github/workflows/migration_tests.yml new file mode 100644 index 00000000000..1a7a3ae92fc --- /dev/null +++ b/.github/workflows/migration_tests.yml @@ -0,0 +1,88 @@ +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 + 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: + - 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 + 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: + - 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:password@127.0.0.1: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:password@127.0.0.1:3306" bundle exec rake spec:no_recreate \ No newline at end of file diff --git a/lib/tasks/spec.rake b/lib/tasks/spec.rake index fe6ab34763d..e62ccc9031b 100644 --- a/lib/tasks/spec.rake +++ b/lib/tasks/spec.rake @@ -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 From b61e2ff3fb312fb85dd4b9d4bcb360d84fc36e22 Mon Sep 17 00:00:00 2001 From: Florian Braun <5863788+FloThinksPi@users.noreply.github.com> Date: Thu, 21 Dec 2023 13:44:02 +0100 Subject: [PATCH 2/3] Introduce a fixed 30min timeout on github actions This saves costs where someone ran a unittests that is in a endless loop. We dont expect for now to excede 30mins per test run. Its normally around 10-20 mins max. --- .github/workflows/docs_test.yml | 1 + .github/workflows/migration_tests.yml | 2 ++ .github/workflows/unit_tests.yml | 2 ++ 3 files changed, 5 insertions(+) diff --git a/.github/workflows/docs_test.yml b/.github/workflows/docs_test.yml index 252dcc7069c..3167d43368a 100644 --- a/.github/workflows/docs_test.yml +++ b/.github/workflows/docs_test.yml @@ -21,6 +21,7 @@ permissions: jobs: Test-Docs: runs-on: ubuntu-latest + timeout-minutes: 30 steps: - uses: actions/checkout@v4 - name: Prepare setup diff --git a/.github/workflows/migration_tests.yml b/.github/workflows/migration_tests.yml index 1a7a3ae92fc..27968bce522 100644 --- a/.github/workflows/migration_tests.yml +++ b/.github/workflows/migration_tests.yml @@ -22,6 +22,7 @@ permissions: jobs: Test-Postgres-Backwards-Compatibillity: runs-on: ubuntu-latest + timeout-minutes: 30 strategy: fail-fast: false max-parallel: 3 @@ -57,6 +58,7 @@ jobs: Test-Mysql-Backwards-Compatibillity: runs-on: ubuntu-latest + timeout-minutes: 30 strategy: fail-fast: false max-parallel: 3 diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 306e60af250..2dacb9c9d6d 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -38,6 +38,7 @@ jobs: Test-Postgres: runs-on: ubuntu-latest + timeout-minutes: 30 strategy: fail-fast: false matrix: @@ -69,6 +70,7 @@ jobs: Test-Mysql: runs-on: ubuntu-latest + timeout-minutes: 30 strategy: fail-fast: false matrix: From 2b33ce94b368f21d0189c1158778ddc2bc325e9b Mon Sep 17 00:00:00 2001 From: Florian Braun <5863788+FloThinksPi@users.noreply.github.com> Date: Thu, 21 Dec 2023 13:53:48 +0100 Subject: [PATCH 3/3] Introduce debug subaction to gather more data how a action is started --- .github/workflows/docs_test.yml | 1 + .github/workflows/migration_tests.yml | 2 ++ .github/workflows/unit_tests.yml | 3 +++ 3 files changed, 6 insertions(+) diff --git a/.github/workflows/docs_test.yml b/.github/workflows/docs_test.yml index 3167d43368a..5bc5f16a85b 100644 --- a/.github/workflows/docs_test.yml +++ b/.github/workflows/docs_test.yml @@ -23,6 +23,7 @@ jobs: 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 diff --git a/.github/workflows/migration_tests.yml b/.github/workflows/migration_tests.yml index 27968bce522..9e841bd2bb8 100644 --- a/.github/workflows/migration_tests.yml +++ b/.github/workflows/migration_tests.yml @@ -42,6 +42,7 @@ jobs: ports: - 5432:5432 steps: + - uses: hmarr/debug-action@v2 - name: Checkout code to run the db migration with uses: actions/checkout@v4 with: @@ -75,6 +76,7 @@ jobs: ports: - 3306:3306 steps: + - uses: hmarr/debug-action@v2 - name: Checkout code to run the db migration with uses: actions/checkout@v4 with: diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 2dacb9c9d6d..5cefdfe22a0 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -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 @@ -56,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 @@ -85,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