Skip to content

Commit 4a4215c

Browse files
committed
chore(dir): run cover on selected modules only
Signed-off-by: Árpád Csepi <csepi.arpad@outlook.com>
1 parent 69be11f commit 4a4215c

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

Taskfile.vars.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ vars:
7272
TRIVY_VERSION: "0.69.3"
7373
TRIVY_BIN: "{{ .BIN_DIR }}/trivy-{{.TRIVY_VERSION}}"
7474

75-
## Default location for coverage tests reports
75+
## Coverage related values
7676
COVERAGE_DIR: '{{ .COVERAGE_DIR | default (print .ROOT_DIR "/.coverage") }}'
77+
OVERRIDEN_COVERAGE_MODULES: "" # NOTE: Modules with space separation for specify which modules to cover
7778

7879
## Runtime CRD
7980
CONTROLLER_GEN_VERSION: "v0.17.3"

Taskfile.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)