I want to test a CLI that should connect to PostgreSQL and MySQL servers using GitHub Actions, on all platforms if possible: Linux, Windows and macOS.
I found instructions on how to run a Postgres service
and how to run a MySQL service
and combined these into a workflow:
name: Test
on: [push]
jobs:
init_flow:
name: 'Run MySQL and Postgres on ${{ matrix.os }}'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
# via https://github.com/actions/example-services/blob/master/.github/workflows/postgres-service.yml
services:
postgres:
image: postgres:10.8
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
# will assign a random free host port
- 5432/tcp
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/checkout@v1
- run: node -v
env:
# use localhost for the host here because we are running the job on the VM.
# If we were running the job on in a container this would be postgres
POSTGRES_HOST: localhost
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
But this only seems to work on Linux, not Windows or macOS, see the results of the action on GitHub:
Windows fails during Initialize Containers
with ##[error]Container operation is only supported on Linux
, macOS even during Set up job
with ##[error]File not found: 'docker'
.
GitHub Actions services
docs do not mention that this will only work on Linux, but I also do not know much about containers or Docker so might be missing something obvious.
(It is not important that MySQL and PostgreSQL run on the same operating system by the way - they only have to be accessible by the main job.)
Is it possible to run MySQL and PostgreSQL for GitHub Actions using Windows and macOS?
If not, what is the best workaround here?
An alternative workaround is to use an external database of course.
A simple way to do this might be the free tiers of Heroku's offering:
They all give you tiny space and limits, but in my case this will probably be enough for now.