From 493b29679b6c04fa9eeaa243457a70c21404c30c Mon Sep 17 00:00:00 2001 From: xunbu Date: Mon, 25 Aug 2025 11:18:02 +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.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-macos.yml | 61 +++++++++++-------------------- 1 file changed, 21 insertions(+), 40 deletions(-) diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index a3b061e..e677bb2 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -1,4 +1,4 @@ -name: Build macOS Application (Universal2) +name: Build macOS Universal2 Application on: workflow_dispatch: @@ -7,7 +7,9 @@ on: jobs: build-macos: - runs-on: macos-latest + # 更改第 1 处:指定使用 macOS 14 (Apple Silicon, arm64) 运行环境 + # 这是构建 universal2 应用的前提 + runs-on: macos-14 steps: # 第 1 步: 检出代码 @@ -35,25 +37,14 @@ jobs: run: | brew install upx - # 第 6 步: 运行 PyInstaller (Universal2 架构) - - name: Build the application with PyInstaller (Universal2) + # 第 6 步: 运行 PyInstaller (macOS universal2 版本) + - name: Build the application with PyInstaller for universal2 run: | - # 设置架构为 universal2 - export ARCHFLAGS="-arch x86_64 -arch arm64" - - # 使用 universal2 标志运行 PyInstaller - uv run pyinstaller lite_mac.spec --noconfirm --target-architecture universal2 + # 更改第 2 处:添加 --target-arch universal2 参数 + # 这个参数会告诉 PyInstaller 构建一个同时支持 Intel 和 Apple Silicon 的应用 + uv run pyinstaller lite_mac.spec --noconfirm --target-arch universal2 - # 第 7 步: 验证二进制文件架构 - - name: Verify universal2 architecture - run: | - # 检查生成的可执行文件是否包含两种架构 - file dist/DocuTranslate-*-mac - lipo -archs dist/DocuTranslate-*-mac - echo "验证二进制文件架构:" - lipo -info dist/DocuTranslate-*-mac - - # 第 8 步: 获取应用版本号 + # 第 7 步: 获取应用版本号 - name: Get application version id: get_version run: | @@ -61,24 +52,22 @@ jobs: echo "VERSION=$VERSION" >> $GITHUB_ENV echo "version=$VERSION" >> $GITHUB_OUTPUT - # 第 9 步: 创建 macOS 应用包结构 (Universal2) + # 第 8 步: 创建 macOS 应用包结构 - name: Create macOS app bundle structure run: | mkdir -p dist/DocuTranslate.app/Contents/MacOS mkdir -p dist/DocuTranslate.app/Contents/Resources # 移动可执行文件 - mv dist/DocuTranslate-*-mac dist/DocuTranslate.app/Contents/MacOS/DocuTranslate + # PyInstaller 生成的 universal2 可执行文件名与 spec 文件中的 name 字段一致 + # 假设 spec 文件中的 name 是 'DocuTranslate',这里可以直接使用 + mv dist/DocuTranslate 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 @@ -96,14 +85,6 @@ jobs: ${{ github.run_number }} CFBundleShortVersionString ${{ env.VERSION }} - CFBundleSupportedPlatforms - - MacOSX - - LSMinimumSystemVersion - 10.15 - LSRequiresNativeExecution - NSHighResolutionCapable @@ -111,14 +92,14 @@ jobs: EOF shell: bash - # 第 10 步: 将 .app 打包成 .dmg 磁盘映像(带版本号) + # 第 9 步: 将 .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-universal2.dmg" + hdiutil create -volname "DocuTranslate Installer" -srcfolder dist/DocuTranslate.app -ov -format UDZO "dist/DocuTranslate-${{ env.VERSION }}-macOS-universal.dmg" - # 第 11 步: 上传 .dmg 文件作为构建产物 - - name: Upload macOS DMG (Universal2) + # 第 10 步: 上传 .dmg 文件作为构建产物 + - name: Upload macOS DMG uses: actions/upload-artifact@v4 with: - name: DocuTranslate-macOS-Universal2 - path: dist/DocuTranslate-${{ env.VERSION }}-macOS-universal2.dmg \ No newline at end of file + name: DocuTranslate-macOS-universal + path: dist/DocuTranslate-${{ env.VERSION }}-macOS-universal.dmg \ No newline at end of file