Deploy Website by Pelican, Travis CI, and GitHub Pages


I use two separate repositories for the source and the built website. One is userpages (source of the website) and the other is siongui.github.io (built website).

Build Website

First add .travis.yml [11] in the root of your source repo. My configuration is as follows:

language: python
python:
- '2.7'
branches:
  only:
  - master
addons:
  apt:
    packages:
    - language-pack-en
    - language-pack-zh-hant
    - language-pack-th
install:
- pip install -r requirements.txt
- make download
script:
- make publish

My website support threes languages (English, Traditional Chinese, Thai), and I need three locales (en_US.UTF8, zh_TW.UTF-8, th_TH.UTF-8) to build each subsites. That's why three language-packs are installed.

Deploy Website to Github Pages

Now Travis CI officially support deploy your static files to GitHub Pages after a successful build. [13]

First save your personal access token in repository settings.

For User Pages, the following is sample config:

deploy:
  provider: pages
  repo: siongui/siongui.github.io
  target_branch: master
  skip_cleanup: true
  github_token: $GITHUB_TOKEN
  local_dir: output
  on:
    branch: master

For Project Pages, the following is sample config:

deploy:
  provider: pages
  skip_cleanup: true
  github_token: $GITHUB_TOKEN
  local_dir: output
  on:
    branch: master

References:

[1]Google Search: pelican travis
[2]Pelican Static Site Generator, Powered by Python
[3]Travis CI - Test and Deploy Your Code with Confidence
[4]GitHub Pages
[5]Publish your Pelican blog on Github pages via Travis-CI
[6]How to automatically build your Pelican blog and publish it to Github Pages | Andrea Zonca's blog
[7]用 Travis-CI 生成 Github Pages 博客 - Farseerfc的小窩
[8]A static site with Pelican, Grunt, Travis & Github Pages
[9]Deploying my blog with Travis
[10]DuckDuckGo Search: pelican travis
[11]Customizing the Build - Travis CI
[12]Creating an access token for command-line use - GitHub Help
[13]GitHub Pages Deployment - Travis CI
[14]Building a Solid Continuous Integration Pipeline with TravisCI for Your Go Projects : golang
[15]Show HN: Minimal Google Analytics Snippet | Hacker News