This repository was archived by the owner on Mar 22, 2025. It is now read-only.
Create build action #1
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
| name: Build and Release Multi-Platform Binaries | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest] | |
| arch: [x64, arm64] | |
| python-version: [3.11] | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| # 检出代码 | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| # 设置 Python | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| # 安装 QEMU(仅针对 ARM64 模拟构建) | |
| - name: Install QEMU (for ARM64 builds) | |
| if: matrix.arch == 'arm64' | |
| uses: docker/setup-qemu-action@v2 | |
| with: | |
| platforms: linux/arm64 | |
| # 安装依赖 | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pyinstaller | |
| # 编译二进制文件 | |
| - name: Build executable | |
| run: | | |
| pyinstaller --onefile --name my_app-${{ matrix.os }}-${{ matrix.arch }} main.py | |
| shell: bash | |
| # 上传构建的二进制文件作为工件 | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: my_app-${{ matrix.os }}-${{ matrix.arch }} | |
| path: | | |
| dist/my_app-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.os == 'windows-latest' && '.exe' || '' }} | |
| release: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 检出代码(GitHub Releases 需要访问仓库) | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| # 下载构建工件 | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v3 | |
| with: | |
| path: ./dist | |
| # 发布到 GitHub Releases | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: dist/* | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |