|
| 1 | +name: CI/CD |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +env: |
| 10 | + SINGBOX_VERSION: "1.12.12" |
| 11 | + |
| 12 | +jobs: |
| 13 | + # Go代码lint检查 |
| 14 | + lint-backend: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up Go |
| 20 | + uses: actions/setup-go@v5 |
| 21 | + with: |
| 22 | + go-version: '1.23' |
| 23 | + |
| 24 | + - name: golangci-lint |
| 25 | + uses: golangci/golangci-lint-action@v6 |
| 26 | + with: |
| 27 | + version: v1.61.0 |
| 28 | + working-directory: ./ |
| 29 | + args: ./backend/... |
| 30 | + |
| 31 | + # 前端ESLint检查 |
| 32 | + lint-frontend: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - name: Set up Node.js |
| 38 | + uses: actions/setup-node@v4 |
| 39 | + with: |
| 40 | + node-version: '18' |
| 41 | + cache: 'npm' |
| 42 | + cache-dependency-path: frontend/package-lock.json |
| 43 | + |
| 44 | + - name: Install dependencies |
| 45 | + run: npm ci |
| 46 | + working-directory: frontend |
| 47 | + |
| 48 | + - name: Run ESLint |
| 49 | + run: npm run lint |
| 50 | + working-directory: frontend |
| 51 | + |
| 52 | + # 后端Go编译测试 |
| 53 | + test-backend: |
| 54 | + runs-on: ubuntu-latest |
| 55 | + steps: |
| 56 | + - uses: actions/checkout@v4 |
| 57 | + |
| 58 | + - name: Set up Go |
| 59 | + uses: actions/setup-go@v5 |
| 60 | + with: |
| 61 | + go-version: '1.23' |
| 62 | + |
| 63 | + - name: Download dependencies |
| 64 | + run: go mod download |
| 65 | + |
| 66 | + - name: Build |
| 67 | + run: CGO_ENABLED=0 go build -o main ./backend |
| 68 | + |
| 69 | + - name: Test |
| 70 | + run: go test ./backend/... -v |
| 71 | + |
| 72 | + # 前端构建测试 |
| 73 | + test-frontend: |
| 74 | + runs-on: ubuntu-latest |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v4 |
| 77 | + |
| 78 | + - name: Set up Node.js |
| 79 | + uses: actions/setup-node@v4 |
| 80 | + with: |
| 81 | + node-version: '18' |
| 82 | + cache: 'npm' |
| 83 | + cache-dependency-path: frontend/package-lock.json |
| 84 | + |
| 85 | + - name: Install dependencies |
| 86 | + run: npm ci |
| 87 | + working-directory: frontend |
| 88 | + |
| 89 | + - name: Build |
| 90 | + run: npm run build |
| 91 | + working-directory: frontend |
| 92 | + |
| 93 | + # 构建并推送Docker镜像 |
| 94 | + build-docker: |
| 95 | + runs-on: ubuntu-latest |
| 96 | + needs: [test-backend, test-frontend] |
| 97 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 98 | + steps: |
| 99 | + - uses: actions/checkout@v4 |
| 100 | + |
| 101 | + - name: Set up Docker Buildx |
| 102 | + uses: docker/setup-buildx-action@v3 |
| 103 | + |
| 104 | + - name: Login to GitHub Container Registry |
| 105 | + uses: docker/login-action@v3 |
| 106 | + with: |
| 107 | + registry: ghcr.io |
| 108 | + username: ${{ github.actor }} |
| 109 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 110 | + |
| 111 | + - name: Build and push |
| 112 | + uses: docker/build-push-action@v5 |
| 113 | + with: |
| 114 | + context: . |
| 115 | + push: true |
| 116 | + tags: | |
| 117 | + ghcr.io/${{ github.repository }}:${{ github.sha }} |
| 118 | + ghcr.io/${{ github.repository }}:latest |
| 119 | + cache-from: type=gha |
| 120 | + cache-to: type=gha,mode=max |
| 121 | + |
| 122 | + # 构建前端dist |
| 123 | + build-frontend-dist: |
| 124 | + runs-on: ubuntu-latest |
| 125 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 126 | + steps: |
| 127 | + - uses: actions/checkout@v4 |
| 128 | + |
| 129 | + - name: Set up Node.js |
| 130 | + uses: actions/setup-node@v4 |
| 131 | + with: |
| 132 | + node-version: '18' |
| 133 | + cache: 'npm' |
| 134 | + cache-dependency-path: frontend/package-lock.json |
| 135 | + |
| 136 | + - name: Install dependencies |
| 137 | + run: npm ci |
| 138 | + working-directory: frontend |
| 139 | + |
| 140 | + - name: Build |
| 141 | + run: npm run build |
| 142 | + working-directory: frontend |
| 143 | + |
| 144 | + - name: Upload frontend dist |
| 145 | + uses: actions/upload-artifact@v4 |
| 146 | + with: |
| 147 | + name: frontend-dist |
| 148 | + path: frontend/dist/ |
| 149 | + retention-days: 1 |
| 150 | + |
| 151 | + # 构建Linux完整发布包 |
| 152 | + build-linux: |
| 153 | + runs-on: ubuntu-latest |
| 154 | + needs: [build-frontend-dist] |
| 155 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 156 | + steps: |
| 157 | + - uses: actions/checkout@v4 |
| 158 | + |
| 159 | + - name: Set up Go |
| 160 | + uses: actions/setup-go@v5 |
| 161 | + with: |
| 162 | + go-version: '1.23' |
| 163 | + |
| 164 | + - name: Download frontend dist |
| 165 | + uses: actions/download-artifact@v4 |
| 166 | + with: |
| 167 | + name: frontend-dist |
| 168 | + path: frontend/dist/ |
| 169 | + |
| 170 | + - name: Download dependencies |
| 171 | + run: go mod download |
| 172 | + |
| 173 | + - name: Build backend |
| 174 | + run: GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main ./backend |
| 175 | + |
| 176 | + - name: Download sing-box |
| 177 | + run: | |
| 178 | + curl -fLo sing-box.tar.gz "https://github.com/SagerNet/sing-box/releases/download/v${{ env.SINGBOX_VERSION }}/sing-box-${{ env.SINGBOX_VERSION }}-linux-amd64.tar.gz" |
| 179 | + tar xzf sing-box.tar.gz |
| 180 | + mv sing-box-*/sing-box . |
| 181 | +
|
| 182 | + - name: Create release package |
| 183 | + run: | |
| 184 | + mkdir -p singbox-proxy-manager-linux-amd64/frontend |
| 185 | + mv main singbox-proxy-manager-linux-amd64/ |
| 186 | + mv sing-box singbox-proxy-manager-linux-amd64/ |
| 187 | + cp -r frontend/dist singbox-proxy-manager-linux-amd64/frontend/ |
| 188 | + mkdir -p singbox-proxy-manager-linux-amd64/config |
| 189 | + cat > singbox-proxy-manager-linux-amd64/start.sh << 'EOF' |
| 190 | + #!/bin/sh |
| 191 | + cd "$(dirname "$0")" |
| 192 | + export PATH="$PWD:$PATH" |
| 193 | + export CONFIG_DIR="$PWD/config" |
| 194 | + export PORT="${PORT:-30000}" |
| 195 | + export ADMIN_PASSWORD="${ADMIN_PASSWORD:-admin123}" |
| 196 | + ./main |
| 197 | + EOF |
| 198 | + chmod +x singbox-proxy-manager-linux-amd64/start.sh |
| 199 | + tar czf singbox-proxy-manager-linux-amd64.tar.gz singbox-proxy-manager-linux-amd64/ |
| 200 | +
|
| 201 | + - name: Upload artifact |
| 202 | + uses: actions/upload-artifact@v4 |
| 203 | + with: |
| 204 | + name: singbox-proxy-manager-linux-amd64 |
| 205 | + path: singbox-proxy-manager-linux-amd64.tar.gz |
| 206 | + retention-days: 30 |
| 207 | + |
| 208 | + # 构建FreeBSD完整发布包 |
| 209 | + build-freebsd: |
| 210 | + runs-on: ubuntu-latest |
| 211 | + needs: [build-frontend-dist] |
| 212 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 213 | + steps: |
| 214 | + - uses: actions/checkout@v4 |
| 215 | + |
| 216 | + - name: Set up Go |
| 217 | + uses: actions/setup-go@v5 |
| 218 | + with: |
| 219 | + go-version: '1.23' |
| 220 | + |
| 221 | + - name: Download frontend dist |
| 222 | + uses: actions/download-artifact@v4 |
| 223 | + with: |
| 224 | + name: frontend-dist |
| 225 | + path: frontend/dist/ |
| 226 | + |
| 227 | + - name: Download dependencies |
| 228 | + run: go mod download |
| 229 | + |
| 230 | + - name: Build backend for FreeBSD |
| 231 | + run: GOOS=freebsd GOARCH=amd64 CGO_ENABLED=0 go build -o main ./backend |
| 232 | + |
| 233 | + - name: Build sing-box for FreeBSD |
| 234 | + run: | |
| 235 | + git clone --depth 1 --branch v${{ env.SINGBOX_VERSION }} https://github.com/SagerNet/sing-box.git |
| 236 | + cd sing-box && GOOS=freebsd GOARCH=amd64 CGO_ENABLED=0 go build -o ../sing-box ./cmd/sing-box |
| 237 | +
|
| 238 | + - name: Create release package |
| 239 | + run: | |
| 240 | + mkdir -p singbox-proxy-manager-freebsd-amd64/frontend |
| 241 | + mv main singbox-proxy-manager-freebsd-amd64/ |
| 242 | + mv sing-box singbox-proxy-manager-freebsd-amd64/ |
| 243 | + cp -r frontend/dist singbox-proxy-manager-freebsd-amd64/frontend/ |
| 244 | + mkdir -p singbox-proxy-manager-freebsd-amd64/config |
| 245 | + cat > singbox-proxy-manager-freebsd-amd64/start.sh << 'EOF' |
| 246 | + #!/bin/sh |
| 247 | + cd "$(dirname "$0")" |
| 248 | + export PATH="$PWD:$PATH" |
| 249 | + export CONFIG_DIR="$PWD/config" |
| 250 | + export PORT="${PORT:-30000}" |
| 251 | + export ADMIN_PASSWORD="${ADMIN_PASSWORD:-admin123}" |
| 252 | + ./main |
| 253 | + EOF |
| 254 | + chmod +x singbox-proxy-manager-freebsd-amd64/start.sh |
| 255 | + tar czf singbox-proxy-manager-freebsd-amd64.tar.gz singbox-proxy-manager-freebsd-amd64/ |
| 256 | +
|
| 257 | + - name: Upload artifact |
| 258 | + uses: actions/upload-artifact@v4 |
| 259 | + with: |
| 260 | + name: singbox-proxy-manager-freebsd-amd64 |
| 261 | + path: singbox-proxy-manager-freebsd-amd64.tar.gz |
| 262 | + retention-days: 30 |
| 263 | + |
| 264 | + # 自动发布到Releases |
| 265 | + auto-release: |
| 266 | + runs-on: ubuntu-latest |
| 267 | + needs: [build-linux, build-freebsd, build-docker] |
| 268 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 269 | + permissions: |
| 270 | + contents: write |
| 271 | + steps: |
| 272 | + - uses: actions/checkout@v4 |
| 273 | + |
| 274 | + - name: Download Linux artifact |
| 275 | + uses: actions/download-artifact@v4 |
| 276 | + with: |
| 277 | + name: singbox-proxy-manager-linux-amd64 |
| 278 | + path: ./ |
| 279 | + |
| 280 | + - name: Download FreeBSD artifact |
| 281 | + uses: actions/download-artifact@v4 |
| 282 | + with: |
| 283 | + name: singbox-proxy-manager-freebsd-amd64 |
| 284 | + path: ./ |
| 285 | + |
| 286 | + - name: Generate version tag |
| 287 | + id: version |
| 288 | + run: echo "tag=v0.0.${{ github.run_number }}" >> $GITHUB_OUTPUT |
| 289 | + |
| 290 | + - name: Create Release |
| 291 | + uses: softprops/action-gh-release@v2 |
| 292 | + with: |
| 293 | + tag_name: ${{ steps.version.outputs.tag }} |
| 294 | + name: "Auto Release ${{ steps.version.outputs.tag }}" |
| 295 | + body: | |
| 296 | + ## 自动构建版本 ${{ steps.version.outputs.tag }} |
| 297 | +
|
| 298 | + Commit: ${{ github.sha }} |
| 299 | +
|
| 300 | + ### 完整发布包(开箱即用) |
| 301 | +
|
| 302 | + 包含:后端程序 + 前端文件 + sing-box + 启动脚本 |
| 303 | +
|
| 304 | + | 平台 | 下载 | |
| 305 | + |------|------| |
| 306 | + | Linux (amd64) | singbox-proxy-manager-linux-amd64.tar.gz | |
| 307 | + | FreeBSD (amd64) | singbox-proxy-manager-freebsd-amd64.tar.gz | |
| 308 | + | Docker | `docker pull ghcr.io/${{ github.repository }}:latest` | |
| 309 | +
|
| 310 | + ### 使用方法 |
| 311 | + ```bash |
| 312 | + tar xzf singbox-proxy-manager-linux-amd64.tar.gz |
| 313 | + cd singbox-proxy-manager-linux-amd64 |
| 314 | + ADMIN_PASSWORD=your_password ./start.sh |
| 315 | + # 访问 http://localhost:30000 |
| 316 | + ``` |
| 317 | + files: | |
| 318 | + singbox-proxy-manager-linux-amd64.tar.gz |
| 319 | + singbox-proxy-manager-freebsd-amd64.tar.gz |
| 320 | + draft: false |
| 321 | + prerelease: false |
0 commit comments