Skip to content

Commit ef30291

Browse files
committed
Fix code coverage collection/reporting. Create Salt specific coverage report.
Signed-off-by: Pedro Algarvio <[email protected]>
1 parent 18defa2 commit ef30291

File tree

6 files changed

+144
-34
lines changed

6 files changed

+144
-34
lines changed

.coveragerc

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ relative_files = True
77
omit =
88
setup.py
99
.nox/*
10-
source =
11-
pkg
10+
source_pkgs =
11+
pkg.tests
1212
salt
1313
tests
1414
tools
15+
disable_warnings = module-not-imported
16+
1517

1618
[report]
1719
# Regexes for lines to exclude from consideration

.github/workflows/ci.yml

+16-4
Original file line numberDiff line numberDiff line change
@@ -2140,15 +2140,27 @@ jobs:
21402140
run: |
21412141
nox --force-color -e combine-coverage
21422142
2143-
- name: Create Code Coverage HTML Report
2143+
- name: Create Salt Code Coverage HTML Report
2144+
run: |
2145+
nox --force-color -e create-html-coverage-report -- salt
2146+
2147+
- name: Upload Salt Code Coverage HTML Report
2148+
uses: actions/upload-artifact@v3
2149+
with:
2150+
name: code-coverage-salt-html-report
2151+
path: artifacts/coverage/html/salt
2152+
retention-days: 7
2153+
if-no-files-found: error
2154+
2155+
- name: Create Full Code Coverage HTML Report
21442156
run: |
21452157
nox --force-color -e create-html-coverage-report
21462158
2147-
- name: Upload Code Coverage HTML Report
2159+
- name: Upload Full Code Coverage HTML Report
21482160
uses: actions/upload-artifact@v3
21492161
with:
2150-
name: code-coverage-html-report
2151-
path: artifacts/coverage/html
2162+
name: code-coverage-full-html-report
2163+
path: artifacts/coverage/html/full
21522164
retention-days: 7
21532165
if-no-files-found: error
21542166

.github/workflows/nightly.yml

+16-4
Original file line numberDiff line numberDiff line change
@@ -2201,15 +2201,27 @@ jobs:
22012201
run: |
22022202
nox --force-color -e combine-coverage
22032203
2204-
- name: Create Code Coverage HTML Report
2204+
- name: Create Salt Code Coverage HTML Report
2205+
run: |
2206+
nox --force-color -e create-html-coverage-report -- salt
2207+
2208+
- name: Upload Salt Code Coverage HTML Report
2209+
uses: actions/upload-artifact@v3
2210+
with:
2211+
name: code-coverage-salt-html-report
2212+
path: artifacts/coverage/html/salt
2213+
retention-days: 7
2214+
if-no-files-found: error
2215+
2216+
- name: Create Full Code Coverage HTML Report
22052217
run: |
22062218
nox --force-color -e create-html-coverage-report
22072219
2208-
- name: Upload Code Coverage HTML Report
2220+
- name: Upload Full Code Coverage HTML Report
22092221
uses: actions/upload-artifact@v3
22102222
with:
2211-
name: code-coverage-html-report
2212-
path: artifacts/coverage/html
2223+
name: code-coverage-full-html-report
2224+
path: artifacts/coverage/html/full
22132225
retention-days: 7
22142226
if-no-files-found: error
22152227

.github/workflows/scheduled.yml

+16-4
Original file line numberDiff line numberDiff line change
@@ -2174,15 +2174,27 @@ jobs:
21742174
run: |
21752175
nox --force-color -e combine-coverage
21762176
2177-
- name: Create Code Coverage HTML Report
2177+
- name: Create Salt Code Coverage HTML Report
2178+
run: |
2179+
nox --force-color -e create-html-coverage-report -- salt
2180+
2181+
- name: Upload Salt Code Coverage HTML Report
2182+
uses: actions/upload-artifact@v3
2183+
with:
2184+
name: code-coverage-salt-html-report
2185+
path: artifacts/coverage/html/salt
2186+
retention-days: 7
2187+
if-no-files-found: error
2188+
2189+
- name: Create Full Code Coverage HTML Report
21782190
run: |
21792191
nox --force-color -e create-html-coverage-report
21802192
2181-
- name: Upload Code Coverage HTML Report
2193+
- name: Upload Full Code Coverage HTML Report
21822194
uses: actions/upload-artifact@v3
21832195
with:
2184-
name: code-coverage-html-report
2185-
path: artifacts/coverage/html
2196+
name: code-coverage-full-html-report
2197+
path: artifacts/coverage/html/full
21862198
retention-days: 7
21872199
if-no-files-found: error
21882200

.github/workflows/templates/ci.yml.jinja

+16-4
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,27 @@
355355
run: |
356356
nox --force-color -e combine-coverage
357357

358-
- name: Create Code Coverage HTML Report
358+
- name: Create Salt Code Coverage HTML Report
359+
run: |
360+
nox --force-color -e create-html-coverage-report -- salt
361+
362+
- name: Upload Salt Code Coverage HTML Report
363+
uses: actions/upload-artifact@v3
364+
with:
365+
name: code-coverage-salt-html-report
366+
path: artifacts/coverage/html/salt
367+
retention-days: 7
368+
if-no-files-found: error
369+
370+
- name: Create Full Code Coverage HTML Report
359371
run: |
360372
nox --force-color -e create-html-coverage-report
361373

362-
- name: Upload Code Coverage HTML Report
374+
- name: Upload Full Code Coverage HTML Report
363375
uses: actions/upload-artifact@v3
364376
with:
365-
name: code-coverage-html-report
366-
path: artifacts/coverage/html
377+
name: code-coverage-full-html-report
378+
path: artifacts/coverage/html/full
367379
retention-days: 7
368380
if-no-files-found: error
369381
<%- endif %>

noxfile.py

+76-16
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,9 @@ def _run_with_coverage(session, *test_cmd, env=None, on_rerun=False):
405405
# Always combine and generate the XML coverage report
406406
try:
407407
session.run(
408-
"coverage", "combine", "--debug=pathmap", env=coverage_base_env
408+
"coverage",
409+
"combine",
410+
env=coverage_base_env,
409411
)
410412
except CommandFailed:
411413
# Sometimes some of the coverage files are corrupt which would trigger a CommandFailed
@@ -417,7 +419,7 @@ def _run_with_coverage(session, *test_cmd, env=None, on_rerun=False):
417419
"xml",
418420
"-o",
419421
str(COVERAGE_OUTPUT_DIR.joinpath("tests.xml").relative_to(REPO_ROOT)),
420-
"--omit=salt/*,artifacts/salt/*",
422+
"--omit=salt/*",
421423
"--include=tests/*,pkg/tests/*",
422424
env=coverage_base_env,
423425
)
@@ -428,7 +430,7 @@ def _run_with_coverage(session, *test_cmd, env=None, on_rerun=False):
428430
"-o",
429431
str(COVERAGE_OUTPUT_DIR.joinpath("salt.xml").relative_to(REPO_ROOT)),
430432
"--omit=tests/*,pkg/tests/*",
431-
"--include=salt/*,artifacts/salt/*",
433+
"--include=salt/*",
432434
env=coverage_base_env,
433435
)
434436
# Generate html report for tests code coverage
@@ -437,7 +439,7 @@ def _run_with_coverage(session, *test_cmd, env=None, on_rerun=False):
437439
"html",
438440
"-d",
439441
str(COVERAGE_OUTPUT_DIR.joinpath("html").relative_to(REPO_ROOT)),
440-
"--omit=salt/*,artifacts/salt/*",
442+
"--omit=salt/*",
441443
"--include=tests/*,pkg/tests/*",
442444
env=coverage_base_env,
443445
)
@@ -448,7 +450,7 @@ def _run_with_coverage(session, *test_cmd, env=None, on_rerun=False):
448450
"-d",
449451
str(COVERAGE_OUTPUT_DIR.joinpath("html").relative_to(REPO_ROOT)),
450452
"--omit=tests/*,pkg/tests/*",
451-
"--include=salt/*,artifacts/salt/*",
453+
"--include=salt/*",
452454
env=coverage_base_env,
453455
)
454456

@@ -499,36 +501,37 @@ def _report_coverage(session):
499501
)
500502
cmd_args = [
501503
"--omit=tests/*,pkg/tests/*",
502-
"--include=salt/*,artifacts/salt/*",
504+
"--include=salt/*",
503505
]
504506

505507
elif report_section == "tests":
506508
json_coverage_file = (
507509
COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "coverage-tests.json"
508510
)
509511
cmd_args = [
510-
"--omit=salt/*,artifacts/salt/*",
512+
"--omit=salt/*",
511513
"--include=tests/*,pkg/tests/*",
512514
]
513515
else:
514516
json_coverage_file = (
515517
COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "coverage.json"
516518
)
517519
cmd_args = [
518-
"--include=salt/*,artifacts/salt/*,tests/*,pkg/tests/*",
520+
"--include=salt/*,tests/*,pkg/tests/*",
519521
]
520522

521523
session.run(
522524
"coverage",
523-
"json",
524-
"-o",
525-
str(json_coverage_file),
525+
"report",
526526
*cmd_args,
527527
env=env,
528528
)
529+
529530
session.run(
530531
"coverage",
531-
"report",
532+
"json",
533+
"-o",
534+
str(json_coverage_file),
532535
*cmd_args,
533536
env=env,
534537
)
@@ -1379,14 +1382,71 @@ def create_html_coverage_report(session):
13791382
"COVERAGE_FILE": str(COVERAGE_FILE),
13801383
}
13811384

1385+
report_section = None
1386+
if session.posargs:
1387+
report_section = session.posargs.pop(0)
1388+
if report_section not in ("salt", "tests"):
1389+
session.error("The report section can only be one of 'salt', 'tests'.")
1390+
if session.posargs:
1391+
session.error(
1392+
"Only one argument can be passed to the session, which is optional "
1393+
"and is one of 'salt', 'tests'."
1394+
)
1395+
1396+
if not IS_WINDOWS:
1397+
# The coverage file might have come from a windows machine, fix paths
1398+
with sqlite3.connect(COVERAGE_FILE) as db:
1399+
res = db.execute(r"SELECT * FROM file WHERE path LIKE '%salt\%'")
1400+
if res.fetchone():
1401+
session_warn(
1402+
session,
1403+
"Replacing backwards slashes with forward slashes on file "
1404+
"paths in the coverage database",
1405+
)
1406+
db.execute(r"UPDATE OR IGNORE file SET path=replace(path, '\', '/');")
1407+
1408+
if report_section == "salt":
1409+
report_dir = str(
1410+
COVERAGE_OUTPUT_DIR.joinpath("html", "salt").relative_to(REPO_ROOT)
1411+
)
1412+
json_coverage_file = (
1413+
COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "coverage-salt.json"
1414+
)
1415+
cmd_args = [
1416+
"--omit=tests/*,pkg/tests/*",
1417+
"--include=salt/*",
1418+
]
1419+
1420+
elif report_section == "tests":
1421+
report_dir = str(
1422+
COVERAGE_OUTPUT_DIR.joinpath("html", "tests").relative_to(REPO_ROOT)
1423+
)
1424+
json_coverage_file = (
1425+
COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "coverage-tests.json"
1426+
)
1427+
cmd_args = [
1428+
"--omit=salt/*",
1429+
"--include=tests/*,pkg/tests/*",
1430+
]
1431+
else:
1432+
report_dir = str(
1433+
COVERAGE_OUTPUT_DIR.joinpath("html", "full").relative_to(REPO_ROOT)
1434+
)
1435+
json_coverage_file = (
1436+
COVERAGE_OUTPUT_DIR.relative_to(REPO_ROOT) / "coverage.json"
1437+
)
1438+
cmd_args = [
1439+
"--include=salt/*,tests/*,pkg/tests/*",
1440+
]
1441+
13821442
# Generate html report for Salt and tests combined code coverage
13831443
session.run(
13841444
"coverage",
13851445
"html",
13861446
"-d",
1387-
str(COVERAGE_OUTPUT_DIR.joinpath("html").relative_to(REPO_ROOT)),
1388-
"--include=salt/*,artifacts/salt/*,tests/*,pkg/tests/*",
1447+
report_dir,
13891448
"--show-contexts",
1449+
*cmd_args,
13901450
env=env,
13911451
)
13921452

@@ -1406,7 +1466,7 @@ def _create_xml_coverage_reports(session):
14061466
"xml",
14071467
"-o",
14081468
str(COVERAGE_OUTPUT_DIR.joinpath("tests.xml").relative_to(REPO_ROOT)),
1409-
"--omit=salt/*,artifacts/salt/*",
1469+
"--omit=salt/*",
14101470
"--include=tests/*,pkg/tests/*",
14111471
env=env,
14121472
)
@@ -1421,7 +1481,7 @@ def _create_xml_coverage_reports(session):
14211481
"-o",
14221482
str(COVERAGE_OUTPUT_DIR.joinpath("salt.xml").relative_to(REPO_ROOT)),
14231483
"--omit=tests/*,pkg/tests/*",
1424-
"--include=salt/*,artifacts/salt/*",
1484+
"--include=salt/*",
14251485
env=env,
14261486
)
14271487
except CommandFailed:

0 commit comments

Comments
 (0)