-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 95064f4
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
__pycache__/ | ||
data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |