GitHub actions code coverage — Without third parties

GitHub actions code coverage — Without third parties

Asit turns out. The way to integrate code coverage into your build pipeline with GitHub actions is to use a third-party solution, like codcov.io and others. Those solutions are fantastic but can cost up to 20$ / month per user. And they come with many advanced features that not everybody needs. For a basic code coverage check on pull requests and a code coverage badge in the README.md I don’t want to pay a monthly subscription.

As it turns out. The way to integrate code coverage into your build pipeline with GitHub actions is to use a third-party solution, like codcov.io and others. Those solutions are fantastic but can cost up to 20$ / month per user. And they come with many advanced features that not everybody needs. For a basic code coverage check on pull requests and a code coverage badge in the README.md I don’t want to pay a monthly subscription.

After digging the Internet for a free solution I found nothing useful. And decided to hack my way around.

In this post, ill show how to use GitHub actions and some cloud storage ( like s3 ) to create a code coverage badge for your repository, and a GitHub status which can be used to protect the master branch, so if a pull request dropped the code coverage it will be blocked for merging.

A GitHub badge is simply a small SVG embedded in the repo README.md. The simplest way to create one is to use shields.io API.

curl https://img.shields.io/badge/coavrege-$total%-$COLOR > badge.svg

Where $COLOR is a bash variable containing a CSS color like red, green, orange. And $total is another bash variable with the percentile between 0 and 100. shields.io are awesome for providing this free utility.

This simple one-liner can create a badge, what’s left is to upload it to a public storage with cache disabled and embed it in a README.md

BADGE GENERATION

example with GCP cloud storage

A GitHub actions workflow can run the above on a push/merge to master branch and upload the badge, notice the “Cache-Control” header, this is important because at least in GCP but probably also on AWS if you upload an object to a public storage its cached by default and then the README.md of your project will always contain an outdated version.

github-actions code-coverage golang ci testing

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Working with GitHub Actions

GitHub launched GitHub Actions in beta which enabled developers to create automated workflows to build, test, and deploy their source code on GitHub. In this article, we will discuss about GitHub Actions and how it can be used to build an automated software development life-cycle workflow.

GitHub Demo Days - Using GitHub Actions for testing cloud native applications

A common challenge that cloud native application developers face is manually testing against inconsistent environments. GitHub Actions can be triggered based on nearly any GitHub event making it possible to build in accountability for updating tests and fixing bugs.

Format Your Terraform Code with Github Actions

So, today I discovered how to automate running a terraform fmt and committing it using Github actions! If you are not aware, GitHub actions are ...

GitHub Arctic Code Vault: Overview

Are you an Arctic Code Vault Contributor or have seen someone posting about it and don't know what it is. So let's take a look at what is an Arctic Code Vault Contributor and who are the ones who gets this batch.

Code Coverage and 100% Coverage

Code Coverage or Test Coverage is a way to measure what lines of code and branches in your code that are utilized during testing. Coverage tools are an important part of software engineering. But there's also lots of different opinions about using it. Should you try for 100% coverage? What code can and should you exclude? What about targets?