DEV Community

Anuj Kapoor
Anuj Kapoor

Posted on

Open Code-Coverage Bot

My Workflow


When you try to search for some code-coverage solution that can utilize Github actions, you will definitely stumble upon two major players Coedcov and Coveralls. But both of them are proprietary and comes with an extra cost attached to it. When you are working on a personal project or an early-stage startup you don't want to spend extra bucks for the same.


So I designed this action which makes use of action artifacts to generate coverage reports and comment them on pull-requests. It also has a feature to upload reports to a file server. I used the same for managing a very data-intensive Django project. With my test-suite workflow, I used to generate reports. I store these reports in a text file in actions-artifacts and also upload them. There is a little preprocessing done on the report to make it comment friendly.

The whole process is divided into two parts:

  • Running tests and generating the report.
  • Modifying the report to send it as an action-bot comment, and uploading it.

Expected Outcome:


the first part was fairly simple, I used to run standard Django can find the syntax in the Yaml file below. For the second part, I created a new action repository open-coverage-action, It takes a text file as input and comments it on a pull-request. I am also working on adding preprocessing of the report to it. Currently, it uses basic bash to extract the part which contains the final result and add some polish, after that stores it in a new file for open-coverage-action. I also use to upload a full report for further reference and also upload-artifact action to upload it as a an artifact.
it pretty much does the job required for my workflow.

Submission Category:

Maintainer Must-Haves

Yaml File or Link to Code

name: pr-coverage

on: pull_request

    runs-on: ubuntu-latest
      max-parallel: 4
        python-version: [3.6]

      - uses: actions/checkout@v2
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
          python-version: ${{ matrix.python-version }}
      - name: Cache pip
        uses: actions/cache@v2
          # This path is specific to Ubuntu
          path: ~/.cache/pip
          # Look to see if there is a cache hit for the corresponding requirements file
          key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
          restore-keys: |
            ${{ runner.os }}-pip-
            ${{ runner.os }}-
      - name: Install Python Dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
      - name: Generating and Uploading Coverage Report
        run: |
          touch local.env
          echo DEBUG_VALUE=1 > local.env
          cd data_api/
          python makemigrations
          python migrate
          coverage run test --noinput --parallel 16
          coverage report > results.txt
          # Modifying coverage report
          echo "Coverage Report: " > report.txt
          echo " Statements | Miss | Cover " >> report.txt
          tail -4 results.txt >> report.txt
          echo "   " >> report.txt
          echo "Link to full report :" >> report.txt
          # uploading report to any other services can be used
          curl -F "file=@results.txt" |     python3 -c "import sys, json; print(json.load(sys.stdin)['link'])" >> report.txt
          SECRET_KEY: ${{ secrets.SECRET_KEY }}
          ADMIN_URL_KEY: ${{ secrets.ADMIN_URL_KEY }}
          DATABASE_NAME: github_actions
          DATABASE_USER: postgres
          DATABASE_PASSWORD: postgres
          DATABASE_PORT: 5432
      - uses: actions/upload-artifact@v2
          name: report
          path: data_api/report.txt
      - uses: actions/download-artifact@v2
          name: report
      - name: Open Coverage Notifier Action
        uses: Bearbobs/open-coverage-action@v1
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          path: data_api/report.txt

Full file can be found in a gist @ workflow

Additional Resources / Info

This is just my first take on this idea. I am planning to reiterate on the preprocessing of the reports, to make it more polished. Currently, this workflow can be directly used by any Django project maintainers. Special thanks to for free text uploading service and Github actions. please refer to the open-coverage-action repository for further reference.
Please reach out for suggestions and feedbacks. Thank You.

Links to the services used:


Top comments (0)