GitHub Actions: How to run `services` on Windows or macOS?

5k views Asked by At

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?

4

There are 4 answers

0
janpio On

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.

3
peterevans On

I'm not sure that it's possible yet. I know that container actions only work on Linux virtual machines at the moment, as you can see from the documentation here.

https://help.github.com/en/articles/about-actions#types-of-actions

services are using containers, so it would make sense that it doesn't work on Windows and MacOS yet.

0
janpio On

For MySQL, I found a (temporary[1]) workaround:

Per Software in virtual environments for GitHub Actions I learned that all operating systems currently have a local installation of MySQL 5.7 running on port 3306 with credentials root:root. You can use this MySQL instance in your jobs.

Unfortunately for me PostgreSQL is not installed.

[1] I recall reading a product manager of GitHub Actions telling people that the installed software might change and especially the databases might go away soon unfortunately (can't recall or find the link though, somewhere in GitHub Community, GitHub Actions)

Turns out the MySQL credentials root:root also only work on Linux, I could not find working ones for Windows and macOS.

0
Sarah Abderemane On

Well, normally it's supported only on Linux. I was wondering if it would be supported in other VMs, so I ask Github. Here the answer :

Currently, Docker container actions can only execute in the GitHub-hosted Linux environment, and is not supported on other environments (such as Windows and MacOS).

More details please reference here: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/about-actions#types-...

We notice that some other users also had reported the same question, we had reported this as a feature request to the appropriate engineering team.

Ref: https://github.community/