build(mac): add x64 support via universal2 architecture, add tc and ja #19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build macOS App | |
| on: | |
| push: | |
| branches: [ "main", "master" ] | |
| paths: | |
| - 'Mac/**' | |
| - '.github/workflows/build-mac.yml' | |
| - 'Windows/Assets/CarpeCast-logo.png' | |
| workflow_dispatch: # 允许手动触发打包 | |
| jobs: | |
| build: | |
| runs-on: macos-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pyinstaller pillow | |
| - name: Compile Swift Helper | |
| working-directory: ./Mac | |
| run: | | |
| # 分别编译 x86_64 和 arm64 架构的 Swift 二进制文件,并使用 lipo 合并为 Universal 2 通用程序 | |
| swiftc nowplaying.swift -target x86_64-apple-macosx10.15 -o mac_nowplaying_x86_64 | |
| swiftc nowplaying.swift -target arm64-apple-macosx11.0 -o mac_nowplaying_arm64 | |
| lipo -create -output mac_nowplaying mac_nowplaying_x86_64 mac_nowplaying_arm64 | |
| chmod +x mac_nowplaying | |
| - name: Build with PyInstaller | |
| working-directory: ./Mac | |
| run: | | |
| # 使用 Pillow 无损将 PNG 转换为 macOS 专用的 .icns 格式 (绕过 sips 的色彩配置文件报错) | |
| python -c "from PIL import Image; Image.open('../Windows/Assets/CarpeCast-logo.png').resize((512,512)).save('icon.icns')" | |
| # 提取版本号和 Hash | |
| VERSION=$(grep -oE 'version = "[^"]+"' sender.py | head -1 | cut -d'"' -f2) | |
| HASH=$(git rev-parse --short HEAD) | |
| # 生成 build_info.json 注入版本信息 | |
| echo "{\"version\": \"$VERSION\", \"commit\": \"$HASH\"}" > build_info.json | |
| # 使用 --windowed 打包,指定名字、图标并添加附加文件,并打包为 Universal 2 通用架构(支持 x64 和 arm64) | |
| pyinstaller --target-arch universal2 --windowed --name "CarpeCast" --icon=icon.icns --add-binary "mac_nowplaying:." --add-data "build_info.json:." sender.py | |
| # 压缩 .app 以防 GitHub Actions 上传时吞掉顶层目录,文件名加上版本号和 Hash | |
| cd dist | |
| ZIP_NAME="CarpeCast-Mac-v${VERSION}-${HASH}.zip" | |
| zip -ry "$ZIP_NAME" CarpeCast.app | |
| echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV | |
| - name: Upload Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: CarpeCast-Mac | |
| path: Mac/dist/CarpeCast-Mac-*.zip |