Skip to content

matrix jobs: how to conditionally use either shell: wsl-bash {0} or just shell #16

@ssbarnea

Description

@ssbarnea

When doing matrix testing on multiple platforms one may want to test on a matrix like below:

matrix:
  os:
  - ubuntu-latest
  - macos-11
  shell:
  - bash
  include:
  - os: windows-latest
    shell: wsl-bash {0}
steps:
- name: Activate WSL
  if: runner.os == 'Windows'
  uses: Vampire/setup-wsl@v1
- name: run something
  run: cat /etc/os-release
  shell: ${{ matrix.shell }} # <-- apparently GHA issue

The problem is that apparently GHA does not allow you use shell: ${{ matrix.shell }}, giving an unexpected error

The workflow is not valid. .github/workflows/ci.yaml (Line: 77, Col: 16): Unrecognized named-value: 'matrix'. Located at position 1 within expression: matrix.shell .github/workflows/ci.yaml (Line: 124, Col: 16): Unrecognized named-value: 'matrix'. Located at position 1 within expression: matrix.shell

The error above makes me think that GHA is not really able to use dynamic expressions on shell:, while it is able to do the same thing on if:, name: or run:.

It would be very useful to have an example where something like this works cross-platforms, especially as in real life the number of steps is considerably bigger and duplicating each "run" and adding conditions makes the workflow files reach an unmaintainable size. Even splitting them into two and using different jobs for windows and non windows does create similar maintenance challenges.

Also posted at https://github.community/t/unable-to-use-expressions-as-argument-to-shell/226230

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions