mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-12 18:11:34 +08:00
132 lines
4.7 KiB
YAML
132 lines
4.7 KiB
YAML
variables:
|
|
PATH: /opt/go-1.23/go/bin/:/opt/node-1.22/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
|
|
GOROOT: /opt/go-1.23/go
|
|
GOPROXY: https://goproxy.cn
|
|
VERSION: $CI_COMMIT_SHORT_SHA
|
|
APP: apipark
|
|
APP_PRE: ${APP}_${VERSION}
|
|
BUILD_DIR: ${APP}-build
|
|
DEPLOY_DESC: "DEV 环境"
|
|
VIEW_ADDR: http://172.18.166.219:8288
|
|
SAVE_DIR: /opt/${APP}
|
|
NODE_OPTIONS: --max_old_space_size=8192
|
|
|
|
stages:
|
|
- sync
|
|
# - notice
|
|
# - build
|
|
# - deploy
|
|
# - webhook
|
|
|
|
sync_job:
|
|
stage: sync
|
|
script:
|
|
# 检查是否已有仓库缓存,若无则克隆
|
|
- if [ ! -d "repo-cache" ]; then
|
|
- git clone https://$GITHUB_USER:$GITHUB_TOKEN@$GITHUB_REPO repo-cache
|
|
- fi
|
|
- cd repo-cache
|
|
# 获取 GitHub main 分支的最新提交
|
|
- git fetch origin
|
|
- GITHUB_SHA=$(git rev-parse origin/main)
|
|
- echo http://$DEPLOY_USER:$DEPLOY_TOKEN@gitlab.eolink.com/apipark/APIPark
|
|
# 获取 GitLab main 分支的最新提交
|
|
- git remote remove gitlab
|
|
- git remote add gitlab http://$DEPLOY_USER:$DEPLOY_TOKEN@gitlab.eolink.com/apipark/APIPark
|
|
# - git remote add gitlab $CI_REPOSITORY_URL
|
|
- git fetch gitlab
|
|
- GITLAB_SHA=$(git rev-parse gitlab/main || echo "none")
|
|
# 比较 SHA,检查是否有更改
|
|
- if [ "$GITHUB_SHA" != "$GITLAB_SHA" ]; then
|
|
- echo "Changes detected, syncing main branch..."
|
|
- git push gitlab refs/remotes/origin/main:refs/heads/main
|
|
- else
|
|
- echo "No changes in main branch, skipping sync."
|
|
- exit 0
|
|
- fi
|
|
# only:
|
|
# - schedules
|
|
variables:
|
|
GIT_STRATEGY: none # 避免 CI 克隆 GitLab 仓库
|
|
cache:
|
|
key: repo-cache
|
|
paths:
|
|
- repo-cache/
|
|
|
|
#build_job:
|
|
# stage: build
|
|
# script:
|
|
# - echo "Building the project..."
|
|
# only:
|
|
# - main
|
|
#
|
|
#feishu-informer: # 飞书回调
|
|
# stage: notice
|
|
# variables:
|
|
# DIFF_URL: "$CI_MERGE_REQUEST_PROJECT_URL/-/merge_requests/$CI_MERGE_REQUEST_IID/diffs"
|
|
# rules:
|
|
# - if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH =~ "main"
|
|
# script:
|
|
# - echo "merge request"
|
|
# - |
|
|
# curl -X POST -H "Content-Type: application/json" \
|
|
# -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代码\"}}" \
|
|
# https://open.feishu.cn/open-apis/bot/v2/hook/1c334752-2874-41a1-8f1b-3060f2d46b6c
|
|
#
|
|
##builder:
|
|
## stage: build
|
|
## rules:
|
|
## - if: $CI_COMMIT_BRANCH == "main"
|
|
## script:
|
|
## - set -e
|
|
## - |
|
|
## if [ ! -d "../artifacts" ]; then
|
|
## mkdir -p ../artifacts
|
|
## fi
|
|
## if [ -d "../artifacts/dist" ]; then
|
|
## cp -r ../artifacts/dist frontend/dist
|
|
## fi
|
|
## - |
|
|
## if [ -n "$(git diff --name-status HEAD~1 HEAD -- frontend)" ]; then
|
|
## ./scripts/build.sh $BUILD_DIR ${VERSION} all ""
|
|
## else
|
|
## ./scripts/build.sh $BUILD_DIR ${VERSION}
|
|
## fi
|
|
## if [ -d "frontend/dist" ]; then
|
|
## echo "copy frontend/dist to artifacts/dist"
|
|
## rm -fr ../artifacts/dist
|
|
## cp -r frontend/dist ../artifacts/dist
|
|
## fi
|
|
## cp $BUILD_DIR/${APP_PRE}_linux_amd64.tar.gz ${SAVE_DIR}
|
|
#
|
|
#deployer:
|
|
# stage: deploy
|
|
# rules:
|
|
# - if: $CI_COMMIT_BRANCH == "main"
|
|
# variables:
|
|
# APIPARK_GUEST_MODE: allow
|
|
# APIPARK_GUEST_ID: dklejrfbhjqwdh
|
|
# script:
|
|
# - 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}
|
|
# when: on_success
|
|
#success:
|
|
# stage: webhook
|
|
# rules:
|
|
# - if: $CI_COMMIT_BRANCH == "main"
|
|
# script:
|
|
# - |
|
|
# curl -X POST -H "Content-Type: application/json" \
|
|
# -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}\"}}" \
|
|
# https://open.feishu.cn/open-apis/bot/v2/hook/c3672932-4dfa-4989-8023-0128bae59338
|
|
# when: on_success
|
|
#failure:
|
|
# stage: webhook
|
|
# rules:
|
|
# - if: $CI_COMMIT_BRANCH == "main"
|
|
# script:
|
|
# - |
|
|
# curl -X POST -H "Content-Type: application/json" \
|
|
# -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}\"}}" \
|
|
# https://open.feishu.cn/open-apis/bot/v2/hook/c3672932-4dfa-4989-8023-0128bae59338
|
|
# when: on_failure
|