Skip to content

Commit

Permalink
Update GH Action
Browse files Browse the repository at this point in the history
  • Loading branch information
manykarim committed Feb 17, 2024
1 parent 031cd28 commit b1d66df
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ jobs:
if: success() || failure()
run: |
pip install -r utils/requirements.txt
python utils/gha_reporter.py
python utils/gha_reporter.py results/output.xml $GITHUB_STEP_SUMMARY
69 changes: 29 additions & 40 deletions utils/gha_reporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from robot.api import ExecutionResult, ResultVisitor
from pytablewriter import MarkdownTableWriter

import sys

class SuitesWithTestsVisitor(ResultVisitor):
def __init__(self):
Expand All @@ -10,61 +10,50 @@ def start_suite(self, suite):
self.suites_with_tests.append(suite)


result = ExecutionResult('results/output.xml')
stats = result.statistics
def main():
output_file = sys.argv[1]
markdown_file = sys.argv[2]

f = open(markdown_file, "w")

result = ExecutionResult(output_file)

stats = result.statistics

with open('test_overview_chart.md', "w") as f:
f.write("```mermaid\n")
f.write("%%{init: {'theme': 'base', 'themeVariables': { 'pie1': '#00FF00', 'pie2': '#FF0000', 'pie3': '#FFFF00'}}}%%\n")
f.write("pie title Test Status\n")
f.write(f' "Passed" : {stats.total.passed}\n')
f.write(f' "Failed" : {stats.total.failed}\n')
f.write(f' "Skipped" : {stats.total.skipped}\n')
f.write("```")

# ```mermaid
# %%{init: {'theme': 'base', 'themeVariables': { 'pie1': '#00FF00', 'pie2': '#FF0000', 'pie3': '#FFFF00'}}}%%
# pie title Test Status
# "Passed" : 386
# "Failed" : 85
# "Skipped" : 15
# ```
f.write("```\n")

suite_visitor = SuitesWithTestsVisitor()
result.visit(suite_visitor)
suites_with_tests = suite_visitor.suites_with_tests
suite_visitor = SuitesWithTestsVisitor()
result.visit(suite_visitor)
suites_with_tests = suite_visitor.suites_with_tests

suite_results = []
for suite in suites_with_tests:
suite_results.append([suite.full_name, suite.statistics.passed, suite.statistics.failed, suite.statistics.skipped, suite.statistics.total, suite.elapsed_time.total_seconds()])
suite_results = []
for suite in suites_with_tests:
suite_results.append([suite.name, suite.statistics.passed, suite.statistics.failed, suite.statistics.skipped, suite.statistics.total, suite.elapsed_time.total_seconds()])

table_columns = ["Test Suite", "Passed ✅", "Failed ❌", "Skipped 🛑", "Total", "Elapsed Time ⏱️"]
table_columns = ["Test Suite", "Passed ✅", "Failed ❌", "Skipped 🛑", "Total", "Elapsed Time ⏱️"]

with open('test_overview.md', "w") as f:
writer = MarkdownTableWriter(table_name= "Test Status", headers = table_columns, value_matrix = suite_results)
writer = MarkdownTableWriter(table_name= "Test Suite Status", headers = table_columns, value_matrix = suite_results)
writer.stream = f
writer.write_table()
f.write("\n")

test_results = {}
for suite in suites_with_tests:
tests_in_suite = []
for test in suite.tests:
status = lambda test: "✅ PASS" if test.status == "PASS" else ("❌ FAIL" if test.status == "FAIL" else "🛑 SKIP")
tests_in_suite.append([test.name, status(test), test.elapsed_time.total_seconds()])
test_results[suite.full_name] = tests_in_suite

with open('test_results.md', "w") as f:
for suite in suites_with_tests:
tests_in_suite = []
for test in suite.tests:
status = lambda test: "✅ PASS" if test.status == "PASS" else ("❌ FAIL" if test.status == "FAIL" else "🛑 SKIP")
tests_in_suite.append([test.name, status(test), test.elapsed_time.total_seconds()])

for suite in test_results:
table_columns = ["Test Case", "Status", "Elapsed Time ⏱️"]
writer = MarkdownTableWriter(table_name= suite, headers = table_columns, value_matrix = test_results[suite])
writer = MarkdownTableWriter(table_name= suite.name, headers = table_columns, value_matrix = tests_in_suite)
writer.stream = f
writer.write_table()
f.write("\n")

import os
if "GITHUB_STEP_SUMMARY" in os.environ :
with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as f :
chart = open('test_overview_chart.md', "r").read()
overview = open('test_overview.md', "r").read()
results = open('test_results.md', "r").read()
print(chart + "\n" + overview + "\n" + results, file=f)
if __name__ == "__main__":
main()

0 comments on commit b1d66df

Please sign in to comment.