Skip to content

Commit dd16f13

Browse files
committed
[int][chore][ci] Automatically sync GitHub
Project: Bluetooth redmine: #id, REDMINE-id ext-redmine: bug|feat#id [Description in detail] Affected branch: [master] Change-Id: Ic3fbd22dfa9a59882c5da5861eb0fb1da16741d8
1 parent 7207d6a commit dd16f13

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

.gitlab-ci.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

0 commit comments

Comments
 (0)