如何通过命令行在github上发布版本?

github在他们的网站上有一个功能,允许您将存储库的特定快照标记为软件的发行版本。

来自github网站的功能截图

有没有办法从命令行执行此操作,而无需登录并使用界面? 我意识到这个功能不是git的一部分,但我希望有某种api或其他人使用的解决方案来实现这个过程的自动化。


你可以使用GitHub V3 API的“Create release”API。

POST /repos/:owner/:repo/releases

请参阅Mathias Lafeldt( mlafeldt )的这个ruby脚本“ create-release.rb ”:

require "net/https"
require "json"

gh_token     = ENV.fetch("GITHUB_TOKEN")
gh_user      = ARGV.fetch(0)
gh_repo      = ARGV.fetch(1)
release_name = ARGV.fetch(2)
release_desc = ARGV[3]

uri = URI("https://api.github.com")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new("/repos/#{gh_user}/#{gh_repo}/releases")
request["Accept"] = "application/vnd.github.manifold-preview"
request["Authorization"] = "token #{gh_token}"
request.body = {
  "tag_name"         => release_name,
  "target_commitish" => "master",
  "name"             => release_name,
  "body"             => release_desc,
  "draft"            => false,
  "prerelease"       => false,
}.to_json

response = http.request(request)
abort response.body unless response.is_a?(Net::HTTPSuccess)

release = JSON.parse(response.body)
puts release

有很多项目提供这个:

  • https://github.com/cheton/github-release-cli in node(javascript)
  • https://github.com/c4milo/github-release in Go(旨在简化)
  • 在Go中https://github.com/aktau/github-release
  • 你甚至可以直接用curl直接做到这一点:

    OWNER=
    REPOSITORY=
    ACCESS_TOKEN=
    VERSION=
    curl --data '{"tag_name": "v$VERSION",
                  "target_commitish": "master",
                  "name": "v$VERSION",
                  "body": "Release of version $VERSION",
                  "draft": false,
                  "prerelease": false}' 
        https://api.github.com/repos/$OWNER/$REPOSITORY/releases?access_token=$ACCESS_TOKEN
    

    从https://www.barrykooij.com/create-github-releases-via-command-line/

    如果你想在stackoverflow上有一个全功能的答案:释放github上的构建工件

    链接地址: http://www.djcxy.com/p/77047.html

    上一篇: How do I release versions on github through the command line?

    下一篇: Should each module in a Maven project have its own Spring application context?