-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
72 lines (58 loc) · 1.73 KB
/
entrypoint.sh
File metadata and controls
72 lines (58 loc) · 1.73 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
set -euo pipefail
echo "env.REPOSITORY_URL: ${REPOSITORY_URL}"
repo_slug() {
local slug="${REPOSITORY_URL#https://github.com/}"
slug="${slug#http://github.com/}"
slug="${slug%.git}"
slug="${slug%/}"
printf '%s\n' "${slug}"
}
get_reg_token() {
curl --fail --silent --show-error -X POST \
-H "Authorization: Bearer ${RUNNER_TOKEN}" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2026-03-10" \
"https://api.github.com/repos/$(repo_slug)/actions/runners/registration-token" \
| jq --exit-status --raw-output '.token'
}
get_remove_token() {
curl --fail --silent --show-error -X POST \
-H "Authorization: Bearer ${RUNNER_TOKEN}" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2026-03-10" \
"https://api.github.com/repos/$(repo_slug)/actions/runners/remove-token" \
| jq --exit-status --raw-output '.token'
}
ensure_directories() {
mkdir -p /home/docker/actions-runner
}
configure_runner() {
local reg_token
reg_token="$(get_reg_token)"
cd /home/docker/actions-runner
./config.sh \
--url "${REPOSITORY_URL}" \
--token "${reg_token}" \
--name "$(hostname)" \
--replace \
--unattended
}
cleanup() {
local reg_token
echo "Removing runner..."
if ! reg_token="$(get_remove_token)"; then
echo "Failed to fetch a removal token; skipping runner removal."
return
fi
cd /home/docker/actions-runner
./config.sh remove --unattended --token "${reg_token}" || true
}
trap 'cleanup; exit 130' INT
trap 'cleanup; exit 143' TERM
main() {
ensure_directories
configure_runner
./run.sh & wait $!
}
main