https://github.com/jimmygchen/runner-fallback-action
Github action to determine the availability of self-hosted runners
https://github.com/jimmygchen/runner-fallback-action
ci github-actions github-runners github-workflows self-hosted-runners
Last synced: about 1 year ago
JSON representation
Github action to determine the availability of self-hosted runners
- Host: GitHub
- URL: https://github.com/jimmygchen/runner-fallback-action
- Owner: jimmygchen
- License: mit
- Created: 2023-08-24T11:10:29.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-09T21:10:08.000Z (almost 2 years ago)
- Last Synced: 2025-05-11T12:17:00.648Z (about 1 year ago)
- Topics: ci, github-actions, github-runners, github-workflows, self-hosted-runners
- Language: JavaScript
- Homepage:
- Size: 284 KB
- Stars: 22
- Watchers: 4
- Forks: 7
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Github Runner Fallback Action
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](https://docs.github.com/en/rest/actions/self-hosted-runners?apiVersion=2022-11-28#list-self-hosted-runners-for-a-repository) 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.
## Usage
```yaml
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](https://github.com/orgs/community/discussions/20019#discussioncomment-5414593).