Calmcode - github actions: matrix

Many Checks via GitHub Actions

1 2 3 4 5 6

Let's configure our file to also check if the code runs for multiple versions of Python. We can do that by setting up a matrix in our .yml file.

name: Python Unit

on:
  pull_request:
    branches:
    - main

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.7', '3.8', '3.9', '3.10']

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install -r requirements.txt
        python -m pip install -r dev-requirements.txt
    - name: Test with pytest
      run: |
        pytest --verbose

When you go to GitHub you should now see multiple versions running.

Larger Grids

We could go even further and also test for different operating systems. The .yml below also checks for the operating systems.

name: Python Unit

on:
  pull_request:
    branches:
    - main

jobs:
  build:
    strategy:
      matrix:
        python-version: ['3.7', '3.8', '3.9', '3.10']
        os: [ubuntu-latest, windows-latest]
    runs-on: ${{ matrix.os }}

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install -r requirements.txt
        python -m pip install -r dev-requirements.txt
    - name: Test with pytest
      run: |
        pytest --verbose

Branch Protection Rules

When you use the matrix, you'll notice that the protected branch rules need to be reconfigured to also account for the new variables.