Warm tip: This article is reproduced from serverfault.com, please click

python-如何在Github操作中访问矩阵变量

(python - How to access matrix variables in Github actions)

发布于 2020-11-27 09:55:31

我已经设置了一个Github工作流来满足我的CI需求,并且matrix每当我使用matrix进行比较时,似乎都会以某种方式将分配给变量的值重置为空字符串

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

我已经指定runs-on: ${{ matrix.os }}失败了:

为作业“ run_tests”评估“运行”时出错。(行:12,列:14):意外值''

如果我指定的runs-on: ubuntu-20.04话就可以了。

完整的Github工作流程:(我已经设置了TOXENV环境变量,因此它可以并行地为每个tox环境运行一个新作业,并避免在每个作业(例如质量)上运行不必要的构建并降低作业速度)

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
Questioner
Aarif
Viewed
0
Krzysztof Madej 2020-11-30 10:18:50

问题与你的include部分有关。我不知道为什么,但是在这里你必须完全定义要添加其他配置的组合。此语法将起作用:

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 }}"