Skip to content

Commit

Permalink
ci: generate coverage badge
Browse files Browse the repository at this point in the history
  • Loading branch information
engineervix committed Jun 4, 2023
1 parent 8b21a11 commit a54be8f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,51 @@ jobs:
# Run tests
invoke test
- name: "Upload coverage data"
uses: actions/upload-artifact@v3
with:
name: covdata
path: .coverage.*

coverage:
name: Coverage
needs: test
runs-on: ubuntu-22.04
steps:
- name: Checkout Code Repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip" # caching pip dependencies

- name: "Download coverage data"
uses: actions/download-artifact@v3
with:
name: covdata

- name: "Extract total coverage"
run: |
export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
echo "total=$TOTAL" >> $GITHUB_ENV
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY
- name: "Create coverage badge"
if: (github.repository == 'engineervix/zed-news') && (github.ref == 'refs/heads/main')
uses: schneegans/dynamic-badges-action@v1.6.0
with:
# GIST_TOKEN is a GitHub personal access token with scope "gist".
auth: ${{ secrets.GIST_TOKEN }}
gistID: f4b1128b188c4e29722bc879e4ab6574
filename: covbadge.json
label: Coverage
message: ${{ env.total }}%
minColorRange: 50
maxColorRange: 90
valColorRange: ${{ env.total }}

# Runs the next steps on the VM
# Creates a GitHub Release when the lint & test jobs succeeds, and only on pushes to tags.
release:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ htmlcov/
.coverage.*
nosetests.xml
coverage.xml
coverage.json
*.cover
*.py,cover
.hypothesis/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com)

[![CI/CD](https://github.com/engineervix/zed-news/actions/workflows/main.yml/badge.svg)](https://github.com/engineervix/zed-news/actions/workflows/main.yml)
[![Coverage](https://img.shields.io/endpoint?url=https://gist.github.com/engineervix/f4b1128b188c4e29722bc879e4ab6574/raw/covbadge.json)](https://github.com/engineervix/zed-news/actions?query=workflow%3A%22CI%2FCD%22)
[![healthchecks.io](https://healthchecks.io/badge/24d88c7e-cc91-4dac-b9a5-d50e52/ewRXZ-TO/zed-news.svg)](https://healthchecks.io)

[![python3](https://img.shields.io/badge/python-3.10-brightgreen.svg)](https://www.python.org/downloads/)
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies = [
dev = [
"black",
"commitizen",
"coverage[toml]",
"DSLR",
"flake8",
"isort",
Expand Down Expand Up @@ -80,6 +81,14 @@ known_first_party = "app"
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
default_section = "THIRDPARTY"

[tool.coverage.run]
include = ["app/core/*"]
branch = true # Measure branch coverage

[tool.coverage.report]
skip_covered = true
show_missing = true

[tool.commitizen]
version_provider = "pep621"
version_files = [
Expand Down
4 changes: 3 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ commitizen==3.2.2
commonmark==0.9.1
# via rich
coverage[toml]==5.5
# via eyed3
# via
# eyed3
# zed-news (pyproject.toml)
curtsies==0.4.1
# via bpython
cwcwidth==0.1.8
Expand Down
4 changes: 3 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,6 @@ def toolchain(c):
@task
def test(c):
"""Run tests"""
c.run("python -m unittest discover app/tests", pty=True)
c.run("coverage run -m unittest discover app/tests", pty=True)
c.run("coverage json", pty=True)
c.run("coverage report -m", pty=True)

0 comments on commit a54be8f

Please sign in to comment.