One of the main reasons why I started this blog was to write about my projects and some interesting things that come along the way. I guess it takes a pandemic to make me write.
A couple of weeks ago, I was reading a few articles on adding continuous integration and deployment to my projects. In the midst of it, I found this article in which the author talks about setting up a CI pipeline to automate building PDFs from LaTex projects on overleaf. He elaborates on the mistakes and discoveries made while exploring GitLab’s repository mirror feature.
As someone who uses LaTex projects on overleaf to make a resume, I thought of automating the process as well but using GitHub and Travis CI. I had some experience with Travis CI as I used it for another project of mine, xkcd (a cli tool to get xkcd comics right from the terminal). The idea in the article above was to automate the extraction of the source code of the project from overleaf, and then build it in GitLab. I was not able to find anything similar to GitLab’s repository mirror feature for GitHub which checks the source of the repository every hour. I relied on Travis
cronjobs for this.
Now, I don’t update my resume every hour but I do it once a month or so. My initial pipeline to build the resume and upload it on my website was something like this:
.texfiles on Overleaf and compile to
Commit the changes and deploy to GitHub pages.
As you can see, we can do better.
Similar to GitLab’s feature, I thought of using a cronjob to run a build every week which compiles the
.tex project into the pdf and pushes the changes back to
pdf/rounakvyas.pdf based on the most recent commit. Overleaf syncs with GitHub seamlessly and also provides a Git URL to access the source code of the project. Awesome.
There are a lot of cli tools that can compile
.tex documents to
Now that I was able to compile the documents. I needed a way to update the resume during each build, i.e, delete the older version and move the updated resume in
pdf/rounakvyas.pdf. A simple bash script did the job.
This was the most irritating part. The script to compile the document and move it to
pdf/rounakvyas.pdf was ready. I just had to make Travis CI automatically push the changes to the master branch.
after_sucess, a hook that is called when the build succeeds. I replaced the
deploy section in
.travis.yml with it.
Another bash script was required to add the changes to GitHub.
Now, a lot of things are happening in this piece of code. Firstly, One can push to GitHub automatically using a Github deploy key or a personal access token. It was easier to encrypt a personal token on Travis so I went with that.
For this, one must generate a personal access token on GitHub. This secret token needs to be stored somewhere but cannot be stored directly in
.travis.yml. If you’re using Travis on public GitHub repositories, your build log is publicly visible. If there are any Git related errors, it is possible that the origin URL (with your GitHub personal access token with access to ALL your public repositories) may be logged, which is a huge security risk.
Travis supports encrypted environment variables and can be added using Travis Command Line Client. Once this is done,
.travis.yml stores the encrypted GitHub token. Now, that we have the access token available on Travis, we can write the script(above) to push the changes to GitHub.
A detailed explanation of this process can be found here.
.travis.yml file looked something like this:
Now, all I have to do is edit the document on overleaf, push to GitHub and the
Here is the link to the GitHub repository.
.tex project. I can push the
Anyway, that was it. I spent an entire day to automate 4-5 minutes of every month. I guess this is how it is during the quarantine.
If something was not clear or right in the above post or if something could have been done in a much more efficient manner then do let me know. :)