A little bit of context: some of the students of the Math-CS degree in the UAM are maintaining a repository with notes of most the subjects we're studying, written in LaTeX. We wanted to share the compiled PDF files with the other students, but there wasn't any CI solution for LaTeX. So, I created one. Latex_cd is a Debian service that monitors a Github repository, compiles the LaTeX files and uploads the PDF results to Dropbox.

Latex_cd is a combination of shell scripts and Ruby helpers, and it's tailored to Github repositories (although it can be adapted to other providers without much hassle). It consists of a Sinatra server (webhook.rb) that receives the Github notifications when new commits are pushed to the repository. When the notification is received, the pullandbuild.sh, the central part of the system, is called.

It seems obvious what does pullandbuild.sh do, right? It pulls new changes from the repository and builds the files. However, it does a little bit more than that. If your LaTeX repository has additional style files, the script will install them to the system. Then, it will check for .tex files in first-level directories and, if they're outdated (that is, either latexmk says that they're not updated or the packages and style files have changed), the script will build them with latexmk and then the PDF results will be uploaded to Dropbox via the dbupload.rb script (you should have previously authorized your account using the dropbox-sdk Ruby gem and saved the access token in a dbtoken file in the repo, I still haven't documented how to do it so you'll have to use your imagination).

The script can also detect compilation errors and/or conflict markers (those <<<<HEAD) and open an issue in the repository with the error message and commit where the error was introduced. This is pretty useful if there're a lot of people contributing with different OS and LaTeX installation. It uses ghi to do that, so you should configure authorization in the repository (see the README for details).

Latex_cd can be started as a Debian/Ubuntu service: the install script will store the latexcd service in /etc/init.d/latexcd with the binaries and repository being placed in /opt/latexcd/ (path configurable in latexcd.conf). The service will run as a separate user (ensure that separated user can run RVM, Ruby and Gem) to avoid issues in your server.

Of course, the system is not complete (it's not even fully documented) but it can be useful if you want to make a CI server for your LaTeX repository. Future features could be expansion to new storage services (OneDrive, Mega, Google Drive), support for multiple repositories, and security/access control (currently, the Sinatra server doesn't verify that the request comes from Github and that it's for the correct repository). As always, pull requests are welcome!