Skip to content

Commit

Permalink
feat: 新增重大功能对github的支持
Browse files Browse the repository at this point in the history
  • Loading branch information
WGrape committed Dec 3, 2022
1 parent e2e6df6 commit 14bd92a
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/api_test.sh
@@ -0,0 +1,21 @@
currentDir=$(pwd)
. $currentDir/.github/include/function.sh
echo -e "------------ The script api_test.sh is running ------------"
echo -e "1. Print the variables"
PrintEnv

if [ "${API_TEST_SWITCH}" == "" ] || [ "${API_TEST_SWITCH}" == "off" ] ; then
echo -e "Because you turn off the switch, so skip api_test.sh"
exit 0
fi

eval $API_TEST_TRIGGER_CMD
if [ $? -ne 0 ]; then
FAILURE_REASON="run API Test failed"
SendFailureNotice
exit 1
else
echo -e "run API Test success"
fi

echo -e "------------ The script api_test.sh is stopped ------------"
25 changes: 25 additions & 0 deletions .github/apidoc_gen.sh
@@ -0,0 +1,25 @@
currentDir=$(pwd)
. $currentDir/.github/include/function.sh
echo -e "------------ The script apidoc_gen.sh is running ------------"
echo -e "1. Print the variables"
PrintEnv

echo -e "2. generate apidoc"
if [ "${APIDOC_TRIGGER_CMD}" != "" ] && [ "${APIDOC_FILE}" != "" ]; then
echo -e "2.1 ${APIDOC_TRIGGER_CMD} && cd $currentDir"
eval $APIDOC_TRIGGER_CMD && cd $currentDir

echo -e "2.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 github wiki: since the official website does not provide the GitHub wiki API, it cannot be updated to the wiki, please ignore this issue"
else
echo -e "No variable configurations for apidoc generator"
fi

echo -e "------------ The script apidoc_gen.sh is stopped ------------"
30 changes: 30 additions & 0 deletions .github/check_code.sh
@@ -0,0 +1,30 @@
currentDir=$(pwd)
. $currentDir/.github/include/function.sh
echo -e "------------ The script check_code.sh is running ------------"
echo -e "1. Print the variables"
PrintEnv

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"
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"
fi

