Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bnaing committed Dec 8, 2022
0 parents commit 95064f4
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
__pycache__/
data
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ubuntu:18.04

RUN apt-get update && apt-get install -qy python3

COPY entrypoint.py /entrypoint.py

ENTRYPOINT python3 /entrypoint.py
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# android-sdk-test-report-action
Android SDK Repository and Use Case layer test report action
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: 'Android SDK Repository and Use Case test report action'
description: 'test report'
author: 'AmityCo'

branding:
icon: 'git-pull-request'
color: 'green'

runs:
using: 'docker'
image: 'Dockerfile'
98 changes: 98 additions & 0 deletions entrypoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import os
from pathlib import Path
import xml.etree.ElementTree as ET


class ResultCount:
title = ""
total = 0
skipped = 0
failed = 0
errors = 0
statusEmoji = ":cross_mark:"
successRate = 0

def __init__(self, title: str) -> None:
self.title = title

def __repr__(self) -> str:
return f"{self.statusEmoji} {self.title} - {self.successRate}% #:pointing_right: total={self.total}, skipped={self.skipped}, failed={self.failed}, errors={self.errors}"

def calculateSuccessRate(self):
success = self.total - (self.failed + self.errors)
self.successRate = round(success * 100 / self.total)
if self.successRate == 100:
self.statusEmoji = ":check_mark:"


class FailedTest:
errors = []

def __repr__(self) -> str:
if len(self.errors) == 0:
return ""
else:
title = ":smiling_tear: Failed Test Cases"
errorsStr = ''.join(self.errors)
return f"{title}#{errorsStr}"

def add(self, methodName: str, className: str):
self.errors.append(f":file: {methodName} in {className}#")


def parse(path, rc: ResultCount, failed: FailedTest):
tree = ET.parse(path)
root = tree.getroot()
attributes = root.attrib

countTotal = attributes["tests"]
countSkipped = attributes["skipped"]
countFailed = attributes["failures"]
countError = attributes["errors"]

rc.total += int(countTotal)
rc.skipped += int(countSkipped)
rc.failed += int(countFailed)
rc.errors += int(countError)

for element in root:
if element.tag == "testcase":
if element.find("failure") != None:
attrib = element.attrib
methodName = attrib["name"]
className = attrib["classname"].split(".")[-1]
failed.add(methodName, className)


def traverse(repo: ResultCount, uc: ResultCount, failed: FailedTest):
pathlist = Path().rglob("TEST-*.xml")
for p in pathlist:
path = str(p)
if path.lower().endswith("repositorytest.xml"):
parse(path, repo, failed)

elif path.lower().endswith("usecasetest.xml"):
parse(path, uc, failed)


def main():
repo = ResultCount("Repository")
uc = ResultCount("Use Case")
failed = FailedTest()

traverse(repo, uc, failed)

repo.calculateSuccessRate()
uc.calculateSuccessRate()

result = ":memo: SDK Test Report#" + str(repo) + "##" + str(uc) + "##" + str(failed)

try:
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print(f'SDK_TEST_REPORT={result}', file=fh)
except:
pass


if __name__ == "__main__":
main()

0 comments on commit 95064f4

Please sign in to comment.