|
| 1 | +name: Release Binaries |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + name: Build ${{ matrix.os }} |
| 11 | + runs-on: ${{ matrix.runs-on }} |
| 12 | + strategy: |
| 13 | + fail-fast: false |
| 14 | + matrix: |
| 15 | + include: |
| 16 | + - os: linux-amd64 |
| 17 | + runs-on: ubuntu-22.04 |
| 18 | + artifact: sb2p-linux-amd64 |
| 19 | + ext: "" |
| 20 | + - os: windows-amd64 |
| 21 | + runs-on: windows-latest |
| 22 | + artifact: sb2p-windows-amd64.exe |
| 23 | + ext: ".exe" |
| 24 | + - os: macos-amd64 |
| 25 | + runs-on: macos-13 |
| 26 | + artifact: sb2p-macos-amd64 |
| 27 | + ext: "" |
| 28 | + - os: macos-arm64 |
| 29 | + runs-on: macos-14 |
| 30 | + artifact: sb2p-macos-arm64 |
| 31 | + ext: "" |
| 32 | + |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - name: Set up Python |
| 37 | + uses: actions/setup-python@v5 |
| 38 | + with: |
| 39 | + python-version: "3.11" |
| 40 | + |
| 41 | + - name: Install build dependencies |
| 42 | + shell: bash |
| 43 | + run: | |
| 44 | + python -m pip install --upgrade pip |
| 45 | + python -m pip install nuitka ordered-set zstandard |
| 46 | + python -m pip install -e ".[cli]" |
| 47 | +
|
| 48 | + - name: Install C compiler (Linux) |
| 49 | + if: runner.os == 'Linux' |
| 50 | + run: sudo apt-get update && sudo apt-get install -y gcc patchelf |
| 51 | + |
| 52 | + - name: Build binary |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + python -m nuitka \ |
| 56 | + --onefile \ |
| 57 | + --output-filename="sb2p${{ matrix.ext }}" \ |
| 58 | + --output-dir=dist \ |
| 59 | + --remove-output \ |
| 60 | + --assume-yes-for-downloads \ |
| 61 | + --python-flag=no_docstrings \ |
| 62 | + --python-flag=-OO \ |
| 63 | + --include-package=singbox2proxy \ |
| 64 | + --include-module=qrcode \ |
| 65 | + --include-module=psutil \ |
| 66 | + --nofollow-import-to=tkinter \ |
| 67 | + --nofollow-import-to=unittest \ |
| 68 | + --nofollow-import-to=test \ |
| 69 | + --nofollow-import-to=distutils \ |
| 70 | + --nofollow-import-to=setuptools \ |
| 71 | + --nofollow-import-to=pydoc \ |
| 72 | + --nofollow-import-to=xmlrpc \ |
| 73 | + --nofollow-import-to=doctest \ |
| 74 | + --nofollow-import-to=pdb \ |
| 75 | + --nofollow-import-to=lib2to3 \ |
| 76 | + --nofollow-import-to=ensurepip \ |
| 77 | + singbox2proxy/__main__.py |
| 78 | +
|
| 79 | + - name: Compress with UPX (Linux) |
| 80 | + if: runner.os == 'Linux' |
| 81 | + run: | |
| 82 | + sudo apt-get install -y upx-ucl || sudo apt-get install -y upx |
| 83 | + upx --best --lzma "dist/sb2p" || true |
| 84 | +
|
| 85 | + - name: Compress with UPX (Windows) |
| 86 | + if: runner.os == 'Windows' |
| 87 | + shell: pwsh |
| 88 | + run: | |
| 89 | + Invoke-WebRequest -Uri "https://github.com/upx/upx/releases/download/v4.2.4/upx-4.2.4-win64.zip" -OutFile upx.zip |
| 90 | + Expand-Archive upx.zip -DestinationPath upx |
| 91 | + ./upx/upx-4.2.4-win64/upx.exe --best --lzma "dist/sb2p.exe" || echo "UPX compression skipped" |
| 92 | +
|
| 93 | + - name: Rename artifact |
| 94 | + shell: bash |
| 95 | + run: mv "dist/sb2p${{ matrix.ext }}" "dist/${{ matrix.artifact }}" |
| 96 | + |
| 97 | + - name: Smoke test (non-Windows) |
| 98 | + if: runner.os != 'Windows' |
| 99 | + shell: bash |
| 100 | + run: | |
| 101 | + chmod +x "dist/${{ matrix.artifact }}" |
| 102 | + "dist/${{ matrix.artifact }}" --version |
| 103 | +
|
| 104 | + - name: Smoke test (Windows) |
| 105 | + if: runner.os == 'Windows' |
| 106 | + shell: pwsh |
| 107 | + run: | |
| 108 | + & "dist/${{ matrix.artifact }}" --version |
| 109 | +
|
| 110 | + - name: Upload artifact |
| 111 | + uses: actions/upload-artifact@v4 |
| 112 | + with: |
| 113 | + name: ${{ matrix.artifact }} |
| 114 | + path: dist/${{ matrix.artifact }} |
| 115 | + |
| 116 | + - name: Upload to release |
| 117 | + if: github.event_name == 'release' |
| 118 | + uses: softprops/action-gh-release@v2 |
| 119 | + with: |
| 120 | + files: dist/${{ matrix.artifact }} |
0 commit comments