Skip to content

Instantly share code, notes, and snippets.

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 rokibhasansagar/b92dc248a6e88e0d9403e45499002165 to your computer and use it in GitHub Desktop.
Save rokibhasansagar/b92dc248a6e88e0d9403e45499002165 to your computer and use it in GitHub Desktop.

Auto Deploy Hexo Organizational/Team Site Using Travis CI

Part 1: Sample Travis Yaml Config (.travis.yml)

language: node_js
node_js:
  - "node"
os: linux
dist: bionic
sudo: required
branches:
  only:
    - sources
git:
  depth: 1
env:
  global:
    - secure: "{Something like hfwh747tbwcnybbvixc7xncgbxmshga9se72h}"
    # Encrypt your Token as __GitOAuthToken__='{The_GitHub_Token}' format, and Paste here
cache:
  apt: true
  directories:
    - node_modules
before_install:
  - npm install -g hexo highlight.js@9.14.2
install:
  - npm install
before_script:
  - git config --global user.name '{GitUserName}'     # Replace your GitHub Username
  - git config --global user.email '{GitUserEMail}'   # Replace your GitHub EMail Address
  - sed -i "s/__GitOAuthToken__/${__GitOAuthToken__}/" _config.yml
script:
  - hexo clean && hexo generate
after_success:
  - hexo deploy --silent

Part 2: In Site's _config.yml, change these:

For Deploy Section

deploy:
  type: git
  message: "Site updated: {{ now('YYYY-MM-DD HH:mm') }}"
  repo:
    github: https://__GitOAuthToken__@github.com/{Organization}/{Organization}.github.io.git
    # This should look like https://hn1vecheu3c3cnmxhda7s2wdg63q3chja@github.com/MyOrg/MyOrg.github.io.git
  branch: master

__GitOAuthToken__ will be loaded from Travis environment variable and then replaced by sed into _config.yml just before Deployment. So, Just change the Organization Name here.

Part 3: Set GitIgnore

.DS_Store
Thumbs.db
db.json
*.log
node_modules/
public/
.deploy*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment