Coverage Badge Setup

This document explains how to add a coverage badge to your GitHub repository using the coverage data generated by Cloud Build.

How it Works

  1. Cloud Build runs tests with coverage and generates a coverage.json file
  2. A coverage percentage is extracted and a badge JSON is created
  3. The badge JSON is uploaded to Google Cloud Storage as a publicly readable file
  4. Shields.io reads the badge data from GCS and generates a badge image

Add Badge to README

Add this badge to your GitHub README.md file:

For dev branch:

![Coverage](https://img.shields.io/endpoint?url=https://storage.googleapis.com/aitana-public-bucket/coverage-badges/backend-api-dev-coverage.json)

For main branch:

![Coverage](https://img.shields.io/endpoint?url=https://storage.googleapis.com/aitana-public-bucket/coverage-badges/backend-api-main-coverage.json)

For prod branch:

![Coverage](https://img.shields.io/endpoint?url=https://storage.googleapis.com/aitana-public-bucket/coverage-badges/backend-api-prod-coverage.json)

Badge Colors

The badge color changes based on coverage percentage:

  • Bright Green: ≥90% coverage
  • Green: ≥80% coverage
  • Yellow: ≥70% coverage
  • Orange: ≥60% coverage
  • Red: <60% coverage

Example Badge URLs

After Cloud Build runs, the badge JSON files will be available at:

  • Dev: https://storage.googleapis.com/aitana-public-bucket/coverage-badges/backend-api-dev-coverage.json
  • Main: https://storage.googleapis.com/aitana-public-bucket/coverage-badges/backend-api-main-coverage.json
  • Prod: https://storage.googleapis.com/aitana-public-bucket/coverage-badges/backend-api-prod-coverage.json

Troubleshooting

Badge Not Updating

  • Check that Cloud Build completed successfully
  • Verify the JSON file exists in GCS
  • Ensure the file is publicly readable
  • Try refreshing the badge by appending ?v=TIMESTAMP to the URL

Badge Shows Error

  • Check the JSON format in the uploaded file
  • Verify the GCS URL is accessible
  • Check Cloud Build logs for errors in the coverage generation step

Manual Badge Update

You can manually check the badge JSON content:

curl https://storage.googleapis.com/aitana-public-bucket/coverage-badges/backend-api-dev-coverage.json

Alternative Badge Services

If shields.io doesn’t work well, you can also use:

  • Badgen: https://badgen.net/https/storage.googleapis.com/aitana-public-bucket/coverage-badges/backend-api-dev-coverage.json
  • Badge Generator API