mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 17:54:30 +08:00
add lint checking and unit testing in build script
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
TYPE=""
|
TYPE=""
|
||||||
|
NO_LINT="0"
|
||||||
|
NO_TEST="0"
|
||||||
RELEASE=${RELEASE_BUILD:-"0"}
|
RELEASE=${RELEASE_BUILD:-"0"}
|
||||||
RELEASE_TYPE="unknown"
|
RELEASE_TYPE="unknown"
|
||||||
VERSION=""
|
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)
|
-r, --release Build release (The script will use environment variable "RELEASE_BUILD" to detect whether this is release building by default)
|
||||||
-o, --output <filename> Package file name (For "package" type only)
|
-o, --output <filename> Package file name (For "package" type only)
|
||||||
-t, --tag Docker tag (For "docker" 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
|
-h, --help Show help
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
@@ -63,6 +67,12 @@ parse_args() {
|
|||||||
DOCKER_TAG="$2"
|
DOCKER_TAG="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--no-lint)
|
||||||
|
NO_LINT="1"
|
||||||
|
;;
|
||||||
|
--no-test)
|
||||||
|
NO_TEST="1"
|
||||||
|
;;
|
||||||
--help | -h)
|
--help | -h)
|
||||||
show_help
|
show_help
|
||||||
exit 0
|
exit 0
|
||||||
@@ -111,6 +121,27 @@ set_build_parameters() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
build_backend() {
|
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="-X main.Version=$VERSION"
|
||||||
backend_build_extra_arguments="$backend_build_extra_arguments -X main.CommitHash=$COMMIT_HASH"
|
backend_build_extra_arguments="$backend_build_extra_arguments -X main.CommitHash=$COMMIT_HASH"
|
||||||
|
|
||||||
@@ -128,6 +159,16 @@ build_frontend() {
|
|||||||
echo "Pulling frontend dependencies..."
|
echo "Pulling frontend dependencies..."
|
||||||
npm install
|
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)..."
|
echo "Building frontend files ($RELEASE_TYPE)..."
|
||||||
|
|
||||||
if [ "$RELEASE" = "0" ]; then
|
if [ "$RELEASE" = "0" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user