Skip to content

Commit 7b78e1b

Browse files
committed
ci: 添加同步到Gitee的GitHub Actions工作流
添加新的工作流文件用于将GitHub仓库同步到Gitee,包括设置SSH密钥、添加远程仓库以及推送分支和标签
1 parent 7ed6c74 commit 7b78e1b

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

.github/workflows/sync.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Sync Github To Image
2+
3+
on:
4+
push:
5+
branches: [main]
6+
#schedule:
7+
# 定时任务,每天 UTC 时间 0 点运行
8+
#- cron: "0 0 * * *"
9+
workflow_dispatch:
10+
11+
jobs:
12+
sync-gitee:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0 # 为了 git pull --unshallow,我们需要获取所有的提交历史
20+
21+
- name: Set up Git user
22+
run: |
23+
git config --global user.email "wangfj11@foxmail.com"
24+
git config --global user.name "AlianBlank"
25+
26+
- name: Set SSH
27+
run: |
28+
mkdir -p ~/.ssh
29+
echo "${{ secrets.GITEE_ID_RSA }}" >> ~/.ssh/id_rsa
30+
chmod 600 ~/.ssh/id_rsa
31+
eval $(ssh-agent -s) && ssh-add ~/.ssh/id_rsa
32+
# 信任域名
33+
ssh-keyscan -H gitee.com >> ~/.ssh/known_hosts
34+
# 查看当前分支
35+
- name: Check current branch
36+
run: echo 当前分支:${{ github.ref_name }} ${{ github.Repository }}
37+
# 查看远端 地址
38+
- name: echo git url
39+
run: echo git@gitee.com:${{ github.Repository }}.git
40+
41+
# 添加远端
42+
- name: add remote url
43+
run: git remote add mirror "git@gitee.com:${{ github.Repository }}.git"
44+
45+
# 获取
46+
- name: fetch
47+
run: git fetch --prune mirror --tags --verbose
48+
49+
# 拉取和推送
50+
- name: pull and push
51+
run: |
52+
if [ "${{ github.ref_name }}" ]; then
53+
git checkout ${{ github.ref_name }}
54+
git push -f mirror ${{ github.ref_name }}
55+
git push -f mirror --tags --verbose
56+
fi

0 commit comments

Comments
 (0)