Building this blog with travis

Since January this blog is automatically build using Travis CI. The main advantage is to always use the latest version of Pelican as travis CI always build its environment from scratch. An other advantage is that I am able to update the site just from my browser for minor modifications (spell correction for instance).

Here is the travis.yml configuration file pass to Travis CI:

language: python

install:
  # https://github.com/wummel/linkchecker/issues/649
  - pip install requests==2.9.1
  - pip install LinkChecker==9.3
  - pip install pelican markdown

  # grab the build theme
  - git clone -b build https://github.com/maggick/maggner-pelican

  # grab the pelican plugins
  - git clone https://github.com/getpelican/pelican-plugins

  # grab the latest published version in order to not erase rss feed
  - git clone https://github.com/maggick/maggick.github.io output

script:
  - linkchecker --check-extern ./content
  - pelican

after_success:
  - cd output
  - git add ./
  - git -c user.name="Travis CI for maggick" -c user.email="keller.mdp@gmail.com" commit -m 'Travis update documentation'
  - git push https://${GH_TOKEN}@github.com/maggick/maggick.github.io.git master

Declaration

Let us break it a bit. First the declaration part:

language: python

We do not need the root right so sudo is not needed. Moreover we use the python language.

install

The installation part:

install:
  # https://github.com/wummel/linkchecker/issues/649
  - pip install requests==2.9.1
  - pip install LinkChecker==9.3
  - pip install pelican markdown

  # grab the build theme
  - git clone -b build https://github.com/maggick/maggner-pelican

  # grab the pelican plugins
  - git clone https://github.com/getpelican/pelican-plugins

  # grab the latest published version in order to not erase rss feed
  - git clone https://github.com/maggick/maggick.github.io output

We install:

  • request in version 2.9.1, this is a python library used by pelican
  • LinkChecker in version 9.3, this is a tool that will check that the link in the different articles give a 200 HTTP response
  • pelican which is used to build the site
  • mardkown because the articles are wrote in markdown

Then we grab the theme used by the site on the build branch directly on github, we also download the pelican plugins. We need to get the last build of the site in order to not re publish all the articles in the RSS feed (it happened once when writing this configuration).

Script

The script part is where the magic happen, this part will build the site and give a red or green status depending of the output of each script. If all of them exit without error the build is green otherwise the build is red.

script:
  - linkchecker --check-extern ./content
  - pelican

The script part used LinkChecker on the content directory where are all articles in the markdown format. This script will test every link on every file and exit with an error if a link return something else that an HTTP 200 OK.

Then we use pelican to build the site. If an error happened during the build the script will also exit with an error.

After success

Finally, after the success of the two script we deploy the site on github pages, we publish the site on github pages:

after_success:
  - cd output
  - git add ./
  - git -c user.name="Travis CI for maggick" -c user.email="keller.mdp@gmail.com" commit -m 'Travis update documentation'
  - git push https://${GH_TOKEN}@github.com/maggick/maggick.github.io.git master

We go in the output directory of the build, we add everything for git, we commit everything using a user crafted for the occasion and my public email address. The commit message is a generic one. Then we push everything on the branch master of the github pages repository.

For this last step I was forced to give a write access to all my repositories to Travis CI using the github API. I do not really like that but as I am monitoring the commit on my own repository I should be able to detect a hack or a malicious action of Travis CI. The next step will be to sign all my commit using GPG but I have not find a suitable solution yet (mostly for commit from browser).