我一直在努力研究如何使用Travis-CI构建标签并将其部署到GitHub。 我在this question上找到了一些相关信息,但不是很清楚,也不适用于我。
我在gitHub上创建了一个新的Release版本0.0.0,我在Play Framework中使用Scala,我的.travis.yml
文件如下:
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。这个文件来自哪里?这有标准吗?
有没有更好的方法呢?
提前感谢您帮我解决这个问题。
答案 0 :(得分:2)
我刚想出如何解决它。 我在代码行上犯了一个错误:
- '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"'
正确的代码是:
- '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"'
请注意,我更改了快照文件名。运行命令play-${PLAY_VERSION}/play dist
另一个重要的事情是我必须将PLAY_VERSION
变量更改为2.2.4
,因为旧版本没有我用于sbt的相同版本的存储库。
所以我相信我可以回答所有问题。希望它可以帮助别人。以下是完整的解决方案:
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