|
6 | 6 | - created |
7 | 7 |
|
8 | 8 | jobs: |
9 | | - |
10 | 9 | get-version-number: |
11 | 10 | runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + VERSION: ${{ steps.get_version.outputs.VERSION }} |
| 13 | + SUB_VERSION: ${{ steps.get_version.outputs.SUB_VERSION }} |
12 | 14 | steps: |
13 | | - |
14 | 15 | - name: "Checkout" |
15 | | - uses: actions/checkout@v6 |
| 16 | + uses: actions/checkout@v4 |
16 | 17 | with: |
17 | 18 | fetch-depth: 0 |
18 | 19 |
|
| 20 | + - name: "Setup Python" |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: '3.12' |
| 24 | + |
19 | 25 | - name: "Get version number" |
20 | 26 | id: get_version |
21 | 27 | run: | |
22 | | - export VERSION=$(git tag --sort=-v:refname | head -n 1) |
23 | | - export SUB_VER=$(git rev-list --no-merges --count $(git describe --tags --abbrev=0)..HEAD) |
24 | | - echo "Currect Version Number: $VERSION.$SUB_VER" |
25 | | - echo "SUB_VER = $SUB_VER" >> version.py |
26 | | - |
27 | | - # Create an environment file |
| 28 | + pip install toml |
| 29 | + # 获取当前 release 的版本号(去掉 v 前缀) |
| 30 | + VERSION="${{ github.event.release.tag_name }}" |
| 31 | + VERSION="${VERSION#v}" |
| 32 | + |
| 33 | + # 获取子版本号 |
| 34 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") |
| 35 | + SUB_VER=$(git rev-list --no-merges --count "$LATEST_TAG"..HEAD 2>/dev/null || echo "0") |
| 36 | + |
| 37 | + echo "Version: $VERSION" |
| 38 | + echo "Sub version: $SUB_VER" |
| 39 | + |
28 | 40 | echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT |
29 | 41 | echo "SUB_VERSION=${SUB_VER}" >> $GITHUB_OUTPUT |
30 | | - |
31 | | - |
32 | | - outputs: |
33 | | - VERSION: ${{ steps.get_version.outputs.VERSION }} |
34 | | - SUB_VERSION: ${{ steps.get_version.outputs.SUB_VERSION }} |
35 | | - |
36 | 42 |
|
37 | 43 | build-windows: |
38 | 44 | needs: get-version-number |
39 | | - runs-on: ${{ matrix.os }} |
| 45 | + runs-on: windows-latest |
40 | 46 | strategy: |
| 47 | + fail-fast: false |
41 | 48 | matrix: |
42 | | - os: [windows-latest] |
43 | | - arch: [x86, x64, arm64] |
| 49 | + arch: [x64] |
44 | 50 | steps: |
45 | | - |
46 | 51 | - name: "Checkout" |
47 | | - uses: actions/checkout@v6 |
| 52 | + uses: actions/checkout@v4 |
48 | 53 |
|
49 | 54 | - name: "Setup Python" |
50 | | - uses: actions/setup-python@v6 |
| 55 | + uses: actions/setup-python@v5 |
51 | 56 | with: |
52 | | - python-version: 3.12 # 保证兼容性 |
| 57 | + python-version: '3.12' |
| 58 | + architecture: ${{ matrix.arch }} |
53 | 59 |
|
54 | | - - name: Setup Poetry |
55 | | - uses: snok/install-poetry@v1.4.1 |
| 60 | + - name: "Setup Poetry" |
| 61 | + uses: snok/install-poetry@v1 |
| 62 | + with: |
| 63 | + version: latest |
| 64 | + virtualenvs-create: true |
| 65 | + virtualenvs-in-project: true |
56 | 66 |
|
57 | | - - name: "Install requirements and build" |
| 67 | + - name: "Install dependencies" |
58 | 68 | shell: bash |
59 | 69 | run: | |
60 | 70 | poetry install --all-groups |
61 | | - poetry run nuitka \ |
62 | | - --standalone\ |
63 | | - --follow-imports\ |
64 | | - --onefile\ |
65 | | - --output-dir=build\ |
66 | | - --lto=yes\ |
67 | | - --windows-icon-from-ico=icon.ico\ |
68 | | - --file-version=${{ needs.get-version-number.outputs.VERSION }}.${{ needs.get-version-number.outputs.SUB_VERSION }}\ |
69 | | - --product-version=${{ needs.get-version-number.outputs.VERSION }}.${{ needs.get-version-number.outputs.SUB_VERSION }}\ |
70 | | - --product-name=OneDisc\ |
71 | | - --enable-console=true\ |
72 | | - --file-description='OneBot Implementation for Discord'\ |
73 | | - --company-name='IT Craft Development Team'\ |
74 | | - --copyright='Copyright (c) 2025 IT Craft Development Team'\ |
| 71 | +
|
| 72 | + - name: "Build with Nuitka" |
| 73 | + shell: bash |
| 74 | + run: | |
| 75 | + poetry run python -m nuitka \ |
| 76 | + --standalone \ |
| 77 | + --onefile \ |
| 78 | + --follow-imports \ |
| 79 | + --include-package=discord \ |
| 80 | + --include-package=websockets \ |
| 81 | + --include-package=aiosqlite \ |
| 82 | + --include-package=sqlalchemy \ |
| 83 | + --include-package=fastapi \ |
| 84 | + --include-package=uvicorn \ |
| 85 | + --include-package=httpx \ |
| 86 | + --include-package=toml \ |
| 87 | + --include-package=starlette \ |
| 88 | + --include-package=pydantic \ |
| 89 | + --include-package=anyio \ |
| 90 | + --include-package=aiohttp \ |
| 91 | + --include-data-files=pyproject.toml=pyproject.toml \ |
| 92 | + --output-dir=build \ |
| 93 | + --output-filename=onedisc.exe \ |
| 94 | + --lto=yes \ |
| 95 | + --windows-icon-from-ico=icon.ico \ |
| 96 | + --file-version=${{ needs.get-version-number.outputs.VERSION }}.${{ needs.get-version-number.outputs.SUB_VERSION }} \ |
| 97 | + --product-version=${{ needs.get-version-number.outputs.VERSION }}.${{ needs.get-version-number.outputs.SUB_VERSION }} \ |
| 98 | + --product-name=OneDisc \ |
| 99 | + --enable-console \ |
| 100 | + --file-description="OneBot Implementation for Discord" \ |
| 101 | + --company-name="IT Craft Development Team" \ |
| 102 | + --copyright="Copyright (c) 2025 IT Craft Development Team" \ |
| 103 | + --assume-yes-for-downloads \ |
75 | 104 | main.py |
76 | | - |
77 | | - |
78 | 105 |
|
79 | 106 | - name: "Rename application" |
| 107 | + shell: pwsh |
80 | 108 | run: | |
81 | | - Move-Item -Path .\build\main.exe -Destination .\build\OneDisc_Windows_${{ matrix.arch }}.exe |
82 | | - |
83 | | - - name: Upload Release Asset |
84 | | - run: | |
85 | | - gh release upload v$env:VERSION .\build\OneDisc_Windows_${{ matrix.arch }}.exe |
| 109 | + $exeFile = Get-ChildItem -Path "build" -Filter "*.exe" -Recurse | Select-Object -First 1 |
| 110 | + if ($exeFile) { |
| 111 | + $destPath = "build\OneDisc_Windows_${{ matrix.arch }}.exe" |
| 112 | + Move-Item -Path $exeFile.FullName -Destination $destPath -Force |
| 113 | + Write-Host "Moved $($exeFile.Name) to $destPath" |
| 114 | + } else { |
| 115 | + Write-Host "Error: No exe file found in build directory" |
| 116 | + Get-ChildItem -Path "build" -Recurse |
| 117 | + exit 1 |
| 118 | + } |
| 119 | +
|
| 120 | + - name: "Upload Release Asset" |
86 | 121 | env: |
87 | | - VERSION: ${{ needs.get-version-number.outputs.VERSION }} |
88 | | - GH_TOKEN: ${{ secret.GITHUB_TOKEN }} |
| 122 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 123 | + run: | |
| 124 | + gh release upload ${{ github.event.release.tag_name }} "build\OneDisc_Windows_${{ matrix.arch }}.exe" --clobber |
89 | 125 |
|
90 | | - build: |
| 126 | + build-linux: |
91 | 127 | needs: get-version-number |
92 | | - runs-on: ${{ matrix.os }} |
| 128 | + runs-on: ubuntu-22.04 |
93 | 129 | strategy: |
| 130 | + fail-fast: false |
94 | 131 | matrix: |
95 | | - os: [ubuntu-22.04, macos-latest] |
96 | | - arch: [x86, x64, arm64] |
| 132 | + arch: [x64] |
97 | 133 | steps: |
| 134 | + - name: "Checkout" |
| 135 | + uses: actions/checkout@v4 |
| 136 | + |
| 137 | + - name: "Setup Python" |
| 138 | + uses: actions/setup-python@v5 |
| 139 | + with: |
| 140 | + python-version: '3.12' |
| 141 | + |
| 142 | + - name: "Setup Poetry" |
| 143 | + uses: snok/install-poetry@v1 |
| 144 | + with: |
| 145 | + version: latest |
| 146 | + virtualenvs-create: true |
| 147 | + virtualenvs-in-project: true |
| 148 | + |
| 149 | + - name: "Install system dependencies" |
| 150 | + run: | |
| 151 | + sudo apt-get update |
| 152 | + sudo apt-get install -y patchelf ccache libffi-dev |
| 153 | +
|
| 154 | + - name: "Install dependencies" |
| 155 | + run: | |
| 156 | + poetry install --all-groups |
| 157 | +
|
| 158 | + - name: "Build with Nuitka" |
| 159 | + run: | |
| 160 | + poetry run python -m nuitka \ |
| 161 | + --standalone \ |
| 162 | + --onefile \ |
| 163 | + --follow-imports \ |
| 164 | + --include-package=discord \ |
| 165 | + --include-package=websockets \ |
| 166 | + --include-package=aiosqlite \ |
| 167 | + --include-package=sqlalchemy \ |
| 168 | + --include-package=fastapi \ |
| 169 | + --include-package=uvicorn \ |
| 170 | + --include-package=httpx \ |
| 171 | + --include-package=toml \ |
| 172 | + --include-package=starlette \ |
| 173 | + --include-package=pydantic \ |
| 174 | + --include-package=anyio \ |
| 175 | + --include-package=aiohttp \ |
| 176 | + --include-data-files=pyproject.toml=pyproject.toml \ |
| 177 | + --output-dir=build \ |
| 178 | + --output-filename=onedisc \ |
| 179 | + --lto=yes \ |
| 180 | + --assume-yes-for-downloads \ |
| 181 | + --static-libpython=no \ |
| 182 | + main.py |
| 183 | +
|
| 184 | + - name: "Rename and package application" |
| 185 | + run: | |
| 186 | + EXE_FILE=$(find build -maxdepth 1 -type f -executable | head -n 1) |
| 187 | + if [ -n "$EXE_FILE" ]; then |
| 188 | + mv "$EXE_FILE" build/OneDisc_Linux_${{ matrix.arch }} |
| 189 | + chmod +x build/OneDisc_Linux_${{ matrix.arch }} |
| 190 | + else |
| 191 | + echo "Error: No executable file found in build directory" |
| 192 | + ls -la build/ |
| 193 | + exit 1 |
| 194 | + fi |
98 | 195 |
|
| 196 | + - name: "Upload Release Asset" |
| 197 | + env: |
| 198 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 199 | + run: | |
| 200 | + gh release upload ${{ github.event.release.tag_name }} "build/OneDisc_Linux_${{ matrix.arch }}" --clobber |
| 201 | +
|
| 202 | + build-macos: |
| 203 | + needs: get-version-number |
| 204 | + runs-on: macos-latest |
| 205 | + strategy: |
| 206 | + fail-fast: false |
| 207 | + matrix: |
| 208 | + include: |
| 209 | + - arch: x64 |
| 210 | + python-arch: x64 |
| 211 | + - arch: arm64 |
| 212 | + python-arch: arm64 |
| 213 | + steps: |
99 | 214 | - name: "Checkout" |
100 | | - uses: actions/checkout@v6 |
| 215 | + uses: actions/checkout@v4 |
101 | 216 |
|
102 | 217 | - name: "Setup Python" |
103 | | - uses: actions/setup-python@v6 |
| 218 | + uses: actions/setup-python@v5 |
104 | 219 | with: |
105 | | - python-version: 3.12 |
| 220 | + python-version: '3.12' |
106 | 221 |
|
107 | | - - name: Setup Poetry |
108 | | - uses: snok/install-poetry@v1.4.1 |
| 222 | + - name: "Setup Poetry" |
| 223 | + uses: snok/install-poetry@v1 |
| 224 | + with: |
| 225 | + version: latest |
| 226 | + virtualenvs-create: true |
| 227 | + virtualenvs-in-project: true |
109 | 228 |
|
110 | | - - name: "Install requirements and build" |
| 229 | + - name: "Install dependencies" |
111 | 230 | run: | |
112 | 231 | poetry install --all-groups |
113 | | - poetry run nuitka --standalone\ |
114 | | - --onefile\ |
115 | | - --follow-imports\ |
116 | | - --show-modules\ |
117 | | - --macos-app-icon=icon.ico\ |
118 | | - --output-dir=build\ |
119 | | - --lto=yes\ |
| 232 | +
|
| 233 | + - name: "Build with Nuitka" |
| 234 | + run: | |
| 235 | + poetry run python -m nuitka \ |
| 236 | + --standalone \ |
| 237 | + --onefile \ |
| 238 | + --follow-imports \ |
| 239 | + --include-package=discord \ |
| 240 | + --include-package=websockets \ |
| 241 | + --include-package=aiosqlite \ |
| 242 | + --include-package=sqlalchemy \ |
| 243 | + --include-package=fastapi \ |
| 244 | + --include-package=uvicorn \ |
| 245 | + --include-package=httpx \ |
| 246 | + --include-package=toml \ |
| 247 | + --include-package=starlette \ |
| 248 | + --include-package=pydantic \ |
| 249 | + --include-package=anyio \ |
| 250 | + --include-package=aiohttp \ |
| 251 | + --include-data-files=pyproject.toml=pyproject.toml \ |
| 252 | + --output-dir=build \ |
| 253 | + --output-filename=onedisc \ |
| 254 | + --lto=yes \ |
| 255 | + --assume-yes-for-downloads \ |
120 | 256 | main.py |
121 | 257 |
|
122 | 258 | - name: "Rename application" |
123 | 259 | run: | |
124 | | - mv build/main.bin ./build/OneDisc_${{ martix.os }}_{{ martix.arch }} |
125 | | - cd build |
126 | | - zip -r onedisc.zip onedisc |
| 260 | + EXE_FILE=$(find build -maxdepth 1 -type f -perm +111 ! -name "*.so" ! -name "*.dylib" | head -n 1) |
| 261 | + if [ -n "$EXE_FILE" ]; then |
| 262 | + mv "$EXE_FILE" build/OneDisc_macOS_${{ matrix.arch }} |
| 263 | + chmod +x build/OneDisc_macOS_${{ matrix.arch }} |
| 264 | + else |
| 265 | + echo "Error: No executable file found in build directory" |
| 266 | + ls -la build/ |
| 267 | + exit 1 |
| 268 | + fi |
127 | 269 |
|
128 | | - - name: Upload Release Asset |
129 | | - run: | |
130 | | - gh release upload v$VERSION .\build\OneDisc_Windows_${{ matrix.arch }}.exe |
| 270 | + - name: "Upload Release Asset" |
131 | 271 | env: |
132 | | - VERSION: ${{ needs.get-version-number.outputs.VERSION }} |
133 | | - GH_TOKEN: ${{ secret.GITHUB_TOKEN }} |
134 | | - |
| 272 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 273 | + run: | |
| 274 | + gh release upload ${{ github.event.release.tag_name }} "build/OneDisc_macOS_${{ matrix.arch }}" --clobber |
0 commit comments