Skip to content

Commit

Permalink
Merge pull request #262 from MaLoefUDS/wip-coverage-reports
Browse files Browse the repository at this point in the history
Integrate code coverage metric into CI

Reviewed-by: Thomas Bock <bockthom@cs.uni-saarland.de>
  • Loading branch information
bockthom authored May 22, 2024
2 parents 2b38824 + 1e8c23b commit 4d35daa
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 13 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
sudo apt-get install --assume-yes libxml2-dev
sudo apt-get install --assume-yes libglpk-dev
sudo apt-get install --assume-yes libfontconfig1-dev
sudo apt-get install --assume-yes libssl-dev
sudo apt-get install --assume-yes libcurl4-openssl-dev
sudo su -c "echo 'deb https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/' >> /etc/apt/sources.list"
wget -qO- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | sudo tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
Expand All @@ -62,8 +64,42 @@ jobs:
run: Rscript install.R

- name: Run Tests
id: run_tests
run: Rscript tests.R

- name: Run Showcase
run: Rscript showcase.R
if: always()

- name: Generate Coverage Report
id: gen_coverage
run: Rscript coverage.R
if: matrix.r-version == 'latest' && steps.run_tests.outcome == 'success'

- name: Store coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: cobertura.xml
if: matrix.r-version == 'latest' && steps.gen_coverage.outcome == 'success'

upload-coverage-report:
name: Upload coverage report
needs: build
runs-on: ubuntu-latest

steps:
- name: Load coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report

- name: Upload Report to CodeCov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: cobertura.xml
disable_search: true
fail_ci_if_error: true
verbose: true

4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ In our development process, we pursue the following idea:
- The current development will be performed on the branch `dev`, i.e., all incoming pull requests are against this branch.

The current build status is as follows:
- `master`: ![Build Status](https://github.com/se-sic/coronet/actions/workflows/pull_request.yml/badge.svg?branch=master)
- `dev`: ![Build Status](https://github.com/se-sic/coronet/actions/workflows/pull_request.yml/badge.svg?branch=dev)
- `master`: ![Build Status](https://github.com/se-sic/coronet/actions/workflows/pull_request.yml/badge.svg?branch=master) [![Coverage Status](https://codecov.io/gh/se-sic/coronet/branch/master/graph/badge.svg?token=2dhAb3ScLy)](https://codecov.io/gh/se-sic/coronet)
- `dev`: ![Build Status](https://github.com/se-sic/coronet/actions/workflows/pull_request.yml/badge.svg?branch=dev) [![Coverage Status](https://codecov.io/gh/se-sic/coronet/branch/dev/graph/badge.svg?token=2dhAb3ScLy)](https://codecov.io/gh/se-sic/coronet)

### Pull Requests

Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
- Add commit-interaction data and add functions `read.commit.interactions` for reading, as well as `get.commit.interactions`, `set.commit.interactions` and utility functions for working with commit-interaction data (PR #252, d82857fbebd1111bb16588a4223bb24a8dcd07de, b4fd2a29c9b5fd561b1106c6febb54a32b0085ab, fd0aa05f824b93545ae8e05833b95b3bd9809286, bca35760eb0aac86c04923f2d534b2d8cece204e) as well as tests for these features (PR #252, eeba7e29932bc973513c963fb9e716e9230d570f, 8bb39f4df39b49dfaff8f19feb6db5e5fbd81fac, 54b6f655248720436af116fe72521f9cb0348429, 7a5497aaf9114017d1b3b9b68b6cccd7ca8ac114, 7b8585f87675795822c07230192d6454de31dcc7, ef725407bf8818c8fff96ea6f343338b7162cbe0)
- Add commit-interaction networks that can be created with `create.author.network` and `create.artifact.network` if the `artifact.relation` and `author.relation` is configured to be `commit.interaction` (PR #252, d82857fbebd1111bb16588a4223bb24a8dcd07de, 329d97ec3de36a9e1bcadc0c7a53c1d92e8b481c) as well as tests for these features (PR #252, 07e7ed744209b0251217fa8f7f35d9b9875face2, 7068cfa10d993dcae3f5e3f76f8cafa99fa8b350)
- Add helper function for prefixing function names with file names in `util-read.R` (PR #252, f8ea987b138173cf0509c7910e0572d8ee1b3f1f)
- Add line-based code coverage reports into CI pipeline. Coverage reports are generated by `coverage.R` (PR #262, 10cac49d005e87c3964cc61711e7f5acef749626, b3b9f4ac7a9911bd00293c68fac88e0f9033bdfb, c815d18dc6266d620a7a145493417b87ac08679e, e8093525fdaf46e54f2f7fcc6358ca7892e795e5, 32d04823e2007c63d2a43ce59bea3057327c19a7)

### Changed/Improved

### Fixed

- Ensure the correct installation of a compatible `Matrix` version for R 3.6 (PR #262, cb1cf42b2136f35b7e85239d36d5f91ff05d8cd7)

## 4.4

### Announcement
Expand Down
67 changes: 67 additions & 0 deletions coverage.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
## This file is part of coronet, which is free software: you
## can redistribute it and/or modify it under the terms of the GNU General
## Public License as published by the Free Software Foundation, version 2.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along
## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
##
## Copyright 2024 by Maximilian Löffler <s8maloef@stud.uni-saarland.de>
## All Rights Reserved.

## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Initialization ----------------------------------------------------------

source("util-init.R")
source("tests/testing-utils.R")


## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Logging -----------------------------------------------------------------

library("methods") # to prevent weird error during logger initialization (see #153)
library("logging")
logging::basicConfig(level = "WARN")
options(mc.cores = 1L)


## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Debug information -------------------------------------------------------

logging::loginfo("Session information:")
sessionInfo()


## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Run tests in subfolder 'tests' ------------------------------------------

logging::loginfo("Generating coverage report.")

## load packages 'testthat' and 'patrick'
library("testthat")
requireNamespace("patrick")
requireNamespace("covr")

## define paths
test.dir = c("./tests")
code.dir = c(".")
excluded.code.files = c("./tests.R", "./coverage.R", "./showcase.R", "./install.R", "./util-init.R")
excluded.test.files = c()

## obtain files
test.files = unlist(sapply(test.dir, list.files, pattern = "\\.R$", full.names = TRUE))
test.files = test.files[!test.files %in% excluded.test.files]
code.files = unlist(sapply(code.dir, list.files, pattern = "\\.R$", full.names = TRUE))
code.files = code.files[!code.files %in% excluded.code.files]

## adjust data path prefix when generating coverage reports
DATA.PATH.PREFIX = "./tests"

## generate and save coverage report
report = covr::file_coverage(source_files = code.files, test_files = test.files)
covr::to_cobertura(report)
17 changes: 11 additions & 6 deletions install.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
## Copyright 2015 by Wolfgang Mauerer <wolfgang.mauerer@oth-regensburg.de>
## Copyright 2015-2017 by Claus Hunsen <hunsen@fim.uni-passau.de>
## Copyright 2017 by Thomas Bock <bockthom@fim.uni-passau.de>
## Copyright 2020-2023 by Thomas Bock <bockthom@cs.uni-saarland.de>
## Copyright 2020-2024 by Thomas Bock <bockthom@cs.uni-saarland.de>
## Copyright 2019 by Anselm Fehnker <fehnker@fim.uni-passau.de>
## Copyright 2021 by Christian Hechtl <hechtl@cs.uni-saarland.de>
## Copyright 2024 by Leo Sendelbach <s8lesend@stud.uni-saarland.de>
## Copyright 2024 by Maximilian Löffler <s8@maloef@stud.uni-saarland.de>
## All Rights Reserved.
##
## Adapted from https://github.com/siemens/codeface/blob/be382e9171fb91b4aa99b99b09b2ef64a6dba0d5/packages.r
Expand All @@ -36,18 +37,20 @@ packages = c(
"sqldf",
"data.table",
"reshape2",
"testthat",
"patrick",
"ggplot2",
"ggraph",
"markovchain",
"lubridate",
"viridis",
"jsonlite",
"xml2",
"rTensor",
"Matrix",
"fastmap",
"purrr"
"purrr",
"testthat",
"patrick",
"covr"
)


Expand Down Expand Up @@ -75,10 +78,12 @@ if (length(p) > 0) {
Matrix.version = installed.packages()[rownames(installed.packages()) == "Matrix", "Version"]
if (compareVersion(Matrix.version, "1.3.0") == -1) {
print("WARNING: Matrix version 1.3.0 or higher is necessary for using coronet. Re-install package Matrix...")
install.packages("Matrix", dependencies = NA, verbose = TRUE, quiet = TRUE)
#install.packages("Matrix", dependencies = NA, verbose = TRUE, quiet = TRUE)
matrix.1.3.4.url = "https://cran.r-project.org/src/contrib/Archive/Matrix/Matrix_1.3-4.tar.gz"
install.packages(matrix.1.3.4.url, repos = NULL, dependencies = NA, verbose = TRUE, quiet = TRUE)
Matrix.version = installed.packages()[rownames(installed.packages()) == "Matrix", "Version"]
if (compareVersion(Matrix.version, "1.3.0") == -1) {
print("WARNING: Re-installation of package Matrix did not end up in the necessary packge version.")
print("WARNING: Re-installation of package Matrix did not end up in the necessary package version.")
}
}
}
8 changes: 4 additions & 4 deletions tests/test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
## Copyright 2021 by Johannes Hostert <s8johost@stud.uni-saarland.de>
## Copyright 2021 by Mirabdulla Yusifli <s8miyusi@stud.uni-saarland.de>
## Copyright 2022 by Jonathan Baumann <joba00002@stud.uni-saarland.de>
## Copyright 2023 by Maximilian Löffler <s8maloef@stud.uni-saarland.de>
## Copyright 2023-2024 by Maximilian Löffler <s8maloef@stud.uni-saarland.de>
## Copyright 2024 by Leo Sendelbach <s8lesend@stud.uni-saarland.de>
## All Rights Reserved.

Expand Down Expand Up @@ -489,7 +489,7 @@ test_that("Cut data and check for right data path", {
project.data = ProjectData$new(project.configuration)
project.data = project.data$get.data.cut.to.same.date(data.sources = c("mails", "commits"))

expected = "./codeface-data/results/testing/test_feature/feature"
expected = paste0(DATA.PATH.PREFIX, "/codeface-data/results/testing/test_feature/feature")
result = project.data$get.data.path()
expect_identical(result, expected, info = "RangeData data path.")

Expand All @@ -514,8 +514,8 @@ test_that("Create RangeData objects from Codeface ranges and check data path", {
range.paths = run.lapply(data, "get.data.path")
range.paths = unlist(range.paths, use.names = FALSE)

expected.paths = c("./codeface-data/results/testing/test_feature/feature/001--v1-v2",
"./codeface-data/results/testing/test_feature/feature/002--v2-v3")
expected.paths = c(paste0(DATA.PATH.PREFIX, "/codeface-data/results/testing/test_feature/feature/001--v1-v2"),
paste0(DATA.PATH.PREFIX, "/codeface-data/results/testing/test_feature/feature/002--v2-v3"))

expect_identical(range.paths, expected.paths, "RangeData data paths")
})
Expand Down
9 changes: 8 additions & 1 deletion tests/testing-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
##
## Copyright 2022 by Jonathan Baumann <joba00002@stud.uni-saarland.de>
## Copyright 2024 by Leo Sendelbach <s8lesend@stud.uni-saarland.de>
## Copyright 2024 by Maximilian Löffler <s8maloef@stud.uni-saarland.de>
## All Rights Reserved.

## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
Expand All @@ -21,6 +22,12 @@
requireNamespace("patrick")
requireNamespace("igraph")

## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Constants ---------------------------------------------------------------

## The path prefix for data files
DATA.PATH.PREFIX = "."

#' Construct the 'cross product' of two patrick::cases objects.
#' Each case of the first object is combined with each case of the second,
#' test names are joined with a comma.
Expand Down Expand Up @@ -150,4 +157,4 @@ assert.sparse.matrices.equal = function(matrix.expected, matrix.actual) {
for (i in seq_len(expected.size)) {
expect_equal(matrix.expected[i], matrix.actual[i])
}
}
}

0 comments on commit 4d35daa

Please sign in to comment.