Skip to content

Commit

Permalink
attempt at coverage .yml
Browse files Browse the repository at this point in the history
  • Loading branch information
jdinovi committed Dec 21, 2023
1 parent df88bf8 commit 8d682a1
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: coverage
on: [push, pull_request]

jobs:
test-coverage:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest]
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up C++ environment
uses: actions/setup-cxx@v2
with:
compiler: 'gcc'

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y gcov
- name: Build
run: |
cd
make build
- name: Generate coverage report
run: |
cd
# Function to calculate coverage for a file
calculate_coverage() {
local file=$1
local lines_executed=$(grep "File '$file'" -A 1 | awk '/Lines executed:/ {print $4}')
local total_lines=$(grep "File '$file'" -A 1 | awk '/Lines executed:/ {print $NF}')
local coverage=$(echo "scale=2; $lines_executed / $total_lines * 100" | bc)
echo $coverage
}
# Extract list of files from the provided output
files_input=$(make coverage | grep "File '" | awk -F"'" '{print $2}')
files=($files_input)
# Calculate coverage for each file and accumulate the total coverage
total_coverage=0
for file in "${files[@]}"; do
file_coverage=$(calculate_coverage "$file")
total_coverage=$(echo "scale=2; $total_coverage + $file_coverage" | bc)
done
COVERAGE=$(echo "scale=2; $total_coverage / ${#files[@]}" | bc)
if [ "$COVERAGE" -gt 89 ]; then
echo "success"
else
echo "failure"
fi

0 comments on commit 8d682a1

Please sign in to comment.