til: github-actions_different-postgresql-versions.md
This data as json
| path | topic | title | url | body | html | shot | created | created_utc | updated | updated_utc | shot_hash | slug |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| github-actions_different-postgresql-versions.md | github-actions | Installing different PostgreSQL server versions in GitHub Actions | https://github.com/simonw/til/blob/main/github-actions/different-postgresql-versions.md | 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: ``` $ /usr/lib/postgresql/13/bin/postgres --version postgres (PostgreSQL) 13.3 (Ubuntu 13.3-1.pgdg20.04+1) ``` You can install alternative PostgreSQL versions by following the [PostgreSQL Ubuntu instructions](https://www.postgresql.org/download/linux/ubuntu/) - like this: ``` sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get -y install postgresql-12 ``` This 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](https://github.com/simonw/django-sql-dashboard/blob/1.0.1/.github/workflows/test.yml) - the relevant sections are below: ```yaml name: Test on: [push] jobs: test: runs-on: ubuntu-latest strategy: matrix: postgresql-version: [10, 11, 12, 13] steps: - name: Install PostgreSQL env: POSTGRESQL_VERSION: ${{ matrix.postgresql-version }} run: | sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get -y install "postgresql-$POSTGRESQL_VERSION" - name: Run tests env: POSTGRESQL_VERSION: ${{ matrix.postgresql-version }} run: | export POSTGRESQL_PATH="/usr/lib/postgresql/$POSTGRESQL_VERSION/bin/postgres" export INITDB_PATH="/usr/lib/postgresql/$POSTGRESQL_VERSION/bin/initdb" pytest ``` I modified my tests to call the `postgres` and `initdb` binaries specified by the `POSTGRESQL_PATH` and `INITDB_PATH` environment variables. | <p>The GitHub Actions <code>ubuntu-latest</code> default runner currently includes an installation of PostgreSQL 13. The server is not running by default but you can interact with it like this:</p> <pre><code>$ /usr/lib/postgresql/13/bin/postgres --version postgres (PostgreSQL) 13.3 (Ubuntu 13.3-1.pgdg20.04+1) </code></pre> <p>You can install alternative PostgreSQL versions by following the <a href="https://www.postgresql.org/download/linux/ubuntu/" rel="nofollow">PostgreSQL Ubuntu instructions</a> - like this:</p> <pre><code>sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get -y install postgresql-12 </code></pre> <p>This works with <code>postgresql-10</code> and <code>postgresql-11</code> as well as <code>postgresql-12</code>.</p> <p>I wanted to use a GitHub Actions matrix to run my tests against all four versions of PostgreSQL. Here's <a href="https://github.com/simonw/django-sql-dashboard/blob/1.0.1/.github/workflows/test.yml">my complete workflow</a> - the relevant sections are below:</p> <div class="highlight highlight-source-yaml"><pre><span class="pl-ent">name</span>: <span class="pl-s">Test</span> <span class="pl-ent">on</span>: <span class="pl-s">[push]</span> <span class="pl-ent">jobs</span>: <span class="pl-ent">test</span>: <span class="pl-ent">runs-on</span>: <span class="pl-s">ubuntu-latest</span> <span class="pl-ent">strategy</span>: <span class="pl-ent">matrix</span>: <span class="pl-ent">postgresql-version</span>: <span class="pl-s">[10, 11, 12, 13]</span> <span class="pl-ent">steps</span>: - <span class="pl-ent">name</span>: <span class="pl-s">Install PostgreSQL</span> <span class="pl-ent">env</span>: <span class="pl-ent">POSTGRESQL_VERSION</span>: <span class="pl-s">${{ matrix.postgresql-version }}</span> <span class="pl-ent">run</span>: <span class="pl-s">|</span> <span class="pl-s"> sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'</span> <span class="pl-s"> wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -</span> <span class="pl-s"> sudo apt-get update</span> <span class="pl-s"> sudo apt-get -y install "postgresql-$POSTGRESQL_VERSION"</span> <span class="pl-s"></span> - <span class="pl-ent">name</span>: <span class="pl-s">Run tests</span> <span class="pl-ent">env</span>: <span class="pl-ent">POSTGRESQL_VERSION</span>: <span class="pl-s">${{ matrix.postgresql-version }}</span> <span class="pl-ent">run</span>: <span class="pl-s">|</span> <span class="pl-s"> export POSTGRESQL_PATH="/usr/lib/postgresql/$POSTGRESQL_VERSION/bin/postgres"</span> <span class="pl-s"> export INITDB_PATH="/usr/lib/postgresql/$POSTGRESQL_VERSION/bin/initdb"</span> <span class="pl-s"> pytest</span></pre></div> <p>I modified my tests to call the <code>postgres</code> and <code>initdb</code> binaries specified by the <code>POSTGRESQL_PATH</code> and <code>INITDB_PATH</code> environment variables.</p> | <Binary: 76,896 bytes> | 2021-07-05T17:43:13-07:00 | 2021-07-06T00:43:13+00:00 | 2021-07-05T17:43:13-07:00 | 2021-07-06T00:43:13+00:00 | 2001828a598aa0775483b5934c907bb8 | different-postgresql-versions |