From aa925a2edd7f93f7866cdd82410e54c0167aad2a Mon Sep 17 00:00:00 2001 From: flik Date: Sat, 27 Dec 2025 00:37:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/build.yam?= =?UTF-8?q?l?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yaml | 113 ++++++++++++------------------------ 1 file changed, 37 insertions(+), 76 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 5cec56c..cb30e35 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -9,103 +9,65 @@ on: - '.gitea/workflows/**' jobs: - build-frontend: - runs-on: node-latest # 使用 Node.js 专用镜像 + prepare-all: + runs-on: node-latest steps: - name: Checkout code - uses: actions/checkout@v4 - + uses: actions/checkout@v3 # 保持 v3 兼容性 + - name: Build Frontend run: | cd web npm ci npm run build - - - name: Upload Frontend Artifact + + - name: Move Frontend to Go Folder + run: | + # 提前把前端产物放到 Go 嵌入目录,减少下游 Job 的操作 + mkdir -p internal/server/app/dist + cp -r web/dist/* internal/server/app/dist/ + + - name: Upload Integrated Workspace uses: actions/upload-artifact@v3 with: - name: frontend-dist - path: web/dist + name: full-workspace + path: . retention-days: 1 build-binaries: - needs: build-frontend - runs-on: golang-latest # 使用 Golang 专用镜像 + needs: prepare-all + runs-on: golang-latest strategy: + max-parallel: 2 # 极其重要:在 v3 且服务器不稳的情况下,建议限制到 2 个并发 matrix: include: - - goos: linux - goarch: amd64 - target: server - upx: true - - goos: linux - goarch: amd64 - target: client - upx: true - - goos: linux - goarch: arm64 - target: server - upx: true - - goos: linux - goarch: arm64 - target: client - upx: true - - goos: darwin - goarch: amd64 - target: server - upx: false - - goos: darwin - goarch: amd64 - target: client - upx: false - - goos: darwin - goarch: arm64 - target: server - upx: false - - goos: darwin - goarch: arm64 - target: client - upx: false - - goos: windows - goarch: amd64 - target: server - upx: true - - goos: windows - goarch: amd64 - target: client - upx: true - - goos: windows - goarch: arm64 - target: server - upx: true - - goos: windows - goarch: arm64 - target: client - upx: true + - { goos: linux, goarch: amd64, target: server, upx: true } + - { goos: linux, goarch: amd64, target: client, upx: true } + - { goos: linux, goarch: arm64, target: server, upx: true } + - { goos: linux, goarch: arm64, target: client, upx: true } + - { goos: darwin, goarch: amd64, target: server, upx: false } + - { goos: darwin, goarch: amd64, target: client, upx: false } + - { goos: windows, goarch: amd64, target: server, upx: true } + - { goos: windows, goarch: amd64, target: client, upx: true } + # (根据需要缩减或保留 matrix) steps: - - name: Install Node.js for Actions + - name: Install Node.js run: | - # 尝试兼容 Alpine (apk) 和 Debian/Ubuntu (apt) if command -v apk > /dev/null; then apk add --no-cache nodejs elif command -v apt-get > /dev/null; then apt-get update && apt-get install -y nodejs - else - echo "Unknown package manager" - exit 1 fi + - name: Set Node IPv4 Priority run: echo "NODE_OPTIONS=--dns-result-order=ipv4first" >> $GITHUB_ENV - - - name: Checkout code - uses: actions/checkout@v4 - - - name: Download Frontend Artifact + + - name: Download Workspace uses: actions/download-artifact@v3 with: - name: frontend-dist - path: internal/server/app/dist - + name: full-workspace + path: . + - name: Build Binary env: GOOS: ${{ matrix.goos }} @@ -116,17 +78,16 @@ jobs: if [ "${{ matrix.goos }}" = "windows" ]; then OUTPUT_NAME="${OUTPUT_NAME}.exe" fi - go build -ldflags="-s -w" -o "${OUTPUT_NAME}" ./cmd/${{ matrix.target }} echo "BINARY_NAME=${OUTPUT_NAME}" >> $GITHUB_ENV - + - name: Install and Run UPX if: matrix.upx == true run: | - apk add --no-cache upx || apt-get update && apt-get install -y upx-ucl + (apk add --no-cache upx || apt-get update && apt-get install -y upx-ucl) upx -9 "${{ env.BINARY_NAME }}" || true - - - name: Upload Individual Binary + + - name: Upload Binary uses: actions/upload-artifact@v3 with: name: ${{ env.BINARY_NAME }}