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