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

问题描述 投票:9回答:3

GitHub在其网站上有一个feature,允许您将存储库的特定快照标记为软件的发行版本。示例网址:https://github.com/github/orchestrator/releases

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

api version-control github automation release
3个回答
5
投票

有很多项目提供:

您甚至可以直接使用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上有一个全功能的答案:Releasing a build artifact on github


3
投票

你可以使用"Create release" APIGitHub V3 API

POST /repos/:owner/:repo/releases

例如,参见create-release.rb的这个ruby脚本“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

1
投票

hub官方Go-based GitHub CLI工具

https://github.com/github/hub

首先安装Go。在Ubuntu:https://askubuntu.com/questions/959932/installation-instructions-for-golang-1-9-into-ubuntu-16-04/1075726#1075726

然后安装hub

go get github.com/github/hub

没有Ubuntu包:https://github.com/github/hub/issues/718

然后从您的回购内部:

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

这个:

  • 首次提示输入密码,然后在本地自动创建和存储API令牌
  • 在名为tag-name的遥控器上创建一个未注释的标签
  • 创建与该标记关联的版本
  • 上传prebuilt.zip作为附件

您还可以使用GITHUB_TOKEN环境变量提供现有API令牌。

对于其他release操作,请参阅:

hub release --help

hub de684cb613c47572cc9ec90d4fd73eef80aef09c上测试过。

没有任何依赖关系的Python示例

如果你像我一样,不想安装另一种语言:

Can someone give a python requests example of uploading a release asset in github?

© www.soinside.com 2019 - 2024. All rights reserved.