Using a matrix defined input for a custom action

I want to use a custom action and provide a different value to an action input parameter based on the matrix element - for example, a platform specific URL.

Is there any way I can do that with the current matrix syntax?

For example, the following will use the Windows-only parameter for a Linux build and vice-versa:

runs-on: ${{ matrix.os }}
strategy:
  matrix:
    os: [ubuntu-latest, windows-latest]
    custom: [linux-only, windows-only]
steps:
  - uses: my-custom-action
    with:
      myInput: ${{ matrix.custom }}

I know I can use the exclude rules for the matrix, but it really does seem cumbersome for more complex scenarios.

Additionally, there might be multiple parameters that have platform specific values I would like to set, which means the exclusion solution will not work here.

Any pointers to how this could be done easier?

Thanks!

It doesn’t seem like you’d want a matrix here.  I think I would approach this by having a script that sets the appropriate values based on the operating system in the matrix, then uses those output values as inputs into the other actions.  For example:

runs-on: ${{ matrix.os }}
strategy:
  matrix:
    os: [ubuntu-latest, windows-latest]
steps:
- run: |
    if ["${{ matrix.os }}" = "ubuntu-latest"]; then
      echo ::set-output name=url::http://linux_url/
      echo ::set-output name=other::foo
    fi
    if ["${{ matrix.os }}" = "windows-latest"]; then
      echo ::set-output name=url::http://windows_url/
      echo ::set-output name=other::bar
    fi
  shell: bash
- uses: custom/action_one@master
  with:
    url: ${{ steps.configure.outputs.url }}
- uses: custom/action_two@master
  with:
    other: ${{ steps.configure.outputs.other }}
2 Likes

Shouldn’t run step have id: configure set?

You sould also be able to do something like this

runs-on: ${{ matrix.config.os }}
strategy:
  matrix:
    config:
    - {os: ubuntu-latest, url: "http://linuxurl" }
    - {os: windows-latest, url: "http://windowsurl" }
steps:
  - uses: my-custom-action
    with:
      myInput: ${{ matrix.config.url }}
7 Likes

This is exactly what I was looking for, thanks a lot!