Skip to content

Commit

Permalink
Merge branch 'main' into release/v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vonbrank authored Mar 3, 2025
2 parents 0ea2dfa + 0e783be commit e66472b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build-templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ jobs:
matrix:
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
permissions:
contents: write
env:
PYTHONUTF8: ${{ matrix.os == 'windows-latest' && '1' || '' }}
steps:
- uses: szenius/set-timezone@v2.0
with:
timezoneLinux: "Asia/Shanghai"
timezoneMacos: "Asia/Shanghai"
timezoneWindows: "China Standard Time"
- uses: actions/checkout@v4
- name: Checkout Haixing-Hu/latex-chinese-fonts
uses: actions/checkout@v4
Expand All @@ -24,3 +31,17 @@ jobs:
with:
name: templates-build-${{ github.run_id }}-${{ matrix.os }}
path: build/*.pdf
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Deploy PDF files to build branch
if: |
matrix.os == 'windows-latest' &&
(github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' && github.ref == 'refs/heads/main' ||
github.event_name == 'pull_request' && github.base_ref == 'main')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python3 ci/deploy.py
58 changes: 58 additions & 0 deletions ci/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import subprocess
import shutil
import stat
from datetime import datetime

def make_writable(func, path, _):
"""修改文件或目录的权限为可写"""
os.chmod(path, stat.S_IWRITE)
func(path)

# 设置路径
WORKING_DIR = os.getcwd() # 使用当前工作目录
BUILD_DIR = os.path.join(WORKING_DIR, "build")
DEPLOY_DIR = os.path.join(WORKING_DIR, "deploy")

# 确保 deploy 目录存在
os.makedirs(DEPLOY_DIR, exist_ok=True)

# 复制 build 目录下的所有 PDF 文件到 deploy 目录
for filename in os.listdir(BUILD_DIR):
if filename.endswith(".pdf"):
src_file = os.path.join(BUILD_DIR, filename)
dest_file = os.path.join(DEPLOY_DIR, filename)
shutil.copy2(src_file, dest_file)
print(f"Copied {src_file} to {dest_file}")

# 获取当前时间戳
now = datetime.now()
timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
branch = "build"

# 使用 GITHUB_TOKEN 进行认证
github_token = os.getenv("GITHUB_TOKEN")
repo_url = f"https://x-access-token:{github_token}@github.com/hitszosa/universal-hit-thesis.git"

# 切换到部署目录
os.chdir(DEPLOY_DIR)

try:
# 初始化 Git 仓库并提交更改
subprocess.run(["git", "init"])
subprocess.run(["git", "add", "."])
subprocess.run(["git", "commit", "-m", f"previews updated: {timestamp}"])
subprocess.run(["git", "remote", "add", "origin", repo_url])
subprocess.run(["git", "branch", "-M", branch])
subprocess.run(["git", "push", "-f", "origin", f"{branch}:{branch}"])
except subprocess.CalledProcessError as e:
print(f"[deploy.py] Error: {e}")
sys.exit(1)
except Exception as e:
print(f"[deploy.py] Error: {e}")
sys.exit(1)
finally:
os.chdir(WORKING_DIR) # 切换回工作目录
# 删除部署目录(递归修改权限后删除)
shutil.rmtree(DEPLOY_DIR, onerror=make_writable)
print(f"Removed deploy directory: {DEPLOY_DIR}")

0 comments on commit e66472b

Please sign in to comment.