Add gitlab ci workflow
Change-Id: I78b1aefdc6d413d1aafc5d8f524f3d36368baae3
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..166434c
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,59 @@
+# use the verse rocker image, as it contains tidyverse, devtools and some texlive
+image: rocker/verse
+
+# define stages of runner. at the moment,
+# just build (no test or deploy).
+stages:
+ - build
+
+build-job:
+ stage: build
+
+ cache:
+ key: icc
+ paths:
+ - ./cache
+
+ artifacts:
+ paths:
+ - "target/*"
+
+ before_script:
+ - source `find .. -name section_helper.sh`
+
+ - start_section install_linux_packages "Installing missing Linux packages"
+ - apt-get update
+ - apt-get install -y build-essential libglpk40 libcurl4-gnutls-dev libxml2-dev libsodium-dev libsecret-1-dev libfontconfig1-dev libssl-dev libxt6 libpq-dev imagemagick ghostscript software-properties-common inkscape scour
+ - add-apt-repository ppa:saiarcot895/chromium-beta
+ - apt update
+ - apt install -y chromium-browser
+ - locale-gen de_DE.utf8 en_GB.utf8 en_US.utf8
+ - end_section install_linux_packages
+
+ - start_section install_fonts "Installing Libertinus and Fira fonts"
+ - wget -O- https://github.com/mozilla/Fira/archive/refs/tags/4.202.tar.gz | tar -C /usr/share/fonts -zx --wildcards "*.otf"
+ - fc-cache
+ - end_section install_fonts
+
+ - start_section testing_chromium Testing chromium PDF export
+ - chromium-browser --headless --no-sandbox --disable-gpu --run-all-compositor-stages-before-draw --no-pdf-header-footer --print-to-pdf=./test.pdf https://www.ids-mannheim.de/
+ - ls -l ./test.pdf
+ - end_section testing_chromium
+
+ - start_section install_r_packages "Installing missing R packages"
+ - R -e "install.packages(c('scales', 'sp', 'raster', 'kableExtra', 'DT', 'svglite'))"
+ - R -e 'devtools::install_git("https://korap.ids-mannheim.de/gerrit/IDS-Mannheim/idsThemeR")'
+ - R -e 'devtools::install_git("https://korap.ids-mannheim.de/gerrit/IDS-Mannheim/posterdown")'
+ - end_section install_r_packages
+
+ script:
+ - start_section installing "Installing posterdown (ids)"
+ - R -e 'devtools::install()'
+ - end_section installing
+ - start_section render "Generating demo artifacts"
+ - R_CACHE_ROOTPATH=./cache R -e "require(rmarkdown); render('inst/rmarkdown/templates/posterdown_ids/skeleton/skeleton.Rmd', output_format='posterdown::posterdown_ids', output_dir='target')"
+ - ./ci/html2pdf target/skeleton.html target/skeleton.pdf 1
+ - inkscape -b white --pdf-poppler -o target/skeleton.svg target/skeleton.pdf || true
+ - scour -i target/skeleton.svg -o target/skeleton_optimized.svg --enable-viewboxing --enable-id-stripping --shorten-ids --indent=none
+ - end_section render
+
diff --git a/ci/html2pdf b/ci/html2pdf
new file mode 100755
index 0000000..971ccd3
--- /dev/null
+++ b/ci/html2pdf
@@ -0,0 +1,11 @@
+#!/bin/sh -eu
+in=$1 out=$2 page0=${3:-} page1=${4:-$page0}
+${CHROME:-chromium-browser} --no-sandbox --headless --disable-gpu \
+ --run-all-compositor-stages-before-draw \
+ --no-pdf-header-footer --print-to-pdf="$out" "$in"
+GS_ARGS=
+if [ -n "$page0" ]; then
+ GS_ARGS="-dFirstPage=$page0 -dLastPage=$page1"
+fi
+gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH $GS_ARGS -sOutputFile="$2.tmp" "$2"
+mv "$2.tmp" "$2"
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"
+}