File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed
Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ workflow :
2+ rules :
3+ - if : $CI_PIPELINE_SOURCE == "schedule"
4+ when : always
5+ - if : $CI_PIPELINE_SOURCE == "web"
6+ when : always
7+ - if : $CI_PIPELINE_SOURCE == "api"
8+ when : always
9+ - if : $CI_PIPELINE_SOURCE == "merge_request_event"
10+ when : always
11+ - if : $CI_PIPELINE_SOURCE == "push"
12+ when : always
13+ - when : never
14+
15+ stages :
16+ - sync_to_github
17+
18+ variables :
19+ GIT_SUBMODULE_STRATEGY : recursive
20+
21+ sync_to_github :
22+ stage : sync_to_github
23+ image : $CI_DOCKER_BASE_REGISTRY:latest
24+ tags :
25+ - docker
26+ variables :
27+ GIT_SUBMODULE_STRATEGY : recursive
28+ before_script :
29+ # 启动SSH Agent
30+ - eval $(ssh-agent -s)
31+ # 添加SSH私钥(base64编码格式)
32+ - echo "$GITHUB_DEPLOY_KEY" | base64 -d | tr -d '\r' | ssh-add -
33+ # 创建SSH目录并配置
34+ - mkdir -p ~/.ssh
35+ - chmod 700 ~/.ssh
36+ # 添加GitHub到known_hosts
37+ - ssh-keyscan github.com >> ~/.ssh/known_hosts
38+ # 配置Git用户信息
39+ - git config --global user.name "$GIT_CI_USER_NAME"
40+ - git config --global user.email "$GIT_CI_USER_EMAIL"
41+ script :
42+ - |
43+ git remote add github git@github.com:${GITHUB_REPO}.git || git remote set-url github git@github.com:${GITHUB_REPO}.git
44+
45+ export CURRENT_BRANCH=${CI_COMMIT_REF_NAME}
46+ echo "Current branch: $CURRENT_BRANCH"
47+
48+ echo "Fetching remote repository info..."
49+ git fetch github
50+
51+ echo "Starting sync to GitHub..."
52+ git push github "HEAD:$CURRENT_BRANCH" --force-with-lease
53+
54+ # 如果是主分支,同时推送标签
55+ if [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "master" ]; then
56+ echo "Pushing tags to GitHub..."
57+ git push github --tags
58+ fi
59+ rules :
60+ - if : ' $CI_PIPELINE_SOURCE == "schedule" && $SYNC_GITHUB'
61+ when : always
62+ - if : ' $CI_PIPELINE_SOURCE == "web" && $SYNC_GITHUB'
63+ when : always
64+ - when : never
You can’t perform that action at this time.
0 commit comments