-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·69 lines (53 loc) · 1.63 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·69 lines (53 loc) · 1.63 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
#!/bin/bash
set -e
if [ -z "$GITHUB_URL" ]; then
echo 1>&2 "error: missing GITHUB_URL environment variable"
exit 1
fi
if [ -z "$GITHUB_TOKEN_FILE" ]; then
if [ -z "$GITHUB_TOKEN" ]; then
echo 1>&2 "error: missing GITHUB_TOKEN environment variable"
exit 1
fi
GITHUB_TOKEN_FILE=/runner/.token
echo -n "$GITHUB_TOKEN" > "$GITHUB_TOKEN_FILE"
fi
unset GITHUB_TOKEN
if [ -n "$RUNNER_WORK_DIRECTORY" ]; then
mkdir -p "$RUNNER_WORK_DIRECTORY"
fi
export AGENT_ALLOW_RUNASROOT="1"
cleanup() {
if [ -e config.sh ]; then
print_header "Cleanup. Removing GitHub Runner..."
# If the agent has some running jobs, the configuration removal process will fail.
# So, give it some time to finish the job.
while true; do
./config.sh remove --token "$(cat "$GITHUB_TOKEN_FILE")" && break
echo "Retrying in 30 seconds..."
sleep 30
done
fi
}
print_header() {
lightcyan='\033[1;36m'
nocolor='\033[0m'
echo -e "${lightcyan}$1${nocolor}"
}
# Let the agent ignore the token env variables
export VSO_AGENT_IGNORE=GITHUB_TOKEN,GITHUB_TOKEN_FILE
print_header "1. Configuring GitHub Runner..."
./config.sh --unattended \
--name "${RUNNER_NAME:-$(hostname)}" \
--url "$GITHUB_URL" \
--token "$(cat "$GITHUB_TOKEN_FILE")" \
--labels "${RUNNER_LABELS:-default}" \
--work "${RUNNER_WORK_DIRECTORY:-_work}" \
--replace
print_header "2. Running GitHub Runner..."
trap 'cleanup; exit 0' EXIT
trap 'cleanup; exit 130' INT
trap 'cleanup; exit 143' TERM
# To be aware of TERM and INT signals call run.sh
# Running it with the --once flag at the end will shut down the agent after the build is executed
./run.sh "$@"