Skip to content

Commit

Permalink
refactor: 代码内部逻辑小幅度重构优化
Browse files Browse the repository at this point in the history
  • Loading branch information
WGrape committed Dec 3, 2022
1 parent 14bd92a commit 63ae395
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .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"
Expand Down
13 changes: 7 additions & 6 deletions .gitlab/apidoc_gen.sh
@@ -1,23 +1,24 @@
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"
SendFailureNotice
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"
Expand Down
17 changes: 9 additions & 8 deletions .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
Expand All @@ -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 ------------"
9 changes: 5 additions & 4 deletions .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
Expand Down
8 changes: 8 additions & 0 deletions .gitlab/include/function.sh
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions .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
Expand Down
7 changes: 4 additions & 3 deletions .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
Expand Down
7 changes: 4 additions & 3 deletions .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 \
Expand Down
9 changes: 5 additions & 4 deletions .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
Expand Down

0 comments on commit 63ae395

Please sign in to comment.