Overwrite runs-on defined in workflow_call

I’m creating a general workflow_call to create easy to use templates that is supposed to be used by both companies and open-source.
Some users will use self hosted servers and others will use “ubuntu-latest”

To my knowledge I have to define runs-on in my workflow_call action:

Is there any way to overwrite runs-on so I instead can use
runs-on: [self-hosted, linux] where I want?

1 Like

I didn’t think about this yet, it seems you can use expression syntax in runs-on with your input.

Example


on:
  workflow_call:
    inputs:
      runs-on:
        type: string
        default: '["windows-latest"]'
jobs:
  myjoba:
    runs-on: ${{fromJSON(inputs.runs-on)}}
    outputs:
      myout: myin
    steps:
    - run: echo Hello World

Call the workflow with runs-on as input.
Multiple labels

on: push
jobs:
  comp:
    name: comp-${{toJSON(strategy)}}
    uses: ChristopherHX/newcomposite-sample/.github/workflows/weirdworkflow.yml@reusable-workflows
    with:
      runs-on: '["self-hosted", "linux"]'

Single label

on: push
jobs:
  comp:
    uses: ChristopherHX/newcomposite-sample/.github/workflows/weirdworkflow.yml@reusable-workflows
    with:
      runs-on: '"windows-latest"'

It isn’t great that inputs cannot be Objects (Arrays), but only string, boolean or number. You have to use json, unless github allows object inputs in the furture.

I’m not shure where inputs are allowed and where it is forbidden, the documentation is outdated so I had to test it myself and it worked

2 Likes

Easier solution then I hoped for, I should have thought of it as well.
Thanks for the quick reply and the great example!

2 Likes

Thanks for jumping in with that speedy reply, @ChristopherHX! Glad to hear this helped, @NissesSenap :slight_smile:

1 Like