Skip to content

Commit

Permalink
Merge pull request #139 from acompany-develop/feature/tanaka/make-bui…
Browse files Browse the repository at this point in the history
…ld-handling

make test&debug terminates mid-process when process fails
  • Loading branch information
come2ry authored Mar 15, 2023
2 parents 9e0bc76 + c69e9e1 commit c9dc98d
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 57 deletions.
59 changes: 48 additions & 11 deletions scripts/debugger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ echo "IS_ENABLE_DATADOG = $IS_ENABLE_DATADOG"

# 引数が正しくない時に発火する関数
usage_exit() {
echo "Usage: $1 'build' or 'run' or ''" 1>&2
echo "Usage: $1 'build' or 'run' or 'all' or ''" 1>&2
exit 1
}
# build()の定義を強要するために未定義関数として宣言
Expand All @@ -33,32 +33,69 @@ setup() {
exit 1
}


if [ $# -eq 1 ]; then
main() {
source $1
setup
build
if [ "$IS_ENABLE_DATADOG" = "1" ]; then
docker-compose $COMPOSE_FILES_OPT up -d datadog
local tmp=$?
if [ $tmp -gt 0 ]; then
echo "$1の読み込みに失敗"
return $tmp
fi
run
else
source $1
case $2 in
all)
main $1 build
tmp=$?
if [ $tmp -gt 0 ]; then
return $tmp
fi
main $1 run
tmp=$?
if [ $tmp -gt 0 ]; then
return $tmp
fi
return $tmp
;;
build)
build
tmp=$?
if [ $tmp -gt 0 ]; then
echo "buildで失敗"
return $tmp
fi
return $tmp
;;
run)
setup
run
tmp=$?
if [ $tmp -gt 0 ]; then
echo "setupで失敗"
return $tmp
fi
if [ "$IS_ENABLE_DATADOG" = "1" ]; then
docker-compose $COMPOSE_FILES_OPT up -d datadog
tmp=$?
if [ $tmp -gt 0 ]; then
echo "datadogで失敗"
return $tmp
fi
fi
run
tmp=$?
if [ $tmp -gt 0 ]; then
echo "runで失敗"
return $tmp
fi
return $tmp
;;
*)
usage_exit
;;
esac
}

mode=$2
if [ $# -eq 1 ]; then
mode='all'
fi
main $1 $mode

exit 0
113 changes: 67 additions & 46 deletions scripts/tester.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ status=0

# 引数が正しくない時に発火する関数
usage_exit() {
echo "Usage: $1 'build' or 'run' or ''" 1>&2
echo "Usage: $1 'build' or 'run' or 'all' or ''" 1>&2
exit 1
}

Expand Down Expand Up @@ -44,62 +44,83 @@ teardown() {
status=$(($status + 1))
}


if [ $# -eq 1 ]; then
# 関数化
main() {
source $1
status=$(($status + $?))
if [ $status -gt 0 ]; then
echo $status >>result
else
setup
status=$(($status + $?))
local tmp=$?
if [ $tmp -gt 0 ]; then
echo "$1の読み込みに失敗"
return $tmp
fi
case $2 in
all)
main $1 build
tmp=$?
if [ $tmp -gt 0 ]; then
return $tmp
fi
main $1 run
tmp=$?
if [ $tmp -gt 0 ]; then
return $tmp
fi
return $tmp
;;
build)
build
status=$(($status + $?))
tmp=$?
if [ $tmp -gt 0 ]; then
echo "buildで失敗"
return $tmp
fi
return $tmp
;;
run)
setup
tmp=$?
if [ $tmp -gt 0 ]; then
echo "setupで失敗"
return $tmp
fi
if [ "$IS_ENABLE_DATADOG" = "1" ]; then
docker-compose $COMPOSE_FILES_OPT up -d datadog
tmp=$?
if [ $tmp -gt 0 ]; then
echo "datadogで失敗"
return $tmp
fi
fi
run
status=$(($status + $?))
tmp=$?
if [ $tmp -gt 0 ]; then
echo "runで失敗"
return $tmp
fi
# NOTE: `docker-compose up`はCMDやENTRYPOINTで異常終了してもexitステータスが`0`になってしまうので別途exitステータスを集積する
run_status=$(docker-compose $COMPOSE_FILES_OPT ps -aq | tr -d '[ ]' | xargs docker inspect -f '{{ .State.ExitCode }}' | grep -v 0 | wc -l | tr -d '[ ]')
status=$(($status + $run_status))
teardown
status=$(($status + $?))
echo $status >>result
fi
else
source $1
status=$(($status + $?))
if [ $status -gt 0 ]; then
echo $status >>result
else
case $2 in
build)
build
status=$(($status + $?))
echo $status >>result
;;
run)
setup
status=$(($status + $?))
if [ "$IS_ENABLE_DATADOG" = "1" ]; then
docker-compose $COMPOSE_FILES_OPT up -d datadog
fi
run
status=$(($status + $?))
# NOTE: `docker-compose up`はCMDやENTRYPOINTで異常終了してもexitステータスが`0`になってしまうので別途exitステータスを集積する
run_status=$(docker-compose $COMPOSE_FILES_OPT ps -aq | tr -d '[ ]' | xargs docker inspect -f '{{ .State.ExitCode }}' | grep -v 0 | wc -l | tr -d '[ ]')
status=$(($status + $run_status))
teardown
status=$(($status + $?))
echo $status >>result
;;
*)
usage_exit
;;
esac
fi
tmp=$?
if [ $tmp -gt 0 ]; then
echo "teardownで失敗"
return $tmp
fi
return $tmp
;;
*)
usage_exit
;;
esac
}

mode=$2
if [ $# -eq 1 ]; then
mode='all'
fi
main $1 $mode
ret=$?
status=$(($status + $ret))
echo $status >>result

# DEBUG: 最後にstatusを表示
echo "["$1"] status:" $status
Expand Down

0 comments on commit c9dc98d

Please sign in to comment.