Cute version badges at Github for your open source abap project
Happy weekend day to you !
Do you have an opensource abap project at Github ? Do you like cute badges and statuses at the top of your readme ? Then this post is for you. Below I describe how to add a badge with your abap package version.
How to add
First of all you should have the version somewhere in your code as a constant (in semantic version format). Typically, you may define it in a common include or interface.
interface zif_my_lib_commons public . constants pkg_version type string value 'v2.1.6'. endinterface.
Supposedly, you’re using abapGit to sync your changes to Github, then this interface will be located in a file like this: src/zif_my_lib_commons.intf.abap. Now edit the README.md file in the root of your repository and add the following line to the very top of it and adjust it as described below:
![abap package version](https://img.shields.io/endpoint?url=https://shield.abap.space/version-shield-json/github/MY_GITHUB_USER/MY_REPO_NAME/src/zif_my_lib_commons.intf.abap/pkg_version)
- MY_GITHUB_USER – with your Github user
- MY_REPO_NAME – with yout repo name
- src/zif_my_lib_commons.intf.abap – with real path to your interface or include
- pkg_version – with the real constant name (if it differs)
Preview and Commit your changes – the badge should be there!
I added a badge to my mockup loader project repository. The readme badge code looks like this:
![abap package version](https://img.shields.io/endpoint?url=https://shield.abap.space/version-shield-json/github/sbcgua/mockup_loader/src/zif_mockup_loader_constants.intf.abap/version)
Based on this file:
And looks line this:
There is also a trend to use APACK manifest to describe your abapGit projects. It does already have version inside defined in a predictable way. So if you implemented one you can directly address it as a target file e.g. https://shield.abap.space/version-shield-json/github/SAP-samples/abap-platform-jak/.apack-manifest.xml.
How does this work ?
First there is an amazing service shields.io that produces Github status badges. In particular, it can retrieve shield configuration from another API.
I implemented such an API for detection of abap package version as an AWS lambda function and published it at shield.abap.space (the code of the lambda can be found in this repository if you’re interested).
The URL from above consists of 2 parts:
- “https://img.shields.io/endpoint?url=” which asks shields.io to render a badge based on settings received from the latter url
- “https://shield.abap.space/version-shield-json/…” the service to search your repository for version and create shield.io config
You may find some additional info and the code (not abap though, sorry) in this repository. Please report issues if you find them, the service is just released 🙂
I hope you find this useful ! 🙂 Let’s make abap coding fun!
UPD: shields.io allows to override certain parts of generated config e.g. if you’d like to change the color or the label of the badge just add additional parameter to the URL (e.g. ‘&label=version’ to override ‘abap package version’ text). For more information see the documentation at shields.io