Skip to content

Commit 4fa902a

Browse files
committed
Squash merge coverage-badge into main
1 parent 6ba1aa8 commit 4fa902a

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,48 @@ jobs:
3232
- name: Test
3333
run: npm test
3434

35+
- name: Generate coverage badge
36+
if: matrix.node-version == '20.x' && (github.ref == 'refs/heads/main')
37+
run: |
38+
# Extract coverage percentage from test output
39+
COVERAGE=$(npm test 2>&1 | grep 'All files' | grep -o '[0-9]*' | head -1)
40+
echo "Coverage: $COVERAGE%"
41+
42+
# Create badges directory
43+
mkdir -p badges
44+
45+
# Determine badge color based on coverage
46+
if [ "$COVERAGE" -ge 90 ]; then
47+
COLOR="brightgreen"
48+
elif [ "$COVERAGE" -ge 80 ]; then
49+
COLOR="green"
50+
elif [ "$COVERAGE" -ge 70 ]; then
51+
COLOR="yellow"
52+
elif [ "$COVERAGE" -ge 60 ]; then
53+
COLOR="orange"
54+
else
55+
COLOR="red"
56+
fi
57+
58+
# Generate badge JSON for shields.io
59+
cat > badges/coverage.json << EOF
60+
{
61+
"schemaVersion": 1,
62+
"label": "coverage",
63+
"message": "${COVERAGE}%",
64+
"color": "$COLOR"
65+
}
66+
EOF
67+
68+
- name: Deploy badges to gh-pages
69+
if: matrix.node-version == '20.x' && (github.ref == 'refs/heads/main')
70+
uses: peaceiris/actions-gh-pages@v3
71+
with:
72+
github_token: ${{ secrets.GITHUB_TOKEN }}
73+
publish_dir: ./badges
74+
destination_dir: badges
75+
keep_files: true
76+
3577
- name: Verify dual module compatibility
3678
run: |
3779
node -e "require('./dist/index.js')" # Test CJS

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# zod-from-json-schema
22

33
[![CI](https://github.com/glideapps/zod-from-json-schema/actions/workflows/ci.yml/badge.svg)](https://github.com/glideapps/zod-from-json-schema/actions/workflows/ci.yml)
4+
[![Coverage](https://img.shields.io/endpoint?url=https://glideapps.github.io/zod-from-json-schema/badges/coverage.json)](https://github.com/glideapps/zod-from-json-schema/actions/workflows/ci.yml)
45
[![npm version](https://img.shields.io/npm/v/zod-from-json-schema.svg)](https://www.npmjs.com/package/zod-from-json-schema)
56

67
A library that creates [Zod](https://github.com/colinhacks/zod) types from [JSON Schema](https://json-schema.org/) at runtime. This is in contrast to [json-schema-to-zod](https://www.npmjs.com/package/json-schema-to-zod), which generates JavaScript source code.

0 commit comments

Comments
 (0)