Github Actions 是Github推出的自动化CI/CD的功能,我们将使用Github Actions 让Github仓库同步到Gitee
同步的原理是利用 SSH 公私钥配对的方式拉取 Github 仓库的代码并推送到 Gitee 仓库中,所以我们需要以下几个步骤
生成 SSH 公私钥添加公钥添加私钥配置代码
1、生成SSH公钥
执行命令:ssh-keygen -t rsa -C "youremail@example.com",连续三次回车,id_rsa 为私钥,id_rsa.pub为公钥
如果提示:already exists(已经存在),则可以到电脑位置:C:\Users\电脑账号名\ .ssh 直接使用
不使用默认SSH参考:生成/添加SSH公钥
2、GitHub项目配置SSH私钥
在Github项目
Settings->Secrets->Actions,名称为:GITEE_RSA_PRIVATE_KEY,值为:上面生成SSH的 私钥,私钥是 id_rsa 文件

3、GitHub配置SSH公钥
在Github
Settings->SSH and GPG keys->New SSH key,名称为:GITEE_RSA_PUBLIC_KEY,值为:上面生成SSH的 公钥

4、Gitee配置SSH公钥
在Gitee
设置->安全设置->SSH公钥,标题为:GITEE_RSA_PUBLIC_KEY,值为:上面生成SSH的 公钥

5、GitHub创建Github workflow
在Github项目
Actions创建一个新的workflow



bash
name: Sync To Gitee
on: [ push, delete, create ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Sync to Gitee
uses: wearerequired/git-mirror-action@master
env:
# 注意在 Settings->Secrets 配置 GITEE_RSA_PRIVATE_KEY
SSH_PRIVATE_KEY: ${{ secrets.GITEE_RSA_PRIVATE_KEY }}
with:
# 注意替换为你的 GitHub 源仓库地址
source-repo: git@github.com:github-username/github-repositoryname.git
# 注意替换为你的 Gitee 目标仓库地址
destination-repo: git@gitee.com:gitee-username/gitee-repositoryname.git
成功运行
