Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Commit

Permalink
Add Helix binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
akoeplinger committed Nov 6, 2018
1 parent a9d8faa commit b4f5d25
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 0 deletions.
Binary file added Microsoft.Azure.KeyVault.Core.dll
Binary file not shown.
Binary file added Microsoft.Data.Edm.dll
Binary file not shown.
Binary file added Microsoft.Data.OData.dll
Binary file not shown.
Binary file added Microsoft.Data.Services.Client.dll
Binary file not shown.
Binary file added Microsoft.DotNet.Helix.Client.dll
Binary file not shown.
Binary file added Microsoft.DotNet.Helix.JobSender.dll
Binary file not shown.
Binary file added Microsoft.Rest.ClientRuntime.dll
Binary file not shown.
Binary file added Microsoft.WindowsAzure.Storage.dll
Binary file not shown.
Binary file added Newtonsoft.Json.dll
Binary file not shown.
95 changes: 95 additions & 0 deletions xunit-reporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env python

import re
import os
import urlparse
import helix.azure_storage
import helix.event
import helix.settings
import helix.logs

log = helix.logs.get_logger()

acceptableXUnitFileNames = [
"testResults.xml",
"test-results.xml",
"test_results.xml"
]

class HelixHelper:
def __init__(self, settings):
self.settings = settings
self.event_client = helix.event.create_from_uri(settings.event_uri)
self.upload_client = helix.azure_storage.get_upload_client(settings)

def error(self, error_type, message, log_uri=None):
self.event_client.error(self.settings, error_type, message, log_uri)

def xunit(self, results_uri, test_count):
self.event_client.send(
{
'Type': 'XUnitTestResult',
'WorkItemId': self.settings.workitem_id,
'WorkItemFriendlyName': self.settings.workitem_friendly_name,
'CorrelationId': self.settings.correlation_id,
'ResultsXmlUri': results_uri,
'TestCount': test_count,
}
)

def upload_file_to_storage(self, file_path):
""" Copy file specified to azure storage account using Helix infrastructure
:param file_path: Path to file to be copied to Azure storage
:type file_path:string
"""
try:
return self.upload_client.upload(file_path, os.path.basename(file_path))
except ValueError:
self.error("FailedUpload", "Failed to upload "+file_path+"after retry")

def findXUnitResults(search_dir):
for root, dirs, files in os.walk(search_dir):
for file_name in files:
if file_name in acceptableXUnitFileNames:
return os.path.join(root, file_name)
return None

def main():
settings = helix.settings.settings_from_env()

if settings.output_uri is None or settings.event_uri is None:
log.error("Unable to report xunit results: output_uri and/or event_uri are not set.")
return 1

helper = HelixHelper(settings)
working_dir = settings.workitem_working_dir

results_path = findXUnitResults(working_dir)

if results_path is None:
log.error("Unable to report xunit results: no test results xml file found.")
return 2

log.info("Uploading results from {}".format(results_path))

with file(results_path) as result_file:
test_count = 0
total_regex = re.compile(r'total="(\d+)"')
for line in result_file:
if '<assembly ' in line:
match = total_regex.search(line)
if match is not None:
test_count = int(match.groups()[0])
break

result_url = helper.upload_file_to_storage(results_path)

log.info("Sending completion event")
helper.xunit(result_url, test_count)

return 0


if __name__ == '__main__':
import sys
sys.exit(main())

0 comments on commit b4f5d25

Please sign in to comment.