调用GitHub API与Travis构建标签 [英] Call GitHub API with Travis to build Tag
问题描述
我在GitHub存储库中创建了一个TravisCI Hook,它在推送到仓库后自动运行构建。我想补充的是,如果生成成功,自动创建一个标签。
I have created a TravisCI Hook in a GitHub repository that automatically run a build after pushing to the repo. What I would like to add is that if the build succeeds a tag is automatically created.
我发现有一种方法使用GitHub API创建标签< a href =http://developer.github.com/v3/git/tags/#create-a-tag-object> http://developer.github.com/v3/git/tags/#create-a -tag-object
I have found out that there is a way to create tags with the GitHub API http://developer.github.com/v3/git/tags/#create-a-tag-object
但是如何控制对我的仓库的访问?我不能在travis.yml中显示我的登录github凭据,因为每个人都可以读它,因为它是cointained在存储库。\
But how do I control access to my repository? I can't expose my login github credentials in the travis.yml because everyone can read it as it is cointained in the repository.\
我是新的自动部署所以如果有任何其他解决方案这样做没有travis请让我也知道。我想实现的是,在成功构建之后为用户创建可下载版本。
I am pretty new to automated deployment so if there is any other solution to do this without travis please let me also know. What I would like to achieve is that a downloadable version is created for the users after a successful build.
Ok我终于找到了正确的travis.yaml配置。
Ok I have finally found the correct travis.yaml Configuration.
它是如何工作的:
推送到存储库后,travis将运行测试我的应用程序。如果测试成功,travis将构建当前版本的预编译版本,并将其上传到我在GitHub Repo上创建的特殊版本。
How does it work: After pushing to the repository, travis will run the tests of my application. If the tests are successful travis will build a precompiled version of the current build and upload it to a special release which I have created on the GitHub Repo.
language: scala
env:
global:
- PLAY_VERSION=2.2.1
- secure: "HD1x0S9ad/3+G9YUkyT/uTw9lEr+tUQEV4QO+M2Ro1JFSVOzLNZiNoh6FrNb06a0TbencTkftyHYmYjp1/CCyTpF9CMCQ4ddB7TVF9hibH1y9ONVrPJIm5BCEpjGDa4fND8bkcChrpcZDQKIO0ZwArEsl2+IRocnbBT+oYqIFNo="
before_script:
- wget http://downloads.typesafe.com/play/${PLAY_VERSION}/play-${PLAY_VERSION}.zip
- unzip -q play-${PLAY_VERSION}.zip
- sudo apt-get install jq
script: play-${PLAY_VERSION}/play test
notifications:
email: false
after_success:
- play-${PLAY_VERSION}/play dist
- cd target/universal/
- 'ASSETID=$(curl -s -H "Authorization: token ${BUILD_KEY}" "https://api.github.com/repos/meisign/fillable/releases/204198/assets" | jq ".[0].id")'
- 'curl -XDELETE -s -H "Authorization: token ${BUILD_KEY}" "https://api.github.com/repos/meisign/fillable/releases/assets/$ASSETID"'
- 'curl -XPOST -s -H "Authorization: token ${BUILD_KEY}" -H "Content-Type: application/zip" --data-binary @./Fillable-1.0-SNAPSHOT.zip "https://uploads.github.com/repos/meisign/fillable/releases/204198/assets?name=Fillable.zip"'
推荐答案
您可以创建 GitHub个人API令牌,将授予您的存储库的访问权限。 public_repo
作用域应该是公共存储库所需要的。
You can create a GitHub Personal API Token that will grant access to your repositories. The public_repo
scope should be all you need for a public repository.
使用此令牌来验证GitHub API 。要在 API中使用令牌,请将其包含在授权标头中。
Use this token for authenticating to the GitHub API. To use the token with the API include it in the Authorization header.
curl -H "Authorization: token <YOUR_TOKEN>" https://api.github.com/user
您也可以使用这个凭证
git push -q https://<token>@github.com/<user>/<repo>
现在有趣的部分,你需要保持这个令牌的秘密。将其公开相当于公开您的用户名和密码。
Now for the fun part, you need to keep that token a secret. Having it public is equivalent to having your username and password public.
您需要确保文档引用并注意您的Travis-CI日志。命令在bash中运行,并且取决于您的写法,或者如果有任何错误,您可以意外地显示您的令牌。
You need to be sure to read through the documentation referenced and keep an eye on your Travis-CI logs. The commands run in bash, and depending how you write it or if there are any errors you could accidentally reveal your token.
令牌秘密Travis-CI具有用于生成公钥和私钥的系统。 加密密钥特定于您的存储库。
To keep that token a secret Travis-CI has a system for generating public and private keys. The encryption keys are specific to your repository.
链接包含所有相关文档;您需要安装Travis命令行界面工具,它可作为Ruby Gem使用。
The link has all of the relevant documentation; you need to install the Travis command line interface tool, it is available as a Ruby Gem.
gem install travis
要对变量(例如您的个人令牌)加密 -
To encrypt a variable (such as your personal token) -
travis encrypt SOMEVAR=secretvalue --add
该命令正在项目目录中运行,并将根据您的存储库提供唯一的公钥以加密您的数据。 - add
标志将自动将安全数据放入您的 .travis.yml
文件中。
Travis assumes that the command is being run in the project directory and will provide the unique Public key to encrypt your data, based on your repository. The --add
flag will automatically place the secured data in your .travis.yml
file.
这就是你把它保密的方法。使用Git或GitHub API创建标签的实现取决于您。一旦你找出来,请分享。
That's how you keep it a secret. The implementation of creating tags with Git or the GitHub API is up to you. Please share once you figure it out.
这篇关于调用GitHub API与Travis构建标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!