Skip to content

Commit a5639bf

Browse files
author
刘健
committed
Update .gitlab-ci.yml file
1 parent 1d66ed8 commit a5639bf

1 file changed

Lines changed: 20 additions & 23 deletions

File tree

.gitlab-ci.yml

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,26 @@ stages:
2121
sync_job:
2222
stage: sync
2323
script:
24-
- echo https://$GITHUB_USER:$GITHUB_TOKEN@$GITHUB_REPO
25-
- echo $CI_REPOSITORY_URL
26-
# # 检查是否已有仓库缓存,若无则克隆
27-
# - if [ ! -d "repo-cache" ]; then
28-
# - git clone --mirror https://$GITHUB_USER:$GITHUB_TOKEN@$GITHUB_REPO repo-cache
29-
# - fi
30-
# - cd repo-cache
31-
# # 获取 GitHub main 分支的最新提交
32-
# - git fetch origin
33-
# - GITHUB_SHA=$(git rev-parse origin/main)
34-
# # 获取 GitLab main 分支的最新提交
35-
## - git remote add gitlab http://$DEPLOY_USER:$DEPLOY_TOKEN@$
36-
# - git remote add gitlab $CI_REPOSITORY_URL
37-
# - git fetch gitlab
38-
# - GITLAB_SHA=$(git rev-parse gitlab/main || echo "none")
39-
# # 比较 SHA,检查是否有更改
40-
# - if [ "$GITHUB_SHA" != "$GITLAB_SHA" ]; then
41-
# - echo "Changes detected, syncing main branch..."
42-
# - git push gitlab refs/remotes/origin/main:refs/heads/main
43-
# - else
44-
# - echo "No changes in main branch, skipping sync."
45-
# - exit 0
46-
# - fi
24+
# 检查是否已有仓库缓存,若无则克隆
25+
- if [ ! -d "repo-cache" ]; then
26+
- git clone https://$GITHUB_USER:$GITHUB_TOKEN@$GITHUB_REPO repo-cache
27+
- fi
28+
- cd repo-cache
29+
# 获取 GitHub main 分支的最新提交
30+
- git fetch origin
31+
- GITHUB_SHA=$(git rev-parse origin/main)
32+
# 获取 GitLab main 分支的最新提交
33+
- git remote add gitlab $CI_REPOSITORY_URL
34+
- git fetch gitlab
35+
- GITLAB_SHA=$(git rev-parse gitlab/main || echo "none")
36+
# 比较 SHA,检查是否有更改
37+
- if [ "$GITHUB_SHA" != "$GITLAB_SHA" ]; then
38+
- echo "Changes detected, syncing main branch..."
39+
- git push gitlab refs/remotes/origin/main:refs/heads/main
40+
- else
41+
- echo "No changes in main branch, skipping sync."
42+
- exit 0
43+
- fi
4744
# only:
4845
# - schedules
4946
variables:

0 commit comments

Comments
 (0)