使用Travis部署到GitHub并构建Tag [英] Using Travis to deploy to GitHub and build Tag
问题描述
我一直在努力一段时间,如何使用Travis-CI来构建和部署一个标签到GitHub。
我在此问题上找到了一些信息,但它不是很清楚,它也不为我工作。
I am struggling for some time on how to use Travis-CI to build and deploy a tag to GitHub. I find some information about that on this question, but it is not very clear and it is also not working for me.
我在gitHub上创建了一个新的发布版本0.0.0,我使用Scala与Play框架和我的 .travis.yml
文件如下:
I created a new Release version 0.0.0 on gitHub and I am using Scala with Play Framework and my .travis.yml
file is as follows:
language: scala
scala:
- 2.10.4
jdk:
- openjdk7
services:
- postgresql
env:
- PLAY_VERSION=2.0.2 DATABASE_USER=postgres DATABASE_PWD='' DATABASE_URL=jdbc:postgresql:testdb BUILD_KEY=xxxxxxxxxxxxxxxxxxxxxxx
before_script:
- psql -c 'create database testdb;' -U postgres
- wget http://download.playframework.org/releases/play-${PLAY_VERSION}.zip
- unzip -q play-${PLAY_VERSION}.zip
- sudo apt-get install jq
script:
- sbt test
after_success:
- play-${PLAY_VERSION}/play dist
- 'ASSETID=$(curl -s -H "Authorization: token ${BUILD_KEY}" "https://api.github.com/repos/Company/spinsurstaging/releases/456729/assets" | jq ".[0].id")'
- 'curl -XDELETE -s -H "Authorization: token ${BUILD_KEY}" "https://api.github.com/repos/Company/spinsurstaging/releases/assets/$ASSETID"'
- 'curl -XPOST -s -H "Authorization: token ${BUILD_KEY}" -H "Content-Type: application/zip" --data-binary @./spinsurstaging-0.0-SNAPSHOT.zip "https://uploads.github.com/repos/Company/spinsurstaging/releases/456729/assets?name= spinsurstaging.zip"'
notifications:
email: false
deploy:
provider: heroku
api_key: "${HEROKU_KEY}"
app: spinsurstaging
主要问题是:如何使它工作?有什么问题吗?
还有:我不明白我将如何发布文件 spinsurstaging-0.0-SNAPSHOT.zip
作为github的发布。这个文件来自哪里?有这样的标准吗?
有更好的方法吗?
Main question is: How to make it work? Is something wrong?
And also: I didn't understand how I will post the file spinsurstaging-0.0-SNAPSHOT.zip
as a release to github. Where is this file coming from? Is there a standard for this?
Is there a better way to do that?
预先感谢您帮助我解决这个问题。
Thank you in advance for helping me out with this issue.
推荐答案
我只是想出了如何解决它。
我在代码行上犯了一个错误:
I just figured out how to solve it. I made a mistake on the line of code:
- 'curl -XPOST -s -H授权:token $ { BUILD_KEY}-HContent-Type:application / zip--data-binary @。/ spinsurstaging-0.0-SNAPSHOT.ziphttps://uploads.github.com/repos/Company/spinsurstaging/releases/456729/ assets?name = spinsurstaging.zip'
正确的代码是:
- 'curl -XPOST -s -H授权:token $ {BUILD_KEY}-HContent-Type:application / zip--data-binary @。/ spinsurstaging-0.0-SNAPSHOT。 ziphttps://uploads.github.com/repos/Company/spinsurstaging/releases/456729/assets?name= spinsurstaging .zip'
请注意,我更改了快照文件名。此快照是在运行命令 play - $ {PLAY_VERSION} / play dist
Note that I change the snapshot filename. This snapshot is created when running the command play-${PLAY_VERSION}/play dist
时创建的。另一个重要的事情是我必须将 PLAY_VERSION
变量更改为 2.2.4
,因为旧版本没有相同的存储库版本我用于sbt。
Another important thing is that I have to change the PLAY_VERSION
variable to 2.2.4
because the older version didn't had a repository for the same version I was using for sbt.
所以我相信我可以回答我的所有问题。希望它帮助别人。以下是完整的解决方案:
So I believe I could answer all my questions. Hope it helps someone else. Here are the complete solution:
language: scala
scala:
- 2.10.4
jdk:
- openjdk7
services:
- postgresql
env:
- PLAY_VERSION=2.2.4 DATABASE_USER=postgres DATABASE_PWD='' DATABASE_URL=jdbc:postgresql:testdb BUILD_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
before_script:
- psql -c 'create database testdb;' -U postgres
- wget http://downloads.typesafe.com/play/${PLAY_VERSION}/play-${PLAY_VERSION}.zip
- unzip -q play-${PLAY_VERSION}.zip
- sudo apt-get install jq
script:
- sbt test
after_success:
- play-${PLAY_VERSION}/play dist
- cd target/universal/
- 'ASSETID=$(curl -s -H "Authorization: token ${BUILD_KEY}" "https://api.github.com/repos/Company/spinsurstaging/releases/456729/assets" | jq ".[0].id")'
- 'curl -XDELETE -s -H "Authorization: token ${BUILD_KEY}" "https://api.github.com/repos/Company/spinsurstaging/releases/assets/$ASSETID"'
- 'curl -XPOST -s -H "Authorization: token ${BUILD_KEY}" -H "Content-Type: application/zip" --data-binary @./spinsurstaging-1.0-SNAPSHOT.zip "https://uploads.github.com/repos/Company/spinsurstaging/releases/456729/assets?name= spinsurstaging'
notifications:
email: false
deploy:
provider: heroku
api_key: "${HEROKU_KEY}"
app: spinsurstaging
这篇关于使用Travis部署到GitHub并构建Tag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!