echo "3." $($(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
if [ $? -ne 0 ]; then
FAILURE_REASON="Failed to run check_code.sh: check failed"
SendFailureNotice
exit 1
else
echo -e "check success"
fi

echo "5. golangci-lint check passed"

echo -e "------------ The script check_code.sh is stopped ------------"
30 changes: 30 additions & 0 deletions .github/health_check.sh
@@ -0,0 +1,30 @@
currentDir=$(pwd)
. $currentDir/.github/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
i=0
while true
do
((i++))

res=$(eval $HEALTH_CHECK_TRIGGER_CMD)
if [ "${res}" == "${HEALTH_CHECK_SUCCESS}" ]; then
echo -e "health check success"
break
fi

if [ $i -ge 100 ]; then
FAILURE_REASON="Failed to run health_check.sh: res not success, real=${res}"
SendFailureNotice
exit 1
fi

sleep 1
done
fi

echo -e "------------ The script health_check.sh is stopped ------------"
33 changes: 33 additions & 0 deletions .github/include/function.sh
@@ -0,0 +1,33 @@
# Print the environment variables.
PrintEnv(){
echo -e "cat /proc/version="$(cat /proc/version)
echo -e "CI_BUILDS_DIR=${CI_BUILDS_DIR}"
echo -e "pwd="$(pwd)
echo -e "ls="$(ls)
}

# Send the failure notice.
SendFailureNotice(){
if [ "${CI_COMMIT_REF_NAME}" == "${CI_DEFAULT_BRANCH}" ]; then
actionName="Request to merge ${CI_COMMIT_REF_NAME}"
elif [ "${CI_COMMIT_REF_NAME}" == "test" ]; then
actionName="Request to merge test"
else
actionName="Commit to ${CI_COMMIT_REF_NAME}"
fi

MESSAGE="${DING_KEYWORD}】CI/CD Failed Notice
Operation: ${actionName}
Project: ${CI_PROJECT_NAME}
Branch: ${CI_COMMIT_REF_NAME}
Operator: ${GITLAB_USER_EMAIL}
Reason: ${FAILURE_REASON}
More: ${CI_PIPELINE_URL}
made by CIManager
"
if [ "${DING_NOTICE_SWITCH}" == "on" ] && [ "${DING_ACCESS_TOKEN}" != "" ] ; then
curl -H 'Content-type: application/json' -d "{\"msgtype\":\"text\", \"text\": {\"content\":\"${MESSAGE}\"}}" "https://oapi.dingtalk.com/robot/send?access_token=${DING_ACCESS_TOKEN}"
else
echo $MESSAGE
fi
}
19 changes: 19 additions & 0 deletions .github/local_build.sh
@@ -0,0 +1,19 @@
currentDir=$(pwd)
. $currentDir/.github/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"
if [ "${LOCAL_BUILD_TRIGGER_CMD}" != "" ]; then
eval $LOCAL_BUILD_TRIGGER_CMD
if [ $? -ne 0 ]; then
FAILURE_REASON="Failed to run local_build.sh: build failed"
SendFailureNotice
exit 1
else
echo -e "build success"
fi
fi

echo -e "------------ The script local_build.sh is stopped ------------"
53 changes: 53 additions & 0 deletions .github/pre_check.sh
@@ -0,0 +1,53 @@
currentDir=$(pwd)
. $currentDir/.github/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"

if [ "${DING_NOTICE_SWITCH}" == "on" ]; then
if [ "${DING_ACCESS_TOKEN}" == "" ]; then
FAILURE_REASON="Failed to run pre_check.sh: the variables DING_ACCESS_TOKEN empty"
SendFailureNotice
exit 1
fi
fi

if [ "${UNIT_TEST_SWITCH}" == "on" ]; then
if [ "${UNIT_TEST_TRIGGER_CMD}" == "" ]; then
FAILURE_REASON="Failed to run pre_check.sh: the variables UNIT_TEST_TRIGGER_CMD empty"
SendFailureNotice
exit 1
fi
fi

if [ "${APIDOC_SWITCH}" == "on" ]; then
if [ "${APIDOC_TRIGGER_CMD}" == "" ] || [ "${APIDOC_FILE}" == "" ] ; then
FAILURE_REASON="Failed to run pre_check.sh: the variables APIDOC_TRIGGER_CMD/APIDOC_FILE empty"
SendFailureNotice
exit 1
elif [ "${GITHUB_HOST}" == "" ] || [ "${GITHUB_API_TOKEN}" == "" ] || [ "${PROJECT_ID}" == "" ] ; then
FAILURE_REASON="Failed to run pre_check.sh: the variables GITHUB_HOST/GITHUB_API_TOKEN/PROJECT_ID empty"
SendFailureNotice
exit 1
fi
fi

if [ "${LOCAL_BUILD_SWITCH}" == "on" ]; then
if [ "${LOCAL_BUILD_TRIGGER_CMD}" == "" ] ; then
FAILURE_REASON="Failed to run pre_check.sh: the variables LOCAL_BUILD_TRIGGER_CMD empty"
SendFailureNotice
exit 1
fi
fi

if [ "${HEALTH_CHECK_SWITCH}" == "on" ]; then
if [ "${HEALTH_CHECK_TRIGGER_CMD}" == "" ] || [ "${HEALTH_CHECK_SUCCESS}" == "" ] ; then
FAILURE_REASON="Failed to run pre_check.sh: the variables HEALTH_CHECK_TRIGGER_CMD/HEALTH_CHECK_SUCCESS empty"
SendFailureNotice
exit 1
fi
fi

echo -e "------------ The script pre_check.sh is stopped ------------"
16 changes: 16 additions & 0 deletions .github/pre_install.sh
@@ -0,0 +1,16 @@
currentDir=$(pwd)
. $currentDir/.github/include/function.sh
echo -e "------------ The script pre_install.sh is running ------------"
echo -e "1. Print the variables"
PrintEnv

# Complete the installation of all dependencies
echo -e "2. 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 \
&& echo 'deb http://mirrors.163.com/debian-security/ stretch/updates main non-free contrib' >> /etc/apt/sources.list \
&& apt-get update -y
apt-get install curl -y

echo -e "------------ The script pre_install.sh is stopped ------------"
22 changes: 22 additions & 0 deletions .github/unit_test.sh
@@ -0,0 +1,22 @@
currentDir=$(pwd)
. $currentDir/.github/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"
if [ "${UNIT_TEST_TRIGGER_CMD}" != "" ]; then
eval $UNIT_TEST_TRIGGER_CMD
if [ $? -ne 0 ]; then
FAILURE_REASON="Failed to run unit_test.sh: test failed"
SendFailureNotice
exit 1
else
echo -e "test success"
fi
else
echo -e "No variable configurations for unit test"
fi

echo -e "------------ The script unit_test.sh is stopped ------------"

0 comments on commit 14bd92a

Please sign in to comment.