Generate the XML code coverage reports before trying to use them

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-09-17 12:45:01 +01:00 committed by Pedro Algarvio
parent 2430a0eeb3
commit 29a57d2d32
7 changed files with 87 additions and 0 deletions

View file

@ -415,6 +415,11 @@ jobs:
run: |
nox -e combine-coverage
- name: Create XML Coverage Reports
if: always() && inputs.skip-code-coverage == false && job.status != 'cancelled'
run: |
nox -e create-xml-coverage-reports
- name: Prepare Test Run Artifacts
id: download-artifacts-from-vm
if: always() && job.status != 'cancelled'

View file

@ -373,6 +373,11 @@ jobs:
run: |
tools --timestamps vm combine-coverage ${{ inputs.distro-slug }}
- name: Create XML Coverage Reports
if: always() && inputs.skip-code-coverage == false && steps.spin-up-vm.outcome == 'success' && job.status != 'cancelled'
run: |
tools --timestamps vm create-xml-coverage-reports ${{ inputs.distro-slug }}
- name: Download Test Run Artifacts
id: download-artifacts-from-vm
if: always() && steps.spin-up-vm.outcome == 'success' && job.status != 'cancelled'

View file

@ -258,6 +258,11 @@ jobs:
run: |
tools --timestamps vm combine-coverage ${{ inputs.distro-slug }}
- name: Create XML Coverage Reports
if: always() && inputs.skip-code-coverage == false && steps.spin-up-vm.outcome == 'success' && job.status != 'cancelled'
run: |
tools --timestamps vm create-xml-coverage-reports ${{ inputs.distro-slug }}
- name: Download Test Run Artifacts
id: download-artifacts-from-vm
if: always() && steps.spin-up-vm.outcome == 'success'

View file

@ -242,6 +242,11 @@ jobs:
run: |
nox --force-color -e combine-coverage
- name: Create XML Coverage Reports
if: always() && inputs.skip-code-coverage == false && job.status != 'cancelled'
run: |
tools --timestamps vm create-xml-coverage-reports ${{ inputs.distro-slug }}
- name: Prepare Test Run Artifacts
id: download-artifacts-from-vm
if: always() && job.status != 'cancelled'

View file

@ -263,6 +263,11 @@ jobs:
run: |
tools --timestamps vm combine-coverage ${{ inputs.distro-slug }}
- name: Create XML Coverage Reports
if: always() && inputs.skip-code-coverage == false && steps.spin-up-vm.outcome == 'success' && job.status != 'cancelled'
run: |
tools --timestamps vm create-xml-coverage-reports ${{ inputs.distro-slug }}
- name: Download Test Run Artifacts
id: download-artifacts-from-vm
if: always() && steps.spin-up-vm.outcome == 'success'

View file

@ -1378,6 +1378,44 @@ def create_html_coverage_report(session):
)
@nox.session(python="3", name="create-xml-coverage-reports")
def create_xml_coverage_reports(session):
_install_coverage_requirement(session)
env = {
# The full path to the .coverage data file. Makes sure we always write
# them to the same directory
"COVERAGE_FILE": str(COVERAGE_FILE),
}
# Generate report for tests code coverage
try:
session.run(
"coverage",
"xml",
"-o",
str(COVERAGE_OUTPUT_DIR.joinpath("tests.xml").relative_to(REPO_ROOT)),
"--omit=salt/*,artifacts/salt/*",
"--include=tests/*",
env=env,
)
except CommandFailed:
session_warn(session, "Failed to generate the tests XML code coverage report")
# Generate report for salt code coverage
try:
session.run(
"coverage",
"xml",
"-o",
str(COVERAGE_OUTPUT_DIR.joinpath("salt.xml").relative_to(REPO_ROOT)),
"--omit=tests/*",
"--include=salt/*,artifacts/salt/*",
env=env,
)
except CommandFailed:
session_warn(session, "Failed to generate the source XML code coverage report")
class Tee:
"""
Python class to mimic linux tee behaviour

View file

@ -547,6 +547,24 @@ def combine_coverage(ctx: Context, name: str):
ctx.exit(returncode)
@vm.command(
name="create-xml-coverage-reports",
arguments={
"name": {
"help": "The VM Name",
"metavar": "VM_NAME",
},
},
)
def create_xml_coverage_reports(ctx: Context, name: str):
"""
Create XML code coverage reports in the VM.
"""
vm = VM(ctx=ctx, name=name, region_name=ctx.parser.options.region)
returncode = vm.create_xml_coverage_reports()
ctx.exit(returncode)
@vm.command(
name="download-artifacts",
arguments={
@ -1415,6 +1433,12 @@ class VM:
"""
return self.run_nox("combine-coverage", session_args=[self.name])
def create_xml_coverage_reports(self):
"""
Create XML coverage reports
"""
return self.run_nox("create-xml-coverage-reports", session_args=[self.name])
def compress_dependencies(self):
"""
Compress .nox/ into nox.<vm-name>.tar.* in the VM