name: Build and Release PDF on: push: tags: - 'v*' - 'release*' workflow_dispatch: permissions: contents: write jobs: build-pdf: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install dependencies run: | # Install pandoc wget -q https://github.com/jgm/pandoc/releases/download/3.1.11/pandoc-3.1.11-1-amd64.deb sudo dpkg -i pandoc-3.1.11-1-amd64.deb rm pandoc-3.1.11-1-amd64.deb # Install TeX Live with XeLaTeX and Chinese support sudo apt-get update sudo apt-get install -y \ texlive-xetex \ texlive-lang-chinese \ texlive-fonts-recommended \ texlive-fonts-extra \ fonts-noto-cjk \ fonts-noto-cjk-extra # Verify installations pandoc --version xelatex --version - name: Build PDF run: | chmod +x bin/pdf bin/preprocess-epub.py mkdir -p output output/temp # Preprocess Markdown files python3 bin/preprocess-epub.py content/zh output/temp # Generate PDF with CI-specific fonts (Noto CJK) pandoc -o output/ddia.pdf \ --metadata-file=metadata.yaml \ -H bin/header-ci.tex \ --toc \ --toc-depth=2 \ --top-level-division=chapter \ --file-scope=true \ --pdf-engine=xelatex \ -V geometry:margin=1in \ -V linestretch=1.5 \ output/temp/_index.md \ output/temp/preface.md \ output/temp/part-i.md \ output/temp/ch1.md \ output/temp/ch2.md \ output/temp/ch3.md \ output/temp/ch4.md \ output/temp/part-ii.md \ output/temp/ch5.md \ output/temp/ch6.md \ output/temp/ch7.md \ output/temp/ch8.md \ output/temp/ch9.md \ output/temp/part-iii.md \ output/temp/ch10.md \ output/temp/ch11.md \ output/temp/ch12.md \ output/temp/ch13.md \ output/temp/ch14.md \ output/temp/colophon.md \ output/temp/glossary.md rm -rf output/temp if [ ! -f "output/ddia.pdf" ]; then echo "Error: PDF file was not created" exit 1 fi ls -lh output/ddia.pdf file output/ddia.pdf - name: Upload PDF artifact uses: actions/upload-artifact@v4 with: name: ddia-pdf path: output/ddia.pdf retention-days: 30 - name: Create/Update Release if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v1 with: files: output/ddia.pdf name: ${{ github.ref_name }} body: | ## 《设计数据密集型应用》PDF 版本 此版本为自动生成的 PDF 电子书。 ### 文件信息 - 文件名: `ddia.pdf` - 生成时间: ${{ github.event.head_commit.timestamp }} - 标签: ${{ github.ref_name }} ### 依赖工具 - Pandoc 3.1.11 - XeLaTeX (TeX Live) - 中文字体: Noto CJK ### 本地生成 如需本地生成 PDF,请确保安装以下依赖: ```bash # macOS brew install pandoc brew install --cask mactex # Ubuntu/Debian sudo apt install pandoc texlive-xetex texlive-lang-chinese # 生成 PDF make pdf ``` draft: false prerelease: false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}