Compare commits
43 Commits
e989c26715
...
main
128
.github/workflows/build-exe.yml
vendored
128
.github/workflows/build-exe.yml
vendored
@@ -1,63 +1,109 @@
|
|||||||
name: Build Windows EXE with Full Image
|
name: Build Windows EXE with Wine
|
||||||
on: [push]
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
branches: ["main"]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: Ubuntu_docker_act
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
# 设定全局环境变量,这些变量在所有 steps 中都生效
|
||||||
|
env:
|
||||||
|
WINEARCH: win64
|
||||||
|
WINEPREFIX: /root/.wine
|
||||||
|
WINEDEBUG: -all # 屏蔽无用的警告日志 (如 missing Gecko)
|
||||||
|
DISPLAY: :99 # 统一使用 99 号虚拟显示器
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# 步骤1:下载你指定的 Python 安装包
|
# 步骤 1: 安装必要依赖
|
||||||
- name: Download Python 3.9.13 installer
|
- name: Install System Dependencies
|
||||||
run: |
|
run: |
|
||||||
wget https://mirrors.tuna.tsinghua.edu.cn/python/3.9.9/python-3.9.9-amd64.exe
|
sudo dpkg --add-architecture i386
|
||||||
ls -lh python-3.9.9-amd64.exe # 确认文件下载成功
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y xvfb wine64 wine32 wine binutils
|
||||||
|
sudo apt-get clean # 及时清理 apt 缓存节省硬盘空间
|
||||||
|
|
||||||
# 步骤2:使用 Xvfb 在 Wine 中静默安装 Python
|
# 步骤 2: 在后台持续运行 Xvfb
|
||||||
|
- name: Start Xvfb
|
||||||
|
run: |
|
||||||
|
# 启动 X 虚拟屏幕并放到后台,供整个工作流期间的 Wine 使用
|
||||||
|
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
|
||||||
|
sleep 3 # 给虚拟显示器几秒钟的启动时间
|
||||||
|
|
||||||
|
# 步骤 3: 下载 Python Windows 安装包
|
||||||
|
- name: Download Python 3.9.1
|
||||||
|
run: |
|
||||||
|
wget https://mirrors.tuna.tsinghua.edu.cn/python/3.9.1/python-3.9.1-amd64.exe -O python-installer.exe
|
||||||
|
ls -lh python-installer.exe
|
||||||
|
|
||||||
|
# 步骤 4: 初始化 Wine 环境
|
||||||
|
- name: Setup Wine Environment
|
||||||
|
run: |
|
||||||
|
# 初始化 Wine,不再使用 xvfb-run
|
||||||
|
wineboot -u
|
||||||
|
# 重要:等待 Wine 后台配置进程完全结束
|
||||||
|
wineserver -w
|
||||||
|
# 将 Wine 配置为 Windows 10 (Python 3.9+ 强制要求 Win8 以上)
|
||||||
|
winecfg -v win10
|
||||||
|
wineserver -w
|
||||||
|
|
||||||
|
# 步骤 5: 在 Wine 中安装 Python
|
||||||
- name: Install Python in Wine
|
- name: Install Python in Wine
|
||||||
run: |
|
run: |
|
||||||
# 使用 xvfb-run 包装 wine 以解决无显示问题
|
# /quiet 表示静默安装,加入 /log 参数抓取日志以便排错
|
||||||
# /quiet: 静默安装,InstallAllUsers=1: 为所有用户安装,PrependPath=1: 自动添加到 PATH
|
wine python-installer.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0 /log python-install.log || (cat python-install.log && exit 1)
|
||||||
# Include_test=0: 不安装测试套件,以节省空间
|
# 重要:静默安装往往是异步的,必须等待 wineserver 彻底结束,防止 X connection 突然断开
|
||||||
xvfb-run wine python-3.9.13-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
|
wineserver -w
|
||||||
echo "Python installation initiated. Waiting for process to complete..."
|
# 安装完后立即删除安装包,释放硬盘
|
||||||
# 等待几秒确保安装完成
|
rm python-installer.exe
|
||||||
sleep 10
|
|
||||||
|
|
||||||
# 步骤3:验证 Python 是否正确安装(关键步骤!)
|
# 步骤 6: 验证并定位 Python 路径
|
||||||
- name: Verify Python installation
|
- name: Verify Python Path
|
||||||
run: |
|
run: |
|
||||||
echo "=== Searching for python.exe ==="
|
# 动态查找 python.exe 路径并存入环境变量
|
||||||
# 查找刚安装的 Python,这能帮你确认确切的路径
|
PYTHON_PATH=$(find $WINEPREFIX/drive_c -name "python.exe" | head -n 1)
|
||||||
PYTHON_EXE_PATH=$(find /root/.wine/drive_c -name "python.exe" -path "*/Python39/*" | head -n 1)
|
if [ -z "$PYTHON_PATH" ]; then
|
||||||
if [ -z "$PYTHON_EXE_PATH" ]; then
|
echo "Python installation failed!"
|
||||||
echo "Python.exe not found! Installation may have failed."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Found Python at: $PYTHON_EXE_PATH"
|
echo "PYTHON_EXE=$PYTHON_PATH" >> $GITHUB_ENV
|
||||||
echo "PYTHON_EXE=$PYTHON_EXE_PATH" >> $GITHUB_ENV # 保存路径供后续步骤使用
|
echo "Found Python at: $PYTHON_PATH"
|
||||||
|
wine "$PYTHON_PATH" --version
|
||||||
echo "=== Verifying Python version ==="
|
|
||||||
# 使用完整路径调用 Python 验证
|
|
||||||
wine "$PYTHON_EXE_PATH" --version
|
|
||||||
|
|
||||||
# 步骤4:使用刚安装的 Python 安装依赖
|
# 步骤 7: 安装 Python 依赖
|
||||||
- name: Install dependencies
|
- name: Install Pip Dependencies
|
||||||
run: |
|
run: |
|
||||||
# 升级 pip
|
# 使用清华源加速
|
||||||
wine "${{ env.PYTHON_EXE }}" -m pip install --upgrade pip
|
wine "$PYTHON_EXE" -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
# 安装所需包。pywin32 必须在这里用 Wine 的 Python 安装
|
wine "$PYTHON_EXE" -m pip install pyinstaller keyboard pywin32 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
wine "${{ env.PYTHON_EXE }}" -m pip install pyinstaller keyboard pywin32
|
wineserver -w
|
||||||
|
|
||||||
# 步骤5:使用正确的 Python 和 PyInstaller 构建 EXE
|
# 步骤 8: 执行 PyInstaller 构建
|
||||||
- name: Build EXE
|
- name: Build EXE
|
||||||
run: |
|
run: |
|
||||||
# 确保在工作目录执行
|
# --clean 参数可以在构建前清理临时文件
|
||||||
wine "${{ env.PYTHON_EXE }}" -m PyInstaller --onefile --windowed --name Shortcut_Sync_PotPlayer main.py
|
wine "$PYTHON_EXE" -m PyInstaller --onefile --windowed --clean --name Shortcut_Sync_PotPlayer main.py
|
||||||
|
wineserver -w
|
||||||
|
|
||||||
# 步骤6:上传构建产物
|
# 步骤 9: 上传 Artifact (Gitea 专用版本)
|
||||||
- name: Upload Artifact
|
- name: Upload Artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: christopherhx/gitea-upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: Shortcut_Sync_PotPlayer
|
name: Shortcut_Sync_PotPlayer
|
||||||
path: dist/Shortcut_Sync_PotPlayer.exe
|
path: dist/Shortcut_Sync_PotPlayer.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
|
||||||
|
api_key: '${{ secrets.GITHUB_TOKEN }}'
|
||||||
|
name: 'Release ${{ github.ref_name }}'
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
Reference in New Issue
Block a user