You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用GitHub Actions部署LaTeX生成的PDF至GitHub Pages遇文件缺失问题

解决GitHub Actions部署LaTeX生成PDF到GitHub Pages时找不到文件的问题

你遇到的问题是部署阶段提示找不到PDF文件,核心原因是actions/deploy-pages的参数配置错误,以下是修复方案:

错误原因分析

在部署步骤中,actions/deploy-pages的artifact_name参数被设置为main.pdf,但这个参数的作用是指定要部署的Pages工件名称,而不是PDF文件名。actions/upload-pages-artifact默认上传的工件名称是github-pages,部署时指定错误的工件名就会导致找不到文件。

修复后的工作流代码

name: Build and Deploy LaTeX document
on:
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4.1.7
      - uses: xu-cheng/latex-action@3.2.0
        with:
          root_file: main.tex
      - uses: actions/upload-artifact@v4.3.3
        with:
          name: main-pdf
          path: main.pdf
  deploy:
    runs-on: ubuntu-latest
    needs: build
    permissions:
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - uses: actions/download-artifact@v4.1.7
        with:
          name: main-pdf
          path: .
      # 可选:添加index.html让GitHub Pages直接跳转或嵌入PDF
      - run: |
          echo '<!DOCTYPE html>
          <html>
            <head>
              <meta http-equiv="refresh" content="0; url=main.pdf">
            </head>
            <body>
              <p>正在跳转至PDF文档,若未跳转请<a href="main.pdf">点击此处</a></p>
            </body>
          </html>' > index.html
      - uses: actions/configure-pages@v5.0.0
      - uses: actions/upload-pages-artifact@v3.0.1
        with:
          path: .
      - uses: actions/deploy-pages@v4.0.5
        with:
          token: ${{ secrets.GH_PAT }}
          # 移除错误的artifact_name参数,默认会识别github-pages工件

关键修改点

  1. 移除actions/deploy-pages中的artifact_name: main.pdf参数,让部署步骤自动使用actions/upload-pages-artifact上传的默认工件(名称为github-pages)。
  2. 可选添加index.html文件:GitHub Pages默认会加载根目录的index.html,添加这个文件可以让访问Pages时自动跳转或嵌入PDF,提升访问体验。

内容的提问来源于stack exchange,提问作者wrong_path

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 08:17:31