How to migrate your repo from GitLab to GitHub without putting too much effort

¿Have you ever had that feeling when you want to migrate your git repo from GitLab to GitHub but you are already too deep into GitLab CI and things are too complicated so you decide to keep the peace and keep both GitLab and GitHub as friends? Well, you are not the first one.

Fortunately enough, GitLab pipeline API offers tools to execute and check results from its pipelines. The idea will be then to call that API from a GitHub action in your repo. Surely there will be some cool project out there that makes this real easy…

There is! This script will only need to be called from the workflow yml like this:

It will also need a bunch of secrets to be set in the GitHub project (GITLAB_HOSTNAME, GITLAB_USERNAME…). Sadly, this script will only work when pushing new changes to the repo, as it works by pushing the commits to the GitLab repo and then waiting for the results of the pipeline. If we wanted to trigger the pipeline without changes (manually executing it or retrying an already executed job), we have to change some things in the script, so we create a fork of our own:

Now, we add the changes. Mainly a new secret to set our GitLab token with permissions to execute pipelines using the API. Also, the call itself to the API, so we will no longer only rely on GitHub pushing to GitLab (which we still do) but also on the pipeline API call, that will be executed in case there is nothing new to push from GitHub to Gitlab:

And that’s it! Now you can set up your fancy new GitHub repo to execute the actions as desired: on every push to any branch, when making changes to a pull request or when pushing something to master. To finish, here are the links to the GitHub repo and the old GitLab repo that we keep for CI and as a mirror:

1 Like