Reputation: 7809
I’m trying to setup GitHub actions for a Python package. I believe the most sane way to do so is what I’m used to from GitLab; run a set of commands inside of a docker image. I would like to use a matrix to test multiple Python versions.
So far I have defined the following workflow:
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
The result can be seen here: https://github.com/remcohaszing/pywakeonlan/actions/runs/87630190
This shows the following error:
The workflow is not valid. .github/workflows/pytest.yaml (Line: 17, Col: 16): Unrecognized named-value: 'python-version'. Located at position 1 within expression: python-version
How do I fix this workflow?
Upvotes: 4
Views: 2397
Reputation: 14776
A couple of points to try:
1) To use values from the matrix, you need to use ${{ matrix.python-version }}
. For more information, see the documentation for jobs.<job_id>.strategy.matrix
.
2) You do not necessarily need to use containers to test multiple versions. GitHub Actions supports this out of the box using language specific "setup" actions. For example, see the official setup-python action. Here is an example of how they do it:
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
Upvotes: 9