更新 compile_py.yml #94
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 贡献者注意: | |
| # 下面的 hook-win10toast.py 迁移不要删 | |
| name: Build and Push Python Binaries | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build-linux: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' # Linux保持原版本 | |
| cache: 'pip' | |
| - name: Compile Python scripts for Linux | |
| run: | | |
| pip install -r requirements_linux.txt | |
| mkdir -p bin/linux | |
| pyinstaller --onefile --distpath bin/linux chat.py | |
| pyinstaller --onefile --distpath bin/linux admin.py | |
| pyinstaller --onefile --noconsole --distpath bin/linux client.py | |
| pyinstaller --onefile --distpath bin/linux clientcli.py # 新增clientcli.py编译 | |
| rm chat.spec client.spec clientcli.spec # 删除新增的spec文件 | |
| rm -rf build/ | |
| - name: Upload Linux binaries | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-binaries | |
| path: bin/linux/ | |
| build-windows: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.6' # 适配Windows 7的Python 3.6 | |
| cache: 'pip' | |
| - name: Compile Python scripts for Windows | |
| run: | | |
| pip install -r requirements.txt | |
| # 动态获取Python安装路径(适配3.6版本) | |
| $site_packages = python -c "import site; print(site.getsitepackages()[0])" | |
| Copy-Item -Path hook-win10toast.py "$site_packages\lib\site-packages\PyInstaller\hooks\" | |
| mkdir -Force bin/windows | |
| pyinstaller --onefile --distpath bin/windows admin.py | |
| pyinstaller --onefile --distpath bin/windows chat.py | |
| pyinstaller --onefile --noconsole --distpath bin/windows client.py | |
| pyinstaller --onefile --distpath bin/windows clientcli.py # 新增clientcli.py编译 | |
| Remove-Item -Path "chat.spec", "client.spec", "clientcli.spec" -Force # 删除新增的spec文件 | |
| Remove-Item -Path ".\build" -Recurse -Force | |
| - name: Upload Windows binaries | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-binaries | |
| path: bin/windows/ | |
| push-binaries: | |
| needs: [build-windows, build-linux] | |
| runs-on: ubuntu-latest | |
| if: success() | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download Windows binaries | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: windows-binaries | |
| path: bin/windows/ | |
| - name: Download Linux binaries | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: linux-binaries | |
| path: bin/linux/ | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "github-actions@users.noreply.github.com" | |
| - name: Add and commit binaries | |
| run: | | |
| git add bin/windows/ | |
| git add bin/linux/ | |
| git commit -m "[skip ci] [Bot] Add compiled binaries" || echo "No changes to commit" | |
| - name: Push changes | |
| run: git push |