Skip to content

Commit 9915f6d

Browse files
authored
test: upload test report to account's object storage (#326)
## πŸ“ Description Storing test executions from dev/main branch to test account's object storage ## πŸ“· Preview **If applicable, include a screenshot or code snippet of this change. Otherwise, please remove this section.**
1 parent e2719eb commit 9915f6d

File tree

4 files changed

+113
-3
lines changed

4 files changed

+113
-3
lines changed

β€Ž.github/workflows/e2e-test-pr.ymlβ€Ž

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,37 @@ jobs:
7878
env:
7979
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8080

81-
- run: make INTEGRATION_TEST_PATH="${{ inputs.test_path }}" testint
82-
if: ${{ steps.validate-tests.outputs.match == '' }}
81+
- name: Run Integration tests
82+
run: |
83+
timestamp=$(date +'%Y%m%d%H%M')
84+
report_filename="${timestamp}_sdk_test_report.xml"
85+
status=0
86+
if ! python3 -m pytest test/integration/${INTEGRATION_TEST_PATH} --junitxml="${report_filename}"; then
87+
echo "Tests failed, but attempting to upload results anyway"
88+
fi
8389
env:
8490
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}
8591

92+
- name: Set release version env
93+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
94+
95+
- name: Add additional information to XML report
96+
run: |
97+
filename=$(ls | grep -E '^[0-9]{12}_sdk_test_report\.xml$')
98+
python test/script/add_to_xml_test_report.py \
99+
--branch_name "${{ env.RELEASE_VERSION }}" \
100+
--gha_run_id "$GITHUB_RUN_ID" \
101+
--gha_run_number "$GITHUB_RUN_NUMBER" \
102+
--xmlfile "${filename}"
103+
104+
- name: Upload test results
105+
run: |
106+
report_filename=$(ls | grep -E '^[0-9]{12}_sdk_test_report\.xml$')
107+
python3 test/script/test_report_upload_script.py "${report_filename}"
108+
env:
109+
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
110+
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}
111+
86112
- uses: actions/github-script@v6
87113
id: update-check-run
88114
if: ${{ inputs.pull_request_number != '' && fromJson(steps.commit-hash.outputs.data).repository.pullRequest.headRef.target.oid == inputs.sha }}

β€Žtest/integration/conftest.pyβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from linode_api4.linode_client import LinodeClient, LongviewSubscription
6+
from linode_api4.linode_client import LinodeClient
77

88
ENV_TOKEN_NAME = "LINODE_TOKEN"
99
RUN_LONG_TESTS = "RUN_LONG_TESTS"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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}")
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import sys
3+
4+
import boto3
5+
from botocore.exceptions import NoCredentialsError
6+
7+
ACCESS_KEY = os.environ.get("LINODE_CLI_OBJ_ACCESS_KEY")
8+
SECRET_KEY = os.environ.get("LINODE_CLI_OBJ_SECRET_KEY")
9+
BUCKET_NAME = "dx-test-results"
10+
11+
linode_obj_config = {
12+
"aws_access_key_id": ACCESS_KEY,
13+
"aws_secret_access_key": SECRET_KEY,
14+
"endpoint_url": "https://us-southeast-1.linodeobjects.com",
15+
}
16+
17+
18+
def upload_to_linode_object_storage(file_name):
19+
try:
20+
s3 = boto3.client("s3", **linode_obj_config)
21+
22+
s3.upload_file(Filename=file_name, Bucket=BUCKET_NAME, Key=file_name)
23+
24+
print(f"Successfully uploaded {file_name} to Linode Object Storage.")
25+
26+
except NoCredentialsError:
27+
print(
28+
"Credentials not available. Ensure you have set your AWS credentials."
29+
)
30+
31+
32+
if __name__ == "__main__":
33+
if len(sys.argv) != 2:
34+
print("Usage: python upload_to_linode.py <file_name>")
35+
sys.exit(1)
36+
37+
file_name = sys.argv[1]
38+
39+
if not file_name:
40+
print("Error: The provided file name is empty or invalid.")
41+
sys.exit(1)
42+
43+
upload_to_linode_object_storage(file_name)

0 commit comments

Comments
Β (0)