Skip to content
Advertisement

How do you add an unstable version of Python in a GitHub Actions test matrix?

I want to update my GitHub Actions workflow to reflect the availability of Python 3.11.

This is the list of available Python versions, which include:

  • “3.11.0-beta.3”
  • “3.11.0-beta.2”

This is the test matrix:

name: Python package

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.8", "3.9", "3.10"]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install flake8 pytest
        pip install -r requirements.txt
    - name: Lint with flake8
      run: |
        # stop the build if there are Python syntax errors or undefined names
        flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
        # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
        flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
    - name: Test with pytest
      run: |
        python -m pytest tests --timesensitive


How do I add the latest Python release?

This doesn’t work:

      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11"] 

Error:

Run actions/setup-python@v2
  with:
    python-version: 3.11
    token: ***
Version 3.11 was not found in the local cache
Error: Version 3.11 with arch x64 not found
The list of all available versions can be found here: https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json

Advertisement

Answer

The error was using 3.11 without further specification as 3.11 doesn’t exist.

This solves the issue:

      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11.0-beta.3"] 
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement