Skip to content

Commit e2e9abe

Browse files
committed
update gitlab-ci.yml
1 parent 0fcc221 commit e2e9abe

File tree

1 file changed

+7
-43
lines changed

1 file changed

+7
-43
lines changed

.gitlab-ci.yml

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,66 +10,30 @@ variables:
1010
VIEW_ADDR: http://172.18.166.219:8288
1111
SAVE_DIR: /opt/${APP}
1212
NODE_OPTIONS: --max_old_space_size=8192
13-
SKIP: "true"
1413

1514
stages:
16-
- sync
1715
- notice
1816
- build
1917
- deploy
2018
- webhook
2119

22-
sync_job:
23-
stage: sync
24-
variables:
25-
GITLAB_REPO: http://$DEPLOY_USER:$DEPLOY_TOKEN@gitlab.eolink.com/apipark/APIPark
26-
GIT_STRATEGY: none # 避免 CI 克隆 GitLab 仓库
27-
script:
28-
# 检查是否已有仓库缓存,若无则克隆
29-
- if [ ! -d "repo-cache" ]; then
30-
- git clone https://$GITHUB_USER:$GITHUB_TOKEN@$GITHUB_REPO repo-cache
31-
- fi
32-
- cd repo-cache
33-
# 获取 GitHub main 分支的最新提交
34-
- git pull origin main
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-
- SKIP=false
44-
- else
45-
- echo "No differences found between GitHub and GitLab main branches."
46-
- fi
47-
# only:
48-
# - schedules
49-
cache:
50-
key: repo-cache
51-
paths:
52-
- repo-cache/
53-
5420
feishu-informer: # 飞书回调
5521
stage: notice
5622
variables:
5723
DIFF_URL: "$CI_MERGE_REQUEST_PROJECT_URL/-/merge_requests/$CI_MERGE_REQUEST_IID/diffs"
5824
rules:
59-
- if: $SKIP == "false"
60-
# rules:
61-
# - if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH =~ "main"
25+
- if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH =~ "main"
6226
script:
6327
- echo "merge request"
6428
- |
6529
curl -X POST -H "Content-Type: application/json" \
6630
-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代码\"}}" \
67-
https://open.feishu.cn/open-apis/bot/v2/hook/1c334752-2874-41a1-8f1b-3060f2d46b6c
31+
${FEISHU_WEBHOOK}
6832
6933
builder:
7034
stage: build
7135
rules:
72-
- if: $SKIP == "false"
36+
- if: $CI_COMMIT_BRANCH == "main"
7337
script:
7438
- set -e
7539
- |
@@ -95,7 +59,7 @@ builder:
9559
deployer:
9660
stage: deploy
9761
rules:
98-
- if: $SKIP == "false"
62+
- if: $CI_COMMIT_BRANCH == "main"
9963
variables:
10064
APIPARK_GUEST_MODE: allow
10165
APIPARK_GUEST_ID: dklejrfbhjqwdh
@@ -110,15 +74,15 @@ success:
11074
- |
11175
curl -X POST -H "Content-Type: application/json" \
11276
-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}\"}}" \
113-
https://open.feishu.cn/open-apis/bot/v2/hook/c3672932-4dfa-4989-8023-0128bae59338
77+
${FEISHU_WEBHOOK}
11478
when: on_success
11579
failure:
11680
stage: webhook
11781
rules:
118-
- if: $SKIP == "false"
82+
- if: $CI_COMMIT_BRANCH == "main"
11983
script:
12084
- |
12185
curl -X POST -H "Content-Type: application/json" \
12286
-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}\"}}" \
123-
https://open.feishu.cn/open-apis/bot/v2/hook/c3672932-4dfa-4989-8023-0128bae59338
87+
${FEISHU_WEBHOOK}
12488
when: on_failure

0 commit comments

Comments
 (0)