Skip to content

Commit 237480f

Browse files
authored
[#258] Cleanup CI and Badge Colors
1 parent d0aeb34 commit 237480f

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

.github/workflows/mc_dc_coverage.yml

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,68 @@ jobs:
3737
tar -xjf /tmp/libgpg-error-1.50.tar.bz2 -C /tmp/
3838
cd /tmp/libgpg-error-1.50 && ./configure && make install
3939
curl -LS https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.11.0.tar.bz2 -o /tmp/libgcrypt-1.11.0.tar.bz2
40-
tar -xjf /tmp/libgcrypt-1.
40+
tar -xjf /tmp/libgcrypt-1.11.0.tar.bz2 -C /tmp/
41+
cd /tmp/libgcrypt-1.11.0 && ./configure && make install
42+
ldconfig
43+
44+
- name: Fix Detached HEAD State
45+
run: git checkout -B ${GITHUB_REF##*/}
46+
47+
- name: Build with Coverage Flags
48+
run: |
49+
export CFLAGS="-fprofile-arcs -ftest-coverage -g"
50+
bash ${GITHUB_WORKSPACE}/support/scripts/build_internal.sh
51+
52+
- name: Generate Coverage Report and Badges
53+
run: |
54+
mkdir -p doc/coverage
55+
gcovr --branches --xml-pretty --exclude-unreachable-branches -o doc/coverage/coverage_report.xml
56+
gcovr --branches --html --html-details -o doc/coverage/coverage_report.html
57+
58+
# Extract overall coverage metrics from the root <coverage> tag
59+
LINE_COVERAGE=$(grep -oP '(?<=<coverage line-rate=")[0-9.]+(?=")' doc/coverage/coverage_report.xml | head -n 1)
60+
BRANCH_COVERAGE=$(grep -oP '(?<=branch-rate=")[0-9.]+(?=")' doc/coverage/coverage_report.xml | head -n 1)
61+
62+
# Convert to percentages
63+
LINE_COVERAGE_PERCENT=$(printf "%.0f" $(echo "$LINE_COVERAGE * 100" | bc))
64+
BRANCH_COVERAGE_PERCENT=$(printf "%.0f" $(echo "$BRANCH_COVERAGE * 100" | bc))
65+
66+
# Debug extracted values
67+
echo "Line Coverage: $LINE_COVERAGE_PERCENT%"
68+
echo "Branch Coverage: $BRANCH_COVERAGE_PERCENT%"
69+
70+
# Determine colors based on coverage percentages
71+
if [ "$LINE_COVERAGE_PERCENT" -ge 80 ]; then
72+
LINE_COLOR="brightgreen"
73+
elif [ "$LINE_COVERAGE_PERCENT" -ge 50 ]; then
74+
LINE_COLOR="yellow"
75+
else
76+
LINE_COLOR="red"
77+
fi
78+
79+
if [ "$BRANCH_COVERAGE_PERCENT" -ge 80 ]; then
80+
BRANCH_COLOR="brightgreen"
81+
elif [ "$BRANCH_COVERAGE_PERCENT" -ge 50 ]; then
82+
BRANCH_COLOR="yellow"
83+
else
84+
BRANCH_COLOR="red"
85+
fi
86+
87+
# Generate badges with dynamic colors
88+
curl -o doc/coverage/line-coverage-badge.svg "https://img.shields.io/badge/line%20coverage-${LINE_COVERAGE_PERCENT}%25-${LINE_COLOR}"
89+
curl -o doc/coverage/branch-coverage-badge.svg "https://img.shields.io/badge/branch%20coverage-${BRANCH_COVERAGE_PERCENT}%25-${BRANCH_COLOR}"
90+
91+
- name: Commit Coverage Badges
92+
run: |
93+
git config user.name "github-actions"
94+
git config user.email "actions@github.com"
95+
git add doc/coverage/line-coverage-badge.svg
96+
git add doc/coverage/branch-coverage-badge.svg
97+
git commit -m "Update coverage badges" || echo "No changes to commit"
98+
git push origin HEAD
99+
100+
- name: Upload Coverage Report
101+
uses: actions/upload-artifact@v3
102+
with:
103+
name: coverage-report
104+
path: doc/coverage

0 commit comments

Comments
 (0)