[pygobject] gitlab-ci: Add coverage reports



commit af7aa11acebd9a34e6aee41dc77c0d7c3000fd47
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Sat Feb 17 15:23:49 2018 +0100

    gitlab-ci: Add coverage reports
    
    Use gcov/lcov and coverage.py; merge all results and provide
    the final html reports as job artifacts.

 .gitignore                    |  1 +
 .gitlab-ci.yml                | 18 ++++++++++++++++++
 .gitlab-ci/Dockerfile         |  1 +
 .gitlab-ci/coverage-docker.sh | 17 +++++++++++++++++
 .gitlab-ci/test-docker.sh     | 20 ++++++++++++++++----
 setup.cfg                     |  7 +++++++
 6 files changed, 60 insertions(+), 4 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 09063e45..ea4475d6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -83,3 +83,4 @@ Makefile.in
 /PyGObject.egg-info/
 *.pyd
 *.dll.a
+.coverage
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index aae4170f..4f426e93 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -3,6 +3,10 @@ services:
 
 image: lazka/pygobject:pyenv
 
+stages:
+  - build_and_test
+  - coverage
+
 before_script:
   - mkdir -p _ccache
   - export CCACHE_BASEDIR=${PWD}
@@ -13,9 +17,23 @@ cache:
     - _ccache/
 
 .defaults: &defaults
+  stage: build_and_test
+  artifacts:
+    paths:
+      - coverage/
   script:
    - bash -x ./.gitlab-ci/test-docker.sh
 
+coverage:
+  stage: coverage
+  artifacts:
+    paths:
+      - coverage/
+  variables:
+    PYENV_VERSION: "3.6.4"
+  script:
+    - bash -x ./.gitlab-ci/coverage-docker.sh
+
 python2.7:
   variables:
     PYENV_VERSION: "2.7.14"
diff --git a/.gitlab-ci/Dockerfile b/.gitlab-ci/Dockerfile
index 1dd8e2af..e7fde966 100644
--- a/.gitlab-ci/Dockerfile
+++ b/.gitlab-ci/Dockerfile
@@ -9,6 +9,7 @@ RUN apt-get update && apt-get install -y \
     gir1.2-gtk-3.0 \
     git \
     gobject-introspection \
+    lcov \
     libbz2-dev \
     libcairo2-dev \
     libffi-dev \
diff --git a/.gitlab-ci/coverage-docker.sh b/.gitlab-ci/coverage-docker.sh
new file mode 100755
index 00000000..6e74a797
--- /dev/null
+++ b/.gitlab-ci/coverage-docker.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+set -e
+
+python -m pip install coverage
+
+python -m coverage combine coverage
+python -m coverage html -d coverage/report-python
+genhtml --ignore-errors=source --rc lcov_branch_coverage=1 \
+    coverage/*.lcov -o coverage/report-c
+
+cd coverage
+rm -f .coverage*
+rm -f *.lcov
+
+ln -s report-python/index.html index-python.html
+ln -s report-c/index.html index-c.html
diff --git a/.gitlab-ci/test-docker.sh b/.gitlab-ci/test-docker.sh
index 2daba871..31be3029 100755
--- a/.gitlab-ci/test-docker.sh
+++ b/.gitlab-ci/test-docker.sh
@@ -5,15 +5,22 @@ set -e
 python --version
 
 python -m pip install git+https://github.com/pygobject/pycairo.git
-python -m pip install flake8 pytest pytest-faulthandler
+python -m pip install flake8 pytest pytest-faulthandler coverage
 
+PYVER=$(python -c "import sys; sys.stdout.write(str(sys.version_info[0]))")
+SOURCE_DIR="$(pwd)"
 PY_PREFIX="$(python -c 'import sys; sys.stdout.write(sys.prefix)')"
+COV_DIR="${SOURCE_DIR}/coverage"
+
+mkdir -p "${COV_DIR}"
+
 export PKG_CONFIG_PATH="${PY_PREFIX}/lib/pkgconfig"
 export MALLOC_CHECK_=3
 export MALLOC_PERTURB_=$((${RANDOM} % 255 + 1))
-PYVER=$(python -c "import sys; sys.stdout.write(str(sys.version_info[0]))")
+export G_SLICE="debug-blocks"
+export COVERAGE_FILE="${COV_DIR}/.coverage.${PYVER}"
+export CFLAGS="-coverage -ftest-coverage -fprofile-arcs"
 
-SOURCE_DIR="$(pwd)"
 rm -Rf /tmp/build
 mkdir /tmp/build
 cd /tmp/build
@@ -37,4 +44,9 @@ if [[ "${PYENV_VERSION}" == "2.7.14" ]]; then
 fi;
 
 # BUILD & TEST AGAIN USING SETUP.PY
-xvfb-run -a python setup.py distcheck
+python setup.py build_tests
+xvfb-run -a python -m coverage run tests/runtests.py
+
+# COLLECT GCOV COVERAGE
+lcov --rc lcov_branch_coverage=1 --directory . --capture --output-file \
+    "${COV_DIR}/${PYVER}.lcov"
diff --git a/setup.cfg b/setup.cfg
index 5933e6a0..f4b4e15e 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,3 +1,10 @@
 [flake8]
 ignore=E501,E123,E124,E402,E731,E722
 builtins=long,unicode,basestring
+
+[coverage:run]
+branch=True
+include=
+    gi/*
+    tests/*
+    pygtkcompat/*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]