1+ name : MCDC Analysis
2+
3+ on :
4+ push :
5+ branches :
6+ - dev
7+ - main
8+ pull_request :
9+ types :
10+ - opened
11+ - reopened
12+ - synchronize
13+ workflow_dispatch :
14+
15+ # Force bash to apply pipefail option so pipeline failures aren't masked
16+ defaults :
17+ run :
18+ shell : bash
19+
20+ env :
21+ SIMULATION : native
22+ TESTS_RAN : false
23+
24+ jobs :
25+ # Checks for duplicate actions. Skips push actions if there is a matching or
26+ # duplicate pull-request action.
27+ checks-for-duplicates :
28+ runs-on : ubuntu-22.04
29+ # Map a step output to a job output
30+ outputs :
31+ should_skip : ${{ steps.skip_check.outputs.should_skip }}
32+ steps :
33+ - id : skip_check
34+ uses : fkirc/skip-duplicate-actions@master
35+ with :
36+ concurrent_skipping : ' same_content'
37+ skip_after_successful_duplicate : ' true'
38+ do_not_skip : ' ["pull_request", "workflow_dispatch", "schedule"]'
39+
40+ mcdc :
41+ needs : checks-for-duplicates
42+ if : ${{ needs.checks-for-duplicates.outputs.should_skip != 'true' || contains(github.ref, 'dev') || contains(github.ref, 'main') }}
43+ name : Build and Run MCDC
44+ runs-on : ubuntu-22.04
45+ container : ghcr.io/core-flight-system/mcdc:latest
46+
47+ steps :
48+ - name : Checkout MCDC Script
49+ uses : actions/checkout@v6
50+ with :
51+ repository : nasa/cFS
52+ path : mcdc
53+ ref : dev
54+
55+ - name : Checkout OSAL
56+ uses : actions/checkout@v6
57+ with :
58+ path : source
59+
60+ - name : Modify osal to include coverage flags
61+ run : |
62+ sed -i 's/target_compile_options.*)/target_compile_options(ut_coverage_compile INTERFACE -pg -O0 -fprofile-arcs -ftest-coverage -fcondition-coverage -fprofile-abs-path)/' source/src/bsp/generic-linux/CMakeLists.txt
63+ sed -i 's/set(UT_COVERAGE_COMPILE_FLAGS.*)/set(UT_COVERAGE_COMPILE_FLAGS -pg --coverage -O0 -fcondition-coverage -fprofile-abs-path)/' source/src/bsp/generic-linux/build_options.cmake
64+ sed -i 's/set(UT_COVERAGE_LINK_FLAGS.*)/set(UT_COVERAGE_LINK_FLAGS -pg --coverage -O0 -fcondition-coverage -fprofile-abs-path)/' source/src/bsp/generic-linux/build_options.cmake
65+
66+ - name : Set up build
67+ run : cmake
68+ -DCMAKE_BUILD_TYPE=Debug
69+ -DENABLE_UNIT_TESTS=TRUE
70+ -DOSAL_OMIT_DEPRECATED=FALSE
71+ -DOSAL_VALIDATE_API=FALSE
72+ -DOSAL_INSTALL_LIBRARIES=FALSE
73+ -DOSAL_CONFIG_DEBUG_PERMISSIVE_MODE=TRUE
74+ -DOSAL_SYSTEM_BSPTYPE=generic-linux
75+ -DCMAKE_PREFIX_PATH=/usr/lib/cmake
76+ -DCMAKE_INSTALL_PREFIX=/usr
77+ -S source
78+ -B build
79+
80+ - name : Build OSAL
81+ working-directory : build
82+ run : make VERBOSE=1
83+
84+ - name : Execute Tests
85+ working-directory : build
86+ run : |
87+ echo "BASE_DIR=build/unit-test-coverage" >> $GITHUB_ENV
88+ (ctest --output-on-failure -j4 2>&1 || true) | tee ../test_results.txt
89+ echo "TESTS_RAN=true" >> $GITHUB_ENV
90+
91+ - name : Grab test modules
92+ if : ${{ env.TESTS_RAN == 'true' }}
93+ run : |
94+ echo "MODULES=$(grep -oP 'Test\s+#\d+: \K[\w\-\_]+(?= )' test_results.txt | tr '\n' ' ' | sed 's/ $//')" >> $GITHUB_ENV
95+ grep -oP 'Test #\d+: \K[\w\-\_]+' test_results.txt | tr '\n' ' ' | sed 's/ $//' >> modules.txt
96+
97+ - name : Run mcdc analysis
98+ if : ${{ env.TESTS_RAN == 'true' }}
99+ run : bash mcdc/.github/scripts/mcdc-analyze.sh
100+
101+ - name : Save PR number
102+ if : github.event_name == 'pull_request' && always()
103+ env :
104+ PR_NUMBER : ${{ github.event.number }}
105+ run : echo $PR_NUMBER > pr_number
106+
107+ - name : Archive unit test results
108+ # Upload if success or failure which supports skipping, unlike always()
109+ if : ${{ env.TESTS_RAN == 'true' }}
110+ uses : actions/upload-artifact@v7
111+ with :
112+ name : Unit test results
113+ path : |
114+ test_results.txt
115+
116+ - name : Archive mcdc results
117+ # Upload if success or failure which supports skipping, unlike always()
118+ if : ${{ env.TESTS_RAN == 'true' }}
119+ uses : actions/upload-artifact@v7
120+ with :
121+ name : MCDC results
122+ path : |
123+ **/*.gcov.json.gz
124+ mcdc_results.txt
125+ pr_number
126+ modules.txt
127+
128+ summary-mcdc :
129+ needs : mcdc
130+ if : github.event_name == 'pull_request' && always()
131+ name : Generate MCDC Comparison Summary
132+ runs-on : ubuntu-22.04
133+
134+ steps :
135+ - name : Checkout MCDC Script
136+ uses : actions/checkout@v6
137+ with :
138+ repository : nasa/cFS
139+ path : mcdc
140+ ref : dev
141+
142+ - name : Download latest main branch artifact
143+ continue-on-error : true
144+ uses : dawidd6/action-download-artifact@v2
145+ with :
146+ github_token : ${{ secrets.GITHUB_TOKEN }}
147+ workflow : mcdc-internal.yml
148+ search_artifacts : true
149+ branch : dev
150+ name : MCDC results
151+ path : main-branch-results
152+
153+ - uses : actions/download-artifact@v8
154+ with :
155+ name : MCDC results
156+
157+ - name : Compare main and PR artifacts
158+ run : |
159+ if [ -f "main-branch-results/mcdc_results.txt" ]; then
160+ echo "Main branch artifact found. Running comparison."
161+ bash mcdc/.github/scripts/mcdc-compare.sh main-branch-results/mcdc_results.txt mcdc_results.txt main-branch-results/modules.txt
162+ else
163+ echo "Main branch artifact not found. Skipping comparison step."
164+ fi
165+
166+ - name : Output summary to workflow
167+ run : |
168+ if [ -s "mcdc_comment.txt" ]; then
169+ echo "### MC/DC Results (Comparison with dev branch)" >> $GITHUB_STEP_SUMMARY
170+ echo '```plaintext' >> $GITHUB_STEP_SUMMARY
171+ cat mcdc_comment.txt >> $GITHUB_STEP_SUMMARY
172+ echo '```' >> $GITHUB_STEP_SUMMARY
173+ elif [ -s "mcdc_results.txt" ]; then
174+ echo "### MC/DC Results (Current PR)" >> $GITHUB_STEP_SUMMARY
175+ echo '```plaintext' >> $GITHUB_STEP_SUMMARY
176+ cat mcdc_results.txt >> $GITHUB_STEP_SUMMARY
177+ echo '```' >> $GITHUB_STEP_SUMMARY
178+ else
179+ echo "No MCDC results found." >> $GITHUB_STEP_SUMMARY
180+ fi
181+
182+ # Output uncovered branches if the file exists and is not empty
183+ if [ -s "uncovered.json" ]; then
184+ echo "" >> $GITHUB_STEP_SUMMARY
185+ echo "<details>" >> $GITHUB_STEP_SUMMARY
186+ echo "<summary>Click to view uncovered branches (uncovered.json)</summary>" >> $GITHUB_STEP_SUMMARY
187+ echo "" >> $GITHUB_STEP_SUMMARY
188+ echo '```json' >> $GITHUB_STEP_SUMMARY
189+ cat uncovered.json >> $GITHUB_STEP_SUMMARY
190+ echo '```' >> $GITHUB_STEP_SUMMARY
191+ echo "" >> $GITHUB_STEP_SUMMARY
192+ echo "</details>" >> $GITHUB_STEP_SUMMARY
193+ echo "" >> $GITHUB_STEP_SUMMARY
194+ fi
195+
196+ - name : Archive mcdc comparison
197+ # Upload if success or failure which supports skipping, unlike always()
198+ if : success() || failure()
199+ uses : actions/upload-artifact@v7
200+ with :
201+ name : MCDC main branch comparison
202+ path : |
203+ mcdc_comment.txt
204+ mcdc_compare.txt
0 commit comments