Skip to content

Commit 2aafa65

Browse files
committed
updates
1 parent 60b5c30 commit 2aafa65

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

send_cobertura_to_bitbucket.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
PARTIAL = "🟡"
1414

1515
# Parse Cobertura XML
16-
def parse_cobertura(xml_path):
16+
def parse_cobertura(xml_path, send_all_coverage):
1717
tree = ET.parse(xml_path)
1818
root = tree.getroot()
1919
annotations = []
@@ -28,39 +28,49 @@ def parse_cobertura(xml_path):
2828
mcdcpair_coverage = line.attrib.get('mcdcpair-coverage', '')
2929

3030
summary = ""
31+
32+
publishAnnotation = send_all_coverage
3133

3234
if hits == 0:
3335
summary = FAIL + " No coverage on line."
36+
publishAnnotation = True
37+
3438
else:
3539
summary = "ST: " + PASS
3640
if branch == 'true':
3741
if condition_coverage.startswith("100.0%"):
3842
summary += " BR: {} {}".format (PASS,condition_coverage)
3943
elif condition_coverage.startswith("0.0%"):
4044
summary += " BR: {} {}".format (FAIL,condition_coverage)
45+
publishAnnotation = True
4146
else:
4247
summary += " BR: {} {}".format (PARTIAL,condition_coverage)
48+
publishAnnotation = True
4349

4450
if functioncall_coverage.startswith("100.0%"):
4551
summary += " FC: {}".format (PASS)
4652
elif functioncall_coverage != '':
4753
summary += " FC: {}".format (FAIL)
54+
publishAnnotation = True
4855

