I\xe2\x80\x99m 尝试为 Python 包设置 GitHub 操作。我相信最明智的方法是我在 GitLab 中使用的 xe2x80x99m ;在 docker 镜像内运行一组命令。我想用一个矩阵来测试多个Python版本。
\n\n到目前为止,我已经定义了以下工作流程:
\n\nname: 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\nRun Code Online (Sandbox Code Playgroud)\n\n结果可以在这里看到: https: //github.com/remcohaszing/pywakeonlan/actions/runs/87630190
\n\n这显示以下错误:
\n\n\n\n\n工作流程无效。.github/workflows/pytest.yaml(行:17,列:16):无法识别的命名值:\'python-version\'。位于表达式中的位置 1:python-version
\n
我该如何修复这个工作流程?
\n有几点值得尝试:
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)
| 归档时间: |
|
| 查看次数: |
1967 次 |
| 最近记录: |