Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: upload test data to test account's obj storage #383

Merged
merged 9 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Testing

on:
workflow_dispatch: null
push:
branches:
- main
Expand All @@ -15,15 +16,79 @@ jobs:
with:
go-version: 'stable'
- run: go version

- name: Run tidy
run: make tidy

- name: Run fmt
run: go fmt ./...

- name: Fail if changes
run: git diff-index --exit-code HEAD

- name: Run linter
run: make lint
- name: Run tests
run: make test

- name: Update system packages
run: sudo apt-get update -y

- name: Install system deps
run: sudo apt-get install -y build-essential

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- 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

- name: Run tests and save json report
run: |
timestamp=$(date +'%Y%m%d%H%M')
report_filename="${timestamp}_linodego_test_report.json"

make test ARGS="-json" | tee "$report_filename"
env:
SKIP_LINT: 1

- name: Convert JSON Report to XML
run: |
filename=$(ls | grep -E '^[0-9]{12}_linodego_test_report\.json')

if [ -f "$filename" ]; then
go_junit_report_dir=$(go env GOPATH)/bin
export PATH="$PATH:$go_junit_report_dir"
xml_filename=$(echo "$filename" | sed 's/\.json$/.xml/')
go-junit-report < "$filename" > "$xml_filename"
echo "Conversion from JSON to XML completed successfully."
else
echo "JSON test report file not found."
exit 1
fi
env:
GO111MODULE: on

- name: Add additional information to XML report
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 }}" \
--gha_run_id "$GITHUB_RUN_ID" \
--gha_run_number "$GITHUB_RUN_NUMBER" \
--xmlfile "${filename}"

- name: Upload test results to bucket
run: |
report_filename=$(ls | grep -E '^[0-9]{12}_linodego_test_report\.xml$')
python3 scripts/test_report_upload_script.py "${report_filename}"
env:
LINODE_CLI_OBJ_ACCESS_KEY: ${{ secrets.LINODE_CLI_OBJ_ACCESS_KEY }}
LINODE_CLI_OBJ_SECRET_KEY: ${{ secrets.LINODE_CLI_OBJ_SECRET_KEY }}

37 changes: 37 additions & 0 deletions scripts/add_to_xml_test_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import argparse
import xml.etree.ElementTree as ET

# 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

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

# 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)

# 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}')
41 changes: 41 additions & 0 deletions scripts/test_report_upload_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import boto3
import sys
import os
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 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 <file_name>')
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)

upload_to_linode_object_storage(file_name)
Loading