Skip to content

Commit d6952f0

Browse files
committed
ci: 添加同步到Gitee的GitHub Actions工作流
1 parent 0b65f17 commit d6952f0

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

.github/workflows/sync.yml

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

0 commit comments

Comments
 (0)