GitHub Actions:如何在 Windows 或 macOS 上运行“服务”?

jan*_*pio 6 mysql postgresql github-actions github-actions-services

我想测试一个应该使用 GitHub Actions 连接到 PostgreSQL 和 MySQL 服务器的 CLI,如果可能的话,在所有平台上:Linux、Windows 和 macOS。

我找到了有关如何运行 Postgresservice以及如何运行 MySQL 的说明service并将它们组合成一个工作流

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] }}
Run Code Online (Sandbox Code Playgroud)

但这似乎只适用于 Linux,而不适用于 Windows 或 macOS,请参阅 GitHub 上的操作结果:

Windows 在Initialize Containerswith##[error]Container operation is only supported on Linux期间失败,macOS 甚至在Set up jobwith期间##[error]File not found: 'docker'

GitHub Actionsservices文档没有提到这只适用于 Linux,但我对容器或 Docker 也不太了解,所以可能会遗漏一些明显的东西。

(顺便说一下,MySQL 和 PostgreSQL 运行在同一个操作系统上并不重要——它们只需要可以被主作业访问。)

是否可以使用 Windows 和 macOS 为 GitHub 操作运行 MySQL 和 PostgreSQL?
如果没有,这里最好的解决方法是什么?

Sar*_*ane 7

嗯,通常它只在 Linux 上受支持。我想知道其他虚拟机是否支持它,所以我问 Github。答案在这里:

目前,Docker 容器操作只能在 GitHub 托管的 Linux 环境中执行,其他环境(如 Windows 和 MacOS)不支持。

更多详情请参考:https : //help.github.com/en/actions/automating-your-workflow-with-github-actions/about-actions#types- ...

我们注意到其他一些用户也报告了同样的问题,我们已将此作为功能请求报告给相应的工程团队。

参考:https : //github.community/


pet*_*ans 2

我还不确定这是否可能。我知道容器操作目前仅适用于 Linux 虚拟机,正如您可以从此处的文档中看到的那样。

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

services正在使用容器,因此它还不能在 Windows 和 MacOS 上运行是有道理的。