-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (65 loc) · 2.33 KB
/
sync.yml
File metadata and controls
78 lines (65 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 这个文件应该放在外部仓库的 .github/workflows/ 目录下
name: Reusable Sync to Gitee Workflow
on:
workflow_call:
inputs:
target_branch:
description: '目标分支名称'
required: true
type: string
repository_name:
description: '仓库名称 (格式: owner/repo)'
required: true
type: string
jobs:
sync-to-gitee:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0 # 获取所有提交历史
- name: Set up Git user
run: |
git config --global user.email "${{ vars.GIT_USER_EMAIL }}"
git config --global user.name "${{ vars.GIT_USER_NAME }}"
- name: Set SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.GITEE_ID_RSA }}" >> ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
eval $(ssh-agent -s) && ssh-add ~/.ssh/id_rsa
# 信任域名
ssh-keyscan -H ${{ vars.GITEE_DOMAIN_URL }} >> ~/.ssh/known_hosts
- name: Check current branch
run: echo "当前分支:${{ inputs.target_branch }} ${{ inputs.repository_name }}"
- name: Echo git url
run: echo "git@${{ vars.GITEE_DOMAIN_URL }}:${{ inputs.repository_name }}.git"
- name: Add remote url
run: git remote add mirror "git@${{ vars.GITEE_DOMAIN_URL }}:${{ inputs.repository_name }}.git"
- name: Fetch
run: git fetch --prune mirror --tags --verbose
- name: Pull and push
run: |
if [ "${{ inputs.target_branch }}" ]; then
git checkout ${{ inputs.target_branch }}
git push -f mirror ${{ inputs.target_branch }}
git push -f mirror --tags --verbose
fi
sync-to-cnb:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0 # 获取所有提交历史
- name: Sync to CNB Repository
uses: docker://tencentcom/git-sync
env:
PLUGIN_TARGET_URL: "https://cnb.cool/${{ inputs.repository_name }}.git"
PLUGIN_AUTH_TYPE: "https"
PLUGIN_USERNAME: "cnb"
PLUGIN_PASSWORD: ${{ secrets.CNB_TOKEN }}
PLUGIN_FORCE: "true"
PLUGIN_SYNC_MODE: "rebase"
PLUGIN_PUSH_TAGS: "true"