Skip to content

Updates img.shields.io with the test coverage

Actions
Updates img.shields.io with the test coverage and updates the repository
v1.2
Latest
Star (0)

action-coverage-badger

Motivation

Img shields can display coverage badge when you pass the percentage in the url (https://img.shields.io/badge/coverage-24%25-red). This URL can be pasted in README.md in html tag <img> which would display a Github Badge. Since the url is static with the coverage percentage hardcoded we needed a mechanism to dynamically update the test coverage % whenever a code is added or removed.

This GHA will be triggered whenever a change is pushed to default branch. It reads the cover.json, updates the coverage % in the README.md, create a PR to default branch and automerges.

Configuration in GHA workflow for Go Coverage

Refer to the example on how to setup the github action https://github.com/maheshrayas/go-badger-test

Makefile

.PHONY: dependencies
## Install dependencies
dependencies:
	go get -u github.com/jstemmer/go-junit-report \
	&& go get github.com/axw/gocov/gocov \

build: dependencies
	go build ./...

test: build
	rm -rf cover.* cover
	mkdir -p cover
	go test ./... -v -coverprofile ./cover.out
	gocov convert cover.out > cover.json
name: updated pr
on:
  pull_request:
  push:
    branches:
      - master

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
        with:
          go-version: 1.16.7
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Run tests
        id: test
        env:
          GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
        run: |
          make test
      - name: release-notifier
        uses: maheshrayas/action-coverage-badge@v1
        with:
          token: '${{ secrets.GITHUB_TOKEN }}'
          user: <gh_user>
          email: <gh_email>

Supported Languages

  • Go

TODO

  • Support other languages

Updates img.shields.io with the test coverage is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Updates img.shields.io with the test coverage and updates the repository
v1.2
Latest

Updates img.shields.io with the test coverage is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.