feat: enhance shellEscape function to handle platform-specific string… #7
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: [master] | |
| pull_request: | |
| branches: [master] | |
| permissions: | |
| contents: write | |
| jobs: | |
| test: | |
| name: Test & Coverage | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests with coverage | |
| run: npx vitest run --coverage | |
| - name: Generate Coverage Badge | |
| run: | | |
| if [ ! -f coverage/coverage-summary.json ]; then | |
| echo "Error: coverage/coverage-summary.json not found" | |
| echo "Coverage report was not generated by vitest" | |
| exit 1 | |
| fi | |
| COVERAGE=$(node -e " | |
| const summary = require('./coverage/coverage-summary.json'); | |
| let pct = summary.total.lines.pct; | |
| if (pct <= 1) pct = pct * 100; | |
| console.log(pct.toFixed(2)); | |
| ") | |
| echo "Coverage: ${COVERAGE}%" | |
| COLOR="red" | |
| if (( $(echo "$COVERAGE >= 90" | bc -l) )); then COLOR="brightgreen" | |
| elif (( $(echo "$COVERAGE >= 80" | bc -l) )); then COLOR="green" | |
| elif (( $(echo "$COVERAGE >= 70" | bc -l) )); then COLOR="yellowgreen" | |
| elif (( $(echo "$COVERAGE >= 60" | bc -l) )); then COLOR="yellow" | |
| elif (( $(echo "$COVERAGE >= 50" | bc -l) )); then COLOR="orange" | |
| fi | |
| mkdir -p .badges | |
| cat > .badges/coverage.json << EOF | |
| { | |
| "schemaVersion": 1, | |
| "label": "Coverage", | |
| "message": "${COVERAGE}%", | |
| "color": "${COLOR}" | |
| } | |
| EOF | |
| - name: Verify badge files exist | |
| run: | | |
| echo "Checking badge files..." | |
| ls -la .badges/ | |
| test -f .badges/coverage.json | |
| echo "All badge files present" | |
| - name: Upload badges | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: badges | |
| path: .badges | |
| if-no-files-found: error | |
| include-hidden-files: true | |
| - name: Upload coverage report | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: coverage/ | |
| update-badges: | |
| name: Update Coverage Badges | |
| needs: [test] | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/master' && github.event_name == 'push' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Switch to badges branch | |
| run: | | |
| git checkout badges 2>/dev/null || git checkout --orphan badges | |
| git rm -rf . 2>/dev/null || true | |
| mkdir -p .badges | |
| - name: Download badges | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: badges | |
| path: .badges/ | |
| continue-on-error: false | |
| - name: Verify downloaded badges | |
| run: | | |
| echo "Listing downloaded badges..." | |
| ls -la .badges/ | |
| echo "Badge files downloaded successfully" | |
| - name: Push badges | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add .badges/ | |
| git diff --cached --quiet && echo "No badge changes" || { | |
| git commit -m "Update coverage badges [skip ci]" | |
| git push origin badges | |
| } |