How to show badge from artifacts in GitHub readme?

One of the artifacts that my build produces is a badge in SVG format.
I would like to show this badge in my GitHub readme.
I can access the file by using the following API call:

https://circleci.com/api/v1.1/project/github/gpetrounrt/buildlogreporter/latest/artifacts/0/Users/circleci/project/artifacts/Coverage/Report/badge_combined.svg?branch=main

However, this cannot be used as we do with other badges like:

[![CircleCI](https://img.shields.io/circleci/build/gh/gpetrounrt/BuildLogReporter/main)](https://circleci.com/gh/gpetrounrt/BuildLogReporter/tree/main)

Is there another URL that I could use to display the badge?

Hi there @gpetrounrt ,

Firstly, I think shields.io may be a service that does not work for private projects or private assets in general.

Artifacts in CircleCI are stored for up to 30 days only, so I am wondering if storing your SVG files as artifacts on CircleCI to be used on a GitHub README may be the best approach here.

If this restriction is still workable for you, you may notice that even after obtaining the artifact URL from CircleCI (e.g., https://12-123456789-gh.circle-artifacts.com/0/Users/circleci/project/artifacts/Coverage/Report/badge_combined.svg), this URL is essentially a HTTP 302 “redirect” to the actual file stored in S3. If this is a private project as well, you’d need to be logged in to CircleCI with sufficient permissions to get the actual URL from the Location header from the response too then.

As such, as an alternative, I wonder if you can make use of secret gists in GitHub to (1) host your SVG file, and (2) make use of the nature of how secret gists are accessible only if one knows the URL :slight_smile:

For example, you can use the update Gist API to update your SVG file in the gist. I believe that since the SVG file’s URL on your gist remains the same (just the contents updated over time), your GitHub README should be able to reference it and display it as an image via Markdown.

Hope this helps!

@kelvintaywl thanks for the reply.
This is what I ended up doing. When the main branch builds successfully, I update the badge images in my Gist and reference the badges from there in the readme. It works like a charm.

1 Like

@gpetrounrt glad to hear that’s the approach you took too!
I’d like to think it’s a pretty sweet setup, given that it’s simple to set up and maintain!

I’m happy to hear that your issue is resolved then :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.