我想测试一个CLI,它应该使用GitHub Actions连接到PostgreSQL和MySQL服务器,并在所有平台上进行测试:Linux、Windows和macOS。
我在如何运行Postgres service
和 如何运行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] }}
但这似乎只在Linux上有效,而在Windows或macOS上并不起作用,请参见GitHub上的操作结果:Windows在执行“Initialize Containers”时失败,并显示“##[error]Container operation is only supported on Linux”,而macOS在执行“Set up job”时失败,并显示“##[error]File not found: 'docker'”。GitHub Actions的服务文档没有提到这只能在Linux上运行,但我也不太了解容器或Docker,可能会遗漏一些显而易见的东西。(顺便说一句,MySQL和PostgreSQL不必在同一操作系统上运行-它们只需可被主任务访问即可。)
是否有可能使用Windows和macOS在GitHub Actions中运行MySQL和PostgreSQL?如果不能,最佳解决方法是什么?