Skip to content

Overwrite runs-on defined in workflow_call #26801

Overwrite runs-on defined in workflow_call #26801
Oct 13, 2021 · 3 answers

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:

  <a href="https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#example-reusable-workflow" target="_blank" rel="noopener nofollow ugc">GitHub Docs</a>

Reusing workflows - GitHub Docs

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

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/.git…

Replies

3 suggested answers

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

0 replies
Answer selected

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

0 replies

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

0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants