Skip to content

Commit 21f218b

Browse files
committed
Shard integration tests by database with on-demand container setup in CI
1 parent 1e6183e commit 21f218b

3 files changed

Lines changed: 50 additions & 51 deletions

File tree

.github/workflows/ci.yml

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,16 @@ jobs:
223223
run: mix docs --warnings-as-errors
224224

225225
integration-test-elixir:
226-
name: integration test (OTP ${{matrix.otp}} | Elixir ${{matrix.elixir}})
226+
name: integration test (${{ matrix.service }} | OTP ${{ matrix.versions.otp }} | Elixir ${{ matrix.versions.elixir }})
227227

228228
runs-on: ubuntu-24.04
229-
timeout-minutes: 30
229+
timeout-minutes: 15
230230

231231
strategy:
232+
fail-fast: false
232233
matrix:
233-
include:
234+
service: [postgresql, mysql, mssql, none]
235+
versions:
234236
- elixir: "1.18.4"
235237
otp: "27.3.4.3"
236238

@@ -247,42 +249,6 @@ jobs:
247249
MIX_OS_DEPS_COMPILE_PARTITION_COUNT: 2
248250
MAKEFLAGS: "-j2"
249251

250-
services:
251-
postgres:
252-
image: postgres:18
253-
ports:
254-
- 5432:5432
255-
env:
256-
POSTGRES_PASSWORD: postgres
257-
options: >-
258-
--health-cmd "pg_isready -U postgres"
259-
--health-interval 2s
260-
--health-timeout 3s
261-
--health-retries 10
262-
mysql:
263-
image: mysql:26
264-
ports:
265-
- 3306:3306
266-
env:
267-
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
268-
options: >-
269-
--health-cmd "mysqladmin ping -h localhost"
270-
--health-interval 2s
271-
--health-timeout 3s
272-
--health-retries 10
273-
mssql:
274-
image: mcr.microsoft.com/mssql/server:2019-latest
275-
env:
276-
ACCEPT_EULA: Y
277-
SA_PASSWORD: some!Password
278-
ports:
279-
- 1433:1433
280-
options: >-
281-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P \"$SA_PASSWORD\" -C -Q 'SELECT 1' 2>/dev/null || /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P \"$SA_PASSWORD\" -Q 'SELECT 1' 2>/dev/null"
282-
--health-interval 2s
283-
--health-timeout 3s
284-
--health-retries 25
285-
286252
steps:
287253
- name: Checkout
288254
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -294,21 +260,26 @@ jobs:
294260
mkdir -p installer/tmp
295261
sudo mount -t tmpfs -o size=4G,uid=$(id -u),gid=$(id -g) tmpfs installer/tmp
296262
263+
- name: Start database container (${{ matrix.service }})
264+
if: matrix.service != 'none'
265+
run: |
266+
docker compose -f integration_test/docker-compose.yml up -d --wait ${{ matrix.service }}
267+
297268
- name: Set up Elixir
298269
uses: erlef/setup-beam@54075bcc5e249e4758d363f27d099f55d843f124 # v1.24.1
299270
with:
300-
elixir-version: ${{ matrix.elixir }}
301-
otp-version: ${{ matrix.otp }}
271+
elixir-version: ${{ matrix.versions.elixir }}
272+
otp-version: ${{ matrix.versions.otp }}
302273

303274
- name: Restore deps and _build cache
304275
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
305276
with:
306277
path: |
307278
integration_test/deps
308279
integration_test/_build
309-
key: integration-deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('integration_test/mix.lock') }}
280+
key: integration-deps-${{ runner.os }}-${{ matrix.versions.otp }}-${{ matrix.versions.elixir }}-${{ hashFiles('integration_test/mix.lock') }}
310281
restore-keys: |
311-
integration-deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}
282+
integration-deps-${{ runner.os }}-${{ matrix.versions.otp }}-${{ matrix.versions.elixir }}
312283
313284
- name: Fetch dependencies
314285
working-directory: integration_test
@@ -323,6 +294,12 @@ jobs:
323294
- name: Run integration tests
324295
working-directory: integration_test
325296
run: |
326-
mix test --include database \
297+
if [ "${{ matrix.service }}" = "none" ]; then
298+
FLAGS="--include database:sqlite3"
299+
else
300+
FLAGS="--include database:${{ matrix.service }} --only database:${{ matrix.service }}"
301+
fi
302+
303+
mix test $FLAGS \
327304
--formatter ExUnit.CLIFormatter \
328305
--formatter Phoenix.Integration.SummaryFormatter
Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
1-
version: '3'
21
services:
3-
postgres:
4-
image: postgres
2+
postgresql:
3+
image: postgres:18
54
ports:
65
- "5432:5432"
76
environment:
87
POSTGRES_PASSWORD: postgres
8+
tmpfs:
9+
- /var/lib/postgresql
10+
healthcheck:
11+
test: ["CMD-SHELL", "pg_isready -U postgres"]
12+
interval: 2s
13+
timeout: 3s
14+
retries: 10
15+
916
mysql:
10-
image: mysql
17+
image: mysql:26
1118
ports:
1219
- "3306:3306"
1320
environment:
1421
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
22+
tmpfs:
23+
- /var/lib/mysql
24+
healthcheck:
25+
test: ["CMD-SHELL", "mysqladmin ping -h localhost --silent"]
26+
interval: 2s
27+
timeout: 3s
28+
retries: 10
29+
1530
mssql:
1631
image: mcr.microsoft.com/mssql/server:2019-latest
1732
environment:
18-
ACCEPT_EULA: Y
19-
SA_PASSWORD: some!Password
33+
ACCEPT_EULA: "Y"
34+
SA_PASSWORD: "some!Password"
2035
ports:
2136
- "1433:1433"
37+
tmpfs:
38+
- /var/opt/mssql
39+
healthcheck:
40+
test: ["CMD-SHELL", "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P \"$$SA_PASSWORD\" -C -Q 'SELECT 1' 2>/dev/null || /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P \"$$SA_PASSWORD\" -Q 'SELECT 1' 2>/dev/null"]
41+
interval: 2s
42+
timeout: 3s
43+
retries: 25

integration_test/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mix local.hex --force
77
apk add --no-progress --update git socat make gcc libc-dev cmake g++
88

99
# Set up local proxies
10-
socat TCP-LISTEN:5432,fork TCP-CONNECT:postgres:5432&
10+
socat TCP-LISTEN:5432,fork TCP-CONNECT:postgresql:5432&
1111
socat TCP-LISTEN:3306,fork TCP-CONNECT:mysql:3306&
1212
socat TCP-LISTEN:1433,fork TCP-CONNECT:mssql:1433&
1313

0 commit comments

Comments
 (0)