Skip to content

Commit e83a46f

Browse files
committed
Changes
1 parent 8d95705 commit e83a46f

File tree

1 file changed

+102
-5
lines changed

1 file changed

+102
-5
lines changed

.github/workflows/test.yml

Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ on:
44
push:
55
branches:
66
- develop
7-
- token-cache-feature
87
pull_request:
98
branches:
109
- develop
11-
- token-cache-feature
1210

1311
jobs:
1412
test:
@@ -50,20 +48,119 @@ jobs:
5048
"host": "${{ secrets.SCM_HOST }}",
5149
"protocol": "${{ secrets.SCM_PROTOCOL }}",
5250
"scope": "${{ secrets.SCM_SCOPE }}",
53-
"logging": "quiet",
51+
"logging": "${{ secrets.SCM_LOGGING }}",
5452
"skip_verify_certificate": ${{ secrets.SCM_SKIP_VERIFY_CERTIFICATE }}
5553
}
5654
EOF
5755
5856
- name: Run tests for ${{ matrix.service }}
5957
run: |
6058
set +e
61-
output=$(go test -timeout 60m -parallel 10 -skip "Test_objects_ApplicationsAPIService_List" ./generated/${{ matrix.service }}/... 2>&1)
59+
60+
# Run tests with JSON output for parsing
61+
go test -timeout 60m -parallel 10 -v -json -skip "Test_objects_ApplicationsAPIService_List" ./generated/${{ matrix.service }}/... > test-output.json 2>&1
6262
exit_code=$?
6363
64+
# Parse JSON output and create summary with failure logs
65+
cat > parse_tests.py << 'PYTHON'
66+
import json
67+
import sys
68+
69+
passed = []
70+
failed = []
71+
skipped = []
72+
test_outputs = {} # Store output for each test
73+
current_test = None
74+
75+
with open('test-output.json', 'r') as f:
76+
for line in f:
77+
try:
78+
data = json.loads(line)
79+
action = data.get('Action')
80+
test_name = data.get('Test', '')
81+
82+
# Track current test for output collection
83+
if action == 'run' and test_name:
84+
current_test = test_name
85+
test_outputs[test_name] = []
86+
87+
# Collect output lines for tests
88+
if action == 'output' and current_test and 'Output' in data:
89+
output_line = data['Output'].rstrip()
90+
if output_line:
91+
test_outputs[current_test].append(output_line)
92+
93+
# Record test results
94+
if action == 'pass' and test_name:
95+
elapsed = data.get('Elapsed', 0)
96+
passed.append((test_name, elapsed))
97+
elif action == 'fail' and test_name:
98+
elapsed = data.get('Elapsed', 0)
99+
failed.append((test_name, elapsed))
100+
elif action == 'skip' and test_name:
101+
skipped.append(test_name)
102+
except:
103+
pass
104+
105+
# Write to GITHUB_STEP_SUMMARY
106+
summary_file = sys.argv[1] if len(sys.argv) > 1 else '/dev/stdout'
107+
with open(summary_file, 'a') as f:
108+
f.write(f"## Test Results: ${{ matrix.service }}\n\n")
109+
f.write(f"**Summary:** {len(passed)} passed ✅, {len(failed)} failed ❌, {len(skipped)} skipped ⏭️\n\n")
110+
111+
if failed:
112+
f.write("### ❌ Failed Tests\n\n")
113+
for test, elapsed in failed:
114+
f.write(f"#### `{test}` ({elapsed:.2f}s)\n\n")
115+
116+
# Extract and display failure output
117+
if test in test_outputs:
118+
output = test_outputs[test]
119+
# Find relevant error messages
120+
error_lines = []
121+
for i, line in enumerate(output):
122+
# Capture lines with errors, failures, or important context
123+
if any(keyword in line for keyword in ['Error:', 'FAIL:', 'panic:', '504 Gateway Timeout', 'expected', 'actual']):
124+
# Include context (previous 2 lines and next 5 lines)
125+
start = max(0, i - 2)
126+
end = min(len(output), i + 6)
127+
error_lines.extend(output[start:end])
128+
break
129+
130+
if error_lines:
131+
f.write("<details>\n<summary>📋 Error Details</summary>\n\n")
132+
f.write("```\n")
133+
f.write('\n'.join(error_lines[-20:])) # Last 20 lines to avoid huge output
134+
f.write("\n```\n")
135+
f.write("</details>\n\n")
136+
else:
137+
f.write("_No detailed error output captured_\n\n")
138+
139+
f.write("---\n\n")
140+
141+
if passed:
142+
f.write("### ✅ Passed Tests\n\n")
143+
f.write("<details>\n<summary>Click to expand ({} tests)</summary>\n\n".format(len(passed)))
144+
f.write("| Test Name | Duration |\n")
145+
f.write("|-----------|----------|\n")
146+
for test, elapsed in passed:
147+
f.write(f"| `{test}` | {elapsed:.2f}s |\n")
148+
f.write("\n</details>\n\n")
149+
150+
if skipped:
151+
f.write("### ⏭️ Skipped Tests\n\n")
152+
f.write("<details>\n<summary>Click to expand ({} tests)</summary>\n\n".format(len(skipped)))
153+
f.write("| Test Name |\n")
154+
f.write("|-----------|\n")
155+
for test in skipped:
156+
f.write(f"| `{test}` |\n")
157+
f.write("\n</details>\n\n")
158+
PYTHON
159+
160+
python3 parse_tests.py "$GITHUB_STEP_SUMMARY"
161+
64162
if [ $exit_code -ne 0 ]; then
65163
echo "❌ Tests failed for ${{ matrix.service }}"
66-
echo "$output" | grep -E "(FAIL|--- FAIL:|panic:|Error:)" || echo "$output"
67164
exit $exit_code
68165
else
69166
echo "✅ All tests passed for ${{ matrix.service }}"

0 commit comments

Comments
 (0)