88 lines
2.8 KiB
YAML
88 lines
2.8 KiB
YAML
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.12'
|
|
|
|
# 第 3 步: 安装 uv
|
|
- name: Install uv
|
|
run: |
|
|
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
|
|
|
# 第 4 步: 安装依赖
|
|
- name: Install dependencies with uv
|
|
run: uv sync
|
|
|
|
# 第 5 步: 安装 UPX (macOS 版本)
|
|
- name: Install UPX
|
|
run: |
|
|
brew install upx
|
|
|
|
# 第 6 步: 运行 PyInstaller (macOS 版本)
|
|
- name: Build the application with PyInstaller
|
|
run: |
|
|
uv run pyinstaller lite_mac.spec --noconfirm
|
|
|
|
# 第 7 步: 创建 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
|
|
chmod +x dist/DocuTranslate.app/Contents/MacOS/DocuTranslate
|
|
|
|
# 复制图标文件
|
|
cp DocuTranslate.icns dist/DocuTranslate.app/Contents/Resources/
|
|
|
|
# 创建 Info.plist
|
|
cat > dist/DocuTranslate.app/Contents/Info.plist << EOF
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>CFBundleExecutable</key>
|
|
<string>DocuTranslate</string>
|
|
<key>CFBundleIconFile</key>
|
|
<string>DocuTranslate.icns</string>
|
|
<key>CFBundleIdentifier</key>
|
|
<string>com.yourcompany.DocuTranslate</string>
|
|
<key>CFBundleName</key>
|
|
<string>DocuTranslate</string>
|
|
<key>CFBundleVersion</key>
|
|
<string>${{ github.run_number }}</string>
|
|
<key>CFBundleShortVersionString</key>
|
|
<string>$(python -c "import docutranslate; print(docutranslate.__version__)")</string>
|
|
<key>NSHighResolutionCapable</key>
|
|
<true/>
|
|
</dict>
|
|
</plist>
|
|
EOF
|
|
shell: bash
|
|
|
|
# 第 8 步: 直接上传 .app 文件夹作为构建产物
|
|
- name: Upload macOS application
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: DocuTranslate-macOS
|
|
path: dist/DocuTranslate.app |