TIPS之 repos-mirror-action github action实现不同仓库代码同步

repos-mirror-action github action实现不同仓库代码同步

Posted by 董江 on Sunday, June 25, 2023

repos-mirror-action github action实现不同仓库代码同步

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

背景

在开源贡献的代码托管的过程中,我们有时候有需要将Github的代码同步到其他远端仓库的需求。具体的,对于我们目前参与的项目来说核心诉求是:以Github社区作为主仓,并且定期自动同步到Gitee作为镜像仓库。

github action: https://github.com/marketplace/actions/repo-mirror-sync

实现

  • 将其他公共或私有存储库(例如模板存储库)与当前存储库同步
  • 支持不同的 git 提供商,如 GitLab、Gittea…作为源(使用 https)。
  • 源存储库和目标存储库不一定需要具有相同的基本历史记录。

因此,可以借助该操作合并两个不同的存储库。

用法

模板库

name: <action-name>

on: 
  - push
  - delete

jobs:
  sync:
    runs-on: ubuntu-latest
    name: Repo Mirror Sync
    steps:
    - uses: actions/checkout@v3
    - name: Repo Mirror Sync
      uses: kubeservice-stack/repos-mirror-action@<latest version>
      with:
        # Such as https://github.com/dongjiang1989/mirror-action.git
        target-url: <target-url>
        # Such as dongjiang1989
        target-username: <target-username>
        # You can store token in your project's 'Setting > Secrets' and reference the name here. Such as ${{ secrets.ACCESS_TOKEN }}
        target-token: <target-token>

配置参数

Variable Description Required [Default]
target-token 回购协议的令牌。可以兑换使用${{ secrets.GITHUB_TOKEN } true
target-username 存储库用户名 true
target-url https协议的目标 URL true
  • target-token 用于创建不存在的repo的API,您可以在这里获取Github令牌,在这里获取Gitee.

其他:代码工程

「如果这篇文章对你有用,请随意打赏」

Kubeservice博客

如果这篇文章对你有用,请随意打赏

使用微信扫描二维码完成支付