Skip to content

Apra-Labs/code-test-coverage-report

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Coverage Report Action

A GitHub Action that parses Cobertura (pytest-cov) coverage reports and posts them as a comment on Pull Requests. Originally designed for JaCoCo, this version has been customized for Python projects.

Features

  • 📊 Overall Project Coverage: Summarizes total coverage.
  • 📁 File-Level Detail: Lists coverage for changed files in a collapsible table.
  • 📉 Status Indicators: Uses emojis (✅/❌) based on configurable thresholds.
  • 🔗 Visual Feedback: Supports linking to full HTML reports (e.g., hosted on GitHub Pages).

Usage

1. Simple Integration

Add this snippet to your .github/workflows/main.yml:

- name: Add coverage to PR
  uses: ./.github/actions/code-coverage-report/
  with:
    paths: coverage.xml
    token: ${{ secrets.GITHUB_TOKEN }}
    title: "Python Coverage"

2. Full Setup with Visual HTML Report

To get a clickable, detailed HTML report, use the following configuration:

- name: Run tests with coverage
  run: |
    pytest --cov=your_package --cov-report=xml --cov-report=html

- name: Deploy Coverage to GitHub Pages
  uses: peaceiris/actions-gh-pages@v3
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    publish_dir: ./htmlcov
    destination_dir: coverage-report

- name: Add coverage to PR
  uses: ./.github/actions/code-coverage-report/
  with:
    paths: coverage.xml
    token: ${{ secrets.GITHUB_TOKEN }}
    min-coverage-overall: 60
    min-coverage-changed-files: 80
    title: "Python Coverage [View Visual Report](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/coverage-report/)"

Inputs

Input Description Required Default
paths Comma-separated paths to Cobertura XML files (supports glob). -
token GitHub personal access token (e.g., ${{ secrets.GITHUB_TOKEN }}). -
title The header title for the PR comment. -
min-coverage-overall Minimum overall coverage percentage required to pass. 80
min-coverage-changed-files Minimum coverage percentage for changed files. 80

Local Testing

You can test the report generation locally without calling GitHub APIs:

# Install dependencies
npm install

# Build the action
npm run build

# Run local test script
node dist/local-test.js <path-to-coverage.xml> [min-overall] [min-files] [title]

Example:

node dist/local-test.js coverage.xml 40 60 "Local Test Report"

Requirements

  • Python: Generated report must be in Cobertura XML format (pytest --cov-report=xml).
  • Node.js: The action runs on node20.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published