简体中文 | English
Forge Mirror 是一个用于在 GitHub、Gitee、GitLab、GitCode 以及通用 Git 服务之间同步仓库的自动化工具。
开源地址:https://github.com/OpenSiFli/forge-mirror
本项目是 https://github.com/Yikun/hub-mirror-action/ 的 fork 后继产品。
- 我们继承了上游项目的核心能力与使用习惯。
- 在此基础上,持续推进参数体系重构、配置结构化(YAML)、可维护性和测试覆盖。
- 文档中提到的 v2 参数与行为,以本仓库的
action.yml和源码实现为准。
steps:
- name: Mirror GitHub org to Gitee org
uses: OpenSiFli/forge-mirror@v2
with:
src_platform: github
src_account: kunpengcompute
dst_platform: gitee
dst_account: kunpengcompute
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
src_account_type: org
dst_account_type: org必填:
src_accountdst_platformdst_accountdst_token
常用可选:
src_platform(默认github)src_key(src_transport=ssh时必填)dst_key(dst_transport=ssh时必填)src_token(用于源端 API 认证,提升私有仓库可见性与 API 限额)src_account_type/dst_account_type(默认user)src_endpoint/dst_endpoint(代码仓库地址,SSH/HTTPS clone 与 push 使用)src_api_endpoint/dst_api_endpoint(API 地址;配置后将覆盖对应平台 API 请求地址)src_transport(默认https)dst_transport(默认ssh)src_ssh_user(源端 SSH 用户名,默认git)dst_ssh_user(目标端 SSH 用户名,默认git)repos(YAML 仓库配置,详见下文)push_strategy(safe/force/no)log_level(DEBUG/INFO/WARNING/ERROR)timeout(如30m)api_timeout(如60、2m)cache_pathlfsdst_visibility(auto/public/private)
完整定义请参考 action.yml。
当 SSH 和 API 地址(或端口)不同,可分开配置:
with:
dst_platform: gitlab
dst_account: sifli
dst_transport: ssh
dst_endpoint: gitlab.sifli.com:8218
dst_api_endpoint: gitlab.sifli.com
dst_key: ${{ secrets.GITLAB_SSH_KEY }}
dst_token: ${{ secrets.GITLAB_TOKEN }}说明:
dst_endpoint用于 git clone/push(SSH/HTTPS 仓库 URL)dst_api_endpoint仅用于 GitLab API(仓库存在性检查、创建仓库、可见性更新等)- 源端同理可使用
src_endpoint+src_api_endpoint
repos 是一个 YAML 字符串,用于统一替代 v1 的 black_list / white_list / static_list / mappings。
repos: |
static:
- repo1
- name: repo2
dst_name: repo2-renamed
visibility: private
push_strategy: force
refs:
branches:
include: [main]
tags:
include: [v*]
include:
- repo1
- repo2
exclude:
- archived-repo
mappings:
old-name: new-name
refs:
branches:
include: [main, release/*]
exclude: [feature/*]
tags:
include: [v*]
exclude: [v*-rc*]-
static- 类型:
list - 作用:显式指定要同步的仓库列表。
- 若
static非空:不再调用源端 API 动态拉取仓库列表。 - 若
static为空:会动态获取源账号下仓库列表。
- 类型:
-
include- 类型:
list[str] - 作用:白名单过滤,仅保留列表内仓库。
- 为空时表示不过滤。
- 类型:
-
exclude- 类型:
list[str] - 作用:黑名单过滤,从候选仓库中剔除。
- 过滤顺序:先
include再exclude。
- 类型:
-
mappings- 类型:
dict[str, str] - 作用:全局仓库名映射,
源仓库名 -> 目标仓库名。
- 类型:
-
refs- 类型:refs 过滤配置(详见下一节)
- 作用:全局分支/标签同步规则。
- 简写字符串(仅仓库名)
static:
- repo1
- repo2- 对象写法(单仓库覆写)
static:
- name: repo2
dst_name: repo2-renamed
visibility: private
push_strategy: force
refs:
branches:
include: [main]对象字段说明:
name:源仓库名dst_name:目标仓库名(可重命名)visibility:该仓库目标可见性策略(auto/public/private)push_strategy:该仓库推送策略(safe/force/no)refs:该仓库的 refs 同步规则(完整覆盖全局refs)
对单个仓库最终配置,优先级如下:
dst_name:static单仓库dst_name> 全局mappings> 同名visibility:static单仓库visibility> 全局dst_visibility>autopush_strategy:static单仓库push_strategy> 全局push_strategy>saferefs:static单仓库refs完整覆盖全局refs(非 merge)
- 动态拉取 + include/exclude
repos: |
include: [repo-a, repo-b, repo-c]
exclude: [repo-c]- 静态列表 + 重命名
repos: |
static:
- name: old-repo
dst_name: new-repo- 仓库级别强制推送
repos: |
static:
- name: release-repo
push_strategy: forcerefs 控制“同步哪些分支和标签(tag)”。支持全局配置和 per-repo 配置。
refs:
branches:
include: ["*"]
exclude: []
tags:
include: ["*"]
exclude: []- 通配符语义使用
fnmatch:*:任意字符?:单个字符
- 执行顺序:先
include,再exclude exclude优先级高于include
refs未配置:同步所有分支与所有 tag(与 v1 行为一致)include未配置:默认[*](全包含)include: []:不包含任何项exclude未配置:默认空列表
- 当某个仓库在
static中配置了refs,它会完整覆盖全局refs。 - 覆盖是“整块替换”,不是字段级合并。
repos: |
static:
- name: repo-a
refs:
branches:
include: [main]
tags:
include: []repos: |
refs:
branches:
include: [release/*]
exclude: [release/tmp-*]
tags:
include: [v*]
exclude: [v*-rc*]用于接入任意 Git 服务器(例如自建 Gitea/Gogs/裸 SSH 服务器)。
with:
src_platform: github
src_account: my-org
dst_platform: git
dst_endpoint: git.example.com/my-org
dst_transport: ssh
dst_key: ${{ secrets.BARE_GIT_SSH_KEY }}
dst_token: dummy-token
repos: |
static:
- repo1
- repo2说明:
platform=git不支持 API 仓库枚举,必须提供repos.static- 不执行 create_repo / update_visibility API
dst_transport=https时,push URL 支持 token 内嵌认证
仓库提供 templates/hub-mirror.yml 组件模板。
include:
- component: $CI_SERVER_FQDN/your-group/forge-mirror/hub-mirror@2.0.0
inputs:
image: $CI_REGISTRY/your-group/forge-mirror:latest
src-platform: github
src-account: kunpengcompute
dst-platform: gitee
dst-account: kunpengcompute
dst-key: $GITEE_PRIVATE_KEY
dst-token: $GITEE_TOKEN
src-account-type: org
dst-account-type: org| v1 | v2 |
|---|---|
src: github/account |
src_platform: github + src_account: account |
dst: gitee/account |
dst_platform: gitee + dst_account: account |
private_key |
删除;分别使用 src_key / dst_key |
account_type |
src_account_type + dst_account_type |
clone_style |
src_transport + dst_transport |
debug: true |
log_level: DEBUG |
force_update: true |
push_strategy: force |
black_list / white_list / static_list / mappings |
合并为 repos YAML |
| (无) | src_token |
| (无) | repos.refs |
| (无) | dst_platform: git |
| (无) | src_api_endpoint / dst_api_endpoint |
ssh_user(统一) |
src_ssh_user + dst_ssh_user |