添加github actions
This commit is contained in:
64
.github/workflows/build-macos.yml
vendored
Normal file
64
.github/workflows/build-macos.yml
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
# .github/workflows/build-macos.yml
|
||||
|
||||
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.11' # 匹配你的 pyproject.toml
|
||||
|
||||
# 第 3 步: 安装 uv (超高速的包管理器)
|
||||
- name: Install uv
|
||||
run: curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
- name: Add uv to PATH
|
||||
run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
||||
|
||||
# 第 4 步: 使用 uv 安装项目及开发依赖
|
||||
# . --dev 会安装 pyproject.toml 中 [dependencies] 和 [dependency-groups].dev 的所有包
|
||||
- name: Install dependencies with uv
|
||||
run: uv pip install ". --dev"
|
||||
|
||||
# 第 5 步: 运行 PyInstaller
|
||||
- name: Build the application with PyInstaller
|
||||
# 使用你的 macOS spec 文件
|
||||
run: pyinstaller lite_mac.spec --noconfirm
|
||||
|
||||
# 第 6 步: 创建 DMG 磁盘映像 (macOS 标准分发格式)
|
||||
- name: Install create-dmg
|
||||
run: brew install create-dmg
|
||||
- name: Create DMG
|
||||
run: |
|
||||
create-dmg \
|
||||
--volname "DocuTranslate Installer" \
|
||||
--window-pos 200 120 \
|
||||
--window-size 600 400 \
|
||||
--icon-size 100 \
|
||||
--icon "DocuTranslate.app" 200 190 \
|
||||
--hide-extension "DocuTranslate.app" \
|
||||
--app-drop-link 400 190 \
|
||||
"dist/DocuTranslate.dmg" \
|
||||
"dist/DocuTranslate.app"
|
||||
|
||||
# 第 7 步: 上传构建产物 (DMG 文件)
|
||||
- name: Upload macOS build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: DocuTranslate-macOS
|
||||
path: dist/DocuTranslate.dmg
|
||||
60
.github/workflows/build-windows.yml
vendored
Normal file
60
.github/workflows/build-windows.yml
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
# .github/workflows/build-windows.yml
|
||||
|
||||
name: Build Windows Application
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
workflow_dispatch:
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
build-windows:
|
||||
runs-on: windows-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.11'
|
||||
|
||||
# 第 3 步: 安装 uv (Windows 版)
|
||||
- name: Install uv
|
||||
run: powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
|
||||
- name: Add uv to PATH
|
||||
run: echo "$env:APPDATA\uv\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||
|
||||
# 第 4 步: 使用 uv 安装项目及开发依赖
|
||||
- name: Install dependencies with uv
|
||||
run: uv pip install ". --dev"
|
||||
|
||||
# 第 5 步: 安装 UPX (用于压缩 exe)
|
||||
- name: Install UPX
|
||||
run: |
|
||||
Invoke-WebRequest -Uri "https://github.com/upx/upx/releases/download/v4.2.4/upx-4.2.4-win64.zip" -OutFile "upx.zip"
|
||||
Expand-Archive -Path "upx.zip" -DestinationPath "upx"
|
||||
echo "$((Get-Item -Path ".\upx\*\").FullName)" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
|
||||
shell: powershell
|
||||
|
||||
# 第 6 步: 运行 PyInstaller
|
||||
- name: Build the application with PyInstaller
|
||||
# 使用你的 Windows spec 文件
|
||||
run: pyinstaller lite.spec --noconfirm
|
||||
|
||||
# 第 7 步: 将单个 exe 文件打包成 .zip
|
||||
- name: Package executable into a zip file
|
||||
run: Compress-Archive -Path dist/DocuTranslate.exe -DestinationPath dist/DocuTranslate-Windows.zip
|
||||
shell: powershell
|
||||
|
||||
# 第 8 步: 上传构建产物 (Zip 文件)
|
||||
- name: Upload Windows build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: DocuTranslate-Windows
|
||||
path: dist/DocuTranslate-Windows.zip
|
||||
Reference in New Issue
Block a user