[英]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 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这样的 Json 工具,我们可以轻松过滤所有 object 以仅显示 prerelease
prerelease: true
的那些,然后,像这样提取最新版本的tag_name
:
jq -r 'map(select(.prerelease)) | first | .tag_name'
Where:在哪里:
JqPlay demo JqPlay 演示
select(.prerelease)
filters to items where prerelease: true
select(.prerelease)
过滤到 prerelease prerelease: true
的项目first
get the first object in the array of releases first
获得版本数组中的第一个 object.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 jq call:如果您不确定该项目是否会有
prerelease
,我们可以在jq调用中添加一个后备:
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.