@@ -15,23 +15,23 @@ jobs:
1515 - uses : actions/checkout@v4
1616 with :
1717 token : ${{ secrets.GITHUB_TOKEN }}
18-
18+
1919 - name : Set up Python 3.11
2020 uses : actions/setup-python@v4
2121 with :
2222 python-version : " 3.11"
23-
23+
2424 - name : Install dependencies
2525 run : |
2626 python -m pip install --upgrade pip
2727 pip install pytest pytest-cov
2828 if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
2929 if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
30-
30+
3131 - name : Test with pytest and generate coverage
3232 run : |
3333 pytest tests/ --cov=anomstack --cov-report=term-missing --cov-report=json
34-
34+
3535 - name : Extract coverage percentage
3636 id : coverage
3737 run : |
4444 ")
4545 echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT
4646 echo "Coverage: $COVERAGE%"
47-
47+
4848 - name : Determine badge color
4949 id : badge-color
5050 run : |
@@ -62,54 +62,54 @@ jobs:
6262 fi
6363 echo "color=$COLOR" >> $GITHUB_OUTPUT
6464 echo "Badge color: $COLOR"
65-
65+
6666 - name : Update coverage badge in README
6767 if : github.ref == 'refs/heads/main' && github.event_name == 'push'
6868 run : |
6969 COVERAGE=${{ steps.coverage.outputs.percentage }}
7070 COLOR=${{ steps.badge-color.outputs.color }}
71-
71+
7272 # Update main README.md
7373 sed -i "s/Coverage-[0-9]*%25-[a-z]*/Coverage-${COVERAGE}%25-${COLOR}/g" README.md
74-
74+
7575 # Update tests/README.md
7676 sed -i "s/\*\*Coverage:\*\* [0-9]*% overall/\*\*Coverage:\*\* ${COVERAGE}% overall/g" tests/README.md
7777 sed -i "s/achieves \*\*[0-9]*% overall coverage\*\*/achieves \*\*${COVERAGE}% overall coverage\*\*/g" tests/README.md
7878 sed -i "s/maintains \*\*[0-9]*% test coverage\*\*/maintains \*\*${COVERAGE}% test coverage\*\*/g" CONTRIBUTING.md
79-
79+
8080 echo "Updated coverage badge to ${COVERAGE}% with color ${COLOR}"
81-
81+
8282 - name : Commit and push changes
8383 if : github.ref == 'refs/heads/main' && github.event_name == 'push'
8484 run : |
8585 git config --local user.email "[email protected] " 8686 git config --local user.name "GitHub Action"
87-
87+
8888 if git diff --quiet; then
8989 echo "No changes to commit"
9090 else
9191 git add README.md tests/README.md CONTRIBUTING.md
9292 git commit -m "🔄 Auto-update coverage badge to ${{ steps.coverage.outputs.percentage }}% [skip ci]"
9393 git push
9494 fi
95-
95+
9696 - name : Comment PR with coverage
9797 if : github.event_name == 'pull_request'
9898 uses : actions/github-script@v6
9999 with :
100100 script : |
101101 const coverage = '${{ steps.coverage.outputs.percentage }}';
102102 const color = '${{ steps.badge-color.outputs.color }}';
103-
103+
104104 const comment = `## 📊 Test Coverage Report
105-
105+
106106 **Coverage:** ${coverage}% (${color})
107-
107+
108108 ${coverage >= 47 ? '✅ Coverage maintained or improved!' : '⚠️ Coverage decreased from baseline (47%)'}
109-
109+
110110 > 💡 See detailed coverage report in the [tests README](./tests/README.md#coverage-report)
111111 `;
112-
112+
113113 github.rest.issues.createComment({
114114 issue_number: context.issue.number,
115115 owner: context.repo.owner,
0 commit comments