Add files via upload #225
This file contains 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: 将 Python 打包为 EXE | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: windows-latest | |
env: | |
PYTHON_VERSION: '3.9' | |
OUTPUT_DIR: 'output' | |
ARTIFACT_NAME: 'Bloret-Launcher-Windows.zip' | |
steps: | |
- name: 检出代码 | |
uses: actions/checkout@v2 | |
- name: 安装 pkg-config 和 gobject-introspection | |
run: | | |
choco install pkgconfiglite | |
choco install gobject-introspection | |
shell: pwsh | |
- name: 安装依赖 | |
run: | | |
pip install --upgrade pip | |
pip install -r requirements.txt | |
shell: pwsh | |
- name: 将 PNG 图标转换为 ICO | |
run: | | |
python -c " | |
from PIL import Image | |
img = Image.open('icons/bloret.png') | |
img.save('icons/bloret.ico', format='ICO') | |
" | |
- name: 验证转换后的 ICO 文件路径 | |
run: | | |
if (-not (Test-Path "icons/bloret.ico")) { exit 1 } | |
shell: pwsh | |
- name: 使用 PyInstaller 打包 | |
run: | | |
pyinstaller --onefile --noconsole --icon=icons/bloret.ico --name=Bloret-Launcher ` | |
--add-data "icons\\bloret.ico;." ` | |
--add-data "config.ini;." ` | |
--add-data "ui;ui" ` | |
--add-data "cmcl.json;." ` | |
--add-data "cmcl.exe;." ` | |
--hidden-import=sip ` | |
--hidden-import=qfluentwidgets ` | |
--hidden-import=win10toast ` | |
--paths=. ` | |
Bloret-Launcher.py | |
shell: pwsh | |
- name: 创建包含其他文件夹的目录 | |
run: | | |
mkdir -p ${{ env.OUTPUT_DIR }} | |
cp dist/Bloret-Launcher.exe ${{ env.OUTPUT_DIR }}/ | |
cp -r icons/ ${{ env.OUTPUT_DIR }}/ | |
cp -r ui/ ${{ env.OUTPUT_DIR }}/ | |
cp -r cmcl.exe ${{ env.OUTPUT_DIR }}/ | |
cp -r cmcl.json ${{ env.OUTPUT_DIR }}/ | |
cp -r config.ini ${{ env.OUTPUT_DIR }}/ | |
cp -r LICENSE.txt ${{ env.OUTPUT_DIR }}/ | |
cp -r servers.dat ${{ env.OUTPUT_DIR }}/ | |
cp -r cmcl_save.json ${{ env.OUTPUT_DIR }}/ | |
- name: 清理旧压缩包 | |
run: | | |
if (Test-Path "${{ env.OUTPUT_DIR }}/${{ env.ARTIFACT_NAME }}") { | |
Remove-Item "${{ env.OUTPUT_DIR }}/${{ env.ARTIFACT_NAME }}" | |
} | |
shell: pwsh | |
- name: 创建压缩包 | |
run: Compress-Archive -Path "${{ env.OUTPUT_DIR }}/*" -DestinationPath "${{ env.OUTPUT_DIR }}/${{ env.ARTIFACT_NAME }}" | |
shell: pwsh | |
- name: 上传构建产物 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Bloret-Launcher | |
path: "${{ env.OUTPUT_DIR }}/${{ env.ARTIFACT_NAME }}" |