仓库地址
github仓库:https://github.com/nuptaxin/jenkins-hello 目标gitee仓库(无需手动创建):https://gitee.com/nuptaxin/jenkins-hello
设置dst_key
首先在本地生成一个ssh密钥对
renzhengxin@renzhenxindeMBP ~ % ssh-keygen -t rsa -f ~/Documents/dst_id_rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/renzhengxin/Documents/dst_id_rsa
Your public key has been saved in /Users/renzhengxin/Documents/dst_id_rsa.pub
The key fingerprint is:
SHA256:21rVVMK/wQ4jTPbHqHldkhf4ZoQhoCa7DrcPlt/lX2g renzhengxin@renzhenxindeMBP
The key's randomart image is:
+---[RSA 3072]----+
| ... o= .|
| . o.o.= |
| . o + . Bo.|
| + o BoO+|
| . S = Xo+|
| o o + ..+ |
| . * . o..E . |
| = + .oo . . |
| o.o.. ... |
+----[SHA256]-----+
在github打开Settings ->Secrets ->Actions ->New Repository secret ,新建一个secret 名为GITEE_PRIVATE_KEY,值为上面生成的密钥对的私钥(文件:/Users/renzhengxin/Documents/dst_id_rsa) 然后登录到gitee,在设置 ->安全设置 ->SSH公钥 中添加上面生成的密钥对的公钥(文件:/Users/renzhengxin/Documents/dst_id_rsa.pub),标题随意,此处标题使用了GITEE_PUBLIC_KEY
设置dst_token
在gitee打开设置 ->安全设置 ->私人令牌 ->生成新令牌 命名随意,此处命名为gitee-token
复制生成的令牌值 在github打开Settings ->Secrets ->Actions ->New repository secret 名为GITEE_TOKEN,值为上面复制的令牌值 github的secrets:
github同步到gitee
在刚才的GitHub仓库中,新建 .github/workflows/SyncToGitee.yml 文件,其中.github/workflows/ 是固定的目录名
name: Sync Github Repos To Gitee
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Sync Github Repos To Gitee
uses: Yikun/hub-mirror-action@v1.1
with:
src: github/nuptaxin
dst: gitee/nuptaxin
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
account_type: user
clone_style: "https"
debug: true
force_update: true
static_list: "jenkins-hello"
timeout: '600s'
提交该action,观察github上的执行视图 点击该action,可以查看执行状态及执行日志 gitee上查看jenkins-hello创建成功并同步
参考文档
利用Github Action实现Github到Gitee的持续同步
|