Skip to content

Commit 19a3378

Browse files
committed
Merge branch 'main' into main-github-pro
2 parents f77bd76 + cef1250 commit 19a3378

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

.gitlab-ci.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
variables:
2+
PATH: /opt/go-1.23/go/bin/:/opt/node-1.22/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
3+
GOROOT: /opt/go-1.23/go
4+
GOPROXY: https://goproxy.cn
5+
VERSION: $CI_COMMIT_SHORT_SHA
6+
APP: apipark
7+
APP_PRE: ${APP}_${VERSION}
8+
BUILD_DIR: ${APP}-build
9+
DEPLOY_DESC: "DEV 环境"
10+
VIEW_ADDR: http://172.18.166.219:8288
11+
SAVE_DIR: /opt/${APP}
12+
NODE_OPTIONS: --max_old_space_size=8192
13+
14+
stages:
15+
- sync
16+
# - notice
17+
# - build
18+
# - deploy
19+
# - webhook
20+
21+
sync_job:
22+
stage: sync
23+
variables:
24+
GITLAB_REPO: http://$DEPLOY_USER:$DEPLOY_TOKEN@gitlab.eolink.com/apipark/APIPark
25+
GIT_STRATEGY: none # 避免 CI 克隆 GitLab 仓库
26+
script:
27+
# 检查是否已有仓库缓存,若无则克隆
28+
- if [ ! -d "repo-cache" ]; then
29+
- git clone https://$GITHUB_USER:$GITHUB_TOKEN@$GITHUB_REPO repo-cache
30+
- fi
31+
- cd repo-cache
32+
# 获取 GitHub main 分支的最新提交
33+
- git pull origin main
34+
35+
# 获取 GitLab main 分支的最新提交
36+
- git fetch ${GITLAB_REPO} main:gitlab-main
37+
- DIFF=$(git diff main gitlab-main)
38+
# 比较 SHA,检查是否有更改
39+
- if [ -n "$DIFF" ]; then
40+
- echo "Differences detected, syncing to GitLab..."
41+
# 推送到 GitLab main 分支
42+
- git push "$GITLAB_REPO" "main:main"
43+
- else
44+
- echo "No differences found between GitHub and GitLab main branches."
45+
- fi
46+
# only:
47+
# - schedules
48+
cache:
49+
key: repo-cache
50+
paths:
51+
- repo-cache/
52+
53+
#build_job:
54+
# stage: build
55+
# script:
56+
# - echo "Building the project..."
57+
# only:
58+
# - main
59+
#
60+
#feishu-informer: # 飞书回调
61+
# stage: notice
62+
# variables:
63+
# DIFF_URL: "$CI_MERGE_REQUEST_PROJECT_URL/-/merge_requests/$CI_MERGE_REQUEST_IID/diffs"
64+
# rules:
65+
# - if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH =~ "main"
66+
# script:
67+
# - echo "merge request"
68+
# - |
69+
# curl -X POST -H "Content-Type: application/json" \
70+
# -d "{\"msg_type\":\"text\",\"content\":{\"text\":\"项目:${CI_PROJECT_NAME}\\n提交人:${GITLAB_USER_NAME}\\n提交信息:${CI_MERGE_REQUEST_TITLE}\\n合并分支信息:${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} -> ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}\\n差异性地址:${DIFF_URL}\\n请及时review代码\"}}" \
71+
# https://open.feishu.cn/open-apis/bot/v2/hook/1c334752-2874-41a1-8f1b-3060f2d46b6c
72+
#
73+
##builder:
74+
## stage: build
75+
## rules:
76+
## - if: $CI_COMMIT_BRANCH == "main"
77+
## script:
78+
## - set -e
79+
## - |
80+
## if [ ! -d "../artifacts" ]; then
81+
## mkdir -p ../artifacts
82+
## fi
83+
## if [ -d "../artifacts/dist" ]; then
84+
## cp -r ../artifacts/dist frontend/dist
85+
## fi
86+
## - |
87+
## if [ -n "$(git diff --name-status HEAD~1 HEAD -- frontend)" ]; then
88+
## ./scripts/build.sh $BUILD_DIR ${VERSION} all ""
89+
## else
90+
## ./scripts/build.sh $BUILD_DIR ${VERSION}
91+
## fi
92+
## if [ -d "frontend/dist" ]; then
93+
## echo "copy frontend/dist to artifacts/dist"
94+
## rm -fr ../artifacts/dist
95+
## cp -r frontend/dist ../artifacts/dist
96+
## fi
97+
## cp $BUILD_DIR/${APP_PRE}_linux_amd64.tar.gz ${SAVE_DIR}
98+
#
99+
#deployer:
100+
# stage: deploy
101+
# rules:
102+
# - if: $CI_COMMIT_BRANCH == "main"
103+
# variables:
104+
# APIPARK_GUEST_MODE: allow
105+
# APIPARK_GUEST_ID: dklejrfbhjqwdh
106+
# script:
107+
# - cd ${SAVE_DIR};mkdir -p ${APP_PRE};tar -zxvf ${APP_PRE}_linux_amd64.tar.gz -C ${APP_PRE};cd ${APP_PRE};./install.sh ${SAVE_DIR};./run.sh restart;cd ${SAVE_DIR} && ./clean.sh ${APP_PRE}
108+
# when: on_success
109+
#success:
110+
# stage: webhook
111+
# rules:
112+
# - if: $CI_COMMIT_BRANCH == "main"
113+
# script:
114+
# - |
115+
# curl -X POST -H "Content-Type: application/json" \
116+
# -d "{\"msg_type\":\"text\",\"content\":{\"text\":\"最近一次提交:${CI_COMMIT_TITLE}\\n提交人:${GITLAB_USER_NAME}\\n项目:${CI_PROJECT_NAME}\\n环境:${DEPLOY_DESC}\\n更新部署完成.\\n访问地址:${VIEW_ADDR}\\n工作流地址:${CI_PIPELINE_URL}\"}}" \
117+
# https://open.feishu.cn/open-apis/bot/v2/hook/c3672932-4dfa-4989-8023-0128bae59338
118+
# when: on_success
119+
#failure:
120+
# stage: webhook
121+
# rules:
122+
# - if: $CI_COMMIT_BRANCH == "main"
123+
# script:
124+
# - |
125+
# curl -X POST -H "Content-Type: application/json" \
126+
# -d "{\"msg_type\":\"text\",\"content\":{\"text\":\"最近一次提交:${CI_COMMIT_TITLE}\\n提交人:${GITLAB_USER_NAME}\\n项目:${CI_PROJECT_NAME}\\n环境:${DEPLOY_DESC}\\n更新部署失败,请及时到gitlab上查看\\n工作流地址:${CI_PIPELINE_URL}\"}}" \
127+
# https://open.feishu.cn/open-apis/bot/v2/hook/c3672932-4dfa-4989-8023-0128bae59338
128+
# when: on_failure

0 commit comments

Comments
 (0)