-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Run Coverage | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install coverage | ||
- name: Run tests with coverage | ||
run: | | ||
coverage run -m unittest discover -s tests -p "test_*.py" | ||
- name: Generate coverage report | ||
run: | | ||
coverage html --directory coverage_html_report | ||
coverage report -m > coverage_report.txt | ||
- name: Upload coverage report | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: coverage-report | ||
path: | | ||
coverage_html_report/ | ||
coverage_report.txt | ||
- name: Set up coverage badge | ||
uses: actions/github-script@v4 | ||
with: | ||
script: | | ||
const fs = require('fs'); | ||
const coverageReport = fs.readFileSync('coverage_report.txt', 'utf8'); | ||
const coveragePercentage = coverageReport.match(/TOTAL\s+\d+\s+\d+\s+(\d+)%/)[1]; | ||
let badgeColor = 'brightgreen'; | ||
if (coveragePercentage < 80) { | ||
badgeColor = 'red'; | ||
} else if (coveragePercentage < 90) { | ||
badgeColor = 'yellow'; | ||
} | ||
const badgeMarkdown = `![Coverage](https://img.shields.io/badge/Coverage-${coveragePercentage}%25-${badgeColor})`; | ||
const readme = fs.readFileSync('README.md', 'utf8'); | ||
const updatedReadme = readme.replace(/!\[Coverage\]\(.*\)/, badgeMarkdown); | ||
fs.writeFileSync('README.md', updatedReadme); |
This file contains 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
This file contains 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