Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format code coverage report to display numbers per package #15577

Merged
67 commits merged into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
81cf316
adding code coverage in PR validation, collecting only on Python3.9
seankane-msft Nov 30, 2020
0cad2ad
adding code coverage in PR validation, collecting only on all version…
seankane-msft Nov 30, 2020
4a3c7f4
adding typechecking to the ignore on code coverage, enabling code cov…
seankane-msft Dec 2, 2020
86d4e0b
adding powershell script to dynamically set the code coverage values
seankane-msft Dec 2, 2020
3b9ae03
changing name of PythonVersion, adding Temp to the end
seankane-msft Dec 2, 2020
8f4eccd
changing to test the dynamic variable in expression
seankane-msft Dec 2, 2020
5317145
making determinations in build-test.yml when the correct version of p…
seankane-msft Dec 2, 2020
c600f2b
syntax error
seankane-msft Dec 2, 2020
b81c758
another syntax error
seankane-msft Dec 3, 2020
bf28a07
reverting back to a powershell script
seankane-msft Dec 3, 2020
ecc6f6e
removing quotation around disablecov
seankane-msft Dec 3, 2020
c7ff8e7
cannot overwrite a read-only variable, which is causing some problems
seankane-msft Dec 3, 2020
b6225f2
reverting back to old changes
seankane-msft Dec 3, 2020
161ca08
changing syntax
seankane-msft Dec 3, 2020
45d94f8
adding coverage arg to the build matrix
seankane-msft Dec 3, 2020
3f8cecb
undoing all changes to build-test.yml
seankane-msft Dec 3, 2020
6c7a5df
addressing merge conflict
seankane-msft Dec 3, 2020
65878b1
adding *mgmt* to the regex for omitting
seankane-msft Dec 3, 2020
ca622a3
removing _generated files from code cov, and mgmt plane libraries
seankane-msft Dec 3, 2020
139cbc1
removing print statements
seankane-msft Dec 3, 2020
61fb569
changing to azure.mgmt from azure-mgmt
seankane-msft Dec 3, 2020
6c51818
reverting to *mgmt* in --omit flag, adding azure-mgmt to remove keywo…
seankane-msft Dec 3, 2020
36836c0
adding custom xml editor to group packages correctly
seankane-msft Dec 4, 2020
7e00b85
forgot to remove code cov call, removing mgmt from omit statement
seankane-msft Dec 4, 2020
83ced4b
adding a step to make sure coverage file exists before attempting par…
seankane-msft Dec 4, 2020
5fd6718
forgot to import logging
seankane-msft Dec 4, 2020
2b523a9
forgot my return statement
seankane-msft Dec 4, 2020
3347a0c
forgot to overwrite coverage file instead of writing to coverage-new.xml
seankane-msft Dec 4, 2020
4d3e8ec
adding some logging to find bugs
seankane-msft Dec 4, 2020
48acd39
removed mgmt from the remove_keywords list to test out new coverage r…
seankane-msft Dec 4, 2020
1f2ef82
fridays work
seankane-msft Dec 7, 2020
f1a1a3c
re-working code coverage report
seankane-msft Dec 7, 2020
8afca46
changes to code coverage report, generates XML in a slightly funky ma…
seankane-msft Dec 10, 2020
9476007
merge conflict
seankane-msft Dec 10, 2020
5ca7e8c
left a f-string in there
seankane-msft Dec 10, 2020
879fec4
adding new script with more debug statements
seankane-msft Dec 10, 2020
4ca7967
what happens if i use jacoco?
seankane-msft Dec 10, 2020
a86ed25
removed an extra call, reverting back to cobertura
seankane-msft Dec 10, 2020
6e5ae1c
cleaned up code cov function, removing commented out code and unused …
seankane-msft Jan 13, 2021
00b9e67
changed name to be just the package, compress all into one package, w…
seankane-msft Jan 13, 2021
b94173e
fixed merge conflict
seankane-msft Jan 13, 2021
d9248f3
some packages were incorrectly removed twice
seankane-msft Jan 14, 2021
7043ae3
system does not support utf-8 encoding
seankane-msft Jan 14, 2021
9074170
updates to code cov report generator
seankane-msft Jan 14, 2021
57767f9
merge conflicts
seankane-msft Feb 8, 2021
c43bbcf
undoing change to recording
seankane-msft Feb 8, 2021
cf726f7
changes with new method of collecting code coverage
seankane-msft Feb 8, 2021
5222d66
incidental change
seankane-msft Feb 8, 2021
1518057
had the import in the wrong file
seankane-msft Feb 8, 2021
764de3c
cleaning up and removing unneeded code
seankane-msft Feb 9, 2021
b439752
more cleanup
seankane-msft Feb 9, 2021
72b9087
removed two methods not used anymore
seankane-msft Feb 11, 2021
9e38670
removing unneeded import
seankane-msft Feb 12, 2021
d1d610c
adding packages to top of list to avoid adding very large html files
seankane-msft Feb 18, 2021
b3f82d4
added a 'classes' node that was removed
seankane-msft Feb 18, 2021
2568db3
removing insides of class node, hoping this will default the line-rat…
seankane-msft Feb 18, 2021
3f39041
trying to use a regex to file py files in the filename attrib
seankane-msft Feb 18, 2021
cb389f7
adding full package nodes to beginning of packages node
seankane-msft Feb 18, 2021
6f60c76
removing changes to create_coverage
seankane-msft Feb 19, 2021
84271fc
reverting to master
seankane-msft Feb 19, 2021
31c2de7
changing order of ops
seankane-msft Feb 19, 2021
49741bf
changes made in create_coverage.py
seankane-msft Feb 19, 2021
dbbf05f
forgot to import
seankane-msft Feb 19, 2021
6184d85
merge conflicts
seankane-msft Feb 19, 2021
e3bf976
fixing import
seankane-msft Feb 19, 2021
899d83e
circular import
seankane-msft Feb 19, 2021
659e3e8
removing commented out code
seankane-msft Feb 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/pipelines/templates/steps/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ steps:

