Continuous deployment with Hugo

For better automation (and easier updating), I’ve added CircleCI for automated building and testing of the website. It will automatically deploy any pushes to the master into a separate git repository (to take advantage of Github Pages).

The idea is rather simple:

  • Dependencies: we download and install the latest Hugo version and make it available in ~/bin which is in $PATH (this happens in dependencies > pre). For syntax highlighting, we need to use Pygments, we’ll add a requirements file which CircleCI automatically installs in a virtualenv.
  • In checkout > post we make sure that all submodules (in this case the theme) are up to date.
  • For actual tests, we just run Hugo in verbose mode. It won’t catch all the errors, but at least we have a good idea.
  • Deployment: Since we just ran our tests, the public directory still contains the website. So before we clone the Github Pages repository, we need to empty that directory. The deploy script) will rebuild the website and commit it to Github.

That comes together in the following circle.yml file:

    - git submodule sync
    - git submodule update --init --recursive

    - git config --global "CircleCI"
    - git config --global ""

    - wget -O ~/tmp/hugo_0.15_linux_amd64.tar.gz
    - cd ~/tmp && tar xzf hugo_0.15_linux_amd64.tar.gz
    - mv ~/tmp/hugo_0.15_linux_amd64/hugo_0.15_linux_amd64 ~/bin/hugo

    - hugo -v

    branch: master
      - rm -rf public
      - git clone public
      - ./

Don’t forget to add a SSH deployment key into Circle CI’s project page (Settings > Permissions > SSH Permissions).