From 2d295b2db73df6e0a9db468dfb2c971f701a6269 Mon Sep 17 00:00:00 2001 From: xunbu Date: Mon, 25 Aug 2025 11:08:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E7=94=9F=E6=88=90universal2?= =?UTF-8?q?=E6=9E=B6=E6=9E=84=E5=8C=851.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-macos.yml | 99 +++++++++++++++---------------- 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index 4beda22..a3b061e 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -1,4 +1,4 @@ -name: Build macOS Universal2 Application +name: Build macOS Application (Universal2) on: workflow_dispatch: @@ -6,7 +6,7 @@ on: types: [created] jobs: - build-macos-universal2: + build-macos: runs-on: macos-latest steps: @@ -14,18 +14,11 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - # 第 2 步: 设置多架构的 Python 环境 - - name: Set up Python x86_64 + # 第 2 步: 设置 Python 环境 + - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.12' - architecture: 'x64' - - - name: Set up Python arm64 - uses: actions/setup-python@v5 - with: - python-version: '3.12' - architecture: 'arm64' # 第 3 步: 安装 uv - name: Install uv @@ -33,61 +26,59 @@ jobs: curl -LsSf https://astral.sh/uv/install.sh | sh echo "$HOME/.cargo/bin" >> $GITHUB_PATH - # 第 4 步: 安装 x86_64 依赖并构建 - - name: Install dependencies and build for x86_64 - env: - ARCH: x86_64 - run: | - echo "Building for x86_64" - /usr/bin/arch -x86_64 python3.12 -m venv .venv-x86_64 - . .venv-x86_64/bin/activate - uv sync - uv run pyinstaller lite_mac.spec --noconfirm --distpath dist_x86_64 + # 第 4 步: 安装依赖 + - name: Install dependencies with uv + run: uv sync - # 第 5 步: 安装 arm64 依赖并构建 - - name: Install dependencies and build for arm64 - env: - ARCH: arm64 - run: | - echo "Building for arm64" - /usr/bin/arch -arm64 python3.12 -m venv .venv-arm64 - . .venv-arm64/bin/activate - uv sync - uv run pyinstaller lite_mac.spec --noconfirm --distpath dist_arm64 - - # 第 6 步: 安装 UPX + # 第 5 步: 安装 UPX (macOS 版本) - name: Install UPX - run: brew install upx - - # 第 7 步: 合并为 Universal 2 二进制文件 - - name: Create Universal 2 binary run: | - lipo -create -output dist/DocuTranslate-universal \ - dist_x86_64/DocuTranslate-*-mac \ - dist_arm64/DocuTranslate-*-mac - chmod +x dist/DocuTranslate-universal + brew install upx + + # 第 6 步: 运行 PyInstaller (Universal2 架构) + - name: Build the application with PyInstaller (Universal2) + run: | + # 设置架构为 universal2 + export ARCHFLAGS="-arch x86_64 -arch arm64" + + # 使用 universal2 标志运行 PyInstaller + uv run pyinstaller lite_mac.spec --noconfirm --target-architecture universal2 + + # 第 7 步: 验证二进制文件架构 + - name: Verify universal2 architecture + run: | + # 检查生成的可执行文件是否包含两种架构 + file dist/DocuTranslate-*-mac + lipo -archs dist/DocuTranslate-*-mac + echo "验证二进制文件架构:" + lipo -info dist/DocuTranslate-*-mac # 第 8 步: 获取应用版本号 - name: Get application version id: get_version run: | - VERSION=$(python3.12 -c "import docutranslate; print(docutranslate.__version__)") + VERSION=$(python -c "import docutranslate; print(docutranslate.__version__)") echo "VERSION=$VERSION" >> $GITHUB_ENV echo "version=$VERSION" >> $GITHUB_OUTPUT - # 第 9 步: 创建 macOS 应用包结构 + # 第 9 步: 创建 macOS 应用包结构 (Universal2) - name: Create macOS app bundle structure run: | mkdir -p dist/DocuTranslate.app/Contents/MacOS mkdir -p dist/DocuTranslate.app/Contents/Resources - # 移动合并后的 Universal 2 可执行文件 - mv dist/DocuTranslate-universal dist/DocuTranslate.app/Contents/MacOS/DocuTranslate + # 移动可执行文件 + mv dist/DocuTranslate-*-mac dist/DocuTranslate.app/Contents/MacOS/DocuTranslate + chmod +x dist/DocuTranslate.app/Contents/MacOS/DocuTranslate + + # 验证应用包内的二进制文件架构 + echo "验证应用包内二进制文件架构:" + lipo -info dist/DocuTranslate.app/Contents/MacOS/DocuTranslate # 复制图标文件 cp DocuTranslate.icns dist/DocuTranslate.app/Contents/Resources/ - # 创建 Info.plist + # 创建 Info.plist (添加架构信息) cat > dist/DocuTranslate.app/Contents/Info.plist << EOF @@ -105,6 +96,14 @@ jobs: ${{ github.run_number }} CFBundleShortVersionString ${{ env.VERSION }} + CFBundleSupportedPlatforms + + MacOSX + + LSMinimumSystemVersion + 10.15 + LSRequiresNativeExecution + NSHighResolutionCapable @@ -115,11 +114,11 @@ jobs: # 第 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-universal.dmg" + hdiutil create -volname "DocuTranslate Installer" -srcfolder dist/DocuTranslate.app -ov -format UDZO "dist/DocuTranslate-${{ env.VERSION }}-macOS-universal2.dmg" # 第 11 步: 上传 .dmg 文件作为构建产物 - - name: Upload macOS DMG + - name: Upload macOS DMG (Universal2) uses: actions/upload-artifact@v4 with: - name: DocuTranslate-macOS-universal - path: dist/DocuTranslate-${{ env.VERSION }}-macOS-universal.dmg \ No newline at end of file + name: DocuTranslate-macOS-Universal2 + path: dist/DocuTranslate-${{ env.VERSION }}-macOS-universal2.dmg \ No newline at end of file