To get the latest release I can run:
curl --silent "https://api.github.com/repos/maxisme/notifi/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
But I want the latest release tag_name that is a draft/pre-release?
We can use the following route to get all the releases :
https://api.github.com/repos/maxisme/notifi/releases
Using a Json tool like jq we can easily filter all the object to only show those where prerelease: true
, then, extract the tag_name
of that latest release like so:
jq -r 'map(select(.prerelease)) | first | .tag_name'
Where:
JqPlay demo
select(.prerelease)
filters to items where prerelease: true
first
get the first object in the array of releases .tag_name
shows the value of the tag_name
key Combining this to a bash one-liner:
jq -r 'map(select(.prerelease)) | first | .tag_name' <<< $(curl --silent https://api.github.com/repos/maxisme/notifi/releases)
Prints:
0.9.9
If you're not sure there will be a prerelease
on the project, we can add a fallback to the jq call:
map(select(.prerelease)) | first | .tag_name // "Not found"
This will now show Not found
if there's no tag_name
on a prelease
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.