更新 .github/workflows/build-exe.yml
Some checks failed
Build Windows EXE with Wine / build (push) Failing after 2m23s
Some checks failed
Build Windows EXE with Wine / build (push) Failing after 2m23s
This commit is contained in:
162
.github/workflows/build-exe.yml
vendored
162
.github/workflows/build-exe.yml
vendored
@@ -1,152 +1,88 @@
|
|||||||
name: Build Windows EXE with Full Image
|
name: Build Windows EXE with Wine
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
# 推荐:只在打标签时触发 Release
|
|
||||||
tags:
|
tags:
|
||||||
- 'v*' # 例如推送 v1.0.0, v2.1.3 等标签时触发
|
- 'v*'
|
||||||
# 如果你想在每次推送时都创建,也可以保留 branches,但通常会打 tag
|
|
||||||
branches: ["main"]
|
branches: ["main"]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# 步骤1:下载 Python 3.9.9 安装包(保持文件名一致)
|
# 步骤 1: 安装必要依赖 (Wine 和 Xvfb)
|
||||||
- name: Download Python 3.9.9 installer
|
- name: Install System Dependencies
|
||||||
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
|
|
||||||
# 验证文件完整性
|
|
||||||
file python-3.9.9-amd64.exe
|
|
||||||
|
|
||||||
- name: Install Xvfb and Dependencies
|
|
||||||
# 仅在需要时安装,节省初始化时间
|
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y xvfb libxrender1 libxtst6 libxi6
|
sudo apt-get install -y xvfb wine64 wine binutils
|
||||||
- name: Run Java with Xvfb
|
sudo apt-get clean # 及时清理 apt 缓存节省硬盘空间
|
||||||
env:
|
|
||||||
# 设置虚拟显示器编号
|
|
||||||
DISPLAY: :99
|
|
||||||
run: |
|
|
||||||
# 1. 启动 Xvfb(后台运行)
|
|
||||||
Xvfb :99 -screen 0 1024x768x16 &
|
|
||||||
|
|
||||||
# 2. 运行你的 Java 构建或测试任务
|
|
||||||
# xvfb-run 是一个包装命令,它能自动处理显示器的开启和关闭,更推荐
|
|
||||||
xvfb-run --auto-servernum ./gradlew test
|
|
||||||
|
|
||||||
|
# 步骤 2: 下载 Python Windows 安装包
|
||||||
- name: Reset Wine environment (clean slate)
|
- name: Download Python 3.9.9
|
||||||
|
run: |
|
||||||
|
wget https://mirrors.tuna.tsinghua.edu.cn/python/3.9.9/python-3.9.9-amd64.exe -O python-installer.exe
|
||||||
|
ls -lh python-installer.exe
|
||||||
|
|
||||||
|
# 步骤 3: 初始化 Wine 环境
|
||||||
|
- name: Setup Wine Environment
|
||||||
run: |
|
run: |
|
||||||
echo "=== 备份并删除旧的 Wine 配置目录 ==="
|
|
||||||
# 如果 ~/.wine 目录存在,先重命名备份(或直接删除)
|
|
||||||
if [ -d "$HOME/.wine" ]; then
|
|
||||||
mv "$HOME/.wine" "$HOME/.wine.bak.$(date +%s)"
|
|
||||||
echo "Old .wine directory backed up."
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "=== 初始化一个新的干净的Wine环境 ==="
|
|
||||||
# 初始化Wine环境,使用 xvfb-run 避免任何图形界面问题
|
|
||||||
# 设置 WINEARCH 为 win64 以支持64位
|
|
||||||
export WINEARCH=win64
|
export WINEARCH=win64
|
||||||
xvfb-run wineboot -u
|
export WINEPREFIX=$HOME/.wine
|
||||||
|
# 使用 xvfb-run 启动,避免 GUI 错误
|
||||||
echo "=== 验证新环境 ==="
|
xvfb-run --auto-servernum wineboot -u
|
||||||
# 等待几秒让环境初始化完成
|
|
||||||
sleep 5
|
sleep 5
|
||||||
wine --version
|
|
||||||
xvfb-run wine cmd /c "echo Wine environment is ready"
|
# 步骤 4: 在 Wine 中安装 Python
|
||||||
|
|
||||||
# 步骤3:安装 Python(使用正确的文件名)
|
|
||||||
- name: Install Python in Wine
|
- name: Install Python in Wine
|
||||||
run: |
|
run: |
|
||||||
echo "Current directory: $(pwd)"
|
# /quiet 表示静默安装,这是在 CI 环境中运行的关键
|
||||||
ls -lah
|
xvfb-run --auto-servernum wine python-installer.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
|
||||||
|
sleep 15
|
||||||
|
# 安装完后立即删除安装包,释放硬盘
|
||||||
|
rm python-installer.exe
|
||||||
|
|
||||||
if [ ! -f python-3.9.9-amd64.exe ]; then
|
# 步骤 5: 验证并定位 Python 路径
|
||||||
echo "Installer not found!"
|
- name: Verify Python Path
|
||||||
|
run: |
|
||||||
|
# 动态查找 python.exe 路径并存入环境变量
|
||||||
|
PYTHON_PATH=$(find $HOME/.wine/drive_c -name "python.exe" | head -n 1)
|
||||||
|
if [ -z "$PYTHON_PATH" ]; then
|
||||||
|
echo "Python installation failed!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
echo "PYTHON_EXE=$PYTHON_PATH" >> $GITHUB_ENV
|
||||||
|
echo "Found Python at: $PYTHON_PATH"
|
||||||
|
wine "$PYTHON_PATH" --version
|
||||||
|
|
||||||
# 直接用 wine 运行
|
# 步骤 6: 安装 Python 依赖
|
||||||
xvfb-run -a wine python-3.9.9-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
|
- name: Install Pip Dependencies
|
||||||
|
|
||||||
# 等待安装
|
|
||||||
sleep 20
|
|
||||||
|
|
||||||
# 步骤4:更彻底地查找 Python
|
|
||||||
- name: Find and verify Python
|
|
||||||
run: |
|
run: |
|
||||||
echo "=== Searching all possible Python locations ==="
|
# 使用清华源加速并节省网络开销
|
||||||
# 查找所有 python.exe
|
wine "$PYTHON_EXE" -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
find /root/.wine/drive_c -name "python.exe" 2>/dev/null | while read path; do
|
wine "$PYTHON_EXE" -m pip install pyinstaller keyboard pywin32 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
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:安装依赖
|
# 步骤 7: 执行 PyInstaller 构建
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
|
||||||
# 先配置 pip 使用清华源(或其他国内源)
|
|
||||||
wine "$PYTHON_EXE" -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
|
||||||
wine "$PYTHON_EXE" -m pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn
|
|
||||||
# 升级 pip
|
|
||||||
wine "$PYTHON_EXE" -m pip install --upgrade pip
|
|
||||||
# 安装包
|
|
||||||
wine "$PYTHON_EXE" -m pip install pyinstaller keyboard pywin32
|
|
||||||
|
|
||||||
# 步骤6:构建 EXE
|
|
||||||
- name: Build EXE
|
- name: Build EXE
|
||||||
run: |
|
run: |
|
||||||
wine "$PYTHON_EXE" -m PyInstaller --onefile --windowed --name Shortcut_Sync_PotPlayer main.py
|
# --clean 参数可以在构建前清理临时文件
|
||||||
|
wine "$PYTHON_EXE" -m PyInstaller --onefile --windowed --clean --name Shortcut_Sync_PotPlayer main.py
|
||||||
|
|
||||||
# 步骤7:上传构建产物(修复版本)
|
# 步骤 8: 上传 Artifact (Gitea 专用版本)
|
||||||
- name: Upload Artifact
|
- name: Upload Artifact
|
||||||
uses: christopherhx/gitea-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
|
||||||
|
|
||||||
- name: Create Release and Upload Asset
|
# 步骤 9: 发布 Release (仅在推送 tag 时执行)
|
||||||
# 使用专门为 Gitea 开发的 release action
|
- name: Create Release
|
||||||
# 这是一个在 Gitea 生态中广泛使用的版本 [citation:2][citation:5]
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
uses: https://gitea.com/actions/release-action@main
|
uses: https://gitea.com/actions/release-action@main
|
||||||
with:
|
with:
|
||||||
# 文件路径:指向你 PyInstaller 生成的 EXE 文件
|
|
||||||
files: dist/Shortcut_Sync_PotPlayer.exe
|
files: dist/Shortcut_Sync_PotPlayer.exe
|
||||||
# API 密钥:使用 Gitea 自动提供的 token,用于认证
|
|
||||||
api_key: '${{ secrets.GITHUB_TOKEN }}'
|
api_key: '${{ secrets.GITHUB_TOKEN }}'
|
||||||
# 可选:设置 Release 的标题,默认会使用 tag 名称
|
|
||||||
name: 'Release ${{ github.ref_name }}'
|
name: 'Release ${{ github.ref_name }}'
|
||||||
# 可选:是否为草稿 (true/false)
|
|
||||||
draft: false
|
draft: false
|
||||||
# 可选:是否为预发布 (true/false)
|
|
||||||
prerelease: false
|
prerelease: false
|
||||||
Reference in New Issue
Block a user