Open Yikun opened 4 years ago
2.0已发布,现在支持github与gitee的双向同步。
请问下,如何优雅的在fork 其他人的GitHub项目代码后,能单向同步更新他人代码呢。不想因自己不小心,就pull给他人而造成困扰。谢谢~
@leopardciaw 加个upstream,然后,每次用rebase更新
git remote add upstream http://github.com/xxx/test.git
git remote update upstream
git rebase upstream/master
git push origin dev:dev
@leopardciaw 加个upstream,然后,每次用rebase更新
git remote add upstream http://github.com/xxx/test.git git remote update upstream git rebase upstream/master git push origin dev:dev
谢谢答复,我试下,不懂再来请教。
你好,可否支持 issue 的同步
@jalenchuh 暂时没有支持计划哈
@Yikun 2.0已发布,现在支持github与gitee的双向同步。
我用github做镜像仓库,用gitee做主仓库,怎么用action定时触发同步从gitee拉取到github,用你的action我没有配置好,出现错误了
2020-09-01T08:26:45.7736441Z [31m(2/3)[0m Importing... 2020-09-01T08:26:45.7822264Z load pubkey "/root/.ssh/id_rsa": invalid format 2020-09-01T08:26:45.8026664Z Warning: Permanently added 'github.com,140.82.114.3' (RSA) to the list of known hosts. 2020-09-01T08:26:46.2317529Z To github.com:codingriver/hugo-project.git 2020-09-01T08:26:46.2318579Z ! [rejected] origin/master -> master (fetch first) 2020-09-01T08:26:46.2319607Z error: failed to push some refs to 'git@github.com:codingriver/hugo-project.git'
配置: 2020-09-01T08:26:36.0366725Z ##[group]Run Yikun/hub-mirror-action@master 2020-09-01T08:26:36.0367327Z with: 2020-09-01T08:26:36.0367713Z src: gitee/codingriver 2020-09-01T08:26:36.0368027Z dst: github/codingriver 2020-09-01T08:26:36.0370476Z dst_key: ***
2020-09-01T08:26:36.0370864Z dst_token: *** 2020-09-01T08:26:36.0371173Z white_list: hugo-project 2020-09-01T08:26:36.0371486Z account_type: user 2020-09-01T08:26:36.0371994Z clone_style: https 2020-09-01T08:26:36.0372336Z cache_path: /github/workspace/hub-mirror-cache 2020-09-01T08:26:36.0372670Z force_update: false 2020-09-01T08:26:36.0372976Z debug: false 如果支持,麻烦楼主给指点下,codingriver@163.com
@codingriver https://github.com/Yikun/hub-mirror-action/issues/37 在项目里提issue哈。
看了下,主要是因为源和目的端的base不一样导致的。
对于这种,建议把force_update
设置为true,进行强制刷新。(目的端请备份)。
另外,单个项目同步建议使用static_list:
@codingriver Yikun/hub-mirror-action#37 在项目里提issue哈。
看了下,主要是因为源和目的端的base不一样导致的。
对于这种,建议把
force_update
设置为true,进行强制刷新。(目的端请备份)。 另外,单个项目同步建议使用static_list:
- white_list会先动态拿列表,然后再判断是否在list里
- static_list直接从配置取值
谢谢,自己看错了,以为rsa配置错了,留言后发现是仓库冲突,已经修复,再次感谢作者提供工具
我最近尝试了一下,发现不行了。然后去看了一眼您的鲲鹏里的运行情况,发现也是不能运行。
@classmatezhu
Please make sure you have the correct access rights
and the repository exists.
Retry 2/3 exited 128, retrying in 2 seconds...
Load key "/root/.ssh/id_rsa": invalid format
Retry 3/3 exited 128, no more retries left.
git@gitee.com: Permission denied (publickey).
Push failed
fatal: Could not read from remote repository.
Total: 1, skip: 0, successed: 0, failed: 1.
看了下,你这个问题是因为key设置的问题,请确认secrets.GITEE_PRIVATE_KEY
已经配置到了gitee侧的账户。鲲鹏目前无问题哦,显示失败是因为部分库为空导致的同步失败。
使用master版本,ssh方式,gh-->gitee正常,gitee-->gh(调换src, dst)失败:
(1/3) Downloading...
Updating repo...
(2/3) Creating...
binocular_vision repo exist, skip creating...
(3/3) Force pushing...
Remote exsits, re-create: set github to git@github.com:numajinfei/binocular_vision.git
(3/3) Force pushing...
Remote exsits, re-create: set github to git@github.com:numajinfei/binocular_vision.git
(3/3) Force pushing...
Cmd('git') failed due to: exit code(128)
cmdline: git push -f github refs/remotes/origin/*:refs/heads/* --tags --prune
stderr: 'Warning: Permanently added the ECDSA host key for IP address '192.30.255.112' to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.'
也有报错如下:
(1/3) Downloading...
Updating repo...
(2/3) Creating...
binocular_vision repo exist, skip creating...
(3/3) Force pushing...
Remote exsits, re-create: set github to git@github.com:numajinfei/binocular_vision.git
(3/3) Force pushing...
Remote exsits, re-create: set github to git@github.com:numajinfei/binocular_vision.git
(3/3) Force pushing...
Cmd('git') failed due to: exit code(128)
cmdline: git push -f github refs/remotes/origin/*:refs/heads/* --tags --prune
stderr: 'git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.'
Total: 1, skip: 0, successed: 0, failed: 1.
Failed: ['binocular_vision']
+ exit 1
@numajinfei 调换顺序以后,token和key也要刷新为新的目的仓的配置。
@Yikun @numajinfei 调换顺序以后,token和key也要刷新为新的目的仓的配置。
gh--repo---secrets下新增了gh token, 而key具体怎么配置? 之前生成的是无密码的,现在需要gitee-->gh 同步的话,gh secrets端是存放pub key? 如gh配置private key,则workflow文件只需变化 token就行,gitee端只有pub key可配置项;只修改token的话,依然出现上述错误
@numajinfei
dst_key
用于在目的端上传代码的私钥(默认可以从~/.ssh/id_rsa获取),可参考生成/添加SSH公钥或generating SSH keys生成,并确认对应公钥已经被正确配置在目的端。对应公钥,Github可以在这里配置,Gitee可以这里配置。dst_token
创建仓库的API tokens, 用于自动创建不存在的仓库,Github可以在这里找到,Gitee可以在这里找到。@Yikun @classmatezhu
Please make sure you have the correct access rights and the repository exists. Retry 2/3 exited 128, retrying in 2 seconds... Load key "/root/.ssh/id_rsa": invalid format Retry 3/3 exited 128, no more retries left. git@gitee.com: Permission denied (publickey). Push failed fatal: Could not read from remote repository. Total: 1, skip: 0, successed: 0, failed: 1.
看了下,你这个问题是因为key设置的问题,请确认
secrets.GITEE_PRIVATE_KEY
已经配置到了gitee侧的账户。鲲鹏目前无问题哦,显示失败是因为部分库为空导致的同步失败。
万分感谢
1. 背景
在开源贡献的代码托管的过程中,我们有时候有需要将Github的代码同步到其他远端仓库的需求。具体的,对于我们目前参与的项目来说核心诉求是:以Github社区作为主仓,并且定期自动同步到Gitee作为镜像仓库。
2. 调研
结论1: 由于会被Github屏蔽,Gitee的自动同步功能暂时无法支持。 这个问题在Gitee的官方反馈中,建议github导入的项目能设置定时同步提及过,官方的明确答复是不支持。最近又再次和官方渠道求证,由于会被Github屏蔽的关系,这个功能不会被支持。本着有轮子用轮子,没轮子造轮子的原则,我们只能选择自己实现。
结论2: 靠手动同步存在时效问题,可能会造成部分commit的丢失。 Gitee本身是提供了手动同步功能的,也算比较好用,但是想想看,如果一个组织下面,发展到有几百上千个项目后,这种机制显然无法解决问题了。因此,我们需要某种计算资源去自动的完成同步。
结论3: 目前我们开源的好几个项目(例如Mindspore, OpenGauss, Kunpeng)都有类似的需求。 作为一个合格的程序员,为了守住DRY(don't repeat yourself,不造重复的轮子)的原则,所以,我们需要实现一个工具,同步简单的配置就可以完成多个项目的同步。
最终结论:我们需要自己实现一个工具,通过某种计算资源自动的去完成周期同步功能。
3. 选型
其实调研结论有了后,我们面对的选型就那么几种:
PS:严格来讲,Github Action其实是第二种选择的子集,其实就是单纯的想体验一把,并且把我们的业务需求实现了。
4. 实现
4.1 Github Action的实现
Github Action提供了2种方式去实现Action:
Docker container. 这种方式相当于在Github提供的计算资源起个container,在container里面把功能实现。具体的原理大致如下:
JavaScript. 这种方式相当于在Github提供的计算资源上,直接用JS脚本去实现功能。
作为以后端开发为主的我们,没太多纠结就选择了第一种类型。关于怎么构建一个Github的Action可以参考Github的官方文档Building actions。官方文档真的写的非常详细了,并且也通了了hello-world级别的入门教程。
4.1 同步的核心代码实现
而最终的关键实现就是,我们需要定义这个容器运行的脚本,原理很简单: 大致就是以上4步:
关心细节的同学,具体可以参考代码:https://github.com/Yikun/gitee-mirror-action/blob/master/entrypoint.sh
5. 怎么用呢?
举了个简单的例子,我们想将Github/kunpengcompute同步到Gitee/kunpengcompute上面,需要做的非常简单,只需要2步:
可以参考官方指引
可以参考鲲鹏库的实现。
上图,大概是每个阶段的原理和最终的效果。现在,这个使用Gitee Mirror Action的workflow已经运行起来了,可以在链接看到。
6. 最后
好啦,这篇硬核软文就写到这里,有同步需求的同学,放心使用。更多用法,可以参考Hub-mirror-action的主页Readme。
Github Action 官方链接:https://github.com/marketplace/actions/hub-mirror-action 代码仓库:https://github.com/Yikun/hub-mirror-action
有任何问题或者疑问,希望可以和大家一起改进这个Action,有问题可以直接提Issue或者PR,不用客气。