code: def create_xml_file(
      result_store_dict: ResultDictType,
      output_path: str,
      verbose: bool = False,
  ):
      """Creates a JUnit-based XML file, with each invocation as a testcase."""
      os.makedirs(os.path.dirname(output_path), exist_ok=True)
      failure_count = 0
      error_count = 0
  
      date_time = datetime.datetime
      attrib = {
          "name": "Bazel Invocations",
          "time": "0.0",
          "timestamp": date_time.isoformat(date_time.utcnow()),
      }
      testsuites = ElemTree.Element("testsuites")
      testsuite = ElemTree.SubElement(testsuites, "testsuite")
      for url, invocation_results in result_store_dict.items():
          invocation_id = url.rsplit("/")[-1]
          if verbose:
              print(f"Creating testcase for invocation {invocation_id}")
          status = invocation_results["status"]
          command = invocation_results.get("command")
          command_type = invocation_results.get("command_type")
  
          case_attrib = attrib.copy()
          if command_type:
              command_type = command_type.title()
              case_name = f"{command_type} invocation {invocation_id}"
          else:
              case_name = f" Invocation {invocation_id}"
          case_attrib.update(
              {
                  "name": case_name,
                  "status": "run",
                  "result": "completed",
              }
          )
  
          testcase = ElemTree.SubElement(
              testsuite, "testcase", attrib=case_attrib
          )
          if status in (
              InvokeStatus.tests_failed,
              InvokeStatus.build_failed,
          ):
              if status == InvokeStatus.tests_failed:
                  failure_count += 1
                  elem_name = "failure"
              else:
                  error_count += 1
                  elem_name = "error"
              if command:
                  failure_msg = (
                      f"\nThe command was:\n\n" f"{command}\n\n"
                  )
              else:
                  failure_msg = (
                      "\nCouldn't parse a bazel command "
                      "matching the invocation, inside the log. "
                      "Please look for it in the build log.\n\n"
                  )
              failure_msg += (
                  f"See the ResultStore link for a detailed view of failed targets:\n"
                  f"{url}\n\n"
              )
              failure_msg += (
                  f"Here's a fragment of the log containing the failure:\n\n"
                  f"[ ... TRUNCATED ... ]\n\n"
                  f'{invocation_results["log_fragment"]}\n'
                  f"\n[ ... TRUNCATED ... ]\n"
              )
              failure = ElemTree.SubElement(
                  testcase,
                  elem_name,
                  message=f"Bazel invocation {invocation_id} failed.",
              )
              failure.text = failure_msg
          else:
              properties = ElemTree.SubElement(testcase, "properties")
              success_msg = (
                  "Build completed successfully.\n"
                  f"See {url} for details."
              )
              ElemTree.SubElement(
                  properties,
                  "property",
                  name="description",
                  value=success_msg,
              )
              if command:
                  ElemTree.SubElement(
                      properties,
                      "property",
                      name="bazel_command",
                      value=command,
                  )
  
          suite_specific = {
              "tests": str(len(result_store_dict)),
              "errors": str(error_count),
              "failures": str(failure_count),
          }
          suite_attrib = attrib.copy()
          suite_attrib.update(suite_specific)
          testsuites.attrib = suite_attrib
          testsuite.attrib = suite_attrib
          indent_xml(testsuites)
  
      tree = ElemTree.ElementTree(testsuites)
      file_path = os.path.join(output_path)
      with open(file_path, "wb") as f:
          f.write(b'<?xml version="1.0"?>\n')
          tree.write(f)
          if verbose:
              print(
                  f"\nWrote XML with Bazel invocation results to {file_path}"
              )
  
file_path: tensorflow/ci/official/utilities/extract_resultstore_links.py
imports: import argparse
  import datetime
  import os
  import re
  from typing import Dict, Union
  import xml.etree.ElementTree
label_desc: Use image node_id 4 for calling a global function with example usage: create_xml_file(result_store_dict, output_path, verbose) without return types