How to Run a Job on Multiple Python Versions in GitHub Actions
A version matrix fans one job out into one parallel run per Python interpreter.
List the versions under strategy.matrix, then pass matrix.python-version to actions/setup-python. Each value becomes its own job.
Steps
- Declare a
python-versionmatrix array. - Feed
matrix.python-versiontoactions/setup-python. - Optionally set
fail-fast: falseto keep other versions running when one fails.
Workflow
.github/workflows/test.yml
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- run: pip install -e '.[test]' && pytestGotchas
- Use quotes around versions so 3.10 is not parsed as the number 3.1.
- Pin a single version for the deploy job; a matrix is for testing.
Related guides
How to Set Up a Matrix of Operating Systems in GitHub ActionsTest on Linux, macOS, and Windows at once in GitHub Actions with an os matrix that drives runs-on, catching p…
How to Use a Matrix Build in GitHub ActionsUse a build matrix in GitHub Actions to run one job across many versions in parallel with strategy.matrix, fa…