Skip to content

Update mc_dc_coverage.yml #19

Update mc_dc_coverage.yml

Update mc_dc_coverage.yml #19

name: CryptoLib Coverage
on:
push:
branches:
- 258-cyclomatic-complexity-and-mcdc-in-ci
paths-ignore:
- 'coverage/line-coverage-badge.svg'
- 'coverage/branch-coverage-badge.svg'
pull_request:
branches:
- 258-cyclomatic-complexity-and-mcdc-in-ci
jobs:
coverage:
runs-on: ubuntu-latest
container:
image: ivvitc/cryptolib:20240814
steps:
# Step 1: Checkout Repository
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for branch operations
# Step 2: Configure Safe Directory
- name: Configure Safe Directory
run: git config --global --add safe.directory $GITHUB_WORKSPACE
# Step 3: Install Dependencies
- name: Install Dependencies
env:
DEBIAN_FRONTEND: noninteractive
TZ: Etc/UTC
run: |
apt-get update
apt-get install -y lcov libcurl4-openssl-dev libmariadb-dev libmariadb-dev-compat python3 gcovr
pip install pycryptodome
curl -LS https://www.gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.50.tar.bz2 -o /tmp/libgpg-error-1.50.tar.bz2
tar -xjf /tmp/libgpg-error-1.50.tar.bz2 -C /tmp/
cd /tmp/libgpg-error-1.50 && ./configure && make install
curl -LS https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.11.0.tar.bz2 -o /tmp/libgcrypt-1.11.0.tar.bz2
tar -xjf /tmp/libgcrypt-1.11.0.tar.bz2 -C /tmp/
cd /tmp/libgcrypt-1.11.0 && ./configure && make install
ldconfig
# Step 4: Fix Detached HEAD State
- name: Fix Detached HEAD State
run: git checkout -B ${GITHUB_REF##*/}
# Step 5: Build with Coverage Flags
- name: Build with Coverage Flags
run: |
export CFLAGS="-fprofile-arcs -ftest-coverage -g"
bash ${GITHUB_WORKSPACE}/support/scripts/build_internal.sh
# Step 6: Generate Coverage Report and Badges
- name: Generate Coverage Report and Badges
run: |
mkdir -p coverage
gcovr --branches --xml-pretty --exclude-unreachable-branches -o coverage/coverage_report.xml
gcovr --branches --html --html-details -o coverage/coverage_report.html
# Extract overall coverage metrics from the root <coverage> tag
LINE_COVERAGE=$(grep -oP '(?<=<coverage line-rate=")[0-9.]+(?=")' coverage/coverage_report.xml | head -n 1)
BRANCH_COVERAGE=$(grep -oP '(?<=branch-rate=")[0-9.]+(?=")' coverage/coverage_report.xml | head -n 1)
# Convert to percentages
LINE_COVERAGE_PERCENT=$(printf "%.0f" $(echo "$LINE_COVERAGE * 100" | bc))
BRANCH_COVERAGE_PERCENT=$(printf "%.0f" $(echo "$BRANCH_COVERAGE * 100" | bc))
# Debug extracted values
echo "Line Coverage: $LINE_COVERAGE_PERCENT%"
echo "Branch Coverage: $BRANCH_COVERAGE_PERCENT%"
# Generate badges
curl -o coverage/line-coverage-badge.svg "https://img.shields.io/badge/line%20coverage-${LINE_COVERAGE_PERCENT}%25-brightgreen"
curl -o coverage/branch-coverage-badge.svg "https://img.shields.io/badge/branch%20coverage-${BRANCH_COVERAGE_PERCENT}%25-brightgreen"
# Step 7: Commit Badges to the Current Branch
- name: Commit Coverage Badges
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git add coverage/line-coverage-badge.svg
git add coverage/branch-coverage-badge.svg
git commit -m "Update coverage badges"
git push origin HEAD
# Step 8: Upload Coverage Report
- name: Upload Coverage Report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage