From e6a2386d224e33ca3567a400054b2c6f82eb8b00 Mon Sep 17 00:00:00 2001 From: Hsdi Date: Mon, 16 Mar 2026 04:14:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Windows=20=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=B7=A5=E4=BD=9C=E6=B5=81=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8A=A8=E6=80=81=20Python=20=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=92=8C=20EXE=20=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/windows-build.yml | 42 +++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 11 deletions(-) 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