Skip to content

⏭ A GitHub Action for mirroring a git repository to another location via SSH.

License

Notifications You must be signed in to change notification settings

morbalint/git-mirror-action

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Git Mirror Action

A GitHub Action for mirroring a git repository to another location via SSH.

Inputs

source_repo

Required SSH URL of the source repo.

destination_repo

Required SSH URL of the destination repo.

branches

Optional (default: ``) When this input is not empty, only mirror selected branches. Branches must be separated by :. Tags are not mirrored. If let unset, mirror the entire repository, as before this input was introduced.

Note : is used because it's one of the illegal characters to be used in a branch name.

force_push_branches

Optional (default: false) Only matters if branches are not empty. If set to true the mirroring will force push the branches.

dry_run

Optional (default: false) Execute a dry run. All steps are executed, but no updates are pushed to the destination repo.

Environment variables

SSH_PRIVATE_KEY: Create a SSH key without a passphrase which has access to both repositories. On GitHub you can add the public key as a deploy key to the repository. GitLab has also deploy keys with write access and for any other services you may have to add the public key to your personal account.
Store the private key as an encrypted secret and use it in your workflow as seen in the example workflow below.

SSH_KNOWN_HOSTS: Known hosts as used in the known_hosts file. StrictHostKeyChecking is disabled in case the variable isn't available.

If you added the private key or known hosts in an environment make sure to reference the environment name in your workflow otherwise the secret is not passed to the workflow.

Example workflow

name: Mirror to Bitbucket Repo

on: [ push, delete, create ]

# Ensures that only one mirror task will run at a time.
concurrency:
  group: git-mirror

jobs:
  git-mirror:
    runs-on: ubuntu-latest
    steps:
      - uses: wearerequired/git-mirror-action@v1
        env:
          SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
          SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }}
        with:
          source_repo: "[email protected]:wearerequired/git-mirror-action.git"
          destination_repo: "[email protected]:wearerequired/git-mirror-action.git"
          branches: "master:hypothetical-other-branch"
          force_push_branches: true
          dry_run: true

Docker

docker run --rm -e "SSH_PRIVATE_KEY=$(cat ~/.ssh/id_rsa)" $(docker build -q .) "$INPUT_SOURCE_REPO" "$INPUT_DESTINATION_REPO"

License

The Dockerfile and associated scripts and documentation in this project are released under the MIT License.

About

⏭ A GitHub Action for mirroring a git repository to another location via SSH.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 95.7%
  • Dockerfile 4.3%