Build NFO Tools #85
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: Build NFO Tools | |
on: | |
push: | |
tags: | |
- 'v*.*.*' | |
workflow_dispatch: | |
env: | |
PYTHONUNBUFFERED: 1 | |
PYTHONUTF8: 1 | |
PYTHONDONTWRITEBYTECODE: 1 | |
jobs: | |
build: | |
runs-on: windows-latest | |
timeout-minutes: 15 | |
permissions: | |
contents: write | |
steps: | |
- name: 检出代码 | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: 设置 Python 版本 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9.13' | |
cache: 'pip' | |
check-latest: false | |
- name: 缓存PyInstaller工作目录 | |
uses: actions/cache@v4 | |
with: | |
path: | | |
build | |
dist/shared | |
key: ${{ runner.os }}-pyinstaller-${{ hashFiles('*.py', 'requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pyinstaller- | |
- name: 安装依赖 | |
run: | | |
python -m pip install --upgrade pip wheel setuptools | |
pip install pillow --no-cache-dir | |
pip install pywin32 --no-cache-dir | |
pip install winshell --no-cache-dir | |
pip install -r requirements.txt --no-cache-dir | |
pip install pyinstaller==6.3.0 | |
- name: 设置构建名称 | |
id: set_build_name | |
shell: pwsh | |
run: | | |
git fetch --tags | |
$latestTag = git describe --tags $(git rev-list --tags --max-count=1) | |
if ($null -eq $latestTag) { | |
Write-Error "未找到任何标签,无法继续。" | |
exit 1 | |
} | |
echo "build_name=$latestTag" | Out-File -FilePath $env:GITHUB_ENV -Append | |
- name: 构建应用 | |
shell: pwsh | |
run: | | |
# 构建前清理 | |
Remove-Item -Path "dist" -Recurse -Force -ErrorAction SilentlyContinue | |
Remove-Item -Path "build" -Recurse -Force -ErrorAction SilentlyContinue | |
Remove-Item -Path "shared_libs" -Recurse -Force -ErrorAction SilentlyContinue | |
# 创建必要目录 | |
New-Item -Path "dist/NFOTools" -ItemType Directory -Force | |
New-Item -Path "shared_libs" -ItemType Directory -Force | |
# 构建 NFO.Editor.Qt5 | |
pyinstaller --name "NFO.Editor" ` | |
--distpath "./dist/shared" ` | |
--workpath "./build/shared" ` | |
--onedir ` | |
--noconsole ` | |
--icon="chuizi.ico" ` | |
--add-data "*.ico;." ` | |
--add-data "mapping_actor.xml;." ` | |
--add-data "Img;Img" ` | |
--hidden-import win32com ` | |
--hidden-import win32com.client ` | |
--hidden-import win32com.client.gencache ` | |
--hidden-import win32com.shell ` | |
--hidden-import win32com.shell.shell ` | |
--hidden-import win32com.shell.shellcon ` | |
--hidden-import win32wnet ` | |
--hidden-import pythoncom ` | |
--hidden-import pywintypes ` | |
--hidden-import winshell ` | |
--hidden-import PIL ` | |
--hidden-import PIL._imaging ` | |
--hidden-import PIL.Image ` | |
--collect-submodules cg_photo_wall ` | |
--collect-submodules cg_crop ` | |
--collect-submodules cg_rename ` | |
--collect-submodules cg_dedupe ` | |
-y ` | |
"NFO.Editor.Qt5.py" | |
Move-Item -Path "dist/shared/NFO.Editor/NFO.Editor.exe" -Destination "dist/NFOTools/" -Force -ErrorAction SilentlyContinue | |
if (Test-Path "dist/shared/NFO.Editor/PyQt5") { | |
Move-Item -Path "dist/shared/NFO.Editor/PyQt5" -Destination "shared_libs/" -Force -ErrorAction SilentlyContinue | |
} | |
if (Test-Path "dist/shared/NFO.Editor/_internal") { | |
Move-Item -Path "dist/shared/NFO.Editor/_internal" -Destination "shared_libs/" -Force -ErrorAction SilentlyContinue | |
} | |
Remove-Item -Path "dist/shared/NFO.Editor" -Recurse -Force -ErrorAction SilentlyContinue | |
# 构建其他工具 | |
$tools = @( | |
@{name="cg_crop"; icon="cg_crop.ico"}, | |
@{name="cg_rename"; icon="chuizi.ico"}, | |
@{name="cg_dedupe"; icon="cg_dedupe.ico"}, | |
@{name="cg_photo_wall"; icon="cg_photo_wall.ico"} | |
) | |
foreach ($tool in $tools) { | |
pyinstaller --name $tool.name ` | |
--distpath "./dist/shared" ` | |
--workpath "./build/shared" ` | |
--onedir ` | |
--noconsole ` | |
--icon=$tool.icon ` | |
--add-data "*.ico;." ` | |
--add-data "Img;Img" ` | |
--add-binary "dist/NFOTools/PyQt5;PyQt5" ` | |
--hidden-import PyQt5.QtCore ` | |
--hidden-import PyQt5.QtGui ` | |
--hidden-import PyQt5.QtWidgets ` | |
--hidden-import PIL ` | |
--hidden-import PIL._imaging ` | |
--hidden-import PIL.Image ` | |
-y ` | |
"$($tool.name).py" | |
Move-Item -Path "dist/shared/$($tool.name)/$($tool.name).exe" -Destination "dist/NFOTools/" -Force -ErrorAction SilentlyContinue | |
Remove-Item -Path "dist/shared/$($tool.name)" -Recurse -Force -ErrorAction SilentlyContinue | |
} | |
# 移动共享依赖到最终目录 | |
Copy-Item -Path "shared_libs/*" -Destination "dist/NFOTools/" -Recurse -Force | |
# 移动额外资源文件 | |
Copy-Item -Path "Img" -Destination "dist/NFOTools/" -Recurse -Force | |
Copy-Item -Path "mapping_actor.xml" -Destination "dist/NFOTools/" -Force | |
Copy-Item -Path "*.ico" -Destination "dist/NFOTools/" -Force | |
# 创建 ZIP 包 | |
Compress-Archive -Path "dist/NFOTools/*" -DestinationPath "NFOTools.${{ env.build_name }}.zip" -Force | |
- name: 上传构建工件 | |
uses: actions/upload-artifact@v4 | |
with: | |
name: nfo-tools-release | |
path: NFOTools.${{ env.build_name }}.zip | |
retention-days: 7 | |
- name: 创建 Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
name: Release ${{ env.build_name }} | |
tag_name: ${{ env.build_name }} | |
draft: false | |
prerelease: false | |
files: NFOTools.${{ env.build_name }}.zip | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |