构建、打包流程、文档以及依赖管理方面的重大改进#2
Conversation
Introduces CI workflows for building and releasing executables using PyInstaller and Nuitka across multiple platforms. Updates .gitignore to exclude .DS_Store, corrects the release date in README, and enhances build.py to include pystray and pillow in hidden imports and data packaging. Documentation is updated and reorganized, including moving build guides to the docs directory and adding instructions for the new workflows.
Modified build workflows to install dependencies using requirements.txt instead of listing packages directly. This ensures consistency between local and CI environments. Also fixed a typo in the branches filter for the PyInstaller workflow.
Added requirements.txt with DrissionPage, pystray, and pillow dependencies. Updated .gitignore to allow requirements.txt and requirements-*.txt files to be tracked.
Refactors the Nuitka GitHub Actions workflow for clearer artifact naming, improved macOS app packaging, and more precise trigger paths. Fixes a typo in the PyInstaller workflow trigger. In linux_do_gui.py, ensures safe content injection in the editor using json.dumps, and improves the stop logic in the GUI to correctly reflect stopped status and reset state.
Replaced direct pip install commands with 'pip install -r requirements.txt' in README and documentation for consistency and easier dependency management. Updated build instructions, file structure, and output file naming conventions in both BUILD_GUIDE.md and Linux 环境安装指南.md. Also adjusted the GitHub Actions workflow for Nuitka on macOS by removing unnecessary flags.
There was a problem hiding this comment.
Pull request overview
This pull request introduces comprehensive improvements to build automation, documentation, and dependency management for the Linux.do forum assistant tool. The changes add automated multi-platform builds using GitHub Actions with both PyInstaller and Nuitka, reorganize documentation into a dedicated docs folder, and standardize dependency management through requirements.txt. Additionally, the PR includes security improvements for string handling using json.dumps() and better state management for the stop functionality.
Changes:
- Added GitHub Actions workflows for automated builds on Linux, macOS, and Windows using PyInstaller and Nuitka
- Created requirements.txt for standardized dependency management and updated all documentation to reference it
- Improved string escaping in linux_do_gui.py to prevent JavaScript injection vulnerabilities
- Enhanced stop/done state tracking with _stop_requested flag
Reviewed changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| requirements.txt | New file defining project dependencies (DrissionPage, pystray, pillow) |
| .github/workflows/build-pyinstaller.yml | Automated multi-platform build workflow using PyInstaller with artifact uploads and releases |
| .github/workflows/build-nuitka.yml | Automated multi-platform build workflow using Nuitka with artifact uploads and releases |
| linux_do_gui.py | Security improvement using json.dumps() for safe JavaScript content passing; added _stop_requested flag for better state management |
| docs/BUILD_GUIDE.md | Updated and reorganized build documentation with GitHub Actions info and requirements.txt references |
| build.py | Added pystray and PIL as hidden imports; included icon data files for all platforms |
| README.md | Updated to reference requirements.txt and new docs structure; corrected changelog date |
| .gitignore | Added exceptions to allow requirements.txt files while excluding other .txt files; added .DS_Store |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "--onefile", | ||
| "--windowed", | ||
| "--name", f"{APP_NAME}_v{APP_VERSION}_Windows", | ||
| "--add-data", f"{MAIN_SCRIPT};.", |
There was a problem hiding this comment.
The main script is incorrectly added as data with --add-data on line 56. PyInstaller should not have the main script added as data - it's already being compiled as the main entry point (line 65). This line should be removed as it's unnecessary and could cause issues.
| "--add-data", f"{MAIN_SCRIPT};.", |
| # 打包图标数据,供运行时托盘与窗口图标使用 | ||
| if os.path.exists(ICON_WIN): | ||
| cmd.extend(["--add-data", f"{ICON_WIN};."]) | ||
|
|
||
| # 如果有图标文件 | ||
| if os.path.exists(ICON_WIN): |
There was a problem hiding this comment.
The icon file handling is duplicated. Lines 68-70 add the icon as data for runtime use, and lines 72-74 add it as the application icon. Both blocks check the same condition (if os.path.exists(ICON_WIN)). While both serve different purposes (--add-data for runtime access, --icon for the executable icon), this could be refactored into a single conditional block for clarity.
| # 打包图标数据,供运行时托盘与窗口图标使用 | |
| if os.path.exists(ICON_WIN): | |
| cmd.extend(["--add-data", f"{ICON_WIN};."]) | |
| # 如果有图标文件 | |
| if os.path.exists(ICON_WIN): | |
| # 打包图标数据,供运行时托盘与窗口图标使用,并设置应用图标 | |
| if os.path.exists(ICON_WIN): | |
| cmd.extend(["--add-data", f"{ICON_WIN};."]) |
| # 打包图标数据,供运行时托盘与窗口图标使用 | ||
| if os.path.exists(ICON_WIN): | ||
| cmd.extend(["--add-data", f"{ICON_WIN}:."]) |
There was a problem hiding this comment.
The icon file handling is duplicated. Lines 146-148 add the icon as data for runtime use. This pattern is repeated across all three build functions. Consider refactoring to avoid code duplication and improve maintainability.
| - master | ||
| - dev | ||
| pull_request: | ||
| workflow_dispatch: |
There was a problem hiding this comment.
The workflow supports workflow_dispatch trigger but doesn't define any inputs. Consider adding a version input parameter similar to the Nuitka workflow to allow manual builds with specific version tags, or document that manual triggers will always create dev builds.
| # 打包图标数据,供运行时托盘与窗口图标使用 | ||
| if os.path.exists(ICON_WIN): | ||
| cmd.extend(["--add-data", f"{ICON_WIN}:."]) | ||
|
|
||
| # 如果有图标文件 | ||
| if os.path.exists(ICON_MAC): | ||
| cmd.extend(["--icon", ICON_MAC]) |
There was a problem hiding this comment.
The icon file handling is duplicated. Lines 107-109 add the icon as data for runtime use, and lines 111-113 add it as the application icon. Both blocks check conditions for icon existence. While both serve different purposes (--add-data for runtime access, --icon for the executable icon), this could be refactored into a single conditional block for clarity.
| inputs: | ||
| version: | ||
| description: 'Version tag for release (e.g., v8.1.0)' | ||
| required: false | ||
| default: '' |
There was a problem hiding this comment.
The workflow defines a version input for workflow_dispatch events but never uses it. The version is always derived from the git reference in the build job (if present), but there's no step to resolve the version like in the PyInstaller workflow. Consider either using the input.version value when provided, or removing the unused input parameter.
| inputs: | |
| version: | |
| description: 'Version tag for release (e.g., v8.1.0)' | |
| required: false | |
| default: '' |
|
感谢你的贡献!这个 PR 的改进方向很好,特别是: - 新增 PyInstaller 和 Nuitka 自动构建工作流 - 统一依赖管理(requirements.txt) - 文档结构优化 - 代码安全改进 不过目前存在一些问题需要解决: 1. 合并冲突:PR 与主分支存在冲突,需要先解决 2. 代码质量问题(Copilot 审查发现): - |
此拉取请求为项目引入了构建和打包流程、文档以及依赖管理方面的重大改进。主要增强功能包括通过 GitHub Actions 使用 PyInstaller 和 Nuitka 添加了自动化多平台构建工作流,改进并重新组织了文档,以及更好的依赖处理。此外还有一些针对更安全字符串处理的小幅代码改进,以及整个项目的更新说明。
构建自动化和打包:
.github/workflows/build-pyinstaller.yml,用于使用 PyInstaller 进行自动化的多平台构建,支持 Linux、macOS 和 Windows,包含构建产物上传和发布版本创建。.github/workflows/build-nuitka.yml,用于使用 Nuitka 进行自动化的多平台构建,包括构建产物上传和 GitHub 发布版本创建。build.py,将pystray和PIL包含为隐式导入,并确保在所有平台上始终打包托盘和窗口图标文件。文档和项目结构:
BUILD_GUIDE.md移动并更新为docs/BUILD_GUIDE.md,扩展了 PyInstaller 和 Nuitka 的说明,阐明了构建产物命名,并记录了新的 GitHub Actions 工作流。README.md以引用requirements.txt进行依赖安装,反映新的文档结构,并更新变更日志日期和说明。docs/Linux 环境安装指南.md,使用requirements.txt进行依赖安装,并改进了故障排除说明。依赖管理:
pip install -r requirements.txt以实现一致的依赖管理。代码改进:
linux_do_gui.py中的字符串转义,使用json.dumps安全地将内容传递给 JavaScript,防止注入漏洞。其他更新:
这些更改共同实现了构建流程的现代化,使跨平台打包可复现且自动化,并改善了新贡献者的上手体验。