Skip to content

Commit

Permalink
Add coveralls CI rule and lcov generator (#564)
Browse files Browse the repository at this point in the history
Adding coveralls so that test coverage can be easily displayed and checked
  • Loading branch information
tnek committed Aug 10, 2021
1 parent 7944f68 commit 1fcb63d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ jobs:
run: bazel build --apple_generate_dsym -c opt :release_driver --define=SANTA_BUILD_TYPE=ci
- name: Test
run: bazel test :unit_tests --define=SANTA_BUILD_TYPE=ci
- name: Generate test coverage
run: sh ./coverage/generate_cov.sh
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./CoverageData/info.lcov
flag-name: Unit
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.DS_Store
default.profraw
*.profraw
*.provisionprofile
bazel-*
Pods
Santa.xcodeproj/xcuserdata
Santa.xcodeproj/project.xcworkspace
Santa.xcworkspace/xcuserdata
Santa.xcworkspace/xcshareddata
CoverageData/*
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Santa ![CI](https://github.com/google/santa/workflows/CI/badge.svg?branch=main)
# Santa ![CI](https://github.com/google/santa/workflows/CI/badge.svg?branch=main) [![Coverage Status](https://coveralls.io/repos/github/google/santa/badge.svg?branch=main)](https://coveralls.io/github/google/santa?branch=main)

<p align="center">
<img src="./Source/santa/Resources/Images.xcassets/AppIcon.appiconset/santa-hat-icon-128.png" alt="Santa Icon" />
Expand Down Expand Up @@ -144,8 +144,8 @@ protect hosts in whatever other ways you see fit.
* [Zentral](https://github.com/zentralopensource/zentral/wiki) - A
centralized service that pulls data from multiple sources and deploy
configurations to multiple services.
* [Zercurity](https://github.com/zercurity/zercurity) - A dockerized service
for managing and monitoring applications across a large fleet utilizing
* [Zercurity](https://github.com/zercurity/zercurity) - A dockerized service
for managing and monitoring applications across a large fleet utilizing
Santa + Osquery.

* Alternatively, `santactl` can configure rules locally (without a sync
Expand Down
37 changes: 37 additions & 0 deletions coverage/generate_cov.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
GIT_ROOT=$(git rev-parse --show-toplevel)
PROFILE_PATH="$GIT_ROOT/CoverageData"
COV_FILE="$PROFILE_PATH/info.lcov"

function build() {
bazel coverage \
--test_env="LLVM_PROFILE_FILE=$PROFILE_PATH/default.profraw" \
--experimental_use_llvm_covmap \
--spawn_strategy=standalone \
--cache_test_results=no \
--test_env=LCOV_MERGER=/usr/bin/true \
--define=SANTA_BUILD_TYPE=ci \
//:unit_tests

xcrun llvm-profdata merge "$PROFILE_PATH/default.profraw" -output "$PROFILE_PATH/default.profdata"
}

function generate_lcov() {
object_files=$(find -L $(bazel info bazel-bin) -type f -exec file -L {} \; | grep "Mach-O" | sed 's,:.*,,')
bazel_base=$(bazel info execution_root)

true > $COV_FILE
for file in $object_files; do
xcrun llvm-cov export -instr-profile "$PROFILE_PATH/default.profdata" -format=lcov \
--ignore-filename-regex="external/.*" \
$file | sed "s,$bazel_base,$GIT_ROOT," >> $COV_FILE
done

}

function main() {
mkdir -p $PROFILE_PATH
build
generate_lcov
}
main

0 comments on commit 1fcb63d

Please sign in to comment.