Giter Site home page Giter Site logo

gitter-badger / hub-mirror-action Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yikun/hub-mirror-action

0.0 0.0 0.0 77 KB

一个Github Action,用于在Github和Gitee之间同步代码。Action for mirroring repos between Hubs (like Github and Gitee).

License: MIT License

Dockerfile 2.63% Shell 97.37%

hub-mirror-action's Introduction

Hub Mirror Action

简体中文 | English

一个用于在hub间(例如Github,Gitee)账户代码仓库同步的action

用法

steps:
- name: Mirror the Github organization repos to Gitee.
  uses: Yikun/hub-mirror-action@master
  with:
    src: github/kunpengcompute
    dst: gitee/kunpengcompute
    dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
    dst_token: ${{ secrets.GITEE_TOKEN }}
    account_type: org

上面的配置完成了kunpencompute组织从github到gitee的同步,你可以在测试和demo找到完整用法。

谁在使用?

参数详解

必选参数

  • src 需要被同步的源端账户名,如github/kunpengcompute,表示Github的kunpengcompute账户。
  • dst 需要同步到的目的端账户名,如gitee/kunpengcompute,表示Gitee的kunpengcompute账户。
  • dst_key 用于在目的端上传代码的私钥(默认可以从~/.ssh/id_rsa获取),可参考生成/添加SSH公钥generating SSH keys生成,并确认对应公钥已经被正确配置在目的端。对应公钥,Github可以在这里配置,Gitee可以这里配置。
  • dst_token 创建仓库的API tokens, 用于自动创建不存在的仓库,Github可以在这里找到,Gitee可以在这里找到。

可选参数

  • account_type 默认为user,源和目的的账户类型,可以设置为org(组织)或者user(用户),目前仅支持同类型账户(即组织到组织,或用户到用户)的同步。
  • clone_style 默认为https,可以设置为ssh或者https。
  • cache_path 默认为'', 将代码缓存在指定目录,用于与actions/cache配合以加速镜像过程。
  • black_list 默认为'', 配置后,黑名单中的repos将不会被同步,如“repo1,repo2,repo3”。
  • white_list 默认为'', 配置后,仅同步白名单中的repos,如“repo1,repo2,repo3”。
  • static_list 默认为'', 配置后,仅同步静态列表,不会再动态获取需同步列表(黑白名单机制依旧生效),如“repo1,repo2,repo3”。
  • force_update 默认为false, 配置后,启用git push -f强制同步,注意:开启后,会强制覆盖目的端仓库
  • debug 默认为false, 配置后,启用debug开关,会显示所有执行命令。

举些例子

组织同步

同步Github的kunpengcompute组织到Gitee

- name: Organization mirror
  uses: Yikun/hub-mirror-action@master
  with:
    src: github/kunpengcompute
    dst: gitee/kunpengcompute
    dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
    dst_token: ${{ secrets.GITEE_TOKEN }}
    account_type: org

黑/白名单

动态获取原端github/Yikun的repos,但仅同步名为hub-mirror-action,不同步hashes这个repo到Gittee

- name: Single repo mirror
  uses: Yikun/hub-mirror-action@master
  with:
    src: github/Yikun
    dst: gitee/yikunkero
    dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
    dst_token: ${{ secrets.GITEE_TOKEN }}
    white_list: "hub-mirror-action"
    black_list: "hashes"

静态名单(可用于单一仓库同步)

不会动态获取原端github/Yikun的repos,仅同步hub-mirror-action这个repo

- name: Black list
  uses: Yikun/hub-mirror-action@master
  with:
    src: github/Yikun
    dst: gitee/yikunkero
    dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
    dst_token: ${{ secrets.GITEE_TOKEN }}
    static_list: "hub-mirror-action"

clone方式

使用ssh方式进行clone

- name: ssh clone style
  uses: Yikun/hub-mirror-action@master
  with:
    src: github/Yikun
    dst: gitee/yikunkero
    dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
    dst_token: ${{ secrets.GITEE_TOKEN }}
    clone_style: "ssh"

指定目录cache

- name: Mirror with specific cache
  uses: Yikun/hub-mirror-action@master
  with:
    src: github/Yikun
    dst: gitee/yikunkero
    dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
    dst_token: ${{ secrets.GITEE_TOKEN }}
    cache_path: /github/workspace/hub-mirror-cache

强制更新,并打开debug日志开关

- name: Mirror with force push (git push -f)
  uses: Yikun/hub-mirror-action@master
  with:
    src: github/Yikun
    dst: gitee/yikunkero
    dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
    dst_token: ${{ secrets.GITEE_TOKEN }}
    force_update: true
    debug: true

设置命令行超时时间为1小时

- name: Mirror with force push (git push -f)
  uses: Yikun/hub-mirror-action@master
  with:
    src: github/Yikun
    dst: gitee/yikunkero
    dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
    dst_token: ${{ secrets.GITEE_TOKEN }}
    force_update: true
    timeout: '1h'

FAQ

  • 如何在secrets添加dst_token和dst_key? 下面是添加secrets的方法,也可以参考secrets官方文档了解更多:
    1. 获取Token和Key,分别获取ssh keytoken
    2. 增加Secrets配置,在配置仓库的Setting-Secrets中新增Secrets,例如GITEE_PRIVATE_KEY、GITEE_TOKEN
    3. 在Workflow中引用, 可以用过类似${{ secrets.GITEE_PRIVATE_KEY }}来访问

参考

最后

如果觉得不错,来个star支持下作者吧!你的Star是我更新代码的动力!:)

想任何想吐槽或者建议的都可以直接飞个issue.

hub-mirror-action's People

Contributors

ouuan avatar yi-xu-0100 avatar yikun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.