Chris Johnson
Chris Johnson

Reputation: 187

Travis CI Deploy Pull Requests

Having some trouble finding info on this, not sure exactly how I'd search for it so figured I'd just throw a question up here...

GitHub pull requests on Travis are pretty much ready to go out of the box, but...I'm interested in deploying each PR to an independent URL (staging.example.com/pull-request-01 or something like that..). It's possible that this is super simple and outlined in Travis' docs, but I'm having trouble finding it.

Does anyone have their CI setup like this?

Upvotes: 1

Views: 1055

Answers (3)

S0AndS0
S0AndS0

Reputation: 910

Some of the documentation from Travis CI that I could find that will likely be useful in sorting out a full answer

TLD

Encrypted variables will only be available to Pull Requests issued from the same repository. Testing for environment variables and Git interaction that triggered Travis CI is required...

script:
  - if [ "$TRAVIS_PULL_REQUEST" == true ]; then bash ./travis/run_on_pull_requests; fi

Once signed into the Travis CI command-line interface, encrypting enviroment variables looks somewhat like...

travis encrypt -r owner/project --pro SOMEVAR="secretvalue"

... then copy output from above (secure: ".... encrypted data ....") into the project's _travis.yml file.


I didn't see anything for DigitalOcean, but there's not much stopping anyone from writing their own script for such things, and for S3 deployment looks like Travis CI has some ready-made magics for such things to read up on (third link above)...

deploy:
  provider: s3
  access_key_id: "YOUR AWS ACCESS KEY"
  secret_access_key: "YOUR AWS SECRET KEY"
  bucket: "S3 Bucket"
  skip_cleanup: true
  on:
    branch: release
    condition: $MY_ENV = super_awesome

Few more answers for your questions

Does anyone have their CI setup like this?

I do not... yet. But I've been exploring Travis CI documentation for sometime and may edit this answer in the future to include more references.

I'm interested in deploying each PR to an independent URL (staging.example.com/pull-request-01 or something like that..) It's possible that this is super simple and outlined in Travis' docs, but I'm having trouble finding it.

Aside from the previously suggested reading material, you'll likely want to do some custom stuff within a run_on_pull_requests script.

Easiest route I can think up at this time would be parsing the commit hash such that URLs look a bit like staging.example.com/pull-request-4d3adbe3f.

Hints on how to maybe construct such a string in a Bash script...

printf 'pull-request-%s' "$(git rev-parse --short HEAD)"


_url="staging.example.com/pull-request-$(git rev-parse --short HEAD)"

I suggest the commit hash route because then anyone with permissions to open Pull Requests (from the given repository), has a predictable route for building the URL on their end.


Consider letting us all know if ya get stuck or fully solve it.

Upvotes: 1

nlyn
nlyn

Reputation: 606

This is also possible with Heroku Review Apps and Gitlab Review Apps. If you're using Docker you could also use this tool, which I built.

Upvotes: 0

Chris Johnson
Chris Johnson

Reputation: 187

Figured out a cool way to do this! Here is a pretty self explanatory Gist that can help someone trying to do this on an Ember project, it could also probably inform any other code stacks..

https://gist.github.com/ChristopherJohnson25/7350169203a2ecfa9193785bede52bd3

Upvotes: 0

Related Questions