-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
42 lines (42 loc) · 1.7 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
name: 'Choose Action Runner'
description: 'Choose self-hosted action runner based on their availability'
branding:
icon: server
color: yellow
inputs:
preferred-runner:
description: 'Runner to choose if it is available'
required: true
fallback-runner:
description: 'Fallback runner if primary-runner is unavailable'
required: true
runners-holder:
description: 'Repository or organization holding the self-hosted runners "repos/{user}/{repo_name}" or "orgs/{org_name}"'
required: false
default: repos/${{ github.repository }}
github-token:
description: 'GitHub API token with read access to organization self hosted runners and read access to repository administration and metadata'
required: true
outputs:
runner:
description: "Chosen runner"
value: ${{ steps.choose-runner.outputs.runner }}
runs:
using: "composite"
steps:
- id: choose-runner
shell: bash
run: |
runners=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ inputs.github-token }}" "https://api.github.com/${{ inputs.runners-holder }}/actions/runners")
echo "All runners:"
echo $runners | jq
available=$(echo "$runners" | jq -r '.runners[] | select(.status == "online")' | jq -r 'select(.name | startswith("${{ inputs.preferred-runner }}"))')
echo "Available runners:"
echo $available | jq
if [ -n "$available" ]; then
echo "Choosing runner: ${{ inputs.preferred-runner }}"
echo "runner=${{ inputs.preferred-runner }}" >> $GITHUB_OUTPUT
else
echo "Choosing runner: ${{ inputs.fallback-runner }}"
echo "runner=${{ inputs.fallback-runner }}" >> $GITHUB_OUTPUT
fi