Skip to content

attempt at coverage .yml #1

attempt at coverage .yml

attempt at coverage .yml #1

Workflow file for this run

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