Skip to content

Commit

Permalink
Add coverage and badge
Browse files Browse the repository at this point in the history
  • Loading branch information
bshastry committed Oct 6, 2023
1 parent db974e9 commit 3bfb5c9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/bandit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install bandit
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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 report

- name: Upload coverage report
uses: actions/upload-artifact@v2
with:
name: coverage-report
path: coverage_html_report/

- 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);
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
python-version: 3.8

- name: Install dependencies
run: pip install -r requirements.txt
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests
run: python test_runner.py
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DocuBot

[![Run Tests](https://github.com/bshastry/docubot/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/bshastry/docubot/actions/workflows/tests.yml)![Bandit Workflow](https://img.shields.io/badge/Bandit-No%20Issues%20Found-brightgreen)
[![Run Tests](https://github.com/bshastry/docubot/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/bshastry/docubot/actions/workflows/tests.yml)![Bandit Workflow](https://img.shields.io/badge/Bandit-No%20Issues%20Found-brightgreen)![Coverage](https://img.shields.io/badge/Coverage-90%25-brightgreen.svg)

DocuBot is a command-line chatbot that answers questions using a knowledge base of documents provided by you.
It allows you to interactively get answers to questions with citations from the documents provided.
Expand Down

0 comments on commit 3bfb5c9

Please sign in to comment.