Auto Deploying on gh-pages

While migrating web apps from susi server repository to repository. Our team autodeployed on gh-pages branch i.e., each time changes are made to code, it gets auto deployed on gh-pages branch. And changes are automatically live and visible on site.

To do this we have to setup travis in our repository. Travis can be easily set in github repository just by adding .travis.yml file into root directory your repo. Depending on type of repository you are dealing with, the configuration of travis changes. For, It is a written on top of ReactJs framework. So we used the following code.

sudo: required
dist: trusty
language: node_js
  - 6
  - npm test
  provider: script
  script: "./"
  - ENCRYPTION_LABEL: "<.... encryption label from previous step ....>"
    - node_modules
    - master


The above travis configuration file, After every commit checks whether the build is passing or not by running npm test command. After checking the commit, next script is run on the commit. The last line tells us to only execute this script for commits in master branch. can be placed anywhere, we jus need to modify its path in .tavis.yml file. Here is code of :

set -e 


if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
    echo "Skipping deploy; just doing a build."
    exit 0
# Save some useful information
REPO=`git config remote.origin.url`
SHA=`git rev-parse --verify HEAD`

git clone $REPO out
cd out
git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
cd ..
git config "Travis CI"
git config ""

if git diff --quiet; then
    echo "No changes to the output on this push; exiting."
    exit 0

# Commit the "changes", i.e. the new version.
# The delta will show diffs between new and old versions.
git add -A .
git commit -m "Deploy to GitHub Pages: ${SHA}"

# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in ../deploy_key.enc -out ../deploy_key -d
chmod 600 ../deploy_key
eval `ssh-agent -s`
ssh-add deploy_key

# Now that we're all set up, we can push.
git push $SSH_REPO $TARGET_BRANCH is automatically deploying master on gh pages branch. To perform this task, it needs admin authorisation of github repo. We do this authentication by encrypted keys.
To create encrypted keys we need to generate a new SSH key, SSH keys can be generated by running following command in terminal.

ssh-keygen -t rsa -b 4096 -C ""


Then add this key to your project’s git repository at the github repo of project.<your name>/<your repo>/settings/keys

Now, We can generate encrypted keys by running following command.

travis encrypt-file deploy_key


This command generates deploy_key.enc file, which shall be placed in the repo. Its location needs to be updated in the placeholders of .travis.yml and

Hence, we achieved the task of auto deployment to gh-pages in Please ensure that account through which encrypted keys are created, always have admin access to repository for continued deployment.