简体   繁体   中英

How can I get the latest pre-release release for my github repo - bash

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 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

  1. select(.prerelease) filters to items where prerelease: true
  2. first get the first object in the array of releases
  3. .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 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM