Skip to content

Commit dda3142

Browse files
authored
Merge branch 'main' into uncrustifyFormatting
2 parents ab45ced + bb7863c commit dda3142

File tree

2 files changed

+195
-30
lines changed

2 files changed

+195
-30
lines changed

.github/workflows/test.yml

Lines changed: 97 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ on:
77
branches: [main]
88
workflow_dispatch:
99

10+
env:
11+
# The bash escape character is \033
12+
bashPass: \033[32;1mPASSED -
13+
bashInfo: \033[33;1mINFO -
14+
bashFail: \033[31;1mFAILED -
15+
bashEnd: \033[0m
16+
1017
jobs:
1118
test-format-check:
1219
runs-on: ubuntu-20.04
@@ -281,41 +288,118 @@ jobs:
281288
uses: ./spellings
282289
with:
283290
path: coreMQTT
291+
284292
test-coverage-cop:
285293
runs-on: ubuntu-latest
286294
steps:
287-
- uses: actions/checkout@v2
288-
- uses: actions/checkout@v2
295+
- uses: actions/checkout@v3
296+
- uses: actions/checkout@v3
289297
with:
290-
repository: FreeRTOS/coreMQTT
298+
repository: skptak/coreMQTT
291299
ref: main
292300
path: coreMQTT
293-
- name: Build
301+
302+
- env:
303+
stepName: Build Core MQTT
304+
name: ${{ env.stepName }}
294305
run: |
306+
# ${{ env.stepName }}
307+
exitStatus=0
308+
309+
echo -e "::group::Install Lcov"
295310
sudo apt-get install -y lcov
311+
echo -e "::endgroup::"
312+
313+
echo -e "::group::${{ env.stepName }}"
296314
cmake -S ./coreMQTT/test -B build/ \
297315
-G "Unix Makefiles" \
298316
-DCMAKE_BUILD_TYPE=Debug \
299317
-DBUILD_CLONE_SUBMODULES=ON \
300318
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Werror -DNDEBUG -DLIBRARY_LOG_LEVEL=LOG_DEBUG'
301319
make -C build/ all
302-
- name: Test
303-
run: |
304-
cd build/
305-
ctest -E system --output-on-failure
306-
cd ..
307-
- name: Run Coverage
320+
exitStatus=$?
321+
echo -e "::endgroup::"
322+
323+
# Only get to here if we passed the build
324+
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
325+
326+
327+
- name: Run CTest for CoreMQTT
328+
run: ctest --test-dir build -E system --output-on-failure
329+
330+
- env:
331+
stepName: Passing Coverage Test
332+
shell: bash
308333
run: |
334+
# ${{ env.stepName }}
335+
echo -e "::group::Build Coverage for coreMQTT"
309336
make -C build/ coverage
337+
echo -e "::endgroup::"
338+
339+
echo -e "::group::${{ env.stepName }}"
310340
declare -a EXCLUDE=("\*test/\*" "\*CMakeCCompilerId\*" "\*mocks\*")
311-
echo ${EXCLUDE[@]} | xargs lcov --rc lcov_branch_coverage=1 -r build/coverage.info -o build/coverage.info
341+
echo ${EXCLUDE[@]} | xargs lcov --rc lcov_branch_coverage=1 --remove build/coverage.info -o build/coverage.info
342+
echo -e "::endgroup::"
343+
312344
lcov --rc lcov_branch_coverage=1 --list build/coverage.info
313-
- name: Test coverage cop action
345+
echo -e "${{ env.bashPass }} ${{env.stepName }} ${{ env.bashEnd }}"
346+
347+
- name: Test Coverage Cop Action
348+
id: success-coverage-cop
314349
uses: ./coverage-cop
315350
with:
316-
path: ./build/coverage.info
351+
coverage-file: ./build/coverage.info
317352
branch-coverage-min: 70
318353
line-coverage-min: 100
354+
355+
- env:
356+
stepName: Create Lower Branch and Line Coverage Report
357+
id: failure-coverage-action
358+
continue-on-error: true
359+
shell: bash
360+
run: |
361+
# ${{ env.stepName }}
362+
echo -e "::group::Build Coverage for coreMQTT"
363+
make -C build/ clean
364+
make -C build/ coverage
365+
echo -e "::endgroup::"
366+
367+
echo -e "::group::${{ env.stepName }}"
368+
declare -a EXCLUDE=("\*test/\*")
369+
set +e
370+
lcov --rc lcov_branch_coverage=1 --remove build/coverage.info -o build/coverage.info
371+
echo -e "::endgroup::"
372+
373+
lcov --rc lcov_branch_coverage=1 --list build/coverage.info
374+
set -e
375+
echo -e "${{ env.bashPass }} ${{env.stepName }} ${{ env.bashEnd }}"
376+
377+
- name: Functional | Failure | Coverage Cop Failure Test Case
378+
id: failure-coverage-cop-action
379+
continue-on-error: true
380+
uses: ./coverage-cop
381+
with:
382+
coverage-file: ./build/coverage.info
383+
branch-coverage-min: 100
384+
line-coverage-min: 100
385+
386+
- env:
387+
stepName: Check Failure Test Case
388+
name: ${{ env.stepName }}
389+
if: success() || failure()
390+
id: check-failure-test-cases
391+
shell: bash
392+
run: |
393+
# ${{ env.stepName }}
394+
exitStatus=0
395+
if [ "${{ steps.failure-coverage-cop-action.outcome }}" = "failure" ]; then
396+
echo -e "${{ env.bashPass }} Functional | Failure | Coverage Cop Failure Test Case | Had Expected "failure" ${{ env.bashEnd }}"
397+
else
398+
echo -e "${{ env.bashFail }} Functional | Failure | Coverage Cop Failure Test Case | Had Unexpected "success" ${{ env.bashEnd }}"
399+
exitStatus=1
400+
fi
401+
exit $exitStatus
402+
319403
test-memory-statistics:
320404
runs-on: ubuntu-latest
321405
steps:

coverage-cop/action.yml

Lines changed: 98 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,123 @@
11
name: 'coverage-cop'
22
description: 'CI Check Coverage results of unit tests (using lcov)'
33
inputs:
4-
path:
4+
coverage-file:
55
description: 'Path to lcov output file containing coverage data.'
66
required: true
77
branch-coverage-min:
88
description: 'The minumum required branch coverage (in %) for success'
99
required: false
10-
default: 100
10+
default: 95
1111
line-coverage-min:
1212
description: 'The minumum required line coverage (in %) for success'
1313
required: false
14-
default: 100
14+
default: 95
1515
runs:
1616
using: "composite"
17-
steps:
18-
- name: Print coverage data
19-
run: lcov --list --rc lcov_branch_coverage=1 ${{ inputs.path }}
17+
steps:
18+
- env:
19+
stepName: Install Dependencies
20+
bashPass: \033[32;1mPASSED -
21+
bashInfo: \033[33;1mINFO -
22+
bashFail: \033[31;1mFAILED -
23+
bashEnd: \033[0
2024
shell: bash
21-
- name: Install lcov (if not present)
22-
run: sudo apt-get install lcov
25+
name: ${{ env.stepName }}
26+
run: |
27+
# ${{ env.stepName }}
28+
echo -e "::group::${{ env.stepName }}"
29+
sudo apt-get install lcov fd-find
30+
echo -e "::endgroup::"
31+
echo -e "${{ env.bashPass }} ${{env.stepName }} ${{ env.bashEnd }}"
32+
33+
- env:
34+
stepName: Check Line and Branch Coverage
35+
bashPass: \033[32;1mPASSED -
36+
bashInfo: \033[33;1mINFO -
37+
bashFail: \033[31;1mFAILED -
38+
bashEnd: \033[0
39+
name: ${{ env.stepName }}
40+
id: action-check-line-and-branch-coverage
2341
shell: bash
24-
- name: Check coverage
2542
run: |
26-
LINE_COVERAGE=$(lcov --list ${{ inputs.path }} | tail -n 1 | cut -d '|' -f 2 | sed -n "s/\([^%]*\)%.*/\1/p")
27-
BRANCH_COVERAGE=$(lcov --rc lcov_branch_coverage=1 --list ${{ inputs.path }} | tail -n 1 | cut -d '|' -f 4 | sed -n "s/\([^%]*\)%.*/\1/p")
43+
# ${{ env.stepName }}
44+
45+
# Print the received code cov report.
46+
# TODO: The way it grabs the line/branch coverage is a little complicated
47+
# I'd like to see if this can be done simpler.
48+
echo -e " ${{ env.bashInfo }} Received LCov Report: ${{ inputs.line-coverage-min }} ${{ env.bashEnd}}"
49+
lcov --list --rc lcov_branch_coverage=1 ${{ inputs.coverage-file }}
50+
LINE_COVERAGE=$(lcov --list ${{ inputs.coverage-file }} | tail -n 1 | cut -d '|' -f 2 | sed -n "s/\([^%]*\)%.*/\1/p")
51+
BRANCH_COVERAGE=$(lcov --rc lcov_branch_coverage=1 --list ${{ inputs.coverage-file }} | tail -n 1 | cut -d '|' -f 4 | sed -n "s/\([^%]*\)%.*/\1/p")
2852
RESULT=0
29-
echo "Required line coverage: ${{ inputs.line-coverage-min }}"
30-
echo "Line coverage: $LINE_COVERAGE"
53+
54+
# Check Line Coverage
55+
echo -e " ${{ env.bashInfo }} Required Line Coverage: ${{ inputs.line-coverage-min }} ${{ env.bashEnd}}"
56+
echo -e " ${{ env.bashInfo }} Received Line Coverage: $LINE_COVERAGE ${{ env.bashEnd}}"
3157
if [[ $(echo "$LINE_COVERAGE < ${{ inputs.line-coverage-min }}" | bc) -ne 0 ]]; then
32-
echo "Line Coverage is too low."
58+
echo -e "${{ env.bashFail }} Line Coverage is too low. ${{ env.bashEnd }}"
3359
RESULT=1
3460
fi
35-
echo "Required branch coverage: ${{ inputs.branch-coverage-min }}"
36-
echo "Branch coverage: $BRANCH_COVERAGE"
61+
62+
echo -e " ${{ env.bashInfo }} Required Branch Coverage: ${{ inputs.branch-coverage-min }} ${{ env.bashEnd}}"
63+
echo -e " ${{ env.bashInfo }} Received Branch Coverage: $BRANCH_COVERAGE ${{ env.bashEnd}}"
3764
if [[ $(echo "$BRANCH_COVERAGE < ${{ inputs.branch-coverage-min }}" | bc) -ne 0 ]]; then
38-
echo "Branch Coverage is too low."
65+
echo -e "${{ env.bashFail }} Branch Coverage is too low. ${{ env.bashEnd }}"
3966
RESULT=1
4067
fi
68+
69+
if [ $RESULT -eq 0 ]; then
70+
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
71+
else
72+
echo -e "::group::Create Failed Codecov HTML Report"
73+
genhtml --rc lcov_branch_coverage=1 --ignore-errors source ${{ inputs.coverage-file }} --legend --title "$(basename `git rev-parse --show-toplevel`) $(git rev-parse HEAD)" --output-directory=CodecovHTMLReport
74+
zip -r CodecovHTMLReport.zip CodecovHTMLReport
75+
echo -e "::endgroup::"
76+
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
77+
fi
4178
exit $RESULT
79+
80+
- name: Upload Failed Codecov HTML Report
81+
if: failure() && ( steps.action-check-line-and-branch-coverage.outcome == 'failure' )
82+
id: upload-codecov-report
83+
uses: actions/upload-artifact@v3
84+
with:
85+
name: CodecovHTMLReport
86+
path: CodecovHTMLReport.zip
87+
retention-days: 5
88+
89+
- env:
90+
stepName: Codecov Report Info
91+
bashPass: \033[32;1m
92+
bashInfo: \033[33;1m
93+
bashFail: \033[31;1m
94+
bashEnd: \033[0
95+
if: failure() && ( steps.upload-codecov-report.outcome == 'success' )
4296
shell: bash
97+
run: |
98+
# ${{ env.stepName }}
99+
echo -e "${{ env.bashInfo }} A zip file of the failed Codecov report has been attached to this workflow ${{ env.bashEnd }}"
100+
echo -e "${{ env.bashInfo }} This can be accessed by returning to the bottom of the summary page of the workflow run ${{ env.bashEnd }}"
101+
echo -e "${{ env.bashInfo }} At the bottom of the page will be a CodecovHTMLReport.zip file that you can download ${{ env.bashEnd }}"
102+
echo -e "${{ env.bashInfo }} Unzip the file and then open the index.html file in your browser for more info missing branch and line coverage ${{ env.bashEnd }}"
103+
exit 1
104+
105+
106+
107+
# We should use this - it creates a link on their website that you can access
108+
# And it displays the results there, which is great.
109+
# But it means we need to set up a Codecov dashboard for each repo and then
110+
# Add that to a secret to use by default when using it.
111+
# CorePKCS11 evidently has this, but I don't know who set that up or what approvals it took
112+
# So For now I'm going to create the html report and add it to the run.
113+
# More info here: https://about.Codecov.io/blog/how-to-set-up-Codecov-with-c-and-github-actions/
114+
# - env:
115+
# stepName: Upload Line and Branch Report
116+
# name: ${{ env.stepName }}
117+
# if: failure()
118+
# uses: Codecov/Codecov-action@v3
119+
# with:
120+
# files: ${{ inputs.coverage-file }}
121+
# flags: unit_tests
122+
# fail_ci_if_error: false
123+
# verbose: false

0 commit comments

Comments
 (0)