在 Docker 容器中的 GitHub 操作中运行多个语言版本的测试

Rem*_*ing 3 github-actions

I\xe2\x80\x99m 尝试为 Python 包设置 GitHub 操作。我相信最明智的方法是我在 GitLab 中使用的 xe2x80x99m ;在 docker 镜像内运行一组命令。我想用一个矩阵来测试多个Python版本。

\n\n

到目前为止,我已经定义了以下工作流程:

\n\n
name: Pytest\n\non:\n  - push\n  - pull_request\n\njobs:\n  pytest:\n    runs-on: ubuntu-latest\n    strategy:\n      matrix:\n        python-version:\n          - 3.5\n          - 3.6\n          - 3.7\n          - 3.8\n    container: python:${{ python-version }}-alpine\n    steps:\n      - uses: actions/checkout@v2\n      - name: Install\n        run: |\n          pip install poetry\n          poetry install\n      - name: PyTest\n        run: poetry run pytest\n
Run Code Online (Sandbox Code Playgroud)\n\n

结果可以在这里看到: https: //github.com/remcohaszing/pywakeonlan/actions/runs/87630190

\n\n

这显示以下错误:

\n\n
\n

工作流程无效。.github/workflows/pytest.yaml(行:17,列:16):无法识别的命名值:\'python-version\'。位于表达式中的位置 1:python-version

\n
\n\n

我该如何修复这个工作流程?

\n

Dan*_*nyB 8

有几点值得尝试:

1) 要使用矩阵中的值,您需要使用${{ matrix.python-version }}。有关更多信息,请参阅 的文档jobs.<job_id>.strategy.matrix

2)不一定需要使用容器来测试多个版本。GitHub Actions 使用特定于语言的“设置”操作来开箱即用地支持此操作。例如,请参阅官方setup-python操作。以下是他们如何做到这一点的示例:

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [ '2.x', '3.x', 'pypy2', 'pypy3' ]
    name: Python ${{ matrix.python-version }} sample
    steps:
      - uses: actions/checkout@v2
      - name: Setup python
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.python-version }}
          architecture: x64
      - run: python my_script.py
Run Code Online (Sandbox Code Playgroud)