Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/scripts/check-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Check if coverage-summary.json exists
if [ ! -f "coverage/coverage-summary.json" ]; then
echo "❌ Coverage summary file not found!"
exit 1
fi

# Read coverage data
coverage=$(cat coverage/coverage-summary.json)

# Extract coverage percentages
statements=$(echo "$coverage" | grep -o '"statements":{[^}]*}' | grep -o '"pct":[0-9.]*' | cut -d: -f2)
branches=$(echo "$coverage" | grep -o '"branches":{[^}]*}' | grep -o '"pct":[0-9.]*' | cut -d: -f2)
functions=$(echo "$coverage" | grep -o '"functions":{[^}]*}' | grep -o '"pct":[0-9.]*' | cut -d: -f2)
lines=$(echo "$coverage" | grep -o '"lines":{[^}]*}' | grep -o '"pct":[0-9.]*' | cut -d: -f2)

# Display coverage summary
echo "Coverage Summary:"
echo " Statements: ${statements}%"
echo " Branches: ${branches}%"
echo " Functions: ${functions}%"
echo " Lines: ${lines}%"

# Define threshold
THRESHOLD=95

# Check thresholds
failed=()

if (( $(echo "$statements < $THRESHOLD" | bc -l) )); then
failed+=("Statements: ${statements}% (min: ${THRESHOLD}%)")
fi

if (( $(echo "$branches < $THRESHOLD" | bc -l) )); then
failed+=("Branches: ${branches}% (min: ${THRESHOLD}%)")
fi

if (( $(echo "$functions < $THRESHOLD" | bc -l) )); then
failed+=("Functions: ${functions}% (min: ${THRESHOLD}%)")
fi

if (( $(echo "$lines < $THRESHOLD" | bc -l) )); then
failed+=("Lines: ${lines}% (min: ${THRESHOLD}%)")
fi

# Report results
if [ ${#failed[@]} -gt 0 ]; then
echo ""
echo "❌ Coverage below threshold:"
for item in "${failed[@]}"; do
echo " $item"
done
exit 1
fi

echo ""
echo "✅ All coverage thresholds met"
exit 0
6 changes: 6 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ jobs:
- name: Build the project
run: npm run build

- name: Run tests with coverage
run: npm run test:coverage

- name: Check coverage thresholds
run: bash .github/scripts/check-coverage.sh

- name: Upload build artifacts
if: github.event.pull_request.merged == true
uses: actions/upload-artifact@v4
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
node_modules/
dist/
package-lock.json
coverage/
package-lock.json
*.log
.DS_Store
*.tgz
15 changes: 15 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/test'],
testMatch: ['**/*.test.ts'],
collectCoverageFrom: [
'src/**/*.ts',
'!src/**/*.d.ts',
'!src/**/*.test.ts'
],
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'html', 'json-summary'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
verbose: true
};
Loading