Published on: July 11, 2023
11 min read
Learn how easy it is to migrate from GitHub to GitLab using GitLab's project import functionality.

If you are using different CI/CD tools and are considering migrating over to GitLab, you may be wondering about the difficulty of the migration process. Migration is usually a concern for DevSecOps teams when considering a new solution. This is due to the fact that migrating may involve heavy lifting. However, migrating to the GitLab AI-powered DevSecOps Platform can be extremely simple and I will show you how step by step. In this blog post, we will go over how to migrate from GitHub to GitLab using our project import functionality. Manually migrating GitHub Actions to GitLab pipelines will be covered as well. I have also created a video going over the migration process for those who prefer that format:
on: push: branches: [ master ] pull_request: branches: [ master ]
jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Python 3.10 uses: actions/setup-python@v4 with: python-version: "3.10" - name: Install dependencies run: | python -m pip install --upgrade pip pip install flake8 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
#### smoke.yml
This file contains the action which performs a smoke test by just running the CLI help menu. It uses the python:3.10 Docker image and installs the application requirements before performing the smoke test.
```yaml
name: "Smoke Tests"
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
smoke-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install Sentiment Analysis Application
run: |
python setup.py install
- name: Run smoke tests
run: |
reddit-sentiment --help
This file contains the Action, which performs unit tests using pytest. It uses the python:3.10 Docker image and installs the application requirements running the unit tests.
name: "Unit Tests"
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
python -m pip install --upgrade pip
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
pytest tests/
Now let's go ahead and migrate these Actions over to GitLab. 2) Go to the recently imported project on GitLab and open up the WebIDE. 3) Create a file at the root called .gitlab-ci.yml. This file defines the GitLab pipeline. 4) Add the following configuration, which will add the GitHub Actions as Jobs in the GitLab pipeline. Notice the comments I added describing each section.
# This creates the stages in which the jobs will run. By default all
# jobs will run in parallel in the stage. Once the jobs are completed
# successfully then you move on to the next stage. The way jobs run
# is completely configurable.
stages:
- test
# With the include statement, you can quickly add jobs which have
# been pre-defined in external YAMLs. The SAST job I included below
# is provided and maintained by GitLab and adds Static Application
# Security Testing (SAST) to your pipeline.
include:
- template: Jobs/SAST.gitlab-ci.yml
# This is the unit test job which does exactly what is defined in
# the GitHub Action in unit.yml. You can see it uses the python:3.10
# Docker image, installs the application dependencies, and then runs
# the unit tests with pytest. It was added with a simple copy and
# paste and minor syntax changes.
unit:
image: python:3.10
stage: test
before_script:
- python -m pip install --upgrade pip
- pip install pytest
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
script:
- pytest tests/
# This is the lint job which does exactly what is defined in the
# GitHub Action in lint.yml. You can see it uses the python:3.10
# Docker image, installs the application dependencies, and then
# performs the linting with flake8. It was added with a simple copy
# and paste and minor syntax changes.
lint:
image: python:3.10
stage: test
before_script:
- python -m pip install --upgrade pip
- pip install flake8
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
script:
- flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# This is the smoke test job which does exactly what is defined in
# the GitHub Action in smoke.yml. You can see it uses the python:3.10
# Docker image, installs the application dependencies, and then runs
# the smoke tests with the Reddit sentiment analysis CLI. It was
# added with a simple copy and paste and minor syntax changes.
smoke:
image: python:3.10
stage: test
before_script:
- python -m pip install --upgrade pip
- pip install setuptools
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- python setup.py install
script:
- reddit-sentiment --help
You can see that scripts being executed in GitLab match those scripts within the GitHub Actions. The only thing that has really changed is the syntax setting up the jobs and stages. To learn more on how to create and configure pipelines, check out the GitLab CI/CD documentation.
5) Let's check in the code. From the WebIDE click on the Source Control Tab in the side panel of the WebIDE. It is the third icon from the top. Then press the Commit to 'main' button, select Continue, and voila, you should now have a running pipeline.
6) Examine the pipeline and make sure the jobs are running properly. Go back to your project and click on the pipeline icon. You can see the the four jobs we created have run.
7) Click on the Unit job and you can see that the unit tests were run successfully.
$ pytest tests/
============================= test session starts ==============================
platform linux -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0
rootdir: /builds/awkwardferny/reddit-sentiment-analyzer
collected 2 items
tests/test_scraper.py .. [100%]
============================== 2 passed in 0.09s ===============================
Cleaning up project directory and file based variables
00:00
Job succeeded
And that's how simple it is to migrate a project over from GitHub to GitLab!
The GitLab importer allows one-click migration from several other platforms. These platforms include:
Thanks for reading! Now you know how easy it is to migrate from GitHub over to GitLab. For more information on GitLab and migrating from GitHub, follow the links below: