Skip to content

Commit

Permalink
update script and workflow to include release info
Browse files Browse the repository at this point in the history
  • Loading branch information
ykim-akamai committed Dec 5, 2023
1 parent 8c9fc48 commit a71c6c0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/e2e-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,11 @@ jobs:
env:
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}

- name: Set release version env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Add additional information to XML report
run: |
filename=$(ls | grep -E '^[0-9]{12}_sdk_test_report\.xml$')
python test/script/add_to_xml_test_report.py \
--branch_name "${{ env.RELEASE_VERSION }}" \
--branch_name "${GITHUB_REF#refs/*/}" \
--gha_run_id "$GITHUB_RUN_ID" \
--gha_run_number "$GITHUB_RUN_NUMBER" \
--xmlfile "${filename}"
Expand Down
53 changes: 40 additions & 13 deletions test/script/add_to_xml_test_report.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
import argparse
import xml.etree.ElementTree as ET
import requests

latest_release_url = "https://api.github.com/repos/linode/linode-cli/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(
"--xmlfile", required=True
) # Added argument for XML file path
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()

Expand All @@ -20,22 +43,26 @@
root = tree.getroot()

# Create new elements for the information
branch_name_element = ET.Element("branch_name")
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 = 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 = 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}")
print(f'Modified XML saved to {modified_xml_file_path}')

0 comments on commit a71c6c0

Please sign in to comment.