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
6 changes: 6 additions & 0 deletions .github/badges/tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"schemaVersion": 1,
"label": "tests",
"message": "20/20 passing",
"color": "brightgreen"
}
101 changes: 101 additions & 0 deletions .github/workflows/test-badge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Test Badge

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

permissions:
contents: write

jobs:
test-and-badge:
name: Run Tests & Update Badge
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v5

- name: Setup Node 20
uses: actions/setup-node@v6
with:
node-version: 20
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run tests with JSON reporter
id: test
run: |
# Run tests and capture output
npm run test -- --reporter=json --reporter=default --outputFile=test-results.json || true

# Check if test results file exists
if [ ! -f test-results.json ]; then
echo "Test results file not found, creating fallback"
echo '{"numTotalTests": 0, "numPassedTests": 0}' > test-results.json
fi

# Parse test results
TOTAL=$(node -p "try { const r = require('./test-results.json'); r.numTotalTests || 0 } catch(e) { 0 }")
PASSED=$(node -p "try { const r = require('./test-results.json'); r.numPassedTests || 0 } catch(e) { 0 }")

echo "total=$TOTAL" >> $GITHUB_OUTPUT
echo "passed=$PASSED" >> $GITHUB_OUTPUT

# Determine color based on pass rate
if [ "$TOTAL" -eq 0 ]; then
COLOR="lightgrey"
elif [ "$PASSED" -eq "$TOTAL" ]; then
COLOR="brightgreen"
elif [ "$PASSED" -ge $((TOTAL * 80 / 100)) ]; then
COLOR="green"
elif [ "$PASSED" -ge $((TOTAL * 60 / 100)) ]; then
COLOR="yellow"
else
COLOR="red"
fi

echo "color=$COLOR" >> $GITHUB_OUTPUT

echo "### 🧪 Test Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Passed:** $PASSED / $TOTAL" >> $GITHUB_STEP_SUMMARY
echo "**Status:** $COLOR" >> $GITHUB_STEP_SUMMARY

- name: Generate badge data
run: |
mkdir -p .github/badges
cat > .github/badges/tests.json << EOF
{
"schemaVersion": 1,
"label": "tests",
"message": "${{ steps.test.outputs.passed }}/${{ steps.test.outputs.total }} passing",
"color": "${{ steps.test.outputs.color }}"
}
EOF

- name: Commit badge data
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .github/badges/tests.json
git diff --staged --quiet || git commit -m "Update test badge [skip ci]"
git push

- name: Upload test results
if: always()
uses: actions/upload-artifact@v5
with:
name: test-results
path: |
test-results.json
.github/badges/tests.json
retention-days: 30
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[![Version](https://img.shields.io/npm/v/react-lite-youtube-embed?label=latest%20version)](https://www.npmjs.com/package/react-lite-youtube-embed) ![Total Downloads](https://img.shields.io/npm/dt/react-lite-youtube-embed?color=%23FF0000&logo=npm) ![GitHub issues by-label](https://img.shields.io/github/issues/ibrahimcesar/react-lite-youtube-embed/bug)

[![Stale Issues & PRs](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/stale.yml/badge.svg)](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/stale.yml) [![CodeQL Security Scan](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/codeql.yml/badge.svg)](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/codeql.yml) [![Automated Release](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/auto-release.yml/badge.svg)](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/auto-release.yml) [![Deploy Demo to GitHub Pages](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/deploy-demo.yml/badge.svg)](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/deploy-demo.yml)
[![Tests](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/ibrahimcesar/react-lite-youtube-embed/main/.github/badges/tests.json)](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/test-badge.yml) [![Stale Issues & PRs](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/stale.yml/badge.svg)](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/stale.yml) [![CodeQL Security Scan](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/codeql.yml/badge.svg)](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/codeql.yml) [![Automated Release](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/auto-release.yml/badge.svg)](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/auto-release.yml) [![Deploy Demo to GitHub Pages](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/deploy-demo.yml/badge.svg)](https://github.com/ibrahimcesar/react-lite-youtube-embed/actions/workflows/deploy-demo.yml)


<p>Developed in 🇧🇷 <span role="img" aria-label="Flag for Brazil">Brazil</p>
Expand Down
Loading