Skip to content

Commit 3bc5f68

Browse files
committed
print errors
Signed-off-by: Huamin Chen <[email protected]>
1 parent 7920404 commit 3bc5f68

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

entrypoint.sh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ debug() {
5555
[ "$DEBUG" == "true" ] && echo "DEBUG: $*" 1>&2
5656
}
5757

58+
echoerr() {
59+
echo "$*" 1>&2;
60+
}
5861
# check if key name is set
5962
if [ -z "$KEY_NAME" ]; then
6063
debug "KEY_NAME is not set"
@@ -66,7 +69,7 @@ fi
6669
get_github_runner_token () {
6770
# fail if github token is not set
6871
if [ -z "$GITHUB_TOKEN" ]; then
69-
debug "GITHUB_TOKEN is not set"
72+
echoerr "GITHUB_TOKEN is not set"
7073
exit 1
7174
fi
7275

@@ -82,19 +85,19 @@ get_github_runner_token () {
8285
debug "runner token: " "$RUNNER_TOKEN"
8386
# fail if then length of runner token is less than 5
8487
if [ ${#RUNNER_TOKEN} -lt 5 ]; then
85-
debug "Failed to get runner token"
88+
echoerr "Failed to get runner token"
8689
exit 1
8790
fi
8891
}
8992

9093
prep_aws_cred () {
9194
# fail if aws access key id is not set
9295
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
93-
debug "AWS_ACCESS_KEY_ID is not set"
96+
echoerr "AWS_ACCESS_KEY_ID is not set"
9497
exit 1
9598
fi
9699
if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
97-
debug "AWS_SECRET_ACCESS_KEY is not set"
100+
echoerr "AWS_SECRET_ACCESS_KEY is not set"
98101
exit 1
99102
fi
100103
export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
@@ -105,7 +108,7 @@ prep_aws_cred () {
105108
prep_create() {
106109
# fail if security group id is not set
107110
if [ -z "$SECURITY_GROUP_ID" ]; then
108-
debug "SECURITY_GROUP_ID is not set"
111+
echoerr "SECURITY_GROUP_ID is not set"
109112
exit 1
110113
fi
111114
# set s3 bucket name if not set and create s3 bucket flag is set to true
@@ -236,7 +239,7 @@ create_runner () {
236239
# create on-demand instance instead
237240
if [ -z "$INSTANCE_ID" ]; then
238241
if [ "$SPOT_INSTANCE_ONLY" == "true" ]; then
239-
debug "SPOT_INSTANCE_ONLY is set to true, exiting"
242+
echoerr "SPOT_INSTANCE_ONLY is set to true, exiting"
240243
exit 1
241244
fi
242245
debug "Failed to create spot instance, creating on-demand instance instead"
@@ -247,7 +250,7 @@ create_runner () {
247250

248251
# Check if instance creation failed
249252
if [ -z "$INSTANCE_ID" ]; then
250-
debug "Failed to create on-demand instance"
253+
echoerr "Failed to create on-demand instance"
251254
exit 1
252255
fi
253256
fi
@@ -257,7 +260,7 @@ create_runner () {
257260

258261
# Check if wait command succeeded
259262
if [ $? -ne 0 ]; then
260-
debug "Instance failed to become ready. Terminating instance."
263+
echoerr "Instance failed to become ready. Terminating instance."
261264
terminate_instance
262265
exit 1
263266
fi
@@ -301,7 +304,7 @@ unregister_runner () {
301304
# If not set, use the command line arguments and run the matching function. This is for local testing.
302305
ACTION=${INPUT_ACTION:-$1}
303306
if [ -z "$ACTION" ]; then
304-
debug "ACTION is not set"
307+
echoerr "ACTION is not set"
305308
exit 1
306309
fi
307310

@@ -314,15 +317,15 @@ case $ACTION in
314317
;;
315318
terminate)
316319
if [ -z "${INSTANCE_ID}" ]; then
317-
debug "Instance ID is not set"
320+
echoerr "Instance ID is not set"
318321
exit 1
319322
fi
320323
prep_aws_cred
321324
terminate_instance
322325
;;
323326
unregister)
324327
if [ -z "${RUNNER_NAME}" ]; then
325-
debug "Runner name is not set"
328+
echoerr "Runner name is not set"
326329
exit 1
327330
fi
328331
unregister_runner
@@ -331,7 +334,7 @@ case $ACTION in
331334
list_runner
332335
;;
333336
*)
334-
debug "Invalid action:"${ACTION}
335-
debug "Usage: $0 {create|terminate|unregister|list}"
337+
echoerr "Invalid action:"${ACTION}
338+
echoerr "Usage: $0 {create|terminate|unregister|list}"
336339
exit 1
337340
esac

0 commit comments

Comments
 (0)