Files
Directory-Scanner/.github/workflows/windows-build.yml
Hsdi e7fa13cd18
All checks were successful
Build Windows EXE with Wine (Universal Template) / build (push) Successful in 7m1s
更新 EXE 文件名称为 DirectoryMonitor,并在安装依赖步骤中增加 golang
2026-03-16 04:26:19 +08:00

129 lines
5.0 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Build Windows EXE with Wine (Universal Template)
on:
push:
tags:
- 'v*'
branches: ["main"]
jobs:
build:
runs-on: ubuntu-latest
# === 用户配置区:新项目只需修改这里 ===
env:
# 项目主入口文件
MAIN_SCRIPT: dir_scanner_gui.py
# 生成的 EXE 文件名称 (不带 .exe 后缀)
EXE_NAME: DirectoryMonitor
# 依赖配置文件路径 (通常为 requirements.txt)
REQUIREMENTS_FILE: requirements.txt
# Python 版本号
PYTHON_VERSION: 3.9.1
# === 系统环境变量 (通常无需修改) ===
WINEARCH: win64
WINEPREFIX: /root/.wine
WINEDEBUG: -all # 屏蔽无用的警告日志 (如 missing Gecko)
DISPLAY: :99 # 统一使用 99 号虚拟显示器
steps:
- name: Checkout Code
uses: actions/checkout@v4
# 步骤 1: 安装必要依赖 (增加 golang 供 Gitea Release Action 使用)
- name: Install System Dependencies
run: |
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y xvfb wine64 wine32 wine binutils golang
sudo apt-get clean # 及时清理 apt 缓存节省硬盘空间
# 步骤 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 Installer
run: |
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 环境
- 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
run: |
# /quiet 表示静默安装,加入 /log 参数抓取日志以便排错
wine python-installer.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0 /log python-install.log || (cat python-install.log && exit 1)
# 重要:静默安装往往是异步的,必须等待 wineserver 彻底结束,防止 X connection 突然断开
wineserver -w
# 安装完后立即删除安装包,释放硬盘
rm python-installer.exe
# 步骤 6: 验证并定位 Python 路径
- name: Verify Python Path
run: |
# 动态查找 python.exe 路径并存入环境变量
PYTHON_PATH=$(find $WINEPREFIX/drive_c -name "python.exe" | head -n 1)
if [ -z "$PYTHON_PATH" ]; then
echo "Python installation failed!"
exit 1
fi
echo "PYTHON_EXE=$PYTHON_PATH" >> $GITHUB_ENV
echo "Found Python at: $PYTHON_PATH"
wine "$PYTHON_PATH" --version
# 步骤 7: 安装 Python 依赖
- name: Install Pip Dependencies
run: |
# 使用清华源加速升级 pip
wine "$PYTHON_EXE" -m pip install --upgrade pip -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 "${{ env.EXE_NAME }}" "${{ env.MAIN_SCRIPT }}"
wineserver -w
# 步骤 9: 上传 Artifact (Gitea 专用版本)
- name: Upload Artifact
uses: christopherhx/gitea-upload-artifact@v4
with:
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/${{ env.EXE_NAME }}.exe
api_key: '${{ secrets.GITHUB_TOKEN }}'
name: 'Release ${{ github.ref_name }}'
draft: false
prerelease: false