-
-
Notifications
You must be signed in to change notification settings - Fork 216
159 lines (138 loc) · 5.99 KB
/
report-tests.yml
File metadata and controls
159 lines (138 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Runs after the test workflow is done, uses results to gen a report for the PR
name: 📣 Report Tests
on:
workflow_run:
workflows: ["🧪 Run Tests"]
types:
- completed
permissions:
contents: read
checks: write # For test reporting
pull-requests: write # For PR comments
actions: read
jobs:
report:
name: Report Test Results
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'cancelled'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
merge-multiple: true
- name: Unit Test Report
id: unit-test-report
uses: dorny/test-reporter@v1
if: always()
with:
name: ⚙️ Unit Tests
path: test-results.xml
reporter: java-junit
fail-on-error: false
continue-on-error: true
- name: API Test Report
id: api-test-report
uses: dorny/test-reporter@v1
if: always()
with:
name: 📡 API Contract Tests
path: api-test-results.xml
reporter: java-junit
fail-on-error: false
continue-on-error: true
- name: E2E Test Report
id: e2e-test-report
uses: dorny/test-reporter@v1
if: always()
with:
name: 🧭 E2E Tests
path: e2e-results.xml
reporter: java-junit
fail-on-error: false
continue-on-error: true
- name: Generate detailed summary
if: always()
run: |
# Read test results
UNIT=$(cat test-result-unit.txt 2>/dev/null || echo "unknown")
API=$(cat test-result-api.txt 2>/dev/null || echo "unknown")
E2E=$(cat test-result-e2e.txt 2>/dev/null || echo "unknown")
# Helper functions
em() { case "$1" in success) echo "✅";; failure) echo "❌";; cancelled|skipped) echo "⏭️";; *) echo "❔";; esac; }
# Format time helper
format_time() {
local ms=$1
if [ "$ms" -gt 60000 ]; then
echo "$((ms / 60000))m $((ms % 60000 / 1000))s"
elif [ "$ms" -gt 1000 ]; then
echo "$((ms / 1000))s"
else
echo "${ms}ms"
fi
}
# Get report data
UNIT_PASSED="${{ steps.unit-test-report.outputs.passed || '0' }}"
UNIT_FAILED="${{ steps.unit-test-report.outputs.failed || '0' }}"
UNIT_SKIPPED="${{ steps.unit-test-report.outputs.skipped || '0' }}"
UNIT_TIME="${{ steps.unit-test-report.outputs.time || '0' }}"
API_PASSED="${{ steps.api-test-report.outputs.passed || '0' }}"
API_FAILED="${{ steps.api-test-report.outputs.failed || '0' }}"
API_SKIPPED="${{ steps.api-test-report.outputs.skipped || '0' }}"
API_TIME="${{ steps.api-test-report.outputs.time || '0' }}"
E2E_PASSED="${{ steps.e2e-test-report.outputs.passed || '0' }}"
E2E_FAILED="${{ steps.e2e-test-report.outputs.failed || '0' }}"
E2E_SKIPPED="${{ steps.e2e-test-report.outputs.skipped || '0' }}"
E2E_TIME="${{ steps.e2e-test-report.outputs.time || '0' }}"
# Count failures
failures=0
[ "$UNIT" = "failure" ] && failures=$((failures + 1))
[ "$API" = "failure" ] && failures=$((failures + 1))
[ "$E2E" = "failure" ] && failures=$((failures + 1))
{
echo "## 📊 Detailed Test Report"
echo ""
if [ "$failures" -eq 0 ]; then
echo "🎉 **All test suites passed!**<br>"
echo "<br>"
else
echo "⚠️ **$failures test suite(s) failed**<br>"
echo "<br>"
fi
# Detailed Unit Test Report
if [ "$UNIT_PASSED" != "0" ] || [ "$UNIT_FAILED" != "0" ] || [ "$UNIT_SKIPPED" != "0" ]; then
echo ""
echo "### $(em "$UNIT") Unit Test Details"
echo "| Metric | Count |"
echo "|--------|-------|"
[ "$UNIT_PASSED" != "0" ] && echo "| ✅ Passed | $UNIT_PASSED |"
[ "$UNIT_FAILED" != "0" ] && echo "| ❌ Failed | $UNIT_FAILED |"
[ "$UNIT_SKIPPED" != "0" ] && echo "| ⏭️ Skipped | $UNIT_SKIPPED |"
[ "$UNIT_TIME" != "0" ] && echo "| ⏱️ Duration | $(format_time $UNIT_TIME) |"
fi
# Detailed API Test Report
if [ "$API_PASSED" != "0" ] || [ "$API_FAILED" != "0" ] || [ "$API_SKIPPED" != "0" ]; then
echo ""
echo "### $(em "$API") API Contract Test Details"
echo "| Metric | Count |"
echo "|--------|-------|"
[ "$API_PASSED" != "0" ] && echo "| ✅ Passed | $API_PASSED |"
[ "$API_FAILED" != "0" ] && echo "| ❌ Failed | $API_FAILED |"
[ "$API_SKIPPED" != "0" ] && echo "| ⏭️ Skipped | $API_SKIPPED |"
[ "$API_TIME" != "0" ] && echo "| ⏱️ Duration | $(format_time $API_TIME) |"
fi
# Detailed E2E Test Report
if [ "$E2E_PASSED" != "0" ] || [ "$E2E_FAILED" != "0" ] || [ "$E2E_SKIPPED" != "0" ]; then
echo ""
echo "### $(em "$E2E") E2E Test Details"
echo "| Metric | Count |"
echo "|--------|-------|"
[ "$E2E_PASSED" != "0" ] && echo "| ✅ Passed | $E2E_PASSED |"
[ "$E2E_FAILED" != "0" ] && echo "| ❌ Failed | $E2E_FAILED |"
[ "$E2E_SKIPPED" != "0" ] && echo "| ⏭️ Skipped | $E2E_SKIPPED |"
[ "$E2E_TIME" != "0" ] && echo "| ⏱️ Duration | $(format_time $E2E_TIME) |"
fi
} >> "$GITHUB_STEP_SUMMARY"