| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# |
| 4 |
# Ephemeral runner startup script. |
| 5 |
# |
| 6 |
# Expects the following environment variables: |
| 7 |
# |
| 8 |
# - repo=<owner>/<name> |
| 9 |
# - access_token=<ghp_***> |
| 10 |
# |
| 11 |
|
| 12 |
set -e -u |
| 13 |
|
| 14 |
# Check the cached registration token. |
| 15 |
token_file=registration-token.json |
| 16 |
set +e |
| 17 |
expires_at=$(jq --raw-output .expires_at "$token_file" 2>/dev/null) |
| 18 |
status=$? |
| 19 |
set -e |
| 20 |
if [[ $status -ne 0 || $(date +%s) -ge $(date -d "$expires_at" +%s) ]]; then |
| 21 |
# Refresh the cached registration token. |
| 22 |
curl \ |
| 23 |
-X POST \ |
| 24 |
-H "Accept: application/vnd.github.v3+json" \ |
| 25 |
-H "Authorization: token $access_token" \ |
| 26 |
"https://api.github.com/repos/$repo/actions/runners/registration-token" \ |
| 27 |
-o "$token_file" |
| 28 |
fi |
| 29 |
|
| 30 |
# (Re-)register the runner. |
| 31 |
registration_token=$(jq --raw-output .token "$token_file") |
| 32 |
./config.sh remove --token "$registration_token" || true |
| 33 |
./config.sh \ |
| 34 |
--url "https://github.com/$repo" \ |
| 35 |
--token "$registration_token" \ |
| 36 |
--labels z15 \ |
| 37 |
--ephemeral |
| 38 |
|
| 39 |
# Run one job. |
| 40 |
./run.sh |