Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ssbarnea opened this issue Jan 29, 2022 · 1 comment

Comments

@ssbarnea
Copy link

ssbarnea commented Jan 29, 2022

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.uint.cloudmunity/t/unable-to-use-expressions-as-argument-to-shell/226230

@ssbarnea
Copy link
Author

ssbarnea commented Feb 4, 2022

In case someone else gets into the same issue, I found a solution, using defaults with fallback values can help you switch the default shell. Look at ansible/team-devtools#29 (comment)

Repository owner locked and limited conversation to collaborators Feb 7, 2022
@Vampire Vampire converted this issue into discussion #19 Feb 7, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant