Skip to content

Commit 922c4f4

Browse files
committed
Add Code Coverage reports in Merge Requests
Motivation: To maintain quality, automated code coverage reports should be generated and archived as build artifacts in CI pipelines. Modifications: Update CI config to run a job for running unit tests with code coverage, and exporting the report to GitLab. Result: Code coverage will be tracked and history recorded to compare individual code changes.
1 parent adbc2e3 commit 922c4f4

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

.gitlab/ci/main.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include: '/.gitlab/ci/platform-test.yml'
2+
13
stages:
24
- Platform Tests
35
- Quality Checks
@@ -27,6 +29,18 @@ Code Climate:
2729
reports:
2830
codequality: gl-code-quality-report.json
2931

32+
Code Coverage:
33+
extends: .platform-test
34+
stage: Quality Checks
35+
allow_failure: false
36+
image: swift:latest
37+
rules:
38+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
39+
changes:
40+
- '*.swift'
41+
script: scripts/generate_code_coverage.sh
42+
coverage: '/TOTAL.*(\s\d+\.\d+%)/'
43+
3044
.standard-platform-test:
3145
rules:
3246
- if: $CI_PIPELINE_SOURCE == "push"

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
</p>
1010

1111
<p>
12-
<a href="https://gitlab.com/Mordil/RediStack/pipelines"><img src="https://gitlab.com/Mordil/RediStack/badges/master/pipeline.svg" alt="Build Status"></a>
12+
<a href="https://gitlab.com/Mordil/RediStack/-/commits/master"><img alt="pipeline status" src="https://gitlab.com/Mordil/RediStack/badges/master/pipeline.svg" /></a>
13+
<a href="https://gitlab.com/Mordil/RediStack/-/commits/master"><img alt="coverage report" src="https://gitlab.com/Mordil/RediStack/badges/master/coverage.svg"/></a>
1314
<a href="https://swiftpackageindex.com/Mordil/RediStack/master/documentation/redistack"><img src="https://img.shields.io/badge/SPI-Documentation-blue.svg" alt="Documentation Coverage"></a>
1415
<a href="https://codeclimate.com/github/Mordil/RediStack/maintainability"><img src="https://api.codeclimate.com/v1/badges/b6fd5e7a3e669165a21b/maintainability" /></a>
1516
</p>

scripts/generate_code_coverage.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
##===----------------------------------------------------------------------===##
4+
##
5+
## This source file is part of the RediStack open source project
6+
##
7+
## Copyright (c) 2022 RediStack project authors
8+
## Licensed under Apache License v2.0
9+
##
10+
## See LICENSE.txt for license information
11+
## See CONTRIBUTORS.txt for the list of RediStack project authors
12+
##
13+
## SPDX-License-Identifier: Apache-2.0
14+
##
15+
##===----------------------------------------------------------------------===##
16+
17+
swift test --enable-code-coverage --enable-test-discovery
18+
19+
BUILD_BIN_PATH=$(swift build --show-bin-path)
20+
CODE_COV_PATH=$(swift test --show-codecov-path)
21+
22+
PROF_DATA_PATH="${CODE_COV_PATH%/*}/default.profdata"
23+
TEST_BINARY_PATH="${BUILD_BIN_PATH}/RediStackPackageTests.xctest"
24+
25+
IGNORE_FILENAME_REGEX="(\.build|TestUtils|Tests)"
26+
27+
llvm-cov report \
28+
$TEST_BINARY_PATH \
29+
--format=text \
30+
--instr-profile="$PROF_DATA_PATH" \
31+
--ignore-filename-regex="$IGNORE_FILENAME_REGEX"

0 commit comments

Comments
 (0)