Github action to determine the availability of self-hosted runners, and fallback to a GitHub runner if the primary runners are offline.
This action uses GitHub API to check the statuses of self hosted-runners that match specific labels, and outputs the runner label(s), or a fallback runner if the self-hosted runner(s) is unavailable.
This output can then used on the runs-on
property of subsequent jobs.
Note: In order to support an array of labels for the runs-on
field, the output is formatted as a JSON string and needs to be parsed using fromJson
. See example usage below.
jobs:
# Job to
determine-runner:
runs-on: ubuntu-latest
outputs:
runner: ${{ steps.set-runner.outputs.use-runner }}
steps:
- name: Determine which runner to use
id: set-runner
uses: jimmygchen/runner-fallback-action@v1
with:
primary-runner: "self-hosted,linux"
fallback-runner: "ubuntu-latest"
github-token: ${{ secrets.YOUR_GITHUB_TOKEN }}
another-job:
needs: determine-runner
runs-on: ${{ fromJson(needs.determine-runner.outputs.runner) }}
steps:
- name: Do something
run: echo "Doing something on ${{ needs.determine-runner.outputs.runner }}"
Credit: this action is based on the pattern described by @ianpurton on this feature request thread.