更新 .github/workflows/build-exe.yml
Some checks failed
Build Windows EXE with Full Image / build (push) Has been cancelled

This commit is contained in:
miu
2026-03-15 18:48:06 +08:00
Unverified
parent e989c26715
commit bd59fbe7e7

View File

@@ -7,55 +7,92 @@ jobs:
steps:
- uses: actions/checkout@v4
# 步骤1下载你指定的 Python 安装包
- name: Download Python 3.9.13 installer
# 步骤1下载 Python 3.9.9 安装包(保持文件名一致)
- name: Download Python 3.9.9 installer
run: |
wget https://mirrors.tuna.tsinghua.edu.cn/python/3.9.9/python-3.9.9-amd64.exe
ls -lh python-3.9.9-amd64.exe # 确认文件下载成功
ls -lh python-3.9.9-amd64.exe
# 验证文件完整性
file python-3.9.9-amd64.exe
# 步骤2使用 Xvfb 在 Wine 中静默安装 Python
# 步骤2先测试 Wine 能否运行简单命令
- name: Test Wine environment
run: |
wine --version
xvfb-run wine cmd /c "echo Wine is working"
# 步骤3安装 Python使用正确的文件名
- name: Install Python in Wine
run: |
# 使用 xvfb-run 包装 wine 以解决无显示问题
# /quiet: 静默安装InstallAllUsers=1: 为所有用户安装PrependPath=1: 自动添加到 PATH
# Include_test=0: 不安装测试套件,以节省空间
xvfb-run wine python-3.9.13-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
echo "Python installation initiated. Waiting for process to complete..."
# 等待几秒确保安装完成
sleep 10
# 使用绝对路径并添加调试信息
echo "Current directory: $(pwd)"
echo "Files in current directory:"
ls -la
# 步骤3验证 Python 是否正确安装(关键步骤!)
- name: Verify Python installation
run: |
echo "=== Searching for python.exe ==="
# 查找刚安装的 Python这能帮你确认确切的路径
PYTHON_EXE_PATH=$(find /root/.wine/drive_c -name "python.exe" -path "*/Python39/*" | head -n 1)
if [ -z "$PYTHON_EXE_PATH" ]; then
echo "Python.exe not found! Installation may have failed."
# 确保文件存在
if [ ! -f "python-3.9.9-amd64.exe" ]; then
echo "Installer not found!"
exit 1
fi
echo "Found Python at: $PYTHON_EXE_PATH"
echo "PYTHON_EXE=$PYTHON_EXE_PATH" >> $GITHUB_ENV # 保存路径供后续步骤使用
echo "=== Verifying Python version ==="
# 使用完整路径调用 Python 验证
wine "$PYTHON_EXE_PATH" --version
# 尝试用 wineconsole 而不是 wine有时更稳定
xvfb-run wineconsole --backend=curses cmd /c "python-3.9.9-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0"
# 步骤4使用刚安装的 Python 安装依赖
# 等待安装完成
sleep 15
# 验证安装进程
echo "Installation completed, checking..."
# 步骤4更彻底地查找 Python
- name: Find and verify Python
run: |
echo "=== Searching all possible Python locations ==="
# 查找所有 python.exe
find /root/.wine/drive_c -name "python.exe" 2>/dev/null | while read path; do
echo "Found: $path"
echo "Version info:"
wine "$path" --version 2>/dev/null || echo "Cannot run $path"
done
# 尝试常见路径
COMMON_PATHS=(
"/root/.wine/drive_c/Python39/python.exe"
"/root/.wine/drive_c/Python39-32/python.exe"
"/root/.wine/drive_c/Program Files/Python39/python.exe"
"/root/.wine/drive_c/users/runner/AppData/Local/Programs/Python/Python39/python.exe"
)
for path in "${COMMON_PATHS[@]}"; do
if [ -f "$path" ]; then
echo "Found Python at standard location: $path"
PYTHON_EXE="$path"
break
fi
done
if [ -z "$PYTHON_EXE" ]; then
echo "Python not found in standard locations"
exit 1
fi
echo "PYTHON_EXE=$PYTHON_EXE" >> $GITHUB_ENV
wine "$PYTHON_EXE" --version
# 步骤5安装依赖
- name: Install dependencies
run: |
# 升级 pip
wine "${{ env.PYTHON_EXE }}" -m pip install --upgrade pip
# 安装所需包。pywin32 必须在这里用 Wine 的 Python 安装
wine "${{ env.PYTHON_EXE }}" -m pip install pyinstaller keyboard pywin32
wine "$PYTHON_EXE" -m pip install --upgrade pip
# 安装
wine "$PYTHON_EXE" -m pip install pyinstaller keyboard pywin32
# 步骤5使用正确的 Python 和 PyInstaller 构建 EXE
# 步骤6构建 EXE
- name: Build EXE
run: |
# 确保在工作目录执行
wine "${{ env.PYTHON_EXE }}" -m PyInstaller --onefile --windowed --name Shortcut_Sync_PotPlayer main.py
wine "$PYTHON_EXE" -m PyInstaller --onefile --windowed --name Shortcut_Sync_PotPlayer main.py
# 步骤6:上传构建产物
# 步骤7:上传产物
- name: Upload Artifact
uses: actions/upload-artifact@v4
with: