diff --git a/.github/workflows/build-macos-x86.yml b/.github/workflows/build-macos-x86.yml new file mode 100644 index 0000000..bc6105f --- /dev/null +++ b/.github/workflows/build-macos-x86.yml @@ -0,0 +1,108 @@ +name: Build macOS X86 Application + +on: + # 允许手动触发工作流 + workflow_dispatch: + # 当在 GitHub 上创建新的 release 时自动触发 + release: + types: [created] + +jobs: + build-macos: + # 步骤 1: 指定运行环境为 macOS 14 (Intel) + # 使用 xlarge runner 确保是 Intel 架构 + runs-on: macos-14-xlarge + + steps: + # 步骤 2: 检出你的代码库 + - name: Checkout repository + uses: actions/checkout@v4 + + # 步骤 3: 设置 Python 环境 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + # 步骤 4: 安装 uv (一个快速的 Python 包安装器) + - name: Install uv + run: | + curl -LsSf https://astral.sh/uv/install.sh | sh + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + + # 步骤 5: 使用 uv 安装项目依赖 + - name: Install dependencies with uv + run: uv sync + + # 步骤 6: 安装 UPX (用于压缩可执行文件) + - name: Install UPX + run: | + brew install upx + + # 步骤 7: 运行 PyInstaller 构建 x86_64 应用 + - name: Build the x86_64 application with PyInstaller + run: | + uv run pyinstaller lite_mac_x86_64.spec --noconfirm + + # 步骤 8: 从代码中获取应用版本号 + - name: Get application version + id: get_version + run: | + VERSION=$(python -c "import docutranslate; print(docutranslate.__version__)") + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "version=$VERSION" >> $GITHUB_OUTPUT + + # 步骤 9: 创建标准的 macOS .app 包结构 + - name: Create macOS app bundle structure + run: | + # 创建必要的目录 + mkdir -p dist/DocuTranslate.app/Contents/MacOS + mkdir -p dist/DocuTranslate.app/Contents/Resources + + # 移动可执行文件到 .app 包中(注意文件名包含 -intel) + mv dist/DocuTranslate-*-mac-intel dist/DocuTranslate.app/Contents/MacOS/DocuTranslate + chmod +x dist/DocuTranslate.app/Contents/MacOS/DocuTranslate + + # 复制应用图标 + cp DocuTranslate.icns dist/DocuTranslate.app/Contents/Resources/ + + # 动态创建 Info.plist 文件,明确指定 x86_64 架构 + cat > dist/DocuTranslate.app/Contents/Info.plist << EOF + + + + + CFBundleExecutable + DocuTranslate + CFBundleIconFile + DocuTranslate.icns + CFBundleIdentifier + com.yourcompany.DocuTranslate + CFBundleName + DocuTranslate + CFBundleVersion + ${{ github.run_number }} + CFBundleShortVersionString + ${{ env.VERSION }} + LSArchitecturePriority + + x86_64 + + NSHighResolutionCapable + + + + EOF + shell: bash + + # 步骤 10: 将 .app 文件打包成 .dmg 磁盘映像 + - name: Create DMG Disk Image with version + run: | + hdiutil create -volname "DocuTranslate Installer" -srcfolder dist/DocuTranslate.app -ov -format UDZO "dist/DocuTranslate-${{ env.VERSION }}-macOS-x86_64.dmg" + + # 步骤 11: 上传 .dmg 文件作为构建产物 + - name: Upload macOS DMG + uses: actions/upload-artifact@v4 + with: + name: DocuTranslate-macOS-x86_64 + path: dist/DocuTranslate-${{ env.VERSION }}-macOS-x86_64.dmg \ No newline at end of file diff --git a/lite_mac_x86_64.spec b/lite_mac_x86_64.spec new file mode 100644 index 0000000..a777d62 --- /dev/null +++ b/lite_mac_x86_64.spec @@ -0,0 +1,56 @@ +# -*- mode: python ; coding: utf-8 -*- +from PyInstaller.utils.hooks import collect_data_files +import docutranslate + +datas = [ + ('./docutranslate/static', 'docutranslate/static'), + ('./docutranslate/template', 'docutranslate/template') +] + +# 只收集 pygments 的数据文件 +datas += collect_data_files('pygments') + +hiddenimports = [ + 'markdown.extensions.tables', + 'pymdownx.arithmatex', + 'pymdownx.superfences', + 'pymdownx.highlight', + 'pygments' +] + +a = Analysis( + ['docutranslate/app.py'], + pathex=[], + binaries=[], + datas=datas, + hiddenimports=hiddenimports, + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=["docling","docutranslate.converter.x2md.converter_docling"], + noarchive=False, + target_arch='x86_64', + optimize=0, +) + +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + a.binaries, + a.datas, + [], + name=f'DocuTranslate-{docutranslate.__version__}-mac', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + runtime_tmpdir=None, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + codesign_identity=None, + entitlements_file=None, + icon='DocuTranslate.icns', +) \ No newline at end of file