4956
if mcdcpair_coverage.startswith("100.0%"):
5057
summary += " MCDC: {} {}".format (PASS, mcdcpair_coverage)
5158
elif mcdcpair_coverage.startswith("0.0%"):
5259
summary += " MCDC: {} {}".format (FAIL, mcdcpair_coverage)
60+
publishAnnotation = True
5361
elif mcdcpair_coverage != '':
5462
summary += " MCDC: {} {}".format (PARTIAL, mcdcpair_coverage)
55-
56-
annotations.append({
57-
"title": "Coverage",
58-
"annotation_type": "COVERAGE",
59-
"summary": summary,
60-
"severity": "LOW",
61-
"path": file_path,
62-
"line": num,
63-
"external_id": "{}#{}".format(file_path,num)
63+
publishAnnotation = True
64+
65+
if publishAnnotation:
66+
annotations.append({
67+
"title": "Coverage",
68+
"annotation_type": "COVERAGE",
69+
"summary": summary,
70+
"severity": "LOW",
71+
"path": file_path,
72+
"line": num,
73+
"external_id": "{}#{}".format(file_path,num)
6474

6575
})
6676
return annotations
@@ -188,7 +198,7 @@ def send_code_coverage_annoations(annotations, workspace, repo_slug, commit_hash
188198
print("Complete")
189199

190200

191-
def run(filename, minimum_passing_coverage, verbose):
201+
def run(filename, minimum_passing_coverage, send_all_coverage, verbose):
192202

193203
workspace = os.environ['BITBUCKET_WORKSPACE']
194204
repo_slug = os.environ['BITBUCKET_REPO_SLUG']
@@ -207,7 +217,7 @@ def run(filename, minimum_passing_coverage, verbose):
207217
verbose
208218
)
209219

210-
annotations = parse_cobertura(filename)
220+
annotations = parse_cobertura(filename, send_all_coverage)
211221

212222
encFmt = getVectorCASTEncoding()
213223

@@ -237,11 +247,19 @@ def run(filename, minimum_passing_coverage, verbose):
237247
help="Path to the Cobertura XML file to parse",
238248
default="cobertura.xml"
239249
)
250+
251+
parser.add_argument(
252+
"-a", "--send_all_coverage",
253+
help="Report all coverage. Default is partial/fail only",
254+
action="store_true",
255+
default=False
256+
)
257+
240258
parser.add_argument(
241-
"-m", "--minimum",
259+
"--minimum_passing_coverage",
242260
type=float,
243-
help="Minimum overall coverage required to pass (e.g., 0.8 for 80%)",
244-
default=0.8
261+
help="Minimum overall coverage required to pass (default 80 percent)",
262+
default=80
245263
)
246264

247265
parser.add_argument(
@@ -252,5 +270,5 @@ def run(filename, minimum_passing_coverage, verbose):
252270

253271
args = parser.parse_args()
254272

255-
run(args.filename, args.minimum, args.verbose)
273+
run(args.filename, args.minimum_passing_coverage, args.send_all_coverage, args.verbose)
256274

vcast_exec.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ def __init__(self, args):
126126

127127
self.html_base_dir = args.html_base_dir
128128
self.use_cte = args.use_cte
129+
self.send_all_coverage = args.send_all_coverage
130+
self.minimum_passing_coverage = args.minimum_passing_coverage
129131

130132
if args.exit_with_failed_count == 'not present':
131133
self.useJunitFailCountPct = False
@@ -378,10 +380,9 @@ def sendToBitBucket(self):
378380

379381
send_cobertura_to_bitbucket.run(
380382
filename = fname,
381-
minimum_passing_coverage = 0.8,
382-
verbose = True) #self.verbose)
383-
384-
383+
minimum_passing_coverage = self.minimum_passing_coverage,
384+
send_all_coverage = self.send_all_coverage,
385+
verbose = self.verbose)
385386

386387
for html_dir in [".", self.html_base_dir, "rebuild_reports"]:
387388
for html in glob.glob(os.path.join(html_dir, "*.html")) \
@@ -581,15 +582,18 @@ def runExec(self):
581582
metricsGroup.add_argument('--cobertura', help='Generate coverage results in Cobertura xml format', action="store_true", default = False)
582583
metricsGroup.add_argument('--cobertura_extended', help='Generate coverage results in extended Cobertura xml format', action="store_true", default = False)
583584
metricsGroup.add_argument('--send_to_bitbucket', help='Generate Junit and Extended Cobertura data to send to BitBucket', action="store_true", default = False)
585+
metricsGroup.add_argument('--send_all_coverage', help='Send all coverage to BitBucket. Default is partial or not coveraged', action="store_true", default = False)
586+
metricsGroup.add_argument('--minimum_passing_coverage', type=float, help="Minimum overall coverage required to pass (default 80 percent)",default=80)
587+
588+
584589
metricsGroup.add_argument('--lcov', help='Generate coverage results in an LCOV format', action="store_true", default = False)
585590
metricsGroup.add_argument('--junit', help='Generate test results in Junit xml format', action="store_true", default = False)
586591
metricsGroup.add_argument('--export_rgw', help='Export RGW data', action="store_true", default = False)
587592
metricsGroup.add_argument('--junit_use_cte_for_classname', help=argparse.SUPPRESS, action="store_true", dest="use_cte")
588593
metricsGroup.add_argument('--sonarqube', help='Generate test results in SonarQube Generic test execution report format (CppUnit)', action="store_true", default = False)
589594
metricsGroup.add_argument('--pclp_input', help='Generate static analysis results from PC-lint Plus XML file to generic static analysis format (codequality)', action="store", default = None)
590595
metricsGroup.add_argument('--pclp_output_html', help='Generate static analysis results from PC-lint Plus XML file to an HTML output', action="store", default = "pclp_findings.html")
591-
metricsGroup.add_argument('--exit_with_failed_count', help='Returns failed test case count as script exit. Set a value to indicate a percentage above which the job will be marked as failed',
592-
nargs='?', default='not present', const='(default 0)')
596+
metricsGroup.add_argument('--exit_with_failed_count', help='Returns failed test case count as script exit. Set a value to indicate a percentage above which the job will be marked as failed', nargs='?', default='not present', const='(default 0)')
593597

594598
reportGroup = parser.add_argument_group('Report Selection', 'VectorCAST Manage reports that can be generated')
595599
reportGroup.add_argument('--aggregate', help='Generate aggregate coverage report VectorCAST Project', action="store_true", default = False)
@@ -603,7 +607,7 @@ def runExec(self):
603607

604608
beGroup.add_argument('--jobs', help='Number of concurrent jobs (default = 1)', default="1")
605609
beGroup.add_argument('--ci', help='Use Continuous Integration Licenses', action="store_true", default = False)
606-
beGroup.add_argument('-l', '--level', help='Environment Name if only doing single environment. Should be in the form of compiler/testsuite', default=None)
610+
beGroup.add_argument('-l', '--level', help='Environment Name if only doing single environment. Should be in the form of compiler/testsuite', default=None)
607611
beGroup.add_argument('-e', '--environment', help='Environment Name if only doing single environment.', default=None)
608612

609613
parser_specify = beGroup.add_mutually_exclusive_group()
@@ -684,6 +688,6 @@ def runExec(self):
684688
vcExec.exportRgw()
685689

686690
if vcExec.useJunitFailCountPct:
687-
print("--exit_with_failed_count=" + args.exit_with_failed_count + " specified. Fail Percent = " + str(round(vcExec.failed_pct,0)) + "% Return code: ", str(vcExec.failed_count))
691+
print("--exit_with_failed_count=" + args.exit_with_failed_count + " specified. Fail Percent = " + str(round(vcExec.failed_pct,0)) + "% Return code: ", str(vcExec.failed_count))
688692
sys.exit(vcExec.failed_count)
689693

0 commit comments

Comments
 (0)