name: Build LaTeX document

on:
  push:
    branches:
      - master

jobs:
  build:
    name: OI-Wiki LaTeX Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Build the LaTeX document
        uses: xu-cheng/latex-action@v3
        with:
          latexmk_use_xelatex: true
          latexmk_shell_escape: true
          args: "-pdf -file-line-error -halt-on-error -interaction=batchmode -8bit"
          extra_system_packages: |
            unzip
            wget
            curl
            coreutils
            nodejs
            npm
            imagemagick
            libwebp
            librsvg
            git
            python3
            py3-pygments
            libxml2
            sqlite-dev
            font-noto
            font-noto-cjk
          pre_compile: |
            umask 0 && npm config set cache /tmp/.npm
            wget "https://mirror.math.princeton.edu/pub/CTAN/fonts/cm-unicode.zip" --no-check-certificate
            git clone https://github.com/googlefonts/RobotoMono
            unzip  ./cm-unicode.zip
            cp -r cm-unicode/fonts/otf/* RobotoMono/fonts/ttf/* /usr/share/fonts
            fc-cache
            git clone https://github.com/OI-wiki/OI-Wiki-export.git --depth=1
            cd ./OI-Wiki-export/remark-snippet
            npm i
            cd ../..
            cd ./OI-Wiki-export/remark-latex
            npm i
            cd ../..
            cd ./OI-Wiki-export/oi-wiki-export
            python3 increase-mem-limit.py
            fmtutil-sys --all
            npm i
            node index.js ../../
          root_file: |
            oi-wiki-export.tex
      - uses: actions/upload-artifact@v4
        with:
          name: OI-wiki-latex-export
          path: ./OI-Wiki-export/oi-wiki-export/oi-wiki-export.pdf
