@@ -61,28 +61,49 @@ jobs:
6161 - name : Coverage Summary
6262 run : |
6363 # Run tests with coverage and capture output
64- TEST_OUTPUT=$( pnpm run test:coverage 2>&1)
64+ pnpm run test:coverage > coverage_output.txt 2>&1
6565
6666 echo "## 📊 Test Coverage Report" >> $GITHUB_STEP_SUMMARY
6767 echo "" >> $GITHUB_STEP_SUMMARY
6868
6969 # Extract test results
70- TEST_COUNT=$(echo "$TEST_OUTPUT" | grep -o '[0-9]\+ passed' | head -1 | grep -o '[0-9]\+')
71- OVERALL_COVERAGE=$(echo "$TEST_OUTPUT" | grep "All files" | awk '{print $3}')
72-
73- # Add coverage table
74- echo "| File | Statements | Branches | Functions | Lines |" >> $GITHUB_STEP_SUMMARY
75- echo "|------|------------|----------|-----------|-------|" >> $GITHUB_STEP_SUMMARY
76-
77- # Parse coverage and add to summary
78- echo "$TEST_OUTPUT" | grep -E "^\s*(All files|[a-z-]+\.ts)" | while read line; do
79- if [[ $line == *"All files"* ]]; then
80- echo "| **Overall** | $(echo $line | awk '{print $3}') | $(echo $line | awk '{print $4}') | $(echo $line | awk '{print $5}') | $(echo $line | awk '{print $6}') |" >> $GITHUB_STEP_SUMMARY
81- elif [[ $line == *.ts* ]]; then
82- filename=$(echo $line | awk '{print $1}')
83- echo "| $filename | $(echo $line | awk '{print $3}') | $(echo $line | awk '{print $4}') | $(echo $line | awk '{print $5}') | $(echo $line | awk '{print $6}') |" >> $GITHUB_STEP_SUMMARY
84- fi
85- done
70+ TEST_COUNT=$(grep -o '[0-9]\+ passed' coverage_output.txt | head -1 | grep -o '[0-9]\+' || echo "0")
71+
72+ # Check if coverage file exists and extract coverage
73+ if [ -f coverage/coverage-summary.json ]; then
74+ OVERALL_COVERAGE=$(node -e "
75+ const fs = require('fs');
76+ const coverage = JSON.parse(fs.readFileSync('coverage/coverage-summary.json', 'utf8'));
77+ console.log(coverage.total.statements.pct + '%');
78+ ")
79+
80+ echo "| File | Statements | Branches | Functions | Lines |" >> $GITHUB_STEP_SUMMARY
81+ echo "|------|------------|----------|-----------|-------|" >> $GITHUB_STEP_SUMMARY
82+
83+ # Add overall coverage
84+ node -e "
85+ const fs = require('fs');
86+ const coverage = JSON.parse(fs.readFileSync('coverage/coverage-summary.json', 'utf8'));
87+ const total = coverage.total;
88+ console.log(\`| **Overall** | \${total.statements.pct}% | \${total.branches.pct}% | \${total.functions.pct}% | \${total.lines.pct}% |\`);
89+ " >> $GITHUB_STEP_SUMMARY
90+
91+ # Add individual file coverage
92+ node -e "
93+ const fs = require('fs');
94+ const coverage = JSON.parse(fs.readFileSync('coverage/coverage-summary.json', 'utf8'));
95+ Object.keys(coverage).forEach(file => {
96+ if (file !== 'total' && file.includes('src/') && !file.includes('__tests__')) {
97+ const filename = file.split('/').pop();
98+ const fileCov = coverage[file];
99+ console.log(\`| \${filename} | \${fileCov.statements.pct}% | \${fileCov.branches.pct}% | \${fileCov.functions.pct}% | \${fileCov.lines.pct}% |\`);
100+ }
101+ });
102+ " >> $GITHUB_STEP_SUMMARY
103+ else
104+ OVERALL_COVERAGE="N/A"
105+ echo "Coverage data not available" >> $GITHUB_STEP_SUMMARY
106+ fi
86107
87108 echo "" >> $GITHUB_STEP_SUMMARY
88109 echo "✅ **${TEST_COUNT} tests passed** with **${OVERALL_COVERAGE} overall coverage**" >> $GITHUB_STEP_SUMMARY
@@ -198,4 +219,4 @@ jobs:
198219 run : pnpm run build
199220
200221 - name : Publish dry run
201- run : pnpm publish --dry-run
222+ run : pnpm publish --dry-run --no-git-checks
0 commit comments