【问题标题】:Run tests for multiple language versions in GitHub actions in a Docker container在 Docker 容器中的 GitHub 操作中运行多种语言版本的测试
【发布时间】:2020-08-09 04:18:54
【问题描述】:

我正在尝试为 Python 包设置 GitHub 操作。我相信最明智的做法是我习惯于 GitLab 的做法。在 docker 镜像中运行一组命令。我想用一个矩阵来测试多个 Python 版本。

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

name: Pytest

on:
  - push
  - pull_request

jobs:
  pytest:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version:
          - 3.5
          - 3.6
          - 3.7
          - 3.8
    container: python:${{ python-version }}-alpine
    steps:
      - uses: actions/checkout@v2
      - name: Install
        run: |
          pip install poetry
          poetry install
      - name: PyTest
        run: poetry run pytest

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

这显示以下错误:

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

如何解决此工作流程?

【问题讨论】:

    标签: github-actions


    【解决方案1】:

    有几点可以尝试:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-01
      • 2020-04-22
      • 2023-03-27
      • 2018-09-21
      • 2021-06-23
      • 2020-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多