Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ------------" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ------------" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ------------" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ------------" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ------------" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ------------" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ------------" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ------------" |