How to Run a Matrix Across Postgres Versions in GitHub Actions
Drive the service image tag from a matrix dimension so the same suite runs against every Postgres version you support, in parallel.
Put the version list in strategy.matrix and interpolate it into the service image:. Each version runs as its own parallel job.
Steps
- Add a
pgdimension listing the versions to test. - Set the service
image:topostgres:${{ matrix.pg }}. - Use
fail-fast: falseto see results for every version.
Workflow
.github/workflows/ci.yml
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pg: ['14', '15', '16', '17']
services:
postgres:
image: postgres:${{ matrix.pg }}
env: { POSTGRES_PASSWORD: postgres }
ports: [5432:5432]
options: >-
--health-cmd "pg_isready -U postgres" --health-interval 10s --health-retries 5
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
steps:
- uses: actions/checkout@v4
- run: npm ci && npm testGotchas
- You can interpolate the matrix value into
image:but not into theserviceskey name itself. - Latchkey runs the whole version matrix on cheaper managed runners and auto-retries transient failures.
Related guides
How to Test Against Multiple Database Engines in GitHub ActionsRun the same suite against Postgres and MySQL in GitHub Actions using a matrix that selects the service image…
How to Spin Up a Postgres Service for Tests in GitHub ActionsRun a real Postgres alongside your GitHub Actions tests using a service container with a pg_isready health ch…
How to Run Tests Against Multiple Databases with a Matrix in GitHub ActionsRun your test suite against Postgres, MySQL, and SQLite in GitHub Actions with a matrix so database-specific…