How to release versions on GitHub via the command line?

GitHub has a feature feature on its website that allows you to mark specific snapshots of your repository as a production version of the software. URL example: https://github.com/github/orchestrator/releases

Is there a way I can do this from the command line without having to log in and use the interface? I understand that this function is not part of git, but I was hoping there was some kind of api or solution that other people use to automate the process.

+10
source share
3 answers

There are many projects offering this:

And you can do it directly with 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 

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

If you need the full stackoverflow response tag: Releasing a build artifact on github

+5
source

You can use the Create Release API of the GitHub V3 API .

 POST /repos/:owner/:repo/releases 

See, for example, this ruby ​​script " create-release.rb " 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 
+3
source

hub official Go-based GitHub CLI tool

https://github.com/github/hub

Ubuntu package added as of 04/19: https://packages.ubuntu.com/search?keywords=hub | https://github.com/github/hub/issues/718

 sudo apt install hub 

Otherwise, for an older version of Ubuntu, first install Go. On Ubuntu: https://askubuntu.com/questions/959932/installation-instructions-for-golang-1-9-into-ubuntu-16-04/1075726#1075726

Then install hub :

 go get github.com/github/hub 

After installing hub from repo:

 hub release create -a prebuilt.zip -m 'release title' tag-name 

this:

  • requests a password for the first time, and then automatically creates and stores the API token locally
  • creates an annotated tag on the remote with the name tag-name
  • creates a release associated with this tag
  • downloads prebuilt.zip as an attachment

You can also provide your existing API token using the GITHUB_TOKEN environment GITHUB_TOKEN .

For other release operations, see:

 hub release --help 

Tested in hub de684cb613c47572cc9ec90d4fd73eef80aef09c .

Python example without any dependencies

If you are like me and don’t want to install another language:

Can someone give an example of Python requests to download a release resource on github?

+2
source

All Articles