hub-mirror
| English | 简体中文 |
Template usage repository of GitHub action-hub-mirror-action, you can manage the mirror repositories actions between GitHub with other hub(only Gitee now).
PS: This template repository only uses part of parameters configuring synchronization workflows. The parameters of usage examples in template need to be modified and configured by yourself to complete the personal workflows configuration.
Table of Contents
Configuration parameter
src(required)
src is source account, such as github/yi-Xu-0100, is the Github account yi-Xu-0100.

dst(required)
dst is destination account, such as gitee/yi-Xu-0100, is the Gitee account yi-Xu-0100.

dst_key(required)
dst_key the SSH key to push code in destination account, You can get the Github SSH key in here,the Gitee SSH key in here.
Set dst_key
- install
Gitand launchGitBash -
Run the following command to generate an
SSHkey pair (The default configuration used by the picture, that is, skip all settings).ssh-keygen -t rsa
-
According to the path obtained in the second step, add the key pair to the two libraries respectively (take
GitHubandGiteeas examples)-
Add the private key (
id_rsa) to theGitHubrepository. Create aGITEE_PRIVATE_KEYvariable through theSecretsin theGitHubrepository settings, and copy the private key content to the value area.
-
Add the public key (
id_rsa.pub) to theGiteerepository. Create ahub-mirrorvariable through theSSH Public Keyin theGiteepersonal settings, and copy the public key content to the value area.
-
dst_token(required)
dst_token is the API token to create non-existent repo. You can get Github token in here, and the Gitee in here.
Set dst_token
Take Gitee as an example, get the token and add it to GitHub.
-
Generate a
GITEE_TOKENthroughpersonal access tokenin theGiteepersonal settings, and copy the token content to the value area.PS: The token only appears once, please save it(it can be generated multiple times).

-
Add the token to the
GitHubrepository, create aGITEE_TOKENvariable through theSecretsin theGitHubrepository settings, and copy the private key content to the value area.
static_list (recommended)
static_list is repos only mirror, but don’t get list from repo api dynamically (the white/black list is still available), like 'repo1,repo2,repo3'. The static_list in the template contains only the current repository (ie template repository) as obtained from actions/github-script. If you need to add or modify it, use comma separations, such as: '$,MY_REPO' . Also, when setting the name of the repository, the following issues need to be considered:
- Pay attention to the case and symbols of the repository name.
- The current action
hub-mirror-action@v0.09will synchronize all repositories and create all repositories cloned underGitHubin anotherhub(Giteewould not show the relation about clone). - The current action
hub-mirror-action@v0.09can not complete the mirror synchronization for the private repository, it may interrupt the synchronization process and result that some repositories to not be synchronized.
acount_type (recommended)
account_type configures the user attributes that use this workflow.
- If it is an individual, it needs to be set to
user. - If it is an organization, it needs to be set to
org.
force_update (recommended)
force_update configures whether or not to force synchronization. This option is used when there is a conflict between the contents of the GitHub and Gitee repositories.
- If configured as
true, theGitHubrepository content is forced to be pushed intoGitee. - If it is configured as
false, it will not force theGitHubrepository content to be pushed toGitee.
cache_path (optional)
Note: Improperly configured cache will still cause the entire repository to take too long to synchronize. See actions/cache configuration for detailed configuration.
The cache_path option needs to be used with actions/cache, which will cache the synchronized repository contents and shorten the synchronization time.
sync2gitee.cache.ymlis an example of usingcache_pathconfigured.sync2gitee.ymlis a using case wherecache_pathis not configured.
Single repository usage
Because static_list only sets the current repository, you can choose to place .github/workflows/sync2gitee.yml in the same path of any repository without adding the parameters, to realize the configuration of synchronizing only the repository containing the file.
PS: You also need Configuration Parameters.
FAQ
Gitee can’t create XXX repository and how to solve it
Gitee repository name creation requirements: Only letters, numbers, or underscores(_), Dash(-), periods ( . ). It must begin with a letter and be 2~191 characters long. If your repository name begins with special symbols and numbers, it will interrupt the creation process and cause synchronization to fail.
Solution:
- Repositories can be imported directly from
GitHubusing the service provided byGitee, see Gitee Help Manual, which also requires that only letters, numbers, underscores(_), dash(-) and periods(.). It must begin with a letter or number. - if the repository name begins with a special symbol, you can use renaming a repository or deleting a repository and creating a repository on github.
`actions/cache’ configuration
The synchronization process in the repository uses the action actions/cache to complete the caching of the repository. The setup of the synchronization repository in template is already done, so no changes are needed. In order to complete the cache configuration, and to build the parameters needed for key, we use three steps to complete the cache configuration, as shown in template/sync2gitee.cache.yaml.
- name: Get current repository name
id: info
uses: actions/github-script@v3.1
with:
github-token: $
result-encoding: string
script: |
core.setOutput('date', new Date(Date.now()).toISOString().replace(/[^0-9]/g, ""))
return context.repo.repo;
- name: Cache src repos
uses: actions/cache@v2.1.3
id: cache
with:
path: $/hub-mirror-cache
key: $-$-$-cache-$
restore-keys: $-$-$-cache-
Explanation:
- The step which
idisinfousesactions/github-scriptto get the repository name (also used for thestatic_listconfiguration) and the trigger timestamp (ISOformat and numbers only). - The
pathvariable sets the path corresponding to the path set by the parametercache_pathinhub-mirror-action(no change is recommended, the currently configured directory is the default value for the parameter configuration). keyvariable configuration is related to the environment, repository owner and repository name, and a trigger timestamp to determine specificity (the information is already available through the process steps, it is recommended not to change it).restore-keysmatches only the preexisting keywords, which guarantees that the most recent cached result will be retrieved each time.keydeletes the old cache file if it has not been triggered for7days or if the cached result store size is larger than5G.- Detailed instructions for configuring
cachecan be found in thecacherepository documentation.
secrets.GITHUB_TOKEN configuration
This parameter is no need to configured and is automatically created and retrieved by GitHub.
Reference: Authentication in Workflow
Thanks
- ShixiangWang/sync2gitee
- Yikun/hub-mirror-action
- actions/checkout
- actions/cache
- actions/github-script