diff --git a/.gitlab/api_test.sh b/.gitlab/api_test.sh index 5236fe5..359184c 100644 --- a/.gitlab/api_test.sh +++ b/.gitlab/api_test.sh @@ -1,8 +1,8 @@ currentDir=$(pwd) . $currentDir/.gitlab/include/function.sh echo -e "------------ The script api_test.sh is running ------------" -echo -e "1. Print the variables" -PrintEnv + +EveryStageCommonOperation if [ "${API_TEST_SWITCH}" == "" ] || [ "${API_TEST_SWITCH}" == "off" ] ; then echo -e "Because you turn off the switch, so skip api_test.sh" diff --git a/.gitlab/apidoc_gen.sh b/.gitlab/apidoc_gen.sh index 9f5db83..2c8d50d 100644 --- a/.gitlab/apidoc_gen.sh +++ b/.gitlab/apidoc_gen.sh @@ -1,15 +1,16 @@ currentDir=$(pwd) . $currentDir/.gitlab/include/function.sh + echo -e "------------ The script apidoc_gen.sh is running ------------" -echo -e "1. Print the variables" -PrintEnv -echo -e "2. generate apidoc" +EveryStageCommonOperation + +echo -e "1. generate apidoc" if [ "${APIDOC_TRIGGER_CMD}" != "" ] && [ "${APIDOC_FILE}" != "" ]; then - echo -e "2.1 ${APIDOC_TRIGGER_CMD} && cd $currentDir" + echo -e "1.1 ${APIDOC_TRIGGER_CMD} && cd $currentDir" eval $APIDOC_TRIGGER_CMD && cd $currentDir - echo -e "2.2 cat ${APIDOC_FILE}" + echo -e "1.2 cat ${APIDOC_FILE}" content=$(cat $APIDOC_FILE) if [ "${content}" == "" ]; then FAILURE_REASON="Failed to run apidoc_gen.sh: content empty" @@ -17,7 +18,7 @@ if [ "${APIDOC_TRIGGER_CMD}" != "" ] && [ "${APIDOC_FILE}" != "" ]; then exit 1 fi - echo -e "2.3. put gitlab wiki" + echo -e "1.3. put gitlab wiki" if [ "${GITLAB_HOST}" != "" ] && [ "${GITLAB_API_TOKEN}" != "" ] && [ "${PROJECT_ID}" != "" ]; then curl --request PUT --data "format=markdown&content=${content}&title=APIDoc" \ --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" "${GITLAB_HOST}/api/v4/projects/${PROJECT_ID}/wikis/APIDoc" diff --git a/.gitlab/check_code.sh b/.gitlab/check_code.sh index aae57a8..bf2aa06 100644 --- a/.gitlab/check_code.sh +++ b/.gitlab/check_code.sh @@ -1,22 +1,23 @@ currentDir=$(pwd) . $currentDir/.gitlab/include/function.sh + echo -e "------------ The script check_code.sh is running ------------" -echo -e "1. Print the variables" -PrintEnv + +EveryStageCommonOperation which "$(go env GOPATH)/bin/golangci-lint" >/dev/null 2>&1 if [ $? -ne 0 ]; then - echo -e "2. command golangci-lint not exist, installing it ..." - echo -e "2.1 git clone https://github.com/WGrape/cache.git && cd cache/golangci-lint && chmod 777 golangci-lint && cp golangci-lint $(go env GOPATH)/bin/ && cd $currentDir && rm -rf ./cache && ls" + echo -e "1. command golangci-lint not exist, installing it ..." + echo -e "1.1 git clone https://github.com/WGrape/cache.git && cd cache/golangci-lint && chmod 777 golangci-lint && cp golangci-lint $(go env GOPATH)/bin/ && cd $currentDir && rm -rf ./cache && ls" git clone https://github.com/WGrape/cache.git && cd cache/golangci-lint && chmod 777 golangci-lint && cp golangci-lint $(go env GOPATH)/bin/ && cd $currentDir && rm -rf ./cache && ls -alh else - echo -e "2. golangci-lint is installed" + echo -e "1. golangci-lint is installed" fi -echo "3." $($(go env GOPATH)/bin/golangci-lint --version) +echo "2." $($(go env GOPATH)/bin/golangci-lint --version) $(go env GOPATH)/bin/golangci-lint --version -echo "4." $(go env GOPATH)/bin/golangci-lint run --timeout=10m +echo "3." $(go env GOPATH)/bin/golangci-lint run --timeout=10m if [ $? -ne 0 ]; then FAILURE_REASON="Failed to run check_code.sh: check failed" SendFailureNotice @@ -25,6 +26,6 @@ else echo -e "check success" fi -echo "5. golangci-lint check passed" +echo "4. golangci-lint check passed" echo -e "------------ The script check_code.sh is stopped ------------" \ No newline at end of file diff --git a/.gitlab/health_check.sh b/.gitlab/health_check.sh index ceec171..3c3fd85 100644 --- a/.gitlab/health_check.sh +++ b/.gitlab/health_check.sh @@ -1,11 +1,12 @@ currentDir=$(pwd) . $currentDir/.gitlab/include/function.sh + echo -e "------------ The script health_check.sh is running ------------" -echo -e "1. Print the variables" -PrintEnv -echo -e "2. Check the service" -if [ "${HEALTH_CHECK_TRIGGER_CMD}" != "" ]; then +EveryStageCommonOperation + +echo -e "1. Check the service" +if [ "${HEALTH_CHECK_TRIGGER_CMD}" != "" ] && [ "${HEALTH_CHECK_SUCCESS}" != "" ]; then i=0 while true do diff --git a/.gitlab/include/function.sh b/.gitlab/include/function.sh index 66991fc..33d422b 100644 --- a/.gitlab/include/function.sh +++ b/.gitlab/include/function.sh @@ -6,6 +6,14 @@ PrintEnv(){ echo -e "ls="$(ls) } +# Actions performed by each task +EveryStageCommonOperation(){ + echo -e "[The following are common operations for each task]" + echo -e "[- Print the variables]" + PrintEnv + echo -e "[The above are common operations for each task]" +} + # Send the failure notice. SendFailureNotice(){ if [ "${CI_COMMIT_REF_NAME}" == "${CI_DEFAULT_BRANCH}" ]; then diff --git a/.gitlab/local_build.sh b/.gitlab/local_build.sh index 91df50d..149e208 100644 --- a/.gitlab/local_build.sh +++ b/.gitlab/local_build.sh @@ -1,10 +1,11 @@ currentDir=$(pwd) . $currentDir/.gitlab/include/function.sh + echo -e "------------ The script local_build.sh is running ------------" -echo -e "1. Print the variables" -PrintEnv -echo -e "2. Build the project at local" +EveryStageCommonOperation + +echo -e "1. Build the project at local" if [ "${LOCAL_BUILD_TRIGGER_CMD}" != "" ]; then eval $LOCAL_BUILD_TRIGGER_CMD if [ $? -ne 0 ]; then diff --git a/.gitlab/pre_check.sh b/.gitlab/pre_check.sh index a1e2e56..b6be50d 100644 --- a/.gitlab/pre_check.sh +++ b/.gitlab/pre_check.sh @@ -1,10 +1,11 @@ currentDir=$(pwd) . $currentDir/.gitlab/include/function.sh + echo -e "------------ The script pre_check.sh is running ------------" -echo -e "1. Print the variables" -PrintEnv -echo -e "2. Check the must variables" +EveryStageCommonOperation + +echo -e "1. Check the must variables" if [ "${DING_NOTICE_SWITCH}" == "on" ]; then if [ "${DING_ACCESS_TOKEN}" == "" ]; then diff --git a/.gitlab/pre_install.sh b/.gitlab/pre_install.sh index 913686e..85f16f7 100644 --- a/.gitlab/pre_install.sh +++ b/.gitlab/pre_install.sh @@ -1,11 +1,12 @@ currentDir=$(pwd) . $currentDir/.gitlab/include/function.sh + echo -e "------------ The script pre_install.sh is running ------------" -echo -e "1. Print the variables" -PrintEnv + +EveryStageCommonOperation # Complete the installation of all dependencies -echo -e "2. apt-get update && apt-get install -y curl" +echo -e "1. apt-get update && apt-get install -y curl" mv /etc/apt/sources.list /etc/apt/sources.list.bak \ && echo 'deb http://mirrors.163.com/debian/ stretch main non-free contrib' > /etc/apt/sources.list \ && echo 'deb http://mirrors.163.com/debian/ stretch-updates main non-free contrib' >> /etc/apt/sources.list \ diff --git a/.gitlab/unit_test.sh b/.gitlab/unit_test.sh index 7edbcba..cf64040 100644 --- a/.gitlab/unit_test.sh +++ b/.gitlab/unit_test.sh @@ -1,11 +1,12 @@ currentDir=$(pwd) . $currentDir/.gitlab/include/function.sh + echo -e "------------ The script unit_test.sh is running ------------" -echo -e "1. Print the variables" -PrintEnv -# 2. Test the directory of dao -echo -e "2. Trigger the unit test" +EveryStageCommonOperation + +# 1. Test the directory of dao +echo -e "1. Trigger the unit test" if [ "${UNIT_TEST_TRIGGER_CMD}" != "" ]; then eval $UNIT_TEST_TRIGGER_CMD if [ $? -ne 0 ]; then