@@ -241,6 +241,13 @@ tasks:
241241 - for : { var: GO_MOD_DIR_UNIT_TEST }
242242 # NOTE: CI does not need go test stdout, local uses separate command to show the report
243243 cmd : |
244+ {{if ne .OVERRIDEN_COVERAGE_MODULES ""}}
245+ if ! echo {{.OVERRIDEN_COVERAGE_MODULES}} | grep -q $(echo "{{.ITEM}}" | sed 's/^\.\///g'); then
246+ echo "Skipping module {{.ITEM}}"
247+ exit 0; # NOTE: Skip module if not in the list
248+ fi
249+ {{end}}
250+
244251 path={{.ITEM}}
245252 coverage_dir_path="${path%/*}"
246253 mkdir -p {{.COVERAGE_DIR}}/unit/${coverage_dir_path}
@@ -252,16 +259,22 @@ tasks:
252259 desc : Run all unit tests with coverage
253260 vars :
254261 COVERAGE_IGNORED_FILES : ' \.pb\.go|mock_|tests|testdata' # NOTE: Need to keep sync with codecov.yml manually
255- COVERAGE_MODULES : " {{ .GO_MOD_DIR_UNIT_TEST }}" # NOTE: Multiple module definition require newline separation
256262 SHOW_TOTAL_ONLY : ' {{ .SHOW_TOTAL_ONLY | default "true" }}'
257263 cmds :
258264 - task : test:unit:coverage
259265
260- - cmd : rm /tmp/total_report_results.txt || true
266+ - cmd : (test -f /tmp/total_report_results.txt && rm /tmp/total_report_results.txt) || true
261267 if : ' {{ eq .SHOW_TOTAL_ONLY "true" }}'
262268
263269 - for : { var: GO_MOD_DIR_UNIT_TEST }
264270 cmd : |
271+ {{if ne .OVERRIDEN_COVERAGE_MODULES ""}}
272+ if ! echo {{.OVERRIDEN_COVERAGE_MODULES}} | grep -q $(echo "{{.ITEM}}" | sed 's/^\.\///g'); then
273+ echo "Skipping module {{.ITEM}} as it is not in the list of modules to cover"
274+ exit 0; # NOTE: Skip module if not in the list
275+ fi
276+ {{end}}
277+
265278 echo "Filtering out ignored files from coverage for {{.ITEM}}"
266279 grep -vE "{{.COVERAGE_IGNORED_FILES}}" {{.COVERAGE_DIR}}/unit/{{.ITEM}}.out > {{.COVERAGE_DIR}}/unit/{{.ITEM}}.out.tmp
267280
0 commit comments