diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 29a1cb3..8be4aa7 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -1,4 +1,4 @@ -name: Build Windows EXE with Wine +name: Build Windows EXE with Wine (Universal Template) on: push: tags: @@ -9,8 +9,18 @@ jobs: build: runs-on: ubuntu-latest - # 设定全局环境变量,这些变量在所有 steps 中都生效 + # === 用户配置区:新项目只需修改这里 === env: + # 项目主入口文件 + MAIN_SCRIPT: dir_scanner_gui.py + # 生成的 EXE 文件名称 (不带 .exe 后缀) + EXE_NAME: dir_scanner + # 依赖配置文件路径 (通常为 requirements.txt) + REQUIREMENTS_FILE: requirements.txt + # Python 版本号 + PYTHON_VERSION: 3.9.1 + + # === 系统环境变量 (通常无需修改) === WINEARCH: win64 WINEPREFIX: /root/.wine WINEDEBUG: -all # 屏蔽无用的警告日志 (如 missing Gecko) @@ -36,9 +46,9 @@ jobs: sleep 3 # 给虚拟显示器几秒钟的启动时间 # 步骤 3: 下载 Python Windows 安装包 - - name: Download Python 3.9.1 + - name: Download Python Installer run: | - wget https://mirrors.tuna.tsinghua.edu.cn/python/3.9.1/python-3.9.1-amd64.exe -O python-installer.exe + wget https://mirrors.tuna.tsinghua.edu.cn/python/${{ env.PYTHON_VERSION }}/python-${{ env.PYTHON_VERSION }}-amd64.exe -O python-installer.exe ls -lh python-installer.exe # 步骤 4: 初始化 Wine 环境 @@ -75,34 +85,44 @@ jobs: echo "Found Python at: $PYTHON_PATH" wine "$PYTHON_PATH" --version - # 步骤 7: 安装 Python 依赖 (增加了 PyQt6) + # 步骤 7: 安装 Python 依赖 - name: Install Pip Dependencies run: | - # 使用清华源加速 + # 使用清华源加速升级 pip wine "$PYTHON_EXE" -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple - wine "$PYTHON_EXE" -m pip install pyinstaller keyboard pywin32 PyQt6 -i https://pypi.tuna.tsinghua.edu.cn/simple + + # 必须安装 pyinstaller 用于后续打包操作 + wine "$PYTHON_EXE" -m pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple + + # 检查并安装 requirements.txt 中的依赖 + if [ -f "${{ env.REQUIREMENTS_FILE }}" ]; then + echo "Installing dependencies from ${{ env.REQUIREMENTS_FILE }}" + wine "$PYTHON_EXE" -m pip install -r "${{ env.REQUIREMENTS_FILE }}" -i https://pypi.tuna.tsinghua.edu.cn/simple + else + echo "Warning: ${{ env.REQUIREMENTS_FILE }} not found, skipping..." + fi wineserver -w # 步骤 8: 执行 PyInstaller 构建 - name: Build EXE run: | # --clean 参数可以在构建前清理临时文件 - wine "$PYTHON_EXE" -m PyInstaller --onefile --windowed --clean --name Shortcut_Sync_PotPlayer main.py + wine "$PYTHON_EXE" -m PyInstaller --onefile --windowed --clean --name "${{ env.EXE_NAME }}" "${{ env.MAIN_SCRIPT }}" wineserver -w # 步骤 9: 上传 Artifact (Gitea 专用版本) - name: Upload Artifact uses: christopherhx/gitea-upload-artifact@v4 with: - name: Shortcut_Sync_PotPlayer - path: dist/Shortcut_Sync_PotPlayer.exe + name: ${{ env.EXE_NAME }} + path: dist/${{ env.EXE_NAME }}.exe # 步骤 10: 发布 Release (仅在推送 tag 时执行) - name: Create Release if: startsWith(github.ref, 'refs/tags/') uses: https://gitea.com/actions/release-action@main with: - files: dist/Shortcut_Sync_PotPlayer.exe + files: dist/${{ env.EXE_NAME }}.exe api_key: '${{ secrets.GITHUB_TOKEN }}' name: 'Release ${{ github.ref_name }}' draft: false