From 0b1cc0ef5b6649f30e1f2928581e748d5d634cfe Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 23 Apr 2023 00:45:56 +0800 Subject: [PATCH] add lint checking and unit testing in build script --- build.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/build.sh b/build.sh index 32d41dfb..c6e435ba 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,8 @@ #!/usr/bin/env sh TYPE="" +NO_LINT="0" +NO_TEST="0" RELEASE=${RELEASE_BUILD:-"0"} RELEASE_TYPE="unknown" VERSION="" @@ -40,6 +42,8 @@ Options: -r, --release Build release (The script will use environment variable "RELEASE_BUILD" to detect whether this is release building by default) -o, --output Package file name (For "package" type only) -t, --tag Docker tag (For "docker" type only) + --no-lint Do not execute lint check before building + --no-test Do not execute unit testing before building -h, --help Show help EOF } @@ -63,6 +67,12 @@ parse_args() { DOCKER_TAG="$2" shift ;; + --no-lint) + NO_LINT="1" + ;; + --no-test) + NO_TEST="1" + ;; --help | -h) show_help exit 0 @@ -111,6 +121,27 @@ set_build_parameters() { } build_backend() { + if [ "$NO_LINT" = "0" ]; then + echo "Executing backend lint checking..." + go vet -v ./... + + if [ "$?" != "0" ]; then + echo_red "Error: Failed to pass lint checking" + exit 1 + fi + fi + + if [ "$NO_TEST" = "0" ]; then + echo "Executing backend unit testing..." + go clean -cache + go test ./... -v + + if [ "$?" != "0" ]; then + echo_red "Error: Failed to pass unit testing" + exit 1 + fi + fi + backend_build_extra_arguments="-X main.Version=$VERSION" backend_build_extra_arguments="$backend_build_extra_arguments -X main.CommitHash=$COMMIT_HASH" @@ -128,6 +159,16 @@ build_frontend() { echo "Pulling frontend dependencies..." npm install + if [ "$NO_LINT" = "0" ]; then + echo "Executing frontend lint checking..." + npm run lint + + if [ "$?" != "0" ]; then + echo_red "Error: Failed to pass lint checking" + exit 1 + fi + fi + echo "Building frontend files ($RELEASE_TYPE)..." if [ "$RELEASE" = "0" ]; then