Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Installing different PostgreSQL server versions in GitHub Actions#
The GitHub Actions ubuntu-latest default runner currently includes an installation of PostgreSQL 13. The server is not running by default but you can interact with it like this:
1$ /usr/lib/postgresql/13/bin/postgres --version2postgres (PostgreSQL) 13.3 (Ubuntu 13.3-1.pgdg20.04+1)You can install alternative PostgreSQL versions by following the PostgreSQL Ubuntu instructions - like this:
1sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'2wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -3sudo apt-get update4sudo apt-get -y install postgresql-12This works with postgresql-10 and postgresql-11 as well as postgresql-12.
I wanted to use a GitHub Actions matrix to run my tests against all four versions of PostgreSQL. Here’s my complete workflow - the relevant sections are below:
1name: Test2
3on: [push]4
5jobs:6 test:7 runs-on: ubuntu-latest8 strategy:9 matrix:10 postgresql-version: [10, 11, 12, 13]11 steps:12 - name: Install PostgreSQL13 env:14 POSTGRESQL_VERSION: ${{ matrix.postgresql-version }}15 run: |16 sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'17 wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -18 sudo apt-get update19 sudo apt-get -y install "postgresql-$POSTGRESQL_VERSION"20 - name: Run tests21 env:22 POSTGRESQL_VERSION: ${{ matrix.postgresql-version }}23 run: |24 export POSTGRESQL_PATH="/usr/lib/postgresql/$POSTGRESQL_VERSION/bin/postgres"25 export INITDB_PATH="/usr/lib/postgresql/$POSTGRESQL_VERSION/bin/initdb"26 pytestI modified my tests to call the postgres and initdb binaries specified by the POSTGRESQL_PATH and INITDB_PATH environment variables.