diff --git a/.gitignore b/.gitignore index 6cc9e40..1ef5067 100644 --- a/.gitignore +++ b/.gitignore @@ -197,4 +197,7 @@ $RECYCLE.BIN/ .tags ansible-lint-junit.xml -output.txt \ No newline at end of file +output.txt + +bin/ +pyvenv.cfg \ No newline at end of file diff --git a/src/ansible_lint_junit/main.py b/src/ansible_lint_junit/main.py index 28d03b0..94a2ebb 100755 --- a/src/ansible_lint_junit/main.py +++ b/src/ansible_lint_junit/main.py @@ -32,8 +32,10 @@ def main(): help="print XML to console as command output", default=False) parser.add_argument("-d", "--dummy-test", dest="dummy", action="store_true", help="Adds single (1) dummy test if there were 0 tests and/or 0 errors", default=False) - parser.add_argument('--version', action='version', + parser.add_argument("--version", action="version", version='%(prog)s {version}'.format(version=version())) + parser.add_argument("-w", "--ignore-warnings", action="store_true", default=False, + help="Ignore ansible-lint warnings") arguments = parser.parse_args() @@ -47,11 +49,6 @@ def main(): testsuites = ET.Element("testsuites") errors_count = "0" - for line in ansible_lint_output: - if len(line): - errors_count = str(len(ansible_lint_output) - 1) - break - if arguments.dummy: testsuite = ET.SubElement( testsuites, "testsuite", errors=errors_count, failures="0", tests="1", time="0") @@ -71,12 +68,13 @@ def main(): parsed_lines = [] for line in ansible_lint_output: if 0 < len(line): - line_match = line_regex.match(line) if not line_match: continue + if arguments.ignore_warnings and line_match.group(3).endswith(" (warning)"): + continue line_data = { "filename": line_match.group(1), "line": int(line_match.group(2)), @@ -84,6 +82,7 @@ def main(): "text": line_match.group(3), } parsed_lines.append(line_data) + errors_count = int(errors_count) + 1 testcase = ET.SubElement( testsuite, "testcase", name="{}-{}".format(line_data['filename'], len(parsed_lines))) @@ -97,6 +96,8 @@ def main(): type="Ansible Lint" ).text = line_data['error'] + testsuite.set("errors", str(errors_count)) + xml_string = ET.tostring(testsuites, encoding='utf8', method='xml') xml_nice = minidom.parseString(xml_string) xml_nice = xml_nice.toprettyxml(indent="\t")