diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml new file mode 100644 index 0000000..f5aeb86 --- /dev/null +++ b/.github/workflows/build-macos.yml @@ -0,0 +1,64 @@ +# .github/workflows/build-macos.yml + +name: Build macOS Application + +on: + push: + branches: [ "main" ] + workflow_dispatch: + release: + types: [created] + +jobs: + build-macos: + runs-on: macos-latest + + steps: + # 第 1 步: 检出你的代码 + - name: Checkout repository + uses: actions/checkout@v4 + + # 第 2 步: 设置 Python 环境 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' # 匹配你的 pyproject.toml + + # 第 3 步: 安装 uv (超高速的包管理器) + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + - name: Add uv to PATH + run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH + + # 第 4 步: 使用 uv 安装项目及开发依赖 + # . --dev 会安装 pyproject.toml 中 [dependencies] 和 [dependency-groups].dev 的所有包 + - name: Install dependencies with uv + run: uv pip install ". --dev" + + # 第 5 步: 运行 PyInstaller + - name: Build the application with PyInstaller + # 使用你的 macOS spec 文件 + run: pyinstaller lite_mac.spec --noconfirm + + # 第 6 步: 创建 DMG 磁盘映像 (macOS 标准分发格式) + - name: Install create-dmg + run: brew install create-dmg + - name: Create DMG + run: | + create-dmg \ + --volname "DocuTranslate Installer" \ + --window-pos 200 120 \ + --window-size 600 400 \ + --icon-size 100 \ + --icon "DocuTranslate.app" 200 190 \ + --hide-extension "DocuTranslate.app" \ + --app-drop-link 400 190 \ + "dist/DocuTranslate.dmg" \ + "dist/DocuTranslate.app" + + # 第 7 步: 上传构建产物 (DMG 文件) + - name: Upload macOS build artifact + uses: actions/upload-artifact@v4 + with: + name: DocuTranslate-macOS + path: dist/DocuTranslate.dmg \ No newline at end of file diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml new file mode 100644 index 0000000..ffcdfd2 --- /dev/null +++ b/.github/workflows/build-windows.yml @@ -0,0 +1,60 @@ +# .github/workflows/build-windows.yml + +name: Build Windows Application + +on: + push: + branches: [ "main" ] + workflow_dispatch: + release: + types: [created] + +jobs: + build-windows: + runs-on: windows-latest + + steps: + # 第 1 步: 检出你的代码 + - name: Checkout repository + uses: actions/checkout@v4 + + # 第 2 步: 设置 Python 环境 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + # 第 3 步: 安装 uv (Windows 版) + - name: Install uv + run: powershell -c "irm https://astral.sh/uv/install.ps1 | iex" + - name: Add uv to PATH + run: echo "$env:APPDATA\uv\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + + # 第 4 步: 使用 uv 安装项目及开发依赖 + - name: Install dependencies with uv + run: uv pip install ". --dev" + + # 第 5 步: 安装 UPX (用于压缩 exe) + - name: Install UPX + run: | + Invoke-WebRequest -Uri "https://github.com/upx/upx/releases/download/v4.2.4/upx-4.2.4-win64.zip" -OutFile "upx.zip" + Expand-Archive -Path "upx.zip" -DestinationPath "upx" + echo "$((Get-Item -Path ".\upx\*\").FullName)" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + shell: powershell + + # 第 6 步: 运行 PyInstaller + - name: Build the application with PyInstaller + # 使用你的 Windows spec 文件 + run: pyinstaller lite.spec --noconfirm + + # 第 7 步: 将单个 exe 文件打包成 .zip + - name: Package executable into a zip file + run: Compress-Archive -Path dist/DocuTranslate.exe -DestinationPath dist/DocuTranslate-Windows.zip + shell: powershell + + # 第 8 步: 上传构建产物 (Zip 文件) + - name: Upload Windows build artifact + uses: actions/upload-artifact@v4 + with: + name: DocuTranslate-Windows + path: dist/DocuTranslate-Windows.zip \ No newline at end of file diff --git a/DocuTranslate.icns b/DocuTranslate.icns new file mode 100644 index 0000000..fa415b0 Binary files /dev/null and b/DocuTranslate.icns differ diff --git a/lite_mac.spec b/lite_mac.spec new file mode 100644 index 0000000..e33b657 --- /dev/null +++ b/lite_mac.spec @@ -0,0 +1,87 @@ +# -*- mode: python ; coding: utf-8 -*- + +# 导入 os 模块以更好地处理路径 +import os +from PyInstaller.utils.hooks import collect_all + +# --- 数据文件和二进制文件 --- +# 路径分隔符已更正为 '/',这在所有平台上都更具兼容性 +datas = [ + ('./docutranslate/static', 'docutranslate/static'), + ('./docutranslate/template', 'docutranslate/template') +] +binaries = [] +hiddenimports=['markdown.extensions.tables','pymdownx.arithmatex','pymdownx.superfences','pymdownx.highlight','pygments'] + +# 使用 collect_all 来收集依赖 +# 这部分代码是跨平台的,无需修改 +for i in ['pygments']: + tmp_ret = collect_all(i) + datas += tmp_ret[0] + binaries += tmp_ret[1] + hiddenimports += tmp_ret[2] + +# --- 分析阶段 --- +a = Analysis( + # 【修改 1】: 使用正斜杠 '/' 作为路径分隔符 + ['docutranslate/app.py'], + pathex=[], + binaries=binaries, + datas=datas, + hiddenimports=hiddenimports, + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=["docling","docutranslate.converter.x2md.converter_docling"], + noarchive=False, + optimize=0, +) + +pyz = PYZ(a.pure) + +# --- EXE 和 COLLECT 阶段 --- +# EXE 仅创建 Unix 可执行文件 +exe = EXE( + pyz, + a.scripts, + [], # binaries 和 datas 移到下面的 BUNDLE/COLLECT 中 + [], + name='DocuTranslate', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + runtime_tmpdir=None, + # 【修改 2】: 如果是 GUI 应用,建议设为 False + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch='universal2', # 推荐 'universal2' 以支持 Apple Silicon 和 Intel + codesign_identity=None, + entitlements_file=None, +) + +# --- BUNDLE 阶段 (macOS 核心) --- +# 【修改 3】: 使用 BUNDLE 创建 .app 包,而不是单独的 EXE +# 这将生成一个标准的 macOS 应用程序 +app = BUNDLE( + exe, + name='DocuTranslate.app', + # 【修改 4】: 使用 .icns 格式的图标 + icon='DocuTranslate.icns', + bundle_identifier='cc.xunbu.docutranslate', # 推荐设置一个唯一的包标识符 + info_plist={ + 'NSHighResolutionCapable': 'True', + 'NSPrincipalClass': 'NSApplication', + 'NSAppleScriptEnabled': False, + 'CFBundleDisplayName': 'DocuTranslate', + 'CFBundleName': 'DocuTranslate', + 'CFBundleVersion': '1.0.0', + 'CFBundleShortVersionString': '1.0', + 'NSHumanReadableCopyright': 'Copyright © 2023 Your Name. All rights reserved.' + } +) + +# 将 a.datas 和 a.binaries 添加到 .app 包中 +app.datas += a.datas +app.binaries += a.binaries \ No newline at end of file