简体   繁体   English

如何使用 git CLI 获取最新版本

[英]how can I use git CLI to get the latest release

I would like to use gitHub "releases" feature to tell my production server when should it update its code base from GitHub.我想使用 gitHub 的“发布”功能来告诉我的生产服务器何时应该从 GitHub 更新其代码库。
I do not want it to grab on each push, but just when a new release is being created.我不希望它在每次推送时抓取,而是在创建新版本时抓取。

My plan was to create a bash script that will check every 10-15 minutes if there is a new release and if it found a new release, it will do a pull request or download the latest release zip file, deploy the new code and restart the node service.我的计划是创建一个 bash 脚本,每 10-15 分钟检查一次是否有新版本,如果发现新版本,它将执行拉取请求或下载最新版本的 zip 文件,部署新代码并重新启动节点服务。

But I am stuck on the first step and that's how can I figure out if there is a new release.但是我坚持第一步,这就是我如何确定是否有新版本。

Any help/pointer or direction will be greatly appreciated.任何帮助/指针或方向将不胜感激。

As I mentioned in " GitHub latest release ", you have an API dedicated to get the latest release. 正如我在“ GitHub最新版本 ”中提到的,您有一个专门用于获取最新版本的API。

GET /repos/:owner/:repo/releases/latest

You can use it (with the appropriate authentication and the right scope ) for a private repo. 您可以将它(具有适当的身份验证正确的范围 )用于私人仓库。

If you cache the latest release, you can trigger your process each time the new latest differs from the one you have cached. 如果您缓存最新版本,则每次新的最新版本与您缓存的版本不同时,都可以触发您的过程。

Using bash with the help of curl, you can use this long one-liner to get the latest release from a public repository: 在curl的帮助下使用bash,您可以使用这个long one-liner从公共存储库获取最新版本:

git clone -b $(basename $(curl -Ls -o /dev/null -w %{url_effective} https://github.com/OWNER/PROJECT/releases/latest)) https://github.com/OWNER/PROJECT.git

A bash function like this: 像这样的bash函数:

gh-clone-latest() {
  local owner=$1 project=$2
  local output_directory=${3:-$owner-$project-release}
  local release_url=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/$owner/$project/releases/latest)
  local release_tag=$(basename $release_url)
  git clone -b $release_tag -- https://github.com/$owner/$project.git $output_directory
}

would reduce that to gh-clone-latest Owner Project . 会减少到gh-clone-latest Owner Project

For a private project, you'll need to authenticate and scope properly, as mentioned in the other answer. 对于私有项目,您需要正确地进行身份验证和范围,如另一个答案中所述。

CLI gh release list命令可以显示发布日期

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

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