Skip to content

Commit

Permalink
feat: CIManager支持github项目
Browse files Browse the repository at this point in the history
  • Loading branch information
WGrape committed Dec 3, 2022
1 parent 9e72278 commit 0cb0644
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 109 deletions.
24 changes: 12 additions & 12 deletions .github/api_test.sh
@@ -1,21 +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
EveryStageCommonOperation

eval $API_TEST_TRIGGER_CMD
if [ $? -ne 0 ]; then
FAILURE_REASON="run API Test failed"
SendFailureNotice
exit 1
if [ "${API_TEST_TRIGGER_CMD}" != "" ]; then
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
else
echo -e "run API Test success"
echo -e "No variable configurations for api test"
fi

echo -e "------------ The script api_test.sh is stopped ------------"
13 changes: 7 additions & 6 deletions .github/apidoc_gen.sh
@@ -1,15 +1,16 @@
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"
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"
Expand All @@ -19,7 +20,7 @@ if [ "${APIDOC_TRIGGER_CMD}" != "" ] && [ "${APIDOC_FILE}" != "" ]; then

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"
echo -e "No variable configurations for apidoc generate"
fi

echo -e "------------ The script apidoc_gen.sh is stopped ------------"
17 changes: 9 additions & 8 deletions .github/check_code.sh
@@ -1,22 +1,23 @@
currentDir=$(pwd)
. $currentDir/.github/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 ------------"
11 changes: 7 additions & 4 deletions .github/health_check.sh
@@ -1,11 +1,12 @@
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
EveryStageCommonOperation

echo -e "1. Check the service"
if [ "${HEALTH_CHECK_TRIGGER_CMD}" != "" ] && [ "${HEALTH_CHECK_SUCCESS}" != "" ]; then
i=0
while true
do
Expand All @@ -25,6 +26,8 @@ if [ "${HEALTH_CHECK_TRIGGER_CMD}" != "" ]; then

sleep 1
done
else
echo -e "No variable configurations for health check"
fi

echo -e "------------ The script health_check.sh is stopped ------------"
57 changes: 32 additions & 25 deletions .github/include/function.sh
@@ -1,33 +1,40 @@
# 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)
echo -e "cat /proc/version="$(cat /proc/version)
echo -e "CI_BUILDS_DIR=${CI_BUILDS_DIR}"
echo -e "pwd="$(pwd)
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
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
if [ "${GITHUB_REF_NAME}" == "main" ] || [ "${GITHUB_REF_NAME}" == "master" ] ; then
actionName="Request to merge ${GITHUB_REF_NAME}"
elif [ "${GITHUB_REF_NAME}" == "test" ]; then
actionName="Request to merge test"
else
actionName="Commit to ${GITHUB_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
MESSAGE="${DING_KEYWORD}】CI/CD Failed Notice
Operation: ${actionName}
Project: ${GITHUB_REPOSITORY}
Branch: ${GITHUB_REF_NAME}
Reason: ${FAILURE_REASON}
More: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}
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
}
9 changes: 6 additions & 3 deletions .github/local_build.sh
@@ -1,10 +1,11 @@
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"
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 All @@ -14,6 +15,8 @@ if [ "${LOCAL_BUILD_TRIGGER_CMD}" != "" ]; then
else
echo -e "build success"
fi
else
echo -e "No variable configurations for local build"
fi

echo -e "------------ The script local_build.sh is stopped ------------"
70 changes: 36 additions & 34 deletions .github/pre_check.sh
@@ -1,53 +1,55 @@
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"
EveryStageCommonOperation

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
echo -e "1. Check the must variables"

# unit_test.sh
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
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

# apidoc_gen.sh
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
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
fi
fi

# local_build.sh
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
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

# health_check.sh
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
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

# include/function.sh > SendFailureNotice()
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

echo -e "------------ The script pre_check.sh is stopped ------------"
7 changes: 4 additions & 3 deletions .github/pre_install.sh
@@ -1,11 +1,12 @@
currentDir=$(pwd)
. $currentDir/.github/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
11 changes: 6 additions & 5 deletions .github/unit_test.sh
@@ -1,11 +1,12 @@
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"
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 All @@ -16,7 +17,7 @@ if [ "${UNIT_TEST_TRIGGER_CMD}" != "" ]; then
echo -e "test success"
fi
else
echo -e "No variable configurations for unit test"
echo -e "No variable configurations for unit test"
fi

echo -e "------------ The script unit_test.sh is stopped ------------"
16 changes: 16 additions & 0 deletions .github/workflows/.github-ci.yml
@@ -0,0 +1,16 @@
name: github-ci
on:
push:
branches:
- main
- testing
- test
jobs:

CIManager:
runs-on: ubuntu-latest
env:
working-directory: .github/
steps:
- uses: actions/checkout@v1
- run: git clone -b testing https://github.com/wgrape/CIManager.git ; cp -an ./CIManager/. ./ ; rm -rf ./CIManager ; bash start.sh github
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Expand Up @@ -49,4 +49,4 @@ stages:
CIManager:
stage: CIManager
script:
- git clone -b testing https://github.com/wgrape/CIManager.git ; cp -an ./CIManager/. ./ ; rm -rf ./CIManager ; bash start.sh
- git clone -b testing https://github.com/wgrape/CIManager.git ; cp -an ./CIManager/. ./ ; rm -rf ./CIManager ; bash start.sh gitlab
1 change: 1 addition & 0 deletions .gitlab/api_test.sh
@@ -1,5 +1,6 @@
currentDir=$(pwd)
. $currentDir/.gitlab/include/function.sh

echo -e "------------ The script api_test.sh is running ------------"

EveryStageCommonOperation
Expand Down

0 comments on commit 0cb0644

Please sign in to comment.