diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 90b88176..092dbe7b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,8 +13,14 @@ jobs: env: EXIT_STATUS: 0 steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 + - name: Clone Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: 'recursive' + + - name: Set up Go + uses: actions/setup-go@v5 with: go-version: 'stable' - run: go version @@ -64,7 +70,7 @@ jobs: if: github.ref == 'refs/heads/main' && github.event_name == 'push' run: | filename=$(ls | grep -E '^[0-9]{12}_linodego_test_report\.xml$') - python scripts/add_to_xml_test_report.py \ + python tod_scripts/add_to_xml_test_report.py \ --branch_name "${GITHUB_REF#refs/*/}" \ --gha_run_id "$GITHUB_RUN_ID" \ --gha_run_number "$GITHUB_RUN_NUMBER" \ @@ -77,7 +83,7 @@ jobs: LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }} run: | report_filename=$(ls | grep -E '^[0-9]{12}_linodego_test_report\.xml$') - python3 scripts/test_report_upload_script.py "${report_filename}" + python tod_scripts/test_report_upload_script.py "${report_filename}" - name: Test Execution Status Handler run: | diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..df7dc11d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tod_scripts"] + path = tod_scripts + url = https://github.com/linode/TOD-test-report-uploader.git diff --git a/scripts/add_to_xml_test_report.py b/scripts/add_to_xml_test_report.py deleted file mode 100644 index 60b10599..00000000 --- a/scripts/add_to_xml_test_report.py +++ /dev/null @@ -1,68 +0,0 @@ -import argparse -import xml.etree.ElementTree as ET -import requests - -latest_release_url = "https://api.github.com/repos/linode/linodego/releases/latest" - - -def get_release_version(): - url = latest_release_url - - try: - response = requests.get(url) - response.raise_for_status() # Check for HTTP errors - - release_info = response.json() - version = release_info["tag_name"] - - # Remove 'v' prefix if it exists - if version.startswith("v"): - version = version[1:] - - return str(version) - - except requests.exceptions.RequestException as e: - print("Error:", e) - except KeyError: - print("Error: Unable to fetch release information from GitHub API.") - - -# Parse command-line arguments -parser = argparse.ArgumentParser(description='Modify XML with workflow information') -parser.add_argument('--branch_name', required=True) -parser.add_argument('--gha_run_id', required=True) -parser.add_argument('--gha_run_number', required=True) -parser.add_argument('--release_tag', required=False) -parser.add_argument('--xmlfile', required=True) # Added argument for XML file path - -args = parser.parse_args() - -# Open and parse the XML file -xml_file_path = args.xmlfile -tree = ET.parse(xml_file_path) -root = tree.getroot() - -# Create new elements for the information -branch_name_element = ET.Element('branch_name') -branch_name_element.text = args.branch_name - -gha_run_id_element = ET.Element('gha_run_id') -gha_run_id_element.text = args.gha_run_id - -gha_run_number_element = ET.Element('gha_run_number') -gha_run_number_element.text = args.gha_run_number - -gha_release_tag_element = ET.Element('release_tag') -gha_release_tag_element.text = get_release_version() - -# Add the new elements to the root of the XML -root.append(branch_name_element) -root.append(gha_run_id_element) -root.append(gha_run_number_element) -root.append(gha_release_tag_element) - -# Save the modified XML -modified_xml_file_path = xml_file_path # Overwrite it -tree.write(modified_xml_file_path) - -print(f'Modified XML saved to {modified_xml_file_path}') diff --git a/scripts/test_report_upload_script.py b/scripts/test_report_upload_script.py deleted file mode 100644 index 4365561e..00000000 --- a/scripts/test_report_upload_script.py +++ /dev/null @@ -1,90 +0,0 @@ -import boto3 -import sys -import os -import xml.etree.ElementTree as ET -from botocore.exceptions import NoCredentialsError - -ACCESS_KEY = os.environ.get('LINODE_CLI_OBJ_ACCESS_KEY') -SECRET_KEY = os.environ.get('LINODE_CLI_OBJ_SECRET_KEY') -BUCKET_NAME = 'dx-test-results' - -linode_obj_config = { - "aws_access_key_id": ACCESS_KEY, - "aws_secret_access_key": SECRET_KEY, - "endpoint_url": "https://us-southeast-1.linodeobjects.com", - "region_name": "us-southeast-1", -} - -def change_xml_report_to_tod_acceptable_version(file_name): - # Load the original XML file - tree = ET.parse(file_name) - root = tree.getroot() - - testsuites_element = root - - # total - total_tests = int(testsuites_element.get('tests')) if testsuites_element.get('tests') is not None else 0 - total_failures = int(testsuites_element.get('failures')) if testsuites_element.get('failures') is not None else 0 - total_errors = int(testsuites_element.get('errors')) if testsuites_element.get('errors') is not None else 0 - total_skipped = int(testsuites_element.get('skipped')) if testsuites_element.get('skipped') is not None else 0 - - # Create a new element with aggregated values - new_testsuites = ET.Element("testsuites") - new_testsuites.set("tests", str(total_tests)) - new_testsuites.set("failures", str(total_failures)) - new_testsuites.set("errors", str(total_errors)) - new_testsuites.set("skipped", str(total_skipped)) - - # Create a new element under - new_testsuite = ET.SubElement(new_testsuites, "testsuite", attrib=testsuites_element.attrib) - - for testcase in root.findall('.//testcase'): - new_testcase = ET.SubElement(new_testsuite, "testcase", attrib=testcase.attrib) - for child in testcase: - new_testcase.append(child) - - branch_name = ET.SubElement(new_testsuite, branch_name) - branch_name.text = root.find('branch_name').text - gha_run_id = ET.SubElement(new_testsuite, gha_run_id) - gha_run_id.text = root.find('gha_run_id').text - gha_run_number = ET.SubElement(new_testsuite, gha_run_number) - gha_run_number.text = root.find('gha_run_number').text - release_tag = ET.SubElement(new_testsuite, release_tag) - release_tag.text = root.find('release_tag').text - - # Save the new XML to a file - try: - new_tree = ET.ElementTree(new_testsuites) - - new_tree.write(file_name, encoding="UTF-8", xml_declaration=True) - - print("XML content successfully over-written to " + file_name) - - except Exception as e: - print("Error writing XML content:", str(e)) - -def upload_to_linode_object_storage(file_name): - try: - s3 = boto3.client('s3', **linode_obj_config) - - s3.upload_file(Filename=file_name, Bucket=BUCKET_NAME, Key=file_name) - - print(f'Successfully uploaded {file_name} to Linode Object Storage.') - - except NoCredentialsError: - print('Credentials not available. Ensure you have set your AWS credentials.') - - -if __name__ == '__main__': - if len(sys.argv) != 2: - print('Usage: python upload_to_linode.py ') - sys.exit(1) - - file_name = sys.argv[1] - - if not file_name: - print('Error: The provided file name is empty or invalid.') - sys.exit(1) - - change_xml_report_to_tod_acceptable_version(file_name) - upload_to_linode_object_storage(file_name) \ No newline at end of file diff --git a/tod_scripts b/tod_scripts new file mode 160000 index 00000000..eec4b995 --- /dev/null +++ b/tod_scripts @@ -0,0 +1 @@ +Subproject commit eec4b99557cef6f40e8b5b7de00357dc49fb041c