I have a github actions workflow like this:
name: Print test type
on: [push]
jobs:
build:
strategy:
fail-fast: false
matrix:
test_type: ['test-alpha', 'test-beta']
os: [ubuntu-latest]
python-version: ['3.7', '3.9']
include:
- os: windows-latest
python-version: '3.8'
runs-on: ${{ matrix.os }}
steps:
- name: Print Alpha
if: ${{ matrix.test_type == 'test-alpha'}}
run: echo "test type is alpha. the os name is ${{ runner.os }}"
- name: Print Beta
if: ${{ matrix.test_type == 'test-beta'}}
run: echo "test type is beta. the os name is ${{ runner.os }}"
When I run this workflow, the windows CI starts and completes but it is not showing any output. In particular, the if statements are not getting executed. Am I missing some point here? Because when I include the test-type
in matrix, I expect to also see windows X py3.8 X {alpha, beta} combination in workflow.
In the ubuntu CI, it works fine - getting executed for all combinations in the matrix (ubuntu X {py3.7,py3.9} X {alpha,beta}.)
CodePudding user response:
The include
method does not work here because Github tries to extend the already existing run configurations. If this does not work (which is the case here), then a new configuration is created for each include
. (For more information: https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs#expanding-or-adding-matrix-configurations)
In your case, however, the new created configurations do not contain a specified test-type. Now there are two possibilities. Either add the test-type manually:
name: Print test type
on: [push]
jobs:
build:
strategy:
fail-fast: false
matrix:
test_type: ['test-alpha', 'test-beta']
os: [ubuntu-latest]
python-version: ['3.7', '3.9']
include:
- os: windows-latest
python-version: '3.8'
test_type: 'test-alpha'
- os: windows-latest
python-version: '3.8'
test_type: 'test-beta'
runs-on: ${{ matrix.os }}
steps:
- name: Print Alpha
if: ${{ matrix.test_type == 'test-alpha'}}
run: echo "test type is alpha. the os name is ${{ runner.os }}"
- name: Print Beta
if: ${{ matrix.test_type == 'test-beta'}}
run: echo "test type is beta. the os name is ${{ runner.os }}"
or remove the unwanted combinations:
name: Print test type
on: [push]
jobs:
build:
strategy:
fail-fast: false
matrix:
test_type: ['test-alpha', 'test-beta']
os: [ubuntu-latest, windows-latest]
python-version: ['3.7', '3.8', '3.9']
exclude:
- os: windows-latest
python-version: '3.7'
- os: windows-latest
python-version: '3.9'
- os: ubuntu-latest
python-version: '3.8'
runs-on: ${{ matrix.os }}
steps:
- name: Print Alpha
if: ${{ matrix.test_type == 'test-alpha'}}
run: echo "test type is alpha. the os name is ${{ runner.os }}"
- name: Print Beta
if: ${{ matrix.test_type == 'test-beta'}}
run: echo "test type is beta. the os name is ${{ runner.os }}"