Skip to content

Commit

Permalink
chore: refactor elixir ci tests (#1949)
Browse files Browse the repository at this point in the history
Update caching strategy for the elixir apps to speed up CI runs.

Also use a matrix for tests against different PG versions.
  • Loading branch information
magnetised authored Nov 7, 2024
1 parent 90ead4f commit 595c905
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 114 deletions.
59 changes: 43 additions & 16 deletions .github/workflows/elixir_client_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,56 @@ jobs:
run: |
docker exec ${{ job.services.postgres.id }} sh -c 'echo "wal_level=logical" >> /var/lib/postgresql/data/postgresql.conf'
docker restart ${{ job.services.postgres.id }}
- uses: erlef/setup-beam@v1
with:
version-type: strict
version-file: ".tool-versions"

- name: Restore dependencies cache
- name: Cache elixir-client dependencies
uses: actions/cache@v4
with:
path: packages/elixir-client/deps
key: ${{ runner.os }}-mix-${{ hashFiles('packages/elixir-client/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
key: ${{ runner.os }}-elixir-client-deps-${{ hashFiles('packages/elixir-client/mix.lock') }}
restore-keys: |
${{ runner.os }}-elixir-client-deps-${{ hashFiles('packages/elixir-client/mix.lock') }}
${{ runner.os }}-elixir-client-deps-
- name: Restore compiled code
uses: actions/cache/restore@v4
- name: Cache elixir-client compiled code
uses: actions/cache@v4
with:
path: |
packages/elixir-client/_build/*/lib
!packages/elixir-client/_build/*/lib/electric
key: ${{ runner.os }}-build-test-${{ hashFiles('packages/elixir-client/mix.lock') }}
!packages/elixir-client/_build/*/lib/electric_client
key: "${{ runner.os }}-elixir-client-build-[${{ github.ref_name }}]-${{ github.sha }}"
restore-keys: |
${{ runner.os }}-elixir-client-build-[${{ github.ref_name }}]-${{ github.sha }}
${{ runner.os }}-elixir-client-build-[${{ github.ref_name }}]-
${{ runner.os }}-elixir-client-build-
- name: Install dependencies
run: mix deps.get && mix deps.compile
- name: Cache sync-service dependencies
uses: actions/cache@v4
with:
path: packages/sync-service/deps
key: "${{ runner.os }}-sync-service-deps-${{ hashFiles('packages/sync-service/mix.lock') }}"
restore-keys: |
${{ runner.os }}-sync-service-deps-${{ hashFiles('packages/sync-service/mix.lock') }}
${{ runner.os }}-sync-service-deps-
- name: Save compiled code
uses: actions/cache/save@v4
- name: Cache sync-service compiled code
uses: actions/cache@v4
with:
path: |
packages/elixir-client/_build/*/lib
!packages/elixir-client/_build/*/lib/electric
key: ${{ runner.os }}-build-test-${{ hashFiles('packages/elixir-client/mix.lock') }}
packages/sync-service/_build/*/lib
!packages/sync-service/_build/*/lib/electric
key: "${{ runner.os }}-sync-service-build-[${{ github.ref_name }}]-${{ github.sha }}"
restore-keys: |
${{ runner.os }}-sync-service-build-[${{ github.ref_name }}]-${{ github.sha }}
${{ runner.os }}-sync-service-build-[${{ github.ref_name }}]-
${{ runner.os }}-sync-service-build-
- name: Install dependencies
run: mix deps.get && mix deps.compile

- name: Compiles without warnings
run: mix compile --force --all-warnings --warnings-as-errors
Expand Down Expand Up @@ -109,15 +129,22 @@ jobs:
working-directory: packages/elixir-client
steps:
- uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
with:
version-type: strict
version-file: ".tool-versions"

- name: Cache dependencies
id: cache-deps
uses: actions/cache@v4
uses: actions/cache/restore@v4
with:
path: packages/elixir-client/deps
key: ${{ runner.os }}-mix-${{ hashFiles('packages/elixir-client/mix.lock') }}
key: ${{ runner.os }}-elixir-client-deps-${{ hashFiles('packages/elixir-client/mix.lock') }}
restore-keys: |
${{ runner.os }}-elixir-client-deps-${{ hashFiles('packages/elixir-client/mix.lock') }}
${{ runner.os }}-elixir-client-deps-
- run: mix deps.get

- run: mix format --check-formatted
117 changes: 38 additions & 79 deletions .github/workflows/elixir_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ permissions:
contents: read

jobs:
build:
name: Build and test with PostgreSQL 14
build_and_test:
name: "Build and test, Postgres ${{ matrix.postgres_version }}"
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/sync-service
strategy:
matrix:
postgres_version: [14, 15]
env:
MIX_ENV: test
POSTGRES_VERSION: 140006
POSTGRES_VERSION: "${{ matrix.postgres_version }}0000"
services:
postgres:
image: postgres:14-alpine
image: "postgres:${{ matrix.postgres_version }}-alpine"
env:
POSTGRES_PASSWORD: password
options: >-
Expand All @@ -38,97 +41,47 @@ jobs:
- 54321:5432
steps:
- uses: actions/checkout@v4

- name: "Set PG settings"
run: |
docker exec ${{ job.services.postgres.id }} sh -c 'echo "wal_level=logical" >> /var/lib/postgresql/data/postgresql.conf'
docker restart ${{ job.services.postgres.id }}
- uses: erlef/setup-beam@v1
with:
version-type: strict
version-file: ".tool-versions"
- name: Restore dependencies cache
uses: actions/cache@v3

- name: Cache dependencies
uses: actions/cache@v4
with:
path: packages/sync-service/deps
key: ${{ runner.os }}-mix-${{ hashFiles('packages/sync-service/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Restore compiled code
uses: actions/cache/restore@v4
key: "${{ runner.os }}-sync-service-deps-${{ hashFiles('packages/sync-service/mix.lock') }}"
restore-keys: |
${{ runner.os }}-sync-service-deps-${{ hashFiles('packages/sync-service/mix.lock') }}
${{ runner.os }}-sync-service-deps-
- name: Cache compiled code
uses: actions/cache@v4
with:
path: |
packages/sync-service/_build/*/lib
!packages/sync-service/_build/*/lib/electric
key: ${{ runner.os }}-build-test-${{ hashFiles('packages/sync-service/mix.lock') }}
key: "${{ runner.os }}-sync-service-build-[${{ github.ref_name }}]-${{ github.sha }}"
restore-keys: |
${{ runner.os }}-sync-service-build-[${{ github.ref_name }}]-${{ github.sha }}
${{ runner.os }}-sync-service-build-[${{ github.ref_name }}]-
${{ runner.os }}-sync-service-build-
- name: Install dependencies
run: mix deps.get && mix deps.compile
- name: Save compiled code
uses: actions/cache/save@v4
with:
path: |
packages/sync-service/_build/*/lib
!packages/sync-service/_build/*/lib/electric
key: ${{ runner.os }}-build-test-${{ hashFiles('packages/sync-service/mix.lock') }}

- name: Compiles without warnings
run: mix compile --force --all-warnings --warnings-as-errors

- name: Run tests
run: mix test
test_pg_15:
name: Build and test with PostgreSQL 15
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/sync-service
env:
MIX_ENV: test
POSTGRES_VERSION: 150001
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_PASSWORD: password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 54321:5432
steps:
- uses: actions/checkout@v4
- name: "Set PG settings"
run: |
docker exec ${{ job.services.postgres.id }} sh -c 'echo "wal_level=logical" >> /var/lib/postgresql/data/postgresql.conf'
docker restart ${{ job.services.postgres.id }}
- uses: erlef/setup-beam@v1
with:
version-type: strict
version-file: ".tool-versions"
- name: Restore dependencies cache
uses: actions/cache@v3
with:
path: packages/sync-service/deps
key: ${{ runner.os }}-mix-${{ hashFiles('packages/sync-service/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Restore compiled code
uses: actions/cache/restore@v4
with:
path: |
packages/sync-service/_build/*/lib
!packages/sync-service/_build/*/lib/electric
key: ${{ runner.os }}-build-test-${{ hashFiles('packages/sync-service/mix.lock') }}
- name: Install dependencies
run: mix deps.get && mix deps.compile
- name: Save compiled code
uses: actions/cache/save@v4
with:
path: |
packages/sync-service/_build/*/lib
!packages/sync-service/_build/*/lib/electric
key: ${{ runner.os }}-build-test-${{ hashFiles('packages/sync-service/mix.lock') }}
- name: Compiles without warnings
run: mix compile --force --all-warnings --warnings-as-errors
- name: Run tests
run: mix test test/electric/postgres/configuration_test.exs

formatting:
name: Check formatting
runs-on: ubuntu-latest
Expand All @@ -137,15 +90,21 @@ jobs:
working-directory: packages/sync-service
steps:
- uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
with:
version-type: strict
version-file: ".tool-versions"
- name: Cache dependencies
id: cache-deps
uses: actions/cache@v4

- name: Restore dependencies cache
uses: actions/cache/restore@v4
with:
path: packages/sync-service/deps
key: ${{ runner.os }}-mixdeps-${{ hashFiles('packages/sync-service/mix.lock') }}
key: "${{ runner.os }}-sync-service-deps-${{ hashFiles('packages/sync-service/mix.lock') }}"
restore-keys: |
${{ runner.os }}-sync-service-deps-${{ hashFiles('packages/sync-service/mix.lock') }}
${{ runner.os }}-sync-service-deps-
- run: mix deps.get

- run: mix format --check-formatted
34 changes: 20 additions & 14 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,43 @@ jobs:
working-directory: integration-tests
steps:
- uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
with:
version-type: strict
version-file: ".tool-versions"
- name: Restore dependencies cache
uses: actions/cache@v3

- name: Cache dependencies
uses: actions/cache@v4
with:
path: packages/sync-service/deps
key: ${{ runner.os }}-mix-${{ hashFiles('packages/sync-service/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Restore compiled code
uses: actions/cache/restore@v4
key: "${{ runner.os }}-sync-service-deps-${{ hashFiles('packages/sync-service/mix.lock') }}"
restore-keys: |
${{ runner.os }}-sync-service-deps-${{ hashFiles('packages/sync-service/mix.lock') }}
${{ runner.os }}-sync-service-deps-
- name: Cache compiled code
uses: actions/cache@v4
with:
path: |
packages/sync-service/_build/*/lib
!packages/sync-service/_build/*/lib/electric
key: ${{ runner.os }}-build-test-${{ hashFiles('packages/sync-service/mix.lock') }}
key: "${{ runner.os }}-sync-service-build-[${{ github.ref_name }}]-${{ github.sha }}"
restore-keys: |
${{ runner.os }}-sync-service-build-[${{ github.ref_name }}]-${{ github.sha }}
${{ runner.os }}-sync-service-build-[${{ github.ref_name }}]-
${{ runner.os }}-sync-service-build-
- name: Install dependencies
run: mix deps.get && mix deps.compile
working-directory: packages/sync-service
- name: Save compiled code
uses: actions/cache/save@v4
with:
path: |
packages/sync-service/_build/*/lib
!packages/sync-service/_build/*/lib/electric
key: ${{ runner.os }}-build-test-${{ hashFiles('packages/sync-service/mix.lock') }}

- name: Compile
run: mix compile --force --all-warnings --warnings-as-errors
working-directory: packages/sync-service

- name: Setup lux
run: make

- name: Run integration tests
run: ./run.sh
19 changes: 14 additions & 5 deletions .github/workflows/ts_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,28 @@ jobs:
node-version: 20
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Restore dependencies cache

- name: Cache dependencies
uses: actions/cache@v4
with:
path: packages/sync-service/deps
key: ${{ runner.os }}-mix-${{ hashFiles('packages/sync-service/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Restore compiled code
key: "${{ runner.os }}-sync-service-deps-${{ hashFiles('packages/sync-service/mix.lock') }}"
restore-keys: |
${{ runner.os }}-sync-service-deps-${{ hashFiles('packages/sync-service/mix.lock') }}
${{ runner.os }}-sync-service-deps-
- name: Cache compiled code
uses: actions/cache@v4
with:
path: |
packages/sync-service/_build/*/lib
!packages/sync-service/_build/*/lib/electric
key: ${{ runner.os }}-build-dev-${{ hashFiles('packages/sync-service/mix.lock') }}
key: "${{ runner.os }}-sync-service-build-[${{ github.ref_name }}]-${{ github.sha }}"
restore-keys: |
${{ runner.os }}-sync-service-build-[${{ github.ref_name }}]-${{ github.sha }}
${{ runner.os }}-sync-service-build-[${{ github.ref_name }}]-
${{ runner.os }}-sync-service-build-
- name: Install dependencies
run: mix deps.get && mix deps.compile
working-directory: packages/sync-service
Expand Down

0 comments on commit 595c905

Please sign in to comment.