- pwsh: |
if (Test-Path -Path '.\_coverage\') {
Get-ChildItem .\_coverage\ |
Get-ChildItem .\_coverage\ -Recurse |
Foreach-Object {
Get-Content $_
}
Expand Down
113 changes: 113 additions & 0 deletions scripts/devops_tasks/code_cov_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import copy
import logging
import os
import xml.etree.ElementTree as ET

root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", ".."))
coverage_file = os.path.join(root_dir, "coverage.xml")


def create_coverage_report():
if not os.path.exists(coverage_file):
logging.info("No coverage file detected at {}".format(coverage_file))
return
logging.info("Modifying coverage file at {}".format(coverage_file))
tree = ET.parse(coverage_file)
root = tree.getroot()

packages = root[1]

recursive_set_name(packages)

packages_to_report = []
for child in packages:
# Order should be: ['azure', '<package-name>', 'azure-<package-name>', ...]
name = child.attrib['name'].split('.')
logging.info("Name: {}".format(name))
folder, package = name[1], name[2]
if (folder, package) not in packages_to_report:
packages_to_report.append((folder, package))
logging.info("Found a package: {}".format(package))

package_names = [p[1] for p in packages_to_report]

packages_root = root.find('packages')
packages_root = packages

packages_nodes = []
for folder, package_name in packages_to_report:
condense_nodes = []
for child in packages:

test_str = "sdk.{}.{}.{}".format(
folder,
package_name,
package_name.replace('-', '.')
)

if package_name in child.attrib['name']:
condense_nodes.append(child)

packages_nodes.append(condense_nodes)

nodes_to_remove = []
for nodes in packages_nodes:
if len(nodes) > 1:
first_package = nodes[0]

first_package_classes = first_package.find('classes')

for node in nodes[1:]:
temp_classes = node.find('classes')

for _class in temp_classes:
first_package_classes.append(_class)
nodes_to_remove.append(node)

for n in nodes_to_remove:
if n not in packages_root:
continue

packages_root.remove(n)

# Last thing with root, change the 'name' attrib to be just the package name
packages_to_add = []
for package in root.find('packages'):
name = package.attrib['name'].split('.')
package.attrib['name'] = name[2]

packages_to_add.append(copy.deepcopy(package))

write_final_xml(packages_to_add)


def write_final_xml(packages_to_add):
if not os.path.exists(coverage_file):
logging.info("No coverage file detected at {}".format(coverage_file))
return

logging.info("Modifying coverage file at {}".format(coverage_file))
tree = ET.parse(coverage_file)
root = tree.getroot()

packages = root[1]

for p in packages_to_add:
packages.insert(0, p)

with open(coverage_file, "wb") as f:
data = ET.tostring(root)
f.write(data)


def recursive_set_name(root):
# Stopping condition
if 'line' in root.attrib:
return

# Add file path to the filename
if root.tag == 'class':
root.set('name', root.attrib['filename'])

for child in root:
recursive_set_name(child)
5 changes: 4 additions & 1 deletion scripts/devops_tasks/create_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import re
from common_tasks import run_check_call

from code_cov_report import create_coverage_report

logging.getLogger().setLevel(logging.INFO)

root_dir = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", ".."))
Expand Down Expand Up @@ -71,4 +73,5 @@ def fix_dot_coverage_file(coverage_file):

if __name__ == "__main__":
collect_tox_coverage_files()
generate_coverage_xml()
generate_coverage_xml()
create_coverage_report()