TIL: Adding an action/workflow status badge to your GitHub repository

Jonas Brømsø - Nov 1 '19 - - Dev Community

If you want to show the GitHub Actions badge on your repository, be aware that the URL has to reflect the name of a given action.

Do note GitHub actions are still in beta.

Like for example this badge for one of my repositories:

GitHub Workflow build status badge

  1. The URL points to GitHub: https://github.com
  2. My account: jonasbn
  3. The relevant (this) repository: til
  4. The workflows directory: workflows and this is the workflows directory located in the directory .github
  5. Now the most tricky part - the name fields from the main.yml file from the above directory (github/workflows/):
name: Markdownlint Workflow
on: push

jobs:
  build:
    name: Markdownlint
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - uses: ./github-action-markdownlint
Enter fullscreen mode Exit fullscreen mode

This value:

name: Markdownlint Workflow

Okay, but since the specified name contains spaces, the have to be explicitly described using URI-encoding (or percent-encoding), meaning space is encoded %20

  1. Last but not least the hard-coded value: badge.svg

So the complete URL for the badge displayes look as follows:

https://github.com/jonasbn/til/workflows/Markdownlint%20Workflow/badge.svg

Do yourself the favor of testing the URL before making commits containing it, it took me several attempts to get right.

Thanks to the nice supporter from GitHub who helped me out.

References

This TIL was lifted from my TIL collection

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .