View on GitHub

hub-mirror

🎞 使用 github action - hub-mirror-action 的模板仓库,可以管理当前 GitHub 与其他的 hub 的存储库(当前仅包含 Gitee)的镜像同步。

hub-mirror

sync2gitee sync2gitee(cached) GitHub last commit LICENSE

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.

GitHub-Name

dst(required)

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

Gitee-Name

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

  1. install Git and launch GitBash
  2. 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
    

    Get SSH key pair

  3. According to the path obtained in the second step, add the key pair to the two libraries respectively (take GitHub and Gitee as examples)

    1. Add the private key (id_rsa) to the GitHub repository. Create a GITEE_PRIVATE_KEY variable through the Secrets in the GitHub repository settings, and copy the private key content to the value area.

      Add the private key

    2. Add the public key (id_rsa.pub) to the Gitee repository. Create a hub-mirror variable through the SSH Public Key in the Gitee personal settings, and copy the public key content to the value area.

      Add the public key

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.

  1. Generate a GITEE_TOKEN through personal access token in the Gitee 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).

    Generate a personal access token

  2. Add the token to the GitHub repository, create a GITEE_TOKEN variable through the Secrets in the GitHub repository settings, and copy the private key content to the value area.

    Add the token

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:

account_type configures the user attributes that use this workflow.

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.

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.

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:

  1. Repositories can be imported directly from GitHub using the service provided by Gitee, see Gitee Help Manual, which also requires that only letters, numbers, underscores(_), dash(-) and periods(.). It must begin with a letter or number.
  2. 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:

secrets.GITHUB_TOKEN configuration

This parameter is no need to configured and is automatically created and retrieved by GitHub.

Reference: Authentication in Workflow

Thanks

LICENSE

MIT