Continuous repository synchroniser between GitHub and GitLab
Ruby 92.48%Shell 7.52%
github-gitlab-sync's Introduction
General Setup
Get GitLab admin user details
Get GitLab sync user details
Get GitHub admin user details
GitHub (<)-> GitLab Sync Setup
Select source GitHub repo
Either: Select/create destination GitLab repo
Generate a ssh keypair.
Install public key to GitHub repo as Deployment Key (with write permissions for reverse sync)
Install public key to GitLab sync user.
Grant GitLab sync user Developer permissions to 2.
Clone 1. add remote 2.
Check branches on 1,2 are consistent/fast-forwardable (or 2 is empty), and sync
Check out synced master.
Update .gitlab-ci.yml with git sync CI task
Commit and push all repo branches to both.
Enable builds on 2. select a builder.
Install private key to secret build variable on 2.
Create a trigger on 2.
Install webhook for trigger on 1. (with GitHub trigger source variable)
Intended Flows
GitHub -> GitLab
Push to GitHub
GitHub webhook calls out to GitLab build trigger
GitLab spawns build tasks including/not-excluding the "triggers" pattern.
Git sync task executes (in GitHub mode).
GitLab version of repository at some unspecified revision/branch is checked out automatically.
Spawn ssh-agent with the stored private key.
Add GitHub remote and fetch.
Fast-forward each GitHub branch into the corresponding GitLab branch, creating if required.
If any changes made, push to GitLab. (This build task ends).
GitLab receives push and starts standard build process.
GitLab executes GitLab->GitHub sync task as part of the standard build, it should be idempotent.
GitLab -> GitHub
Push to GitLab
GitLab spawns build tasks.
Git sync task executes (in GitLab mode).
GitLab version of repository at some current revision/branch is checked out automatically.
Spawn ssh-agent with the stored private key.
Add GitHub remote and fetch.
Fast-forward each GitLab branch into the corresponding GitHub branch, creating if required.
If any changes made, push to GitHub. (This build task ends).
GitHub receives push, triggers GitLab webhook, the resulting push should be idempotent.
Limitations
Force pushes on any repo will break the sync, good motivation to forbid them.
All normal build tasks will need to be marked as excluding triggers, ones that need to be triggered need special
handling, with build variables to select correct mode.
git-sync-remote should be pre-installed on the build machine at the moment