#StandWithUkraine

Link to the latest GitHub release binary

You can now link directly to a download in the latest release: https://github.com/[USER]/[REPOSITORY]/releases/latest/download/[FILENAME]

These days I build my WordPress plugins for Composer install. I still provide standalone releases for people who don’t use it. Now and then people skip over install instructions and download the source of the plugin. Which does not work by itself.

I decided to improve this and provide a more visible direct download option in the readme files.

Latest release URL

To host standalone release I generate a zip archive and attach it to a GitHub release. Before I linked to the releases section, e.g. https://github.com/Rarst/laps/releases.

That page can look very busy and in current design links to attached assets are tiny.

You can now use a link that will always go to the latest release, e.g. https://github.com/Rarst/laps/releases/latest.

But it still points to a page, not a direct download.

Latest binary URL

Direct download URL is available via GitHub API though. We need to get to it and a way to send a client to it.

The latest release API call will give us all the information about that, e.g. https://api.github.com/repos/rarst/laps/releases/latest.

GitHub readme files are very static and cannot retrieve this information. For that, I had added a simple WordPress redirect endpoint to my own site. It queries GitHub API and a sends client to the direct download. I have added a white list and caching to it, so that the whole Internet doesn’t start to pipe things through my site. :)

Now I had the link that would always go to the latest release download: https://www.rarst.net/download/laps.

Dynamic image

While I researched this I had noticed that Shields badge service has a dynamic option. It can query arbitrary JSON file, extract data with jsonpath from it, and put into a badge image.

I already use Shields badges on readme pages. That looked like a good way to create a prominent image for the download button.

After some tinkering, I have made a button that queries GitHub API and extracts release file name from it:

https://img.shields.io/badge/dynamic/json.svg?<br></br>label=download<br></br>&url=https://api.github.com/repos/rarst/laps/releases/latest<br></br>&query=$.assets[0].name<br></br>&style=for-the-badge

And the result looks like this:

Large download button with file name in it.

All together

Now I combine the two and get a download button in the readme. It is completely static and GitHub is ok with it. But it will always show and send a client to the very latest release download.

Related Posts