Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
copy

GitHub Action

Mirror Git

v0.1.2

Mirror Git

copy

Mirror Git

Synchronize git repositories like a mirror

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Mirror Git

uses: k8scat/[email protected]

Learn more about this action in k8scat/action-mirror-git

Choose a version

action-mirror-git

Synchronize git repositories like a mirror.

Examples

Support

  • Any git server like GitHub, GitLab, BitBucket, Gitee etc.
  • Protocol under HTTPS and SSH
  • Sync branches, tags, commits
  • Ignore specific repositories
  • Specify repositories without pushing tags
  • Auto create repository on the dest git server with custom script
  • Notify with Slack, DingTalk or Lark

Any git server

# GitHub
source_host: github.com

# Self-hosted
source_host: git.example.com
source_port: 8443

Protocol under HTTPS and SSH

# HTTPS will use personal access token to authenticate, the token username is required on some git servers like Gitee
source_protocol: https
source_token: github-token-created-under-k8scat-account

# Gitee
# The source_username will be used as the token username if source_token_username is not specified
source_protocol: https
source_username: huayin-opensource
source_token: gitee-token-created-under-k8scat-account
source_token_username: k8scat

# SSH requires the private key to authenticate
dest_protocol: ssh
dest_private_key: |
  -----BEGIN OPENSSH PRIVATE KEY-----
  b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
  ...
  OOWdOkxLqLsiMAAAAEdGVzdAECAwQFBgc=
  -----END OPENSSH PRIVATE KEY-----

Sync branches, tags, commits

# Branch and commits will be synced by default

# Sync tags by default, if you only want to sync branches, you can set push_tags to false
push_tags: "false"

Refer to Duplicating a repository.

Ignore specific repositories

# repo5 and repo6 will not be synced
ignored_repos: "repo5,repo6"

Specify repositories without pushing tags

# repo3 and repo4 will only sync branches and commits
skip_tags_repos: "repo3,repo4"

Auto create repository

# Custom script to create repository
dest_create_repo_script: |
  if ! gh auth status; then
    echo "${INPUT_DEST_TOKEN}" | gh auth login --with-token
    gh auth status
  fi
  repo="${INPUT_DEST_USERNAME}/${REPO_NAME}"
  found=$(gh repo list ${INPUT_DEST_USERNAME} -L 1000 --json name -t "{{range .}}{{if (eq .name \"${REPO_NAME}\")}}{{.name}}{{end}}{{end}}")
  if [[ -n "${found}" ]]; then
    echo "repo ${REPO_NAME} already exists"
    exit 0
  fi
  gh repo create "${INPUT_DEST_USERNAME}/${REPO_NAME}" --private

# Specify the script url to create repository
dest_create_repo_script: https://example.com/create_repo.sh

Notify

# Slack
slack_webhook: ${{ secrets.SLACK_WEBHOOK }}

# DingTalk
dingtalk_webhook: ${{ secrets.DINGTALK_WEBHOOK }}

# Lark
lark_webhook: ${{ secrets.LARK_WEBHOOK }}

Run

docker run \
  --rm \
  -e INPUT_SOURCE_PROTOCOL="https" \
  -e INPUT_SOURCE_HOST="github.com" \
  -e INPUT_SOURCE_USERNAME="source_user" \
  -e INPUT_SOURCE_TOKEN="xxx" \
  -e INPUT_DEST_PROTOCOL="ssh" \
  -e INPUT_DEST_HOST="github.com" \
  -e INPUT_DEST_USERNAME="dest_user" \
  -e INPUT_DEST_PRIVATE_KEY="xxx" \
  -e INPUT_PUSH_TAGS="true" \
  -e INPUT_MIRROR_REPOS="repo1,repo2,repo3" \
  -e INPUT_IGNORED_REPOS="repo1" \
  -e INPUT_SKIP_TAGS_REPOS="repo2" \
  -e INPUT_DEST_CREATE_REPO_SCRIPT="xxx" \
  -e INPUT_SOURCE_PORT \
  -e INPUT_SOURCE_PRIVATE_KEY \
  -e INPUT_DEST_PORT \
  -e INPUT_DEST_TOKEN \
  -e INPUT_SLACK_WEBHOOK \
  -e INPUT_DINGTALK_WEBHOOK \
  -e INPUT_LARK_WEBHOOK="xxx" \
  -e INPUT_NOTIFY_PREFIX="Mirror Git" \
  -e INPUT_NOTIFY_SUFFIX="Powered by https://github.com/k8scat/action-mirror-git" \
  gigrator/mirror-git:0.1.2

LICENSE

MIT