简体   繁体   English

如何获得我的 github 存储库的最新预发布版本 - bash

[英]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?但我想要最新版本的 tag_name 是草稿/预发布吗?

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:使用像这样的 Json 工具,我们可以轻松过滤所有 object 以仅显示 prerelease prerelease: true的那些,然后,像这样提取最新版本的tag_name

jq -r 'map(select(.prerelease)) | first | .tag_name'

Where:在哪里:
JqPlay demo JqPlay 演示

  1. select(.prerelease) filters to items where prerelease: true select(.prerelease)过滤到 prerelease prerelease: true的项目
  2. first get the first object in the array of releases first获得版本数组中的第一个 object
  3. .tag_name shows the value of the tag_name key .tag_name显示tag_name键的值

Combining this to a bash one-liner:将此组合到 bash 单线:

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:如果您不确定该项目是否会有prerelease ,我们可以在调用中添加一个后备:

map(select(.prerelease)) | first | .tag_name // "Not found"

This will now show Not found if there's no tag_name on a prelease .如果prelease tag_name现在将显示Not found

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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