GitHub REST API does have an api to get all the tags of a repo, and does have an api to get the latest release of a repo, but does not have one to get the latest tag 😔
😎 Use https://shields.io as the API!
- Get
svg
and then parse it
USER="qmk"
REPO="qmk_firmware"
curl -fsSL "https://shields.io/github/v/tag/${USER}/${REPO}.svg?sort=semver" | \
awk -F 'title>' '{print $2}' | \
cut -d 'v' -f 2 | \
cut -d '<' -f 1
- https://shields.io/github/v/tag/qmk/qmk_firmware.svg?sort=semver will respond a single line string in svg format
- because it is single line, we cannot use
grep
to get the version number...
- because it is single line, we cannot use
- the structure of the svg file looks like this:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="86" height="20" role="img" aria-label="tag: v0.14.29">
<title>tag: v0.14.29</title>
<linearGradient id="s" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
<stop offset="1" stop-opacity=".1"/>
</linearGradient>
<clipPath id="r">
<rect width="86" height="20" rx="3" fill="#fff"/>
</clipPath>
<g clip-path="url(#r)">
<rect width="27" height="20" fill="#555"/>
<rect x="27" width="59" height="20" fill="#fe7d37"/>
<rect width="86" height="20" fill="url(#s)"/>
</g>
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110">
<text aria-hidden="true" x="145" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="170">tag</text>
<text x="145" y="140" transform="scale(.1)" fill="#fff" textLength="170">tag</text>
<text aria-hidden="true" x="555" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="490">v0.14.29</text>
<text x="555" y="140" transform="scale(.1)" fill="#fff" textLength="490">v0.14.29</text>
</g>
</svg>
- Get
json
and then parse it
USER="qmk"
REPO="qmk_firmware"
curl -fsSL 'https://shields.io/github/v/tag/${USER}/${REPO}.json?sort=semver' | \
awk -F 'value' '{print $2}' | \
cut -d '"' -f 3 | \
cut -d 'v' -f 2
- https://shields.io/github/v/tag/qmk/qmk_firmware.json?sort=semver will respond a single line string in json format
- because it is single line, we cannot use
grep
to get the version number...
- because it is single line, we cannot use
- the structure of the svg file looks like this:
{
"label": "tag",
"message": "v0.14.29",
"color": "orange",
"link": [],
"name": "tag",
"value": "v0.14.29"
}
- Obviously, there are so many tools and ways to parse
svg
andjson
🤣, so the options is unlimited!