Add gitlab CI script

Change-Id: I485c743d215dfb83c5f69ac6528f516c31f78332
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..588666c
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,28 @@
+include:
+  local: ci/install-rkorapclient-ci.yml
+
+test-korapclient-on-stable:
+  extends: .install-rkorapclient
+  image: ubuntu:latest
+  cache:
+    key: rkorapclient-ubuntu-stable
+    paths:
+    - apt-cache/
+    - ccache/
+    - rlib/
+  script:
+    - python3 -m pip install pip -U
+    - python3 -m pip install setuptools -U
+    - python3 -m pip install pytest -U
+    - python3 -m pip install .
+    - python3 -m pytest -v
+
+
+test-korapclient-on-rolling:
+  extends: .install-rkorapclient
+  image: ubuntu:rolling
+  script:
+    - python3 -m pip install pip -U --break-system-packages
+    - python3 -m pip install pytest -U --break-system-packages
+    - python3 -m pip install . --break-system-packages
+    - python3 -m pytest -v
diff --git a/ci/Makevars b/ci/Makevars
new file mode 100644
index 0000000..1292033
--- /dev/null
+++ b/ci/Makevars
@@ -0,0 +1,11 @@
+VER=
+CXX17=$(CCACHE) g++$(VER)
+CCACHE=ccache
+#CCACHE=
+CC=$(CCACHE) gcc$(VER)
+CXX=$(CCACHE) g++$(VER)
+CXX11=$(CCACHE) g++$(VER)
+CXX14=$(CCACHE) g++$(VER)
+CXX17=$(CCACHE) g++$(VER)
+FC=$(CCACHE) gfortran$(VER)
+F77=$(CCACHE) gfortran$(VER)
diff --git a/ci/ccache.conf b/ci/ccache.conf
new file mode 100644
index 0000000..95b69c3
--- /dev/null
+++ b/ci/ccache.conf
@@ -0,0 +1,3 @@
+max_size = 5.0G
+sloppiness = include_file_ctime
+hash_dir = false
diff --git a/ci/install-rkorapclient-ci.yml b/ci/install-rkorapclient-ci.yml
new file mode 100644
index 0000000..3fc7d87
--- /dev/null
+++ b/ci/install-rkorapclient-ci.yml
@@ -0,0 +1,51 @@
+.install-rkorapclient:
+  variables:
+    # Set `CCACHE_BASEDIR` and `CCACHE_DIR` to point `ccache` towards the cached
+    # path on the gitlab-runner. This enables to cache the output of `ccache`
+    # between various runs.
+    CCACHE_BASEDIR: ${CI_PROJECT_DIR}
+    CCACHE_DIR: ${CI_PROJECT_DIR}/ccache
+    # Set `ccache` to `content` to prevent rebuilding of the CI/CD containers to
+    # trigger a recreate of the cache. By using `content` the compiler's `mtime`
+    # is not considered as part of the hash.
+    CCACHE_COMPILERCHECK: "content"
+    # Enable caching for `apt-get`.
+    APT_CACHE_DIR: ${CI_PROJECT_DIR}/apt-cache
+    # Export `noninteractive` frontend to prevent requesting user input
+    DEBIAN_FRONTEND: noninteractive
+    R_LIBS_USER: ${CI_PROJECT_DIR}/rlib
+
+  cache:
+    key: rkorapclient
+    paths:
+      - apt-cache/
+      - ccache/
+      - rlib/
+
+  before_script:
+    - source ./ci/section_helper.sh
+
+    - start_section install_linux_packages "Installing missing Linux packages"
+    - mkdir -pv $APT_CACHE_DIR ccache $R_LIBS_USER /usr/local/sbin ~/.ccache ~/.R
+    - cp ci/Makevars ~/.R/Makevars
+    - cp ci/ccache.conf ${CI_PROJECT_DIR}/ccache/ccache.conf
+    - cp ci/ccache.conf ~/.ccache/ccache.conf
+    - echo "R_LIBS='$R_LIBS_USER'" > .Renviron
+    - echo "MAKEFLAGS=-j$(nproc)" >> ~/.R/Makevars
+    - echo "MAKE=make -j$(nproc)" >> ~/.R/Makevars
+    - apt-get update
+    - apt-get install -y -o dir::cache::archives="$APT_CACHE_DIR" --no-install-recommends software-properties-common dirmngr ccache wget python3-pip
+    - wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
+    - add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"
+     # - add-apt-repository ppa:c2d4u.team/c2d4u4.0+
+    - grep -E "sudo apt.* install" Readme.md | sed -e 's/.*sudo apt.* install/apt-get install --no-install-recommends -o dir::cache::archives="$APT_CACHE_DIR" -y libharfbuzz-dev libfribidi-dev /g' | sh
+    - ln -s $(which ccache) /usr/local/sbin/gcc
+    - ln -s $(which ccache) /usr/local/sbin/g++
+    - end_section install_linux_packages
+    - start_section installing "Installing RKorAPClient from CRAN"
+    - export PATH=/usr/local/sbin:$PATH
+    # - export RENV_CONFIG_REPOS_OVERRIDE=https://packagemanager.posit.co/cran/__linux__/$(lsb_release --short --codename)/latest
+    # - echo "options(repos = c(CRAN = \"$RENV_CONFIG_REPOS_OVERRIDE\"))" >> ~/.Rprofile
+    - R -q -e "install.packages(c('remotes', 'RKorAPClient'), dependencies = TRUE)"
+    - end_section installing
+  script:
diff --git a/ci/section_helper.sh b/ci/section_helper.sh
new file mode 100644
index 0000000..ddefe0d
--- /dev/null
+++ b/ci/section_helper.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+# Reference: https://docs.gitlab.com/ee/ci/jobs/#custom-collapsible-sections
+
+#
+# Takes 2 Parameters a new section id and a heading/title
+#
+function start_section() {
+  id=$1
+  title=$2
+  echo -e "\e[0Ksection_start:$(date +%s):${id}[collapsed=true]\r\e[0K\e[36;1m${title}\e[0m"
+}
+
+#
+# Takes 1 Parameter, the unique section id of the section that should end
+#
+function end_section() {
+  id=$1
+  echo -e "\e[0Ksection_end:$(date +%s):${id}\r\e[0K"
+}