36

Does GitHub have an official 'badge' for their new 'actions' feature?

I came across this request on their official repo and there seems to be an official one:

https://github.com/{github_id}/{repository}/workflows/{workflow_name}/badge.svg

as per this comment, but I am unable to get it to work. Is it actually working? When I use it, I get the below output:

Unrendered GitHub badge

Note that I have replaced {github_id} with my username, {repository} with my repo name and {workflow_name} with the corresponding workflow name (removing the curly braces). Does anyone else have this issue?
Edit: I am working on a private repo, in case it makes a difference.

J. Doe
  • 1,291
  • 2
  • 10
  • 19
  • I suspect that since your repo is private, you would need to provide some sort of authentication in the URL to make it work, which isn't great as that would expose your repo's access token to anyone who looked at the HTML. Maybe make a test repo (that's public) and see if that makes a difference. If the badge for the public repo works, then you know the problem is authentication. – rmunn Aug 30 '19 at 02:50
  • 2
    @rmunn, thank you for your reply. Turns out, the badge 'update' is a very slow process. I just created another branch and started doing rest of the stuff. After about 10-15 minutes, I noticed that the image had updated, but the pipeline status was 'unknown'. After some more time (I think around 10 minutes), the badge became green as required. Unlike azure-pipelines, etc. which are quick, this renders pretty slowly for some reason. – J. Doe Aug 30 '19 at 03:04
  • 1
    Great; glad that it's working. Since it's working, I'd suggest that you answer your own question, then after 48 hours have passed you can accept your own answer. That will let people know, if they later find your question in a search, that the question isn't still waiting for an answer. – rmunn Aug 30 '19 at 03:14
  • @rmunn, fair enough. Sorry that it took me so long, but I have noted my observations below. I agree it is a good idea. – J. Doe Sep 07 '19 at 19:32
  • You can simply copy the correct markdown from your own repository Actions tab > Select the workflow > Click on the Create status badge button. This worked for my private and internal repos. – It's actually me Jul 29 '20 at 19:10

5 Answers5

60

You can get the actions badge by navigating to the required workflow on your repo on GitHub.com, clicking on the settings button on the right (the one with 3 dots beside the workflow search) and clicking on the Create status badge button.

enter image description here

Here, you can select the badge for the required branch and event and use the generated markdown.

For eg, below is the badge that I generated for the default branch and event of the CI workflow of my fork:

Build and Deploy

The markdown for the above badge:

[![Build and Deploy](https://github.com/kratostaine/spring-authorization-server/actions/workflows/continuous-integration-workflow.yml/badge.svg)](https://github.com/kratostaine/spring-authorization-server/actions/workflows/continuous-integration-workflow.yml)
Madhu Bhat
  • 13,559
  • 2
  • 38
  • 54
  • 1
    No I can't. My workflow is triggered by workflow_dispatch and the badge always says "failed build" even though the build succeeds. – Niklas Rosencrantz Apr 17 '22 at 06:20
  • FWIW, as I write this, there no longer is a "Create status badge" button after selecting the workflow under Actions. OK, I've got to amend what I said. Clicking the button with the 3 dots immediately to the right of the "Filter workflow runs" textbox, produces a dropdown with "Create status badge" and "Disable workflow" as options. – Rod May 25 '23 at 15:54
  • Thank you for highlighting, @Rod. I have updated the answer accordingly. – Madhu Bhat May 25 '23 at 16:22
12

As it turns out, badge update/rendering is a slow process. After adding the badge to my README.md, I just started off with work in another branch. After about 10 minutes (at least in my case), the badge appeared but the pipeline status was shown as 'unknown'. It updated again after about 10 minutes and with the correct pipeline status ('passing' in my case).

So, once you are done, just continue with your other stuff and it will update on its own, in sometime. Hope this helps someone!

J. Doe
  • 1,291
  • 2
  • 10
  • 19
7

Worked for me:

[GITHUB-BADGE](https://github.com/{username}/{repository}/workflows/{name}/badge.svg)

GITHUB-BADGE

More info here: Adding a workflow status badge to your repository

Machavity
  • 30,841
  • 27
  • 92
  • 100
Dmitry Kaltovich
  • 2,046
  • 19
  • 21
  • 1
    Link is dead, currently can be found at https://docs.github.com/en/free-pro-team@latest/actions/managing-workflow-runs/adding-a-workflow-status-badge – stijn Jan 12 '21 at 08:22
6

I ran into another related problem of the name of the workflow containing spaces. These have to use URI escapes:

From main.yml

name: Hello World

Has to use a URI formatted like this:

https://github.com/{username}/{repository}/workflows/Hello%20World/badge.svg

This is not the right answer to the exact problem described here, but it is an alternative remedy to a problem demonstrating the same diagnostics - so I hope it helps somebody.

n8henrie
  • 2,737
  • 3
  • 29
  • 45
jonasbn
  • 183
  • 4
  • 11
-1

After actual verification, I came up with the following solutions

solution 1: you can use the name of your workflow .yml file.

https://github.com/{username}/{repository}/workflows/{your_`.yml`_file_name}/badge.svg

demo

https://github.com/xgqfrms/ChatGPT/blob/main/.github/workflows/gp-pages.yml#L3

enter image description here

CI is the workflows file name

https://github.com/xgqfrms/chatgpt/workflows/CI/badge.svg

enter image description here

solution 2: follow the GitHub docs

2.1 automatically created

demo

[![GitHub Actions Testing ✅](https://github.com/xgqfrms/cdn/actions/workflows/testing.yml/badge.svg)](https://github.com/xgqfrms/cdn/actions/workflows/testing.yml)

https://github.com/xgqfrms/cdn/actions/workflows/testing.yml

enter image description here

enter image description here

2.2 manually created

https://github.com/<OWNER>/<REPOSITORY>/actions/workflows/<WORKFLOW_FILE>/badge.svg

https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/adding-a-workflow-status-badge

demo

https://github.com/xgqfrms/cdn/blob/gh-pages/.github/workflows/testing.yml#L1

enter image description here

testing.yml has .yml in its name.

https://github.com/xgqfrms/cdn/actions/workflows/testing.yml/badge.svg

enter image description here

refs

https://github.com/xgqfrms/xgqfrms/issues/26

xgqfrms
  • 10,077
  • 1
  • 69
  • 68