3

I've set up a Github workflow for my CI needs, and it seems to somehow reset values assigned to matrix variables to an empty string whenever I do a comparison using matrix values e.g

if: matrix.python-version == '3.8' && matrix.toxenv=='quality'

and I've specified runs-on: ${{ matrix.os }} it fails saying:

Error when evaluating 'runs-on' for job 'run_tests'. (Line: 12, Col: 14): Unexpected value ''

if I specify runs-on: ubuntu-20.04 it works just fine.

complete Github workflow: (I've setup TOXENV environment variables so it runs a new job for each tox environment in parallel, and to avoid unnecessary builds running with every job (e.g quality) and slowing down the jobs)

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

jobs:
  run_tests:
    name: Tests
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-20.04]
        python-version: ['3.5', '3.8', '3.9']
        toxenv: ['django22', 'django30','django31']
        include:
          - python-version: "3.8"
            toxenv: "quality"
        exclude:
          - python-version: "3.5"
            toxenv: "django30"
          - python-version: "3.5"
            toxenv: "django31"

    steps:
    - uses: actions/checkout@v2
    - name: setup python
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install pip
      run: pip install -r requirements/pip.txt

    - name: Install Dependencies
      run: pip install -r requirements/ci.txt

    - name: Run Tests
      env:
        TOXENV: python${{ matrix.python-version }}-${{ matrix.toxenv }}
      run: tox

    # it'll run a separate job for quality checks with python 3.8
    - name: Run Quality
      if: matrix.python-version == '3.8' && matrix.toxenv=='quality'
      env:
        TOXENV: ${{ matrix.toxenv }}
      run: tox

    - name: Run Coverage
      if: matrix.python-version == '3.8' && matrix.toxenv=='django22'
      uses: codecov/codecov-action@v1
      with:
        flags: unittests
        fail_ci_if_error: true

1 Answer 1

5

The issue is related to your include section. I don't know why but here you must define fully for which combination you want to add another configuration. This syntax would work:

jobs:
  run_tests:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-20.04]
        python-version: ['3.5', '3.8', '3.9']
        toxenv: ['django22', 'django30','django31']
        include:
          - python-version: '3.8'
            toxenv: 'quality'
            os: [ubuntu-20.04]
        exclude:
          - python-version: '3.5'
            toxenv: 'django30'
          - python-version: '3.5'
            toxenv: 'django31'
    steps:
    - name: Get color
      run: echo "${{ matrix.os }} - ${{ matrix.python-version }} - ${{ matrix.toxenv }}"
Sign up to request clarification or add additional context in comments.

3 Comments

so any configuration we add in include section should contain all the key/values otherwise it would be set to an empty string for which we didn't mention any value?
just tested this, it works! thank you, and the assumption I made above is right we've to specify all the key/values for matrix in include section that we would normally specify.
Yeah, I found it too. Is strange but it works :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.