- Get GitLab admin user details
- Get GitLab sync user details
- Get GitHub admin user details
- 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)
- 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.
- 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.
- 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
- GitLab has undocumented support for Cloning repositories over SSH using an oauth2 token. Use username oauth2 and the token as the password. (See https://gitlab.com/gitlab-org/gitlab-ee/commit/54f6d8c7b5a1c67a222011c35ad70909da0e686d)
- GitHub has the ability to clone/push using OAuth2 tokens if the "repo" scope is provided.