Skip to content

Commit

Permalink
test: add release info to xml file before uploading to obj storage (#437
Browse files Browse the repository at this point in the history
)

* fix script and workflow to include release info in xml

* Update scripts/add_to_xml_test_report.py

Co-authored-by: Lena Garber <114949949+lgarber-akamai@users.noreply.github.com>

---------

Co-authored-by: Zhiwei Liang <121905282+zliang-akamai@users.noreply.github.com>
Co-authored-by: Lena Garber <114949949+lgarber-akamai@users.noreply.github.com>
  • Loading branch information
3 people committed Dec 6, 2023
1 parent 8990c63 commit 2fe6f94
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ jobs:
- name: Install Python deps
run: pip3 install requests wheel boto3

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

- name: Install go-junit-report
run: go install github.com/jstemmer/go-junit-report/v2@latest

Expand All @@ -68,7 +65,7 @@ jobs:
run: |
filename=$(ls | grep -E '^[0-9]{12}_linodego_test_report\.xml$')
python scripts/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
31 changes: 31 additions & 0 deletions scripts/add_to_xml_test_report.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
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()
Expand All @@ -25,10 +52,14 @@
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
Expand Down

0 comments on commit 2fe6f94

Please sign in to comment.