-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |