前几天,我想整理一下自己的简历信息,按照以往的习惯,用 LaTeX 编写的。 但是当我想发布到网上,以便分享简历对应的链接时,我需要将 PDF 上传到某个地方。

简历对应的 PDF 文件是二进制文件,我不想在仓库中直接存储。 所以想利用 GitHub Actions 自动编译 LaTeX 文件,并将生成的 PDF 文件发布到 GitHub Pages 上。

经过一番测试,利用 xu-cheng/latex-action 成功在 Actions 中编译出了 PDF 文件。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# https://github.com/ringsaturn/latex-to-pages-demo/blob/main/.github/workflows/build.yml
name: Compile

concurrency:
  group: "pages"
  cancel-in-progress: true

on:
  push:
    branches: main
  pull_request:
    branches: main

jobs:
  make-pdf:
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
      - uses: actions/checkout@v4
      - name: Compile LaTeX (XeLaTeX)
        uses: xu-cheng/latex-action@v4
        with:
          root_file: |
            main-en.tex
            main-zh.tex
            main-ja.tex

          texlive_version: 2025
          latexmk_use_xelatex: true  # To support CJK characters
          extra_system_packages: "fontconfig font-noto-cjk font-noto-cjk-extra"

      - name: Move PDFs to public directory
        run: |
          mv *.pdf public/

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: public/

  deploy:
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    permissions:
      contents: read
      pages: write
      id-token: write
    if: github.ref == 'refs/heads/main'
    needs: make-pdf
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4

示例仓库地址为 ringsaturn/latex-to-pages-demo

效果: