Auto deploy from Travis to Github
-
Create a key and save it to a file called
deploy_rsa
ssh-keygen -t rsa -b 4096 -C 'build@travis-ci.org' -f ./deploy_rsa
-
Add the key, encrypted, to Travis
travis encrypt-file deploy_rsa --add
-
Add the encrypted key to git
git add deploy_rsa.enc
-
Go to the repository settings/deploy keys page on Github and add a new Deploy Key. Add the output of the following command + check Allow write
cat deploy_rsa.pub
-
Remove the actual key file so it won’t be commited to the repo by accident
rm deploy_rsa deploy_rsa.pub
-
Create a
.travis-deploy.sh
script:
#!/bin/sh
set -e
# setup ssh-agent and provide the GitHub deploy key
eval "$(ssh-agent -s)"
chmod 600 deploy_rsa
ssh-add deploy_rsa
# This method depends on how you build your project.
# This is a node.js example:
# commit the assets in build/ to the gh-pages branch and push to GitHub using SSH
./node_modules/.bin/gh-pages -d dist/ -b gh-pages -r git@github.com:${TRAVIS_REPO_SLUG}.git
- Make the script runnable
chmod +x .travis-deploy.sh
- Call the
.travis-deploy.sh
script in your.travis.yml
file
deploy:
- provider: script
skip_cleanup: true
script: "./.travis-deploy.sh"
on:
branch: master