Generate PDF and upload to official website server #105
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Generate PDF and upload to official website server | |
on: | |
schedule: | |
# 每天凌晨 3 点(北京时间)运行 | |
- cron: "0 19 * * *" | |
# 添加 workflow_dispatch 以允许手动触发 | |
workflow_dispatch: | |
jobs: | |
generate-pdf-and-upload: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: 检出仓库代码 | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
ref: master | |
# Step 2: 下载必要的可执行文件和字体文件 | |
- name: Download binaries and fonts | |
run: | | |
mkdir -p ./bin | |
mkdir -p ./fonts | |
wget -P ./bin ${{ secrets.MERICO_DOCS_ASSETS_ALIYUN_OSS_PATH }}bin/pandoc.deb | |
wget -P ./fonts ${{ secrets.MERICO_DOCS_ASSETS_ALIYUN_OSS_PATH }}fonts/wenquanyi-micro-hei-mono-regular.ttf | |
wget -P ./fonts ${{ secrets.MERICO_DOCS_ASSETS_ALIYUN_OSS_PATH }}fonts/wenquanyi-micro-hei-regular.ttf | |
# Step 3: 安装 pandoc | |
- name: Install pandoc | |
run: | | |
sudo dpkg -r pandoc | |
sudo dpkg -i ./bin/pandoc.deb | |
pandoc --version | |
# Step 4: 安装 TinyTeX | |
- name: Install dependencies | |
run: | | |
sudo apt-get update | |
chmod +x ./scripts/install_tinytex_bin_unix.sh | |
./scripts/install_tinytex_bin_unix.sh | |
env: | |
TINYTEX_INSTALLER: "TinyTeX-2" | |
# Step 5: 将 TinyTeX 添加到 PATH | |
- name: Add TinyTeX to PATH | |
run: | | |
sudo ~/.TinyTeX/bin/x86_64-linux/tlmgr path add | |
export PATH="${HOME}/.TinyTeX/bin/x86_64-linux:$PATH" | |
tlmgr --version | |
echo "${HOME}/.TinyTeX/bin/x86_64-linux" >> $GITHUB_PATH | |
# Step 6: 安装字体 | |
- name: Install fonts | |
run: | | |
sudo mkdir -p /usr/share/fonts/truetype/custom | |
sudo cp ./fonts/*.ttf /usr/share/fonts/truetype/custom/ | |
sudo fc-cache -f -v | |
# Step 7: 设置 Python 环境 | |
- name: Set up Python environment | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ">=3.10" | |
# Step 8: 根据 toc 将所有文档合并为一整篇 markdown 文档 | |
- name: Merge by toc | |
run: | | |
python scripts/merge_by_toc.py | |
# Step 9: 将刚才合并好的文档转换为 pdf 文档 | |
- name: Generate pdf | |
run: | | |
chmod +x ./scripts/generate_pdf.sh | |
./scripts/generate_pdf.sh | |
# Step 10: 设置 SSH 环境,为接下来的 scp 做准备 | |
- name: Set up SSH environment | |
run: | | |
mkdir -p ~/.ssh | |
echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config | |
echo "${{ secrets.OFFICIAL_WEBSITE_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
# Step 11: 将生成的 pdf 文件传输到官网服务器 | |
- name: Copy files to official website server using SCP | |
run: | | |
scp -o ServerAliveInterval=60 merico_ee_guideline.pdf ${{ secrets.OFFICIAL_WEBSITE_PDF_TARGET }} | |
# Step 12: 清理 SSH key | |
- name: Clean up SSH key | |
run: rm -f ~/.ssh/id_rsa |