Continuous Deployment of LaTeX Documents

10 Feb 2022

I store my resume as a source .tex file in a GitHub repository. When I need to send it to someone, I either have to find the most recent version in my emails or go through the process of rebuilding it.

I wanted to set up a job that would automatically build the final .pdf file everytime I push an updated version. That way I would always know where to look for it. For the sake of this excercise, I will ignore the fact that just syncing your repo with Overleaf is by far the easiest option.

Building the Document

My initial idea was to start with an Ubuntu runner, set up a minimal TexLive environment and then use texliveonfly to install just the packages required by the document.

apt-get install texlive
tlmgr install texliveonfly
texliveonfly cv_en/jan_cervenka.tex 
pdflatex cv_en/jan_cervenka.tex

When I was not able to get the tlmgr package manager working, I resorted to a more straightforward approach. I run the job in a container using texlive/texlive:latest-full Docker image that includes pretty much every LaTeX package you could ever need. The downside is that the compressed image is over 2 GB which means it takes some time to start everything up. The average run duration of the entire job is under 2 minutes, which I think is still acceptable.

Publishing the Document

The built .pdf needs to be somehow published. This can be done in two ways (that I know of):

I use both approaches (there are pre-made actions available: artifact, release). Each build produces the resume as an artifact and each new tag triggers a release.

git tag v2022
git push -u origin v2022

Important detail is that artifacts are retained only for 90 days.

Putting It All Together

Because of the pre-made actions handling the most complex parts, the entire job is very short.

name: Build

on: push

jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: texlive/texlive:latest-full

    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Build Resume
      run:
        pdflatex cv_en/jan_cervenka.tex
    - name: Upload Artifacts
      uses: actions/upload-artifact@v3
      with:
        name: resume-build
        path: |
          jan_cervenka.pdf
          jan_cervenka.log
    - name: Release
      uses: softprops/action-gh-release@v1
      if: startsWith(github.ref, 'refs/tags/')
      with:
        files: |
          jan_cervenka.pdf
          jan_cervenka.log