1+ name : Test Suite
2+
3+ on :
4+ push :
5+ branches : [ main, develop ]
6+ pull_request :
7+ branches : [ main ]
8+
9+ jobs :
10+ test :
11+ runs-on : ubuntu-latest
12+
13+ strategy :
14+ matrix :
15+ node-version : [18.x, 20.x]
16+
17+ steps :
18+ - name : Checkout code
19+ uses : actions/checkout@v4
20+
21+ - name : Set up Node.js ${{ matrix.node-version }}
22+ uses : actions/setup-node@v4
23+ with :
24+ node-version : ${{ matrix.node-version }}
25+ cache : ' npm'
26+
27+ - name : Run tests in Docker
28+ run : make test
29+ env :
30+ CI : true
31+
32+ - name : Upload test results
33+ if : always()
34+ uses : actions/upload-artifact@v4
35+ with :
36+ name : test-results-${{ matrix.node-version }}
37+ path : |
38+ test-results/
39+ coverage/
40+
41+ - name : Upload coverage to Codecov
42+ if : matrix.node-version == '20.x'
43+ uses : codecov/codecov-action@v3
44+ with :
45+ file : ./coverage/lcov.info
46+ flags : unittests
47+ name : codecov-umbrella
48+ fail_ci_if_error : false
49+
50+ - name : Comment PR with results
51+ if : github.event_name == 'pull_request' && matrix.node-version == '20.x'
52+ uses : actions/github-script@v7
53+ with :
54+ script : |
55+ const fs = require('fs');
56+
57+ // Read test results
58+ let testSummary = '## Test Results\n\n';
59+
60+ try {
61+ const results = JSON.parse(fs.readFileSync('test-results/results.json', 'utf8'));
62+ testSummary += `✅ **${results.numPassedTests}** passed\n`;
63+ if (results.numFailedTests > 0) {
64+ testSummary += `❌ **${results.numFailedTests}** failed\n`;
65+ }
66+ testSummary += `⏱️ Duration: ${(results.testResults[0].duration / 1000).toFixed(2)}s\n`;
67+ } catch (e) {
68+ testSummary += '❌ Failed to parse test results\n';
69+ }
70+
71+ // Read coverage summary
72+ testSummary += '\n## Coverage\n\n';
73+ try {
74+ const coverage = JSON.parse(fs.readFileSync('coverage/coverage-summary.json', 'utf8'));
75+ const total = coverage.total;
76+ testSummary += `| Type | Coverage |\n`;
77+ testSummary += `|------|----------|\n`;
78+ testSummary += `| Lines | ${total.lines.pct}% |\n`;
79+ testSummary += `| Statements | ${total.statements.pct}% |\n`;
80+ testSummary += `| Functions | ${total.functions.pct}% |\n`;
81+ testSummary += `| Branches | ${total.branches.pct}% |\n`;
82+ } catch (e) {
83+ testSummary += '❌ Failed to parse coverage results\n';
84+ }
85+
86+ github.rest.issues.createComment({
87+ issue_number: context.issue.number,
88+ owner: context.repo.owner,
89+ repo: context.repo.repo,
90+ body: testSummary
91+ });
92+
93+ - name : Check coverage thresholds
94+ if : matrix.node-version == '20.x'
95+ run : |
96+ node -e "
97+ const coverage = require('./coverage/coverage-summary.json');
98+ const total = coverage.total;
99+ const threshold = 80;
100+
101+ const failed = [];
102+ if (total.lines.pct < threshold) failed.push('lines');
103+ if (total.statements.pct < threshold) failed.push('statements');
104+ if (total.functions.pct < threshold) failed.push('functions');
105+ if (total.branches.pct < threshold) failed.push('branches');
106+
107+ if (failed.length > 0) {
108+ console.error('Coverage thresholds not met for:', failed.join(', '));
109+ process.exit(1);
110+ } else {
111+ console.log('All coverage thresholds met!');
112+ }
113+ "
0 commit comments