Skip to content

Instantly share code, notes, and snippets.

@jonico
Last active July 8, 2024 13:30
Show Gist options
  • Save jonico/a94d03cac7a858e0613926d9f1bc7f2b to your computer and use it in GitHub Desktop.
Save jonico/a94d03cac7a858e0613926d9f1bc7f2b to your computer and use it in GitHub Desktop.
Dynamic selection of GitHub Runners - as GitHub Action matrix builds currently do not allow dynamic values
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
outputs:
runner: ${{ steps.runner.outputs.runner }}
steps:
- id: runner
run: echo "::set-output name=runner::macos-latest"
test:
needs: [build]
runs-on: ${{ needs.build.outputs.runner }}
steps:
- run: echo I Ran
@truonghuynguyen
Copy link

Hi @jonico, can we do multiple tags? I tried the similar as above, the value of outouts.runner is [ tag1, tag2 ], but it treats outouts.runner as a whole string, instead of an array of tags.

@jonico
Copy link
Author

jonico commented Oct 21, 2021

@gongdo
Copy link

gongdo commented Dec 20, 2021

@truonghuynguyen, I have exactly same needs, and it works for me:

runs-on: [ self-hosted, "${{ needs.build.outputs.runner }}" ]

Unfortunately, I couldn't find how to attach several runners dynamically.
I didn't test but, If you have fixed number of runners, than you might try like this:

runs-on: [ self-hosted, "${{ needs.build.outputs.runner1 }}", "${{ needs.build.outputs.runner2 }}" ]

@grahamhency
Copy link

This was super helpful for a project I'm working on, thanks! 🎉

@plusiv
Copy link

plusiv commented May 21, 2022

@truonghuynguyen, I have exactly same needs, and it works for me:

runs-on: [ self-hosted, "${{ needs.build.outputs.runner }}" ]

Unfortunately, I couldn't find how to attach several runners dynamically. I didn't test but, If you have fixed number of runners, than you might try like this:

runs-on: [ self-hosted, "${{ needs.build.outputs.runner1 }}", "${{ needs.build.outputs.runner2 }}" ]

Works fine for me, thanks!! 🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment