0

Context

I would like to eliminate the manual exporting of build status badges that my CI does to GitHub. To do this, I intend to create/use a build status badge in the README.md of repo repo_a, that reflects the build status of the head commit head_commit_c of branch branch_b status of the head of a branch. This build status of head_commit_c is already set by my self-hosted CI, so I hope I won't also have to output the build status badge (anymore).

Question

(How) can one set a build status badge in a README.md of a GitHub repository repo_a with branch branch_b based on the latest(HEAD) commit commit_c of that branch?

Related example

In this repository I saw that some markdown badges contain a .js. I assumed this is somehow able to retrieve some property of a GitHub repository, for example the amount of stars:

[![GitHub branches](https://badgen.net/github/branches/Naereen/Strapdown.js)](https://github.com/Naereen/Strapdown.js/)

So I thought there might be a related .js file that parses the latest GitHub commit status and converts it into an .svg/badge.

Attempt I

Based on the documentation linked in the comments, I tried:

![example branch parameter](https://github.com/github/docs/actions/workflows/main.yml/badge.svg?branch=main)

Which returns: enter image description here

I think this is because it refers to a workflow file which does not exist in this case, as I run my own CI.

So if this workflow file named main.yml can directly link the build status result of a branch, to the latest commit status in that branch, I imagine one could add such a workflow file. I did not yet determine whether this indeed is the case, and if yes, how.

Note

So I do not mean a link that parses the url of a specific commit, but an automatically updated link to the latest commit build status.

a.t.
  • 2,002
  • 3
  • 26
  • 66
  • 1
    Your *related example* returns `image/svg+xml` and does not execute any JavaScript. `Strapdown.js` is just a string parameter of this API and their backend calculates an SVG. GitHub offers branch-specific workflow status badges according to the [docs](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/adding-a-workflow-status-badge#using-the-branch-parameter). – Matt Mar 03 '22 at 08:47
  • Thank you for your feedback, I incorrectly assumed the *related example* executed JavaScript, and I was unaware I made that assumption. I adjusted the question to reflect your insight. Thank you for referring to the relevant docs segment! I've tried to implement the example given, however, I did not yet resolve how to deal with the `workflow file` as I run my own CI, instead of using GitHub actions. I would expect the `.yml` only refers to build status results of GitHub actions, instead of to the commit build status directly. However, I have not found if that's true or not. – a.t. Mar 03 '22 at 10:03
  • If you are using your own CI, you need to find a way to get the badge from this CI system and then use the appropriate URL in the readme. – Matt Mar 03 '22 at 10:16
  • @Matt, that would be optimal, however, for the time being, I thought this sub-optimal strategy of getting the build status badge directly from the commit sha would be acceptable. – a.t. Mar 03 '22 at 10:59

0 Answers0