我试图找出一个在GitHub上生成构建的单命令进程.
我预计会做的是运行某种命令发布,比如说,make release脚本会构建发布工件,然后以某种方式将其上传到GitHub.
但是,我对如何在GitHub上实际获取发布工件感到很困惑.源代码很棒,但不是每个人都想做自己的构建.:-)
Von*_*onC 19
更新2014年1月,有一个非官方的命令行应用程序,由Nicolas Hillegeer()发布,称为github-release,用于创建发布和上传(二进制)工件.
它使用上面提到的新github发布API.查看项目的Makefile,了解如何更自动化它.aktau
例:
# create a formal release
$ github-release release \
--user aktau \
--repo gofinance \
--tag v0.1.0 \
--name "the wolf of source street" \
--description "Not a movie, contrary to popular opinion. Still, my first release!" \
--pre-release
Run Code Online (Sandbox Code Playgroud)
由于二进制资产,此API略有不同.我们在请求发布资产时使用Accept标头进行内容协商.
传递标准API媒体类型以获取API表示:
$ curl -i -H "Authorization: token TOKEN" \
-H "Accept: application/vnd.github.manifold-preview" \
"https://uploads.github.com/repos/hubot/singularity/releases/assets/123"
HTTP/1.1 200 OK
{
"id": 123,
...
}
Run Code Online (Sandbox Code Playgroud)
传递"application/octet-stream"以下载二进制内容.
$ curl -i -H "Authorization: token TOKEN" \
-H "Accept: application/octet-stream" \
"https://uploads.github.com/repos/hubot/singularity/releases/assets/123"
HTTP/1.1 302 Found
Run Code Online (Sandbox Code Playgroud)
上传由对同伴"
uploads.github.com"服务的单个请求处理.
$ curl -H "Authorization: token TOKEN" \
-H "Accept: application/vnd.github.manifold-preview" \
-H "Content-Type: application/zip" \
--data-binary @build/mac/package.zip \
"https://uploads.github.com/repos/hubot/singularity/releases/123/assets?name=1.0.0-mac.zip"
Run Code Online (Sandbox Code Playgroud)
2013年7月2日更新,您现在可以定义版本.

这取代了旧的二进制上传服务,该服务已于2012年12月删除!
make release脚本构建了发布工件,然后以某种方式将其上传到github.
这意味着将它("它"是由一个或多个文件传递,通常包括二进制文件)添加到常规本地存储库,然后将该存储库推送到其匹配的GitHub存储库.
话虽如此,GitHub在任何"发布"任务中都没有提到的原因是因为Git是一个源代码管理系统,并且不适合二进制文件.
它当然可以包含那些文件(二进制文件),但不会定期使用它们,因为一段时间后repo的大小膨胀:每次克隆需要更长时间.
请参阅什么是Git限制,还有" git - 源文件和存储库应该在同一台机器上吗? ".
制备:
1)下载github-releases并将其可执行文件放入PATH中.
2)在https://github.com/settings/applications#personal-access-tokens创建一个令牌,让我们说abc123
上传工件:
1)假设您刚刚编译了您决定调用版本3.1的内容,并希望上传它.
2)确保你已经承诺了一切.
3)运行以下五个命令:
git tag v3.1
git push
git push --tags
github-release release --security-token abc123 --user <you> --repo <yourrepo> \
--tag v3.1
github-release upload --security-token abc123 --user <you> --repo <yourrepo> \
--tag v3.1 --name <thefile> --file <thefile>
Run Code Online (Sandbox Code Playgroud)
您可以上载多个文件,例如用于不同的操作系统.
(基于VonC的回答,遗憾的是没有详细说明如何上传工件)
hub 基于 Go 的官方 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
Run Code Online (Sandbox Code Playgroud)
没有Ubuntu包:https : //github.com/github/hub/issues/718
然后从你的回购里面:
hub release create -a prebuilt.zip -m 'release title' tag-name
Run Code Online (Sandbox Code Playgroud)
这个:
tag-nameprebuilt.zip作为附件上传您还可以为您现有的 API 令牌提供GITHUB_TOKEN环境变量。
其他release操作见:
hub release --help
Run Code Online (Sandbox Code Playgroud)
在hub de684cb613c47572cc9ec90d4fd73eef80aef09c 上测试。
没有任何外部依赖的 Python APIv3 上传示例
用法:
GITHUB_TOKEN=<token> ./create-release username/reponame <tag-name> <path-to-upload>
Run Code Online (Sandbox Code Playgroud)
脚本:
#!/usr/bin/env python3
import json
import os
import sys
from urllib.parse import urlencode
from urllib.request import Request, urlopen
repo = sys.argv[1]
tag = sys.argv[2]
upload_file = sys.argv[3]
token = os.environ['GITHUB_TOKEN']
url_template = 'https://{}.github.com/repos/' + repo + '/releases'
# Create.
_json = json.loads(urlopen(Request(
url_template.format('api'),
json.dumps({
'tag_name': tag,
'name': tag,
'prerelease': True,
}).encode(),
headers={
'Accept': 'application/vnd.github.v3+json',
'Authorization': 'token ' + token,
},
)).read().decode())
# This is not the tag, but rather some database integer identifier.
release_id = _json['id']
# Upload.
with open(upload_file, 'br') as myfile:
content = myfile.read()
_json = json.loads(urlopen(Request(
url_template.format('uploads') + '/' + str(release_id) + '/assets?' \
+ urlencode({'name': os.path.split(upload_file)[1]}),
content,
headers={
'Accept': 'application/vnd.github.v3+json',
'Authorization': 'token ' + token,
'Content-Type': 'application/zip',
},
)).read().decode())
Run Code Online (Sandbox Code Playgroud)
如果它们已经存在,发布和资产创建都将失败并显示 422。通过首先删除版本或资产来解决这个问题。这是一个例子。
| 归档时间: |
|
| 查看次数: |
17657 次 |
| 最近记录: |