Skip to content

v9.5.3

v9.5.3 #77

Workflow file for this run

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
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.Qt5" `
--distpath "./dist/shared" `
--workpath "./build/shared" `
--onedir `
--noconsole `
--icon="chuizi.ico" `
--add-data "chuizi.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 `
-y `
"NFO.Editor.Qt5.py"
Move-Item -Path "dist/shared/NFO.Editor.Qt5/NFO.Editor.Qt5.exe" -Destination "dist/NFOTools/" -Force -ErrorAction SilentlyContinue
if (Test-Path "dist/shared/NFO.Editor.Qt5/PyQt5") {
Move-Item -Path "dist/shared/NFO.Editor.Qt5/PyQt5" -Destination "shared_libs/" -Force -ErrorAction SilentlyContinue
}
if (Test-Path "dist/shared/NFO.Editor.Qt5/_internal") {
Move-Item -Path "dist/shared/NFO.Editor.Qt5/_internal" -Destination "shared_libs/" -Force -ErrorAction SilentlyContinue
}
Remove-Item -Path "dist/shared/NFO.Editor.Qt5" -Recurse -Force -ErrorAction SilentlyContinue
# 构建其他工具...
# cg_crop
pyinstaller --name "cg_crop" `
--distpath "./dist/shared" `
--workpath "./build/shared" `
--onedir `
--noconsole `
--icon="chuizi.ico" `
--add-data "chuizi.ico;." `
--add-data "Img;Img" `
--hidden-import win32com `
--hidden-import win32com.client `
--hidden-import win32com.shell `
--hidden-import pythoncom `
--hidden-import pywintypes `
--hidden-import PIL `
--hidden-import PIL._imaging `
--hidden-import PIL.Image `
-y `
"cg_crop.py"
Move-Item -Path "dist/shared/cg_crop/cg_crop.exe" -Destination "dist/NFOTools/" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "dist/shared/cg_crop" -Recurse -Force -ErrorAction SilentlyContinue
# cg_rename
pyinstaller --name "cg_rename" `
--distpath "./dist/shared" `
--workpath "./build/shared" `
--onedir `
--noconsole `
--icon="chuizi.ico" `
--add-data "chuizi.ico;." `
--add-data "mapping_actor.xml;." `
--hidden-import win32com `
--hidden-import win32com.client `
--hidden-import win32com.shell `
--hidden-import pythoncom `
--hidden-import pywintypes `
--hidden-import PIL `
--hidden-import PIL._imaging `
--hidden-import PIL.Image `
-y `
"cg_rename.py"
Move-Item -Path "dist/shared/cg_rename/cg_rename.exe" -Destination "dist/NFOTools/" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "dist/shared/cg_rename" -Recurse -Force -ErrorAction SilentlyContinue
# cg_dedupe
pyinstaller --name "cg_dedupe" `
--distpath "./dist/shared" `
--workpath "./build/shared" `
--onedir `
--noconsole `
--icon="chuizi.ico" `
--add-data "chuizi.ico;." `
--hidden-import win32com `
--hidden-import win32com.client `
--hidden-import win32com.shell `
--hidden-import pythoncom `
--hidden-import pywintypes `
--hidden-import PIL `
--hidden-import PIL._imaging `
--hidden-import PIL.Image `
-y `
"cg_dedupe.py"
Move-Item -Path "dist/shared/cg_dedupe/cg_dedupe.exe" -Destination "dist/NFOTools/" -Force -ErrorAction SilentlyContinue
Remove-Item -Path "dist/shared/cg_dedupe" -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 "chuizi.ico" -Destination "dist/NFOTools/" -Force
- name: 创建 NSIS 安装脚本
shell: pwsh
run: |
@'
!include "MUI2.nsh"
!define PRODUCT_NAME "NFO Tools"
!define PRODUCT_VERSION "${{ env.build_name }}"
!define PRODUCT_PUBLISHER "NFO Tools"
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "NFOTools.Setup.${{ env.build_name }}.exe"
InstallDir "$PROGRAMFILES\NFO Tools"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "SimpChinese"
Section "MainSection" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File /r "dist\NFOTools\*.*"
CreateDirectory "$SMPROGRAMS\NFO Tools"
CreateShortCut "$SMPROGRAMS\NFO Tools\NFO Editor.lnk" "$INSTDIR\NFO.Editor.Qt5.exe"
CreateShortCut "$SMPROGRAMS\NFO Tools\CG Crop.lnk" "$INSTDIR\cg_crop.exe"
CreateShortCut "$SMPROGRAMS\NFO Tools\CG Rename.lnk" "$INSTDIR\cg_rename.exe"
CreateShortCut "$SMPROGRAMS\NFO Tools\NFO Dedupe.lnk" "$INSTDIR\cg_dedupe.exe"
WriteUninstaller "$INSTDIR\uninstall.exe"
CreateShortCut "$SMPROGRAMS\NFO Tools\Uninstall.lnk" "$INSTDIR\uninstall.exe"
SectionEnd
Section "Uninstall"
Delete "$INSTDIR\uninstall.exe"
Delete "$INSTDIR\cg_crop.exe"
Delete "$INSTDIR\NFO.Editor.Qt5.exe"
Delete "$INSTDIR\cg_rename.exe"
Delete "$INSTDIR\cg_dedupe.exe"
Delete "$INSTDIR\chuizi.ico"
Delete "$SMPROGRAMS\NFO Tools\NFO Editor.lnk"
Delete "$SMPROGRAMS\NFO Tools\CG Crop.lnk"
Delete "$SMPROGRAMS\NFO Tools\CG Rename.lnk"
Delete "$SMPROGRAMS\NFO Tools\NFO Dedupe.lnk"
Delete "$SMPROGRAMS\NFO Tools\Uninstall.lnk"
RMDir /r "$INSTDIR"
RMDir "$SMPROGRAMS\NFO Tools"
SectionEnd
'@ | Out-File -FilePath "installer.nsi" -Encoding utf8
- name: 安装 NSIS
run: |
choco install nsis -y --no-progress
- name: 构建安装程序
run: |
makensis installer.nsi
- name: 上传构建工件
uses: actions/upload-artifact@v4
with:
name: nfo-tools-installer
path: NFOTools.Setup.${{ env.build_name }}.exe
retention-days: 7
release:
needs: build
runs-on: windows-latest
permissions:
contents: write
steps:
- name: 检出代码
uses: actions/checkout@v4
with:
fetch-depth: 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: 下载安装程序
uses: actions/download-artifact@v4
with:
name: nfo-tools-installer
path: dist
- name: 创建 Release
uses: softprops/action-gh-release@v1
with:
name: Release ${{ env.build_name }}
tag_name: ${{ env.build_name }}
draft: false
prerelease: false
files: dist/*.exe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}