1
1
#! /bin/bash
2
+ # 'set -e' stops the execution of a script if a command or pipeline has an error.
3
+ # This is the opposite of the default shell behaviour, which is to ignore errors in scripts.
4
+ set -e
2
5
3
- # NOTE: `uname -m` is more accurate and universal than `arch`
4
- # See https://en.wikipedia.org/wiki/Uname
5
- unamem=" $( uname -m) "
6
- case $unamem in
7
- * aarch64* |arm64)
8
- architecture=" arm64" ;;
9
- * 64* )
10
- architecture=" amd64" ;;
11
- * 86* )
12
- architecture=" 386" ;;
13
- * armv5* )
14
- architecture=" armv5" ;;
15
- * armv6* )
16
- architecture=" armv6" ;;
17
- * armv7* )
18
- architecture=" armv7" ;;
19
- * )
20
- echo " Unknown architecture: $unamem "
21
- ;;
22
- esac
6
+ # Set defaults
7
+ os_name=" "
8
+ architecture=" "
23
9
24
- unameu=" $( tr ' [:lower:]' ' [:upper:]' <<< " $(uname)" ) "
25
- if [[ $unameu == * DARWIN* ]]; then
26
- os_name=" darwin"
27
- elif [[ $unameu == * LINUX* ]]; then
28
- os_name=" linux"
29
- elif [[ $unameu == * FREEBSD* ]]; then
30
- os_name=" freebsd"
31
- elif [[ $unameu == * NETBSD* ]]; then
32
- os_name=" netbsd"
33
- elif [[ $unameu == * OPENBSD* ]]; then
34
- os_name=" openbsd"
35
- elif [[ $unameu == * WIN* || $unameu == MSYS* ]]; then
36
- # Should catch cygwin
37
- os_name=" windows"
38
- else
39
- echo " Unknown OS: $( uname) "
40
- fi
10
+ # Get to the current directory
11
+ current_dir=" $( dirname " $( realpath " $0 " ) " ) "
12
+ source " ${current_dir} /detector.sh"
41
13
42
14
instance_id () {
43
15
# Use randomly generated instance IDs (AWS format) as default runner names
44
16
letters=$( tr -dc ' [:lower:]' < /dev/urandom | head -c 4)
45
17
digits=$( tr -dc ' 0-9' < /dev/urandom | head -c 12)
46
18
eid=$( echo " $letters$digits " | fold -w1 | shuf | tr -d ' \n' )
47
- echo " 0$eid "
19
+ echo " i- 0$eid "
48
20
}
49
21
50
22
# Env vars (docker-compose.yml)
51
- RUNNER_NAME=" ${RUNNER_NAME:- " i- $( instance_id) " } "
23
+ RUNNER_NAME=" ${RUNNER_NAME:- " $( instance_id) " } "
52
24
RUNNER_GROUP=" ${RUNNER_GROUP:- " default" } "
53
25
WORK_DIR=" ${WORK_DIR:- " _work" } "
54
26
LABELS=" ${LABELS:- " docker-node,$os_name -$architecture " } "
@@ -57,7 +29,7 @@ repo_level_runner() {
57
29
# https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-a-repository
58
30
REG_TOKEN=$( curl -sX POST \
59
31
-H " Accept: application/vnd.github.v3+json" \
60
- -H " Authorization: token ${GIT_TOKEN} " \
32
+ -H " Authorization: Bearer ${GIT_TOKEN} " \
61
33
" https://api.github.com/repos/${GIT_OWNER} /${GIT_REPOSITORY} /actions/runners/registration-token" \
62
34
| jq .token --raw-output)
63
35
cd " /home/docker/actions-runner" || exit 1
@@ -76,7 +48,7 @@ org_level_runner() {
76
48
# https://docs.github.com/en/rest/actions/self-hosted-runners#create-a-registration-token-for-an-organization
77
49
REG_TOKEN=$( curl -sX POST \
78
50
-H " Accept: application/vnd.github.v3+json" \
79
- -H " Authorization: token ${GIT_TOKEN} " \
51
+ -H " Authorization: Bearer ${GIT_TOKEN} " \
80
52
" https://api.github.com/orgs/${GIT_OWNER} /actions/runners/registration-token" \
81
53
| jq .token --raw-output)
82
54
cd " /home/docker/actions-runner" || exit 1
@@ -90,10 +62,10 @@ org_level_runner() {
90
62
}
91
63
92
64
if [ -n " ${GIT_REPOSITORY} " ]; then
93
- echo " Creating repository level self-hosted runner ['${RUNNER_NAME} '] for ${GIT_REPOSITORY} "
65
+ echo " Creating a repository level self-hosted runner ['${RUNNER_NAME} '] for ${GIT_REPOSITORY} "
94
66
repo_level_runner
95
67
else
96
- echo " Creating organization level self-hosted runner '${RUNNER_NAME} '"
68
+ echo " Creating an organization level self-hosted runner '${RUNNER_NAME} '"
97
69
org_level_runner
98
70
fi
99
71
@@ -105,4 +77,4 @@ cleanup() {
105
77
trap ' cleanup; exit 130' INT
106
78
trap ' cleanup; exit 143' TERM
107
79
108
- ./run.sh & wait $!
80
+ ./run.sh & wait $!
0 commit comments