|
| 1 | +import argparse |
| 2 | +import xml.etree.ElementTree as ET |
| 3 | + |
| 4 | +# Parse command-line arguments |
| 5 | +parser = argparse.ArgumentParser( |
| 6 | + description="Modify XML with workflow information" |
| 7 | +) |
| 8 | +parser.add_argument("--branch_name", required=True) |
| 9 | +parser.add_argument("--gha_run_id", required=True) |
| 10 | +parser.add_argument("--gha_run_number", required=True) |
| 11 | +parser.add_argument( |
| 12 | + "--xmlfile", required=True |
| 13 | +) # Added argument for XML file path |
| 14 | + |
| 15 | +args = parser.parse_args() |
| 16 | + |
| 17 | +# Open and parse the XML file |
| 18 | +xml_file_path = args.xmlfile |
| 19 | +tree = ET.parse(xml_file_path) |
| 20 | +root = tree.getroot() |
| 21 | + |
| 22 | +# Create new elements for the information |
| 23 | +branch_name_element = ET.Element("branch_name") |
| 24 | +branch_name_element.text = args.branch_name |
| 25 | + |
| 26 | +gha_run_id_element = ET.Element("gha_run_id") |
| 27 | +gha_run_id_element.text = args.gha_run_id |
| 28 | + |
| 29 | +gha_run_number_element = ET.Element("gha_run_number") |
| 30 | +gha_run_number_element.text = args.gha_run_number |
| 31 | + |
| 32 | +# Add the new elements to the root of the XML |
| 33 | +root.append(branch_name_element) |
| 34 | +root.append(gha_run_id_element) |
| 35 | +root.append(gha_run_number_element) |
| 36 | + |
| 37 | +# Save the modified XML |
| 38 | +modified_xml_file_path = xml_file_path # Overwrite it |
| 39 | +tree.write(modified_xml_file_path) |
| 40 | + |
| 41 | +print(f"Modified XML saved to {modified_xml_file_path}") |
0 commit comments