How do I release versions on github through the command line?

github has a feature on their website that allows you to mark particular snapshots of your repository as release versions of software.

来自github网站的功能截图

Is there a way I can do this from the command line, without having to log on and use the interface? I realize the feature is not a part of git, but I was hoping there is some kind of api or solution other people use to make the process automated.


You could use the "Create release" API of the GitHub V3 API.

POST /repos/:owner/:repo/releases

See for instance this ruby script " create-release.rb " by Mathias Lafeldt ( mlafeldt ):

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

There are many projects offering this:

  • https://github.com/cheton/github-release-cli in node (javascript)
  • https://github.com/c4milo/github-release in Go (aims simplicity)
  • https://github.com/aktau/github-release in Go
  • And you can even do this directly with curl directly:

    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
    

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

    If you want a full featured answer on stackoverflow: Releasing a build artifact on github

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

    上一篇: 需要阅读Python中特定范围的文本文件

    下一篇: 如何通过命令行在github上发布版本?