Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

  • Linux ✔
  • Windows ❌
  • macOS ❌

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?

like image 380
janpio Avatar asked Oct 13 '19 09:10

janpio


People also ask

Where do I run actions in GitHub?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Actions. In the left sidebar, click the workflow you want to run. Above the list of workflow runs, select Run workflow.

Do GitHub Actions run locally?

github/workflows/ files (or for any changes to embedded GitHub actions), you can use act to run the actions locally. The environment variables and filesystem are all configured to match what GitHub provides. Local Task Runner - I love make.

What user do GitHub Actions run as?

/github/workspace - Note: GitHub Actions must be run by the default Docker user (root).


2 Answers

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/

like image 163
Sarah Abderemane Avatar answered Oct 02 '22 00:10

Sarah Abderemane


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.

like image 26
peterevans Avatar answered Oct 02 '22 01:10

peterevans