Skip to content

Instantly share code, notes, and snippets.

@HoverBaum
Created August 11, 2016 03:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HoverBaum/d11361337d2c59f0de591c9c9390c1a9 to your computer and use it in GitHub Desktop.
Save HoverBaum/d11361337d2c59f0de591c9c9390c1a9 to your computer and use it in GitHub Desktop.
Deploy Hexo blog using Travis.
# Deploy hexo site by travis-ci
# https://github.com/jkeylu/deploy-hexo-site-by-travis-ci
# LICENSE: MIT
#
# 1. Copy this file to the root of your repository, then rename it to '.travis.yml'
# 2. Replace 'YOUR NAME' and 'YOUR EMAIL' at line 29
# 3. Add an Environment Variable 'DEPLOY_REPO'
# 1. Generate github access token on https://github.com/settings/applications#personal-access-tokens
# 2. Add an Environment Variable on https://travis-ci.org/{github username}/{repository name}/settings/env_vars
# Variable Name: DEPLOY_REPO
# Variable Value: https://{githb access token}@github.com/{github username}/{repository name}.git
# Example: DEPLOY_REPO=https://6b75cfe9836f56e6d21187622730889874476c23@github.com/jkeylu/test-hexo-on-travis-ci.git
# 4. Make sure Travis is configured to hide your Variable, else others will see your access token and can mess with all your repos.
language: node_js
# Every once in a while this should be bumped up
# https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Choosing-Node-versions-to-test-against
node_js:
- "6"
# Only create a new version on pushes to certain branches.
branches:
only:
- master
before_install:
- npm install -g hexo
install:
- npm install
# Notice: Replace 'YOUR NAME' and 'YOUR EMAIL'
before_script:
- git config --global user.name 'Travis'
- git config --global user.email 'travis@no-email.com'
# - git clone git://github.com/heroicyang/hexo-theme-modernist.git themes/modernist
# Maybe add minification scripts here
script:
- hexo generate
after_success:
- mkdir .deploy # Create a folder to use for teh pages branch
- cd .deploy
- git clone --depth 1 --branch gh-pages --single-branch $DEPLOY_REPO . || (git init && git remote add -t gh-pages origin $DEPLOY_REPO)
- rm -rf ./* # Clear old verion
- cp -r ../public/* . # Copy over files for new version
- git add -A .
- git commit -m 'Site updated' # Make a new commit for new version
- git branch -m gh-pages
- git push -q -u origin gh-pages # Push silently so we don't leak information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment