-
Notifications
You must be signed in to change notification settings - Fork 3
383 lines (323 loc) · 13.6 KB
/
validation-tests.yml
File metadata and controls
383 lines (323 loc) · 13.6 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
name: Validation Tests
on:
# Run every Monday at 8:00 AM UTC (early Monday morning)
schedule:
- cron: '0 8 * * 1'
# Run on pull requests
pull_request:
branches:
- main
- master
# Allow manual trigger
workflow_dispatch:
permissions:
contents: read
pull-requests: write
issues: write
jobs:
dotnet-tests:
name: .NET Tests
runs-on: ubuntu-latest
outputs:
status: ${{ steps.test.outcome }}
results: ${{ steps.test-details.outputs.results }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Run .NET tests
id: test
continue-on-error: true
working-directory: ./libraryValidations/Dotnet
run: dotnet test --no-build --logger "console;verbosity=normal" 2>&1 | tee test-output.txt
- name: Parse .NET test results
id: test-details
if: always()
working-directory: ./libraryValidations/Dotnet
run: |
echo 'results<<EOF' >> $GITHUB_OUTPUT
python3 <<'PYTHON'
import json
import re
results = {}
try:
with open('test-output.txt', 'r') as f:
content = f.read()
# Look for test method names in the output
# Pattern: "TestMethodName (status)"
for match in re.finditer(r'(\w+)\s+\([\d.]+m?s?\):\s+(PASSED|FAILED|passed|failed)', content, re.IGNORECASE):
test_name = match.group(1)
status = match.group(2).upper()
results[test_name] = '✅' if status == 'PASSED' else '❌'
# If we didn't find tests this way, try parsing the summary line
if not results:
summary_match = re.search(r'Failed[!]?\s*-\s*Failed:\s*(\d+),\s*Passed:\s*(\d+)', content)
if summary_match:
failed_count = int(summary_match.group(1))
passed_count = int(summary_match.group(2))
# Create generic test entries
for i in range(passed_count):
results[f'Test_{i+1}'] = '✅'
for i in range(failed_count):
results[f'FailedTest_{i+1}'] = '❌'
except Exception as e:
print(f"Error parsing: {e}")
print(json.dumps(results))
PYTHON
echo 'EOF' >> $GITHUB_OUTPUT
python-tests:
name: Python Tests
runs-on: ubuntu-latest
outputs:
status: ${{ steps.test.outcome }}
results: ${{ steps.test-details.outputs.results }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
working-directory: ./libraryValidations/Python
run: |
pip install -r requirements.txt
- name: Run Python tests
id: test
continue-on-error: true
working-directory: ./libraryValidations/Python
run: |
pytest test_json_validations.py --junitxml=results.xml --verbose || true
if [ ! -z "${{ secrets.APP_CONFIG_VALIDATION_CONNECTION_STRING }}" ]; then
pytest test_json_validations_with_provider.py --junitxml=results_provider.xml --verbose || true
fi
- name: Parse Python test results
id: test-details
if: always()
working-directory: ./libraryValidations/Python
run: |
echo "=== Listing Python test output files ==="
ls -la *.xml 2>/dev/null || echo "No XML files found"
echo "=========================================="
echo 'results<<EOF' >> $GITHUB_OUTPUT
python3 <<'PYTHON'
import xml.etree.ElementTree as ET
import json
import os
results = {}
for xml_file in ['results.xml', 'results_provider.xml']:
if os.path.exists(xml_file):
print(f"Parsing {xml_file}", flush=True)
tree = ET.parse(xml_file)
root = tree.getroot()
for testcase in root.findall('.//testcase'):
test_name = testcase.get('name')
failed = testcase.find('failure') is not None or testcase.find('error') is not None
results[test_name] = '❌' if failed else '✅'
print(json.dumps(results), flush=True)
PYTHON
echo 'EOF' >> $GITHUB_OUTPUT
javascript-tests:
name: JavaScript Tests
runs-on: ubuntu-latest
outputs:
status: ${{ steps.test.outcome }}
results: ${{ steps.test-details.outputs.results }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
working-directory: ./libraryValidations/JavaScript
run: npm install
- name: Build
working-directory: ./libraryValidations/JavaScript
run: npm run build
- name: Run JavaScript tests
id: test
continue-on-error: true
working-directory: ./libraryValidations/JavaScript
run: |
npm install --save-dev jest-junit
npx jest --reporters=jest-junit --testResultsProcessor=jest-junit || true
- name: Parse JavaScript test results
id: test-details
if: always()
working-directory: ./libraryValidations/JavaScript
run: |
echo "=== Listing JavaScript test output files ==="
ls -la junit.xml 2>/dev/null || echo "No junit.xml found"
find . -maxdepth 2 -name "*.xml" -type f 2>/dev/null | head -10
echo "=========================================="
echo 'results<<EOF' >> $GITHUB_OUTPUT
XML_FILE=""
if [ -f "junit.xml" ]; then
XML_FILE="junit.xml"
elif [ -f "test-results/junit.xml" ]; then
XML_FILE="test-results/junit.xml"
fi
if [ ! -z "$XML_FILE" ]; then
echo "Parsing JavaScript $XML_FILE"
export XML_FILE
python3 <<'PYTHON'
import xml.etree.ElementTree as ET
import json
import os
xml_file = os.environ.get('XML_FILE')
if xml_file and os.path.exists(xml_file):
tree = ET.parse(xml_file)
root = tree.getroot()
results = {}
for testcase in root.findall('.//testcase'):
test_name = testcase.get('name')
failed = testcase.find('failure') is not None or testcase.find('error') is not None
results[test_name] = '❌' if failed else '✅'
print(json.dumps(results), flush=True)
else:
print("{}")
PYTHON
else
echo "No JavaScript test results XML found"
echo "{}"
fi
echo 'EOF' >> $GITHUB_OUTPUT
spring-tests:
name: Spring Tests
runs-on: ubuntu-latest
outputs:
status: ${{ steps.test.outcome }}
results: ${{ steps.test-details.outputs.results }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Run Spring tests
id: test
continue-on-error: true
working-directory: ./libraryValidations/Spring/validation-tests
run: mvn test
- name: Parse Spring test results
id: test-details
if: always()
working-directory: ./libraryValidations/Spring/validation-tests
run: |
echo "=== Listing Spring test output files ==="
ls -la target/surefire-reports/ 2>/dev/null || echo "No surefire-reports directory"
find target -name "*.xml" -type f 2>/dev/null | head -10
echo "=========================================="
echo 'results<<EOF' >> $GITHUB_OUTPUT
python3 <<'PYTHON'
import xml.etree.ElementTree as ET
import json
import os
import glob
results = {}
xml_files = glob.glob('target/surefire-reports/TEST-*.xml')
print(f"Found {len(xml_files)} Spring test result files", flush=True)
for xml_file in xml_files:
print(f"Parsing {xml_file}", flush=True)
tree = ET.parse(xml_file)
root = tree.getroot()
for testcase in root.findall('.//testcase'):
test_name = testcase.get('name')
failed = testcase.find('failure') is not None or testcase.find('error') is not None
results[test_name] = '❌' if failed else '✅'
print(json.dumps(results), flush=True)
PYTHON
echo 'EOF' >> $GITHUB_OUTPUT
test-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [dotnet-tests, python-tests, javascript-tests, spring-tests]
if: always()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Generate test matrix
id: matrix
env:
DOTNET_RESULTS: ${{ needs.dotnet-tests.outputs.results }}
PYTHON_RESULTS: ${{ needs.python-tests.outputs.results }}
JAVASCRIPT_RESULTS: ${{ needs.javascript-tests.outputs.results }}
SPRING_RESULTS: ${{ needs.spring-tests.outputs.results }}
run: |
python3 <<'PYTHON'
import json
import os
# Debug: print raw results
print("=== Debug: Raw Results ===")
print(f"DOTNET: {os.environ.get('DOTNET_RESULTS', 'EMPTY')}")
print(f"PYTHON: {os.environ.get('PYTHON_RESULTS', 'EMPTY')}")
print(f"JAVASCRIPT: {os.environ.get('JAVASCRIPT_RESULTS', 'EMPTY')}")
print(f"SPRING: {os.environ.get('SPRING_RESULTS', 'EMPTY')}")
print("========================\n")
# Parse results from each language
try:
dotnet_results = json.loads(os.environ.get('DOTNET_RESULTS', '{}'))
except:
dotnet_results = {}
try:
python_results = json.loads(os.environ.get('PYTHON_RESULTS', '{}'))
except:
python_results = {}
try:
javascript_results = json.loads(os.environ.get('JAVASCRIPT_RESULTS', '{}'))
except:
javascript_results = {}
try:
spring_results = json.loads(os.environ.get('SPRING_RESULTS', '{}'))
except:
spring_results = {}
# Collect all unique test names across all languages
all_tests = set()
all_tests.update(dotnet_results.keys())
all_tests.update(python_results.keys())
all_tests.update(javascript_results.keys())
all_tests.update(spring_results.keys())
# Sort tests for consistent output
sorted_tests = sorted(all_tests)
print(f"Found {len(sorted_tests)} unique tests")
# Generate markdown table
with open('summary.md', 'w') as f:
f.write("## 🧪 Validation Test Results\n\n")
if not sorted_tests:
f.write("⚠️ No test results found. Check individual job outputs for details.\n\n")
else:
f.write("| Test Name | .NET | Python | JavaScript | Spring |\n")
f.write("|-----------|------|--------|------------|--------|\n")
for test in sorted_tests:
# Get result for each language, default to ⚠️ if not found
dotnet = dotnet_results.get(test, '⚠️')
python = python_results.get(test, '⚠️')
javascript = javascript_results.get(test, '⚠️')
spring = spring_results.get(test, '⚠️')
f.write(f"| {test} | {dotnet} | {python} | {javascript} | {spring} |\n")
f.write(f"\n_Workflow run: ${{ github.run_id }}_\n")
# Print to console
with open('summary.md', 'r') as f:
print(f.read())
PYTHON
cat summary.md >> $GITHUB_STEP_SUMMARY
- name: Comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const summary = fs.readFileSync('summary.md', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: summary
});