Using Travis to deploy to GitHub and build Tag
-
21-12-2019 - |
سؤال
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.
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
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 "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"'
The correct code is:
- '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"'
Note that I change the snapshot filename. This snapshot is created when running the command play-${PLAY_VERSION}/play dist
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