GitHub在其网站上有一个feature,允许您将存储库的特定快照标记为软件的发行版本。示例网址:https://github.com/github/orchestrator/releases
有没有办法可以从命令行执行此操作,而无需登录并使用界面?我意识到这个功能不是git的一部分,但我希望其他人可以使用某种api或解决方案来使流程自动化。
有很多项目提供:
您甚至可以直接使用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
你可以使用"Create release" API的GitHub 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
hub
官方Go-based GitHub CLI工具
首先安装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
这个:
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?