Upgrade vitest to 4 #70
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| node-version: [18.x, 20.x, 22.x, 24.x] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive # Required for JSON Schema Test Suite submodule | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: "npm" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build | |
| run: npm run build | |
| - name: Test (including JSON Schema Test Suite) | |
| run: npm test | |
| - name: Generate coverage badge | |
| if: matrix.node-version == '20.x' && (github.ref == 'refs/heads/main') | |
| run: | | |
| # Extract coverage percentage from test output | |
| COVERAGE=$(npm test 2>&1 | grep 'All files' | grep -o '[0-9]*' | head -1) | |
| echo "Coverage: $COVERAGE%" | |
| # Create badges directory | |
| mkdir -p badges | |
| # Determine badge color based on coverage | |
| if [ "$COVERAGE" -ge 90 ]; then | |
| COLOR="brightgreen" | |
| elif [ "$COVERAGE" -ge 80 ]; then | |
| COLOR="green" | |
| elif [ "$COVERAGE" -ge 70 ]; then | |
| COLOR="yellow" | |
| elif [ "$COVERAGE" -ge 60 ]; then | |
| COLOR="orange" | |
| else | |
| COLOR="red" | |
| fi | |
| # Generate badge JSON for shields.io | |
| cat > badges/coverage.json << EOF | |
| { | |
| "schemaVersion": 1, | |
| "label": "coverage", | |
| "message": "${COVERAGE}%", | |
| "color": "$COLOR" | |
| } | |
| EOF | |
| - name: Deploy badges to gh-pages | |
| if: matrix.node-version == '20.x' && (github.ref == 'refs/heads/main') | |
| uses: peaceiris/actions-gh-pages@v3 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./badges | |
| destination_dir: badges | |
| keep_files: true | |
| - name: Verify dual module compatibility | |
| run: | | |
| node -e "require('./dist/index.js')" # Test CJS | |
| node --input-type=module -e "import * as mod from './dist/index.mjs'; console.log(typeof mod.convertJsonSchemaToZod === 'function')" # Test ESM |