Skip to content

Commit

Permalink
Add uploading of coverage to codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Dec 3, 2021
1 parent 92bb467 commit bd45dc6
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 45 deletions.
17 changes: 17 additions & 0 deletions .github/actions/install_dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: install_dependencies
description: Installs dependencies for the pip build

inputs:
os:
required: true


runs:
using: "composite"
steps:
- name: Install Ubuntu dependencies
if: inputs.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install libxcb-image0 libxcb-icccm4 libxcb-keysyms1 libxcb-randr0 libxcb-render0 libxcb-render-util0 libxcb-shape0 libxcb-shm0 libxcb-xfixes0 libxcb-xinerama0 libfontconfig1 libxcb-xkb1 libxkbcommon-x11-0 libdbus-1-3 x11-xserver-utils herbstluftwm
shell: bash
84 changes: 40 additions & 44 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Build libres
run: |
mkdir cmake-build
cmake -S libres -B cmake-build -DBUILD_TESTS=ON
cmake -S libres -B cmake-build -DBUILD_TESTS=ON -DCOVERAGE=ON
cmake --build cmake-build
- name: Run tests
Expand All @@ -56,6 +56,20 @@ jobs:
export PATH=$PWD/bin:$PATH
ctest --output-on-failure
- name: Install gcovr
run: |
python3 -m pip install gcovr
- name: generate coverage report
run: |
gcovr -r libres/ --exclude-directories ".*tests" cmake-build/ --xml -o cov.xml
- name: Upload c coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: cmake-build/cov.xml

build-wheels:
timeout-minutes: 30
strategy:
Expand All @@ -71,11 +85,13 @@ jobs:
with:
fetch-depth: 0

- name: Install Ubuntu dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install libxcb-image0 libxcb-icccm4 libxcb-keysyms1 libxcb-randr0 libxcb-render0 libxcb-render-util0 libxcb-shape0 libxcb-shm0 libxcb-xfixes0 libxcb-xinerama0 libfontconfig1 libxcb-xkb1 libxkbcommon-x11-0 libdbus-1-3 x11-xserver-utils herbstluftwm
- uses: './.github/actions/install_dependencies'
with:
os: ${{ matrix.os }}

- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Build Linux Wheel
uses: docker://quay.io/pypa/manylinux2014_x86_64
Expand All @@ -84,11 +100,6 @@ jobs:
args: ${{ matrix.python-version }}
if: matrix.os == 'ubuntu-latest'

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Build macOS Wheel
run: pip wheel . --no-deps -w dist
if: matrix.os == 'macos-latest'
Expand Down Expand Up @@ -118,18 +129,15 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- name: Install Ubuntu dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install libxcb-image0 libxcb-icccm4 libxcb-keysyms1 libxcb-randr0 libxcb-render0 libxcb-render-util0 libxcb-shape0 libxcb-shm0 libxcb-xfixes0 libxcb-xinerama0 libfontconfig1 libxcb-xkb1 libxkbcommon-x11-0 libdbus-1-3 x11-xserver-utils herbstluftwm
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- uses: './.github/actions/install_dependencies'
with:
os: ${{ matrix.os }}

- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -148,10 +156,8 @@ jobs:
env:
DISPLAY: ':99.0'
run: |
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 640x480x24 -ac +extension GLX
sleep 3
herbstluftwm &
sleep 1
ci/github/start_herbstluftwm.sh &
sleep 5
pushd tests
pytest ert_tests -sv --durations=0 -m "not integration_test"
Expand All @@ -166,10 +172,8 @@ jobs:
env:
DISPLAY: ':99.0'
run: |
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 640x480x24 -ac +extension GLX
sleep 3
herbstluftwm &
sleep 1
ci/github/start_herbstluftwm.sh &
sleep 5
pushd tests
pytest ert_tests -sv --durations=0 -m "integration_test"
Expand All @@ -196,18 +200,15 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- name: Install Ubuntu dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install libxcb-image0 libxcb-icccm4 libxcb-keysyms1 libxcb-randr0 libxcb-render0 libxcb-render-util0 libxcb-shape0 libxcb-shm0 libxcb-xfixes0 libxcb-xinerama0 libfontconfig1 libxcb-xkb1 libxkbcommon-x11-0 libdbus-1-3 x11-xserver-utils herbstluftwm
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- uses: './.github/actions/install_dependencies'
with:
os: ${{ matrix.os }}

- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -252,18 +253,13 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- name: Install Ubuntu dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install libxcb-image0 libxcb-icccm4 libxcb-keysyms1 libxcb-randr0 libxcb-render0 libxcb-render-util0 libxcb-shape0 libxcb-shm0 libxcb-xfixes0 libxcb-xinerama0 libfontconfig1 libxcb-xkb1 libxkbcommon-x11-0 libdbus-1-3 x11-xserver-utils herbstluftwm
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- uses: './.github/actions/install_dependencies'
with:
os: ${{ matrix.os }}
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Python coverage

on:
push:
branches:
- main
- 'version-**'
tags: "*"
pull_request:

jobs:
python-test-coverage:
name: Python Coverage
timeout-minutes: 30
runs-on: ubuntu-latest
strategy:
matrix:
system-under-test: ['res', 'ert']
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: './.github/actions/install_dependencies'
with:
os: ubuntu-latest

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install with dependencies
run: |
pip install -r dev-requirements.txt
pip install .
- name: Run ert tests
if: matrix.system-under-test == 'ert'
env:
DISPLAY: ':99.0'
run: |
ci/github/start_herbstluftwm.sh &
sleep 5
# We run the tests from the test directory as pytest-cov (at least as
# of 3.0.0) will create an incorrect report when a directory matches
# the package name
cd tests
pytest ert_tests --cov=ert --cov=ert3 --cov=ert_data --cov=ert_gui --cov=ert_shared --cov=ert_logging --cov=res --cov-report=xml:cov.xml
- name: Run res tests
if: matrix.system-under-test == 'res'
run: |
cd tests
pytest libres_tests --cov=res --cov-report=xml:cov.xml
- name: Upload python coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: tests/cov.xml
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![GitHub contributors](https://img.shields.io/github/contributors-anon/equinor/ert)](https://img.shields.io/github/contributors-anon/equinor/ert)
[![Code Style](https://github.com/equinor/ert/actions/workflows/style.yml/badge.svg)](https://github.com/equinor/ert/actions/workflows/style.yml)
[![Type checking](https://github.com/equinor/ert/actions/workflows/typing.yml/badge.svg)](https://github.com/equinor/ert/actions/workflows/typing.yml)
[![codecov](https://codecov.io/gh/equinor/ert/branch/add_code_coverage/graph/badge.svg?token=keVAcWavZ1)](https://codecov.io/gh/equinor/ert)
[![Run test-data](https://github.com/equinor/ert/actions/workflows/run_ert2_test_data_setups.yml/badge.svg)](https://github.com/equinor/ert/actions/workflows/run_ert2_test_data_setups.yml)
[![Run polynomial demo](https://github.com/equinor/ert/actions/workflows/run_examples_polynomial.yml/badge.svg)](https://github.com/equinor/ert/actions/workflows/run_examples_polynomial.yml)
[![Run SPE1 demo](https://github.com/equinor/ert/actions/workflows/run_examples_spe1.yml/badge.svg)](https://github.com/equinor/ert/actions/workflows/run_examples_spe1.yml)
Expand Down
6 changes: 6 additions & 0 deletions ci/github/start_herbstluftwm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -euo pipefail

/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -screen 0 640x480x24 -ac +extension GLX
sleep 3
herbstluftwm
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fixes:
- "*/site-packages/::"
- "/home/runner/work/ert/ert/::"
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ setuptools_scm
pytest-snapshot
flake8>=4.0.0
cmake-format

pytest-cov
5 changes: 5 additions & 0 deletions libres/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.6.1)
project(res C CXX)

option(BUILD_TESTS "Should the tests be built" OFF)
option(COVERAGE "Should binaries record coverage information" OFF)

set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -52,6 +53,10 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
"RelWithDebInfo")
endif()

if(COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -Wall")
endif()

# -----------------------------------------------------------------
# Conan: C++ package manager
# https://docs.conan.io/en/latest/howtos/cmake_launch.html
Expand Down

0 comments on commit bd45dc6

Please sign in to comment.