forked from SanderKnape/github-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
40 lines (31 loc) · 1.15 KB
/
entrypoint.sh
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
#!/bin/sh
registration_url="https://github.com/${GITHUB_OWNER}"
if [ -z "${GITHUB_REPOSITORY}" ]; then
token_url="https://api.github.com/orgs/${GITHUB_OWNER}/actions/runners/registration-token"
else
token_url="https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPOSITORY}/actions/runners/registration-token"
registration_url="${registration_url}/${GITHUB_REPOSITORY}"
fi
echo "Requesting token at '${token_url}'"
payload=$(curl -sX POST -H "Authorization: token ${GITHUB_PAT}" ${token_url})
export RUNNER_TOKEN=$(echo $payload | jq .token --raw-output)
if [ -z "${RUNNER_NAME}" ]; then
RUNNER_NAME=$(hostname)
fi
./config.sh \
--name ${RUNNER_NAME} \
--token ${RUNNER_TOKEN} \
--url ${registration_url} \
--work ${RUNNER_WORKDIR} \
--labels ${RUNNER_LABELS} \
--unattended \
--replace
remove() {
payload=$(curl -sX POST -H "Authorization: token ${GITHUB_PAT}" ${token_url%/registration-token}/remove-token)
export REMOVE_TOKEN=$(echo $payload | jq .token --raw-output)
./config.sh remove --unattended --token "${REMOVE_TOKEN}"
}
trap 'remove; exit 130' INT
trap 'remove; exit 143' TERM
./run.sh "$*" &
wait $!