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
Git
and launchGitBash
-
Run the following command to generate an
SSH
key 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
GitHub
andGitee
as examples)-
Add the private key (
id_rsa
) to theGitHub
repository. Create aGITEE_PRIVATE_KEY
variable through theSecrets
in theGitHub
repository settings, and copy the private key content to the value area. -
Add the public key (
id_rsa.pub
) to theGitee
repository. Create ahub-mirror
variable through theSSH Public Key
in theGitee
personal 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_TOKEN
throughpersonal access token
in theGitee
personal 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
GitHub
repository, create aGITEE_TOKEN
variable through theSecrets
in theGitHub
repository 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.09
will synchronize all repositories and create all repositories cloned underGitHub
in anotherhub
(Gitee
would not show the relation about clone). - The current action
hub-mirror-action@v0.09
can 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
, theGitHub
repository content is forced to be pushed intoGitee
. - If it is configured as
false
, it will not force theGitHub
repository 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.yml
is an example of usingcache_path
configured.sync2gitee.yml
is a using case wherecache_path
is 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
GitHub
using 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
id
isinfo
usesactions/github-script
to get the repository name (also used for thestatic_list
configuration) and the trigger timestamp (ISO
format and numbers only). - The
path
variable sets the path corresponding to the path set by the parametercache_path
inhub-mirror-action
(no change is recommended, the currently configured directory is the default value for the parameter configuration). key
variable 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-keys
matches only the preexisting keywords, which guarantees that the most recent cached result will be retrieved each time.key
deletes the old cache file if it has not been triggered for7
days or if the cached result store size is larger than5G
.- Detailed instructions for configuring
cache
can be found in thecache
repository 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