From fb51bedbdfd640e2b520c61592efa852f00c5a5a Mon Sep 17 00:00:00 2001 From: flik Date: Fri, 26 Dec 2025 23:40:03 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/build?= =?UTF-8?q?.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yaml | 171 +++++++++++++++++++++--------------- 1 file changed, 98 insertions(+), 73 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 375c81b..9ea2bce 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -1,5 +1,4 @@ name: Build Multi-Platform Binaries - on: push: paths: @@ -10,85 +9,111 @@ on: - '.gitea/workflows/**' jobs: - build: - runs-on: ubuntu-latest + build-frontend: + runs-on: node-latest # 使用 Node.js 专用镜像 steps: - name: Checkout code uses: actions/checkout@v4 - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version: '1.24' - cache: true - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - cache: 'npm' - cache-dependency-path: web/package-lock.json - + - name: Build Frontend run: | cd web npm ci npm run build - - - name: Copy Frontend to Embed Path - run: cp -r web/dist internal/server/app/dist - - - name: Install UPX - run: | - sudo apt-get update - sudo apt-get install -y upx-ucl - - - name: Build all platforms - run: | - mkdir -p dist - - # Linux amd64 - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" \ - -o dist/server-linux-amd64 ./cmd/server - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" \ - -o dist/client-linux-amd64 ./cmd/client - - # Linux arm64 - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" \ - -o dist/server-linux-arm64 ./cmd/server - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" \ - -o dist/client-linux-arm64 ./cmd/client - - # Darwin amd64 - CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" \ - -o dist/server-darwin-amd64 ./cmd/server - CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" \ - -o dist/client-darwin-amd64 ./cmd/client - - # Darwin arm64 - CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" \ - -o dist/server-darwin-arm64 ./cmd/server - CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" \ - -o dist/client-darwin-arm64 ./cmd/client - - # Windows amd64 - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" \ - -o dist/server-windows-amd64.exe ./cmd/server - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" \ - -o dist/client-windows-amd64.exe ./cmd/client - - - name: Compress with UPX - run: | - # UPX 压缩 Linux 和 Windows 二进制 (macOS 不支持) - upx -9 dist/server-linux-amd64 dist/client-linux-amd64 || true - upx -9 dist/server-linux-arm64 dist/client-linux-arm64 || true - upx -9 dist/server-windows-amd64.exe dist/client-windows-amd64.exe || true - - - name: List artifacts - run: ls -lah dist/ - - - name: Upload artifacts + + - name: Upload Frontend Artifact uses: actions/upload-artifact@v3 with: - name: gotunnel-binaries - path: dist/ + name: frontend-dist + path: web/dist + retention-days: 1 + + build-binaries: + needs: build-frontend + runs-on: golang-latest # 使用 Golang 专用镜像 + strategy: + 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 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download Frontend Artifact + uses: actions/download-artifact@v3 + with: + name: frontend-dist + path: internal/server/app/dist + + - name: Build Binary + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + CGO_ENABLED: 0 + run: | + OUTPUT_NAME="${{ matrix.target }}-${{ matrix.goos }}-${{ matrix.goarch }}" + 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 + upx -9 "${{ env.BINARY_NAME }}" || true + + - name: Upload Individual Binary + uses: actions/upload-artifact@v3 + with: + name: ${{ env.BINARY_NAME }} + path: ${{ env.BINARY_NAME }} \ No newline at end of file From 589ebf1255faa5b05cc73fe04d9cd0d041d92978 Mon Sep 17 00:00:00 2001 From: flik Date: Sat, 27 Dec 2025 00:15:35 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/build?= =?UTF-8?q?.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 9ea2bce..357888d 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -83,6 +83,17 @@ jobs: target: client upx: true steps: + - name: Install Node.js for Actions + 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: Checkout code uses: actions/checkout@v4 From 6b820b471bced91f985656c24a422504bfb2fa55 Mon Sep 17 00:00:00 2001 From: flik Date: Sat, 27 Dec 2025 00:28:30 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/build?= =?UTF-8?q?.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 357888d..5cec56c 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -94,6 +94,9 @@ jobs: 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 From aa925a2edd7f93f7866cdd82410e54c0167aad2a Mon Sep 17 00:00:00 2001 From: flik Date: Sat, 27 Dec 2025 00:37:19 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/build?= =?UTF-8?q?.yaml?= 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 }} From 444d2b0a9745ad1fe249f67b4fa1983eec4b9bd5 Mon Sep 17 00:00:00 2001 From: flik Date: Sat, 27 Dec 2025 00:41:37 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/build?= =?UTF-8?q?.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yaml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index cb30e35..d4e917d 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -13,7 +13,7 @@ jobs: runs-on: node-latest steps: - name: Checkout code - uses: actions/checkout@v3 # 保持 v3 兼容性 + uses: actions/checkout@v3 - name: Build Frontend run: | @@ -23,17 +23,23 @@ jobs: - name: Move Frontend to Go Folder run: | - # 提前把前端产物放到 Go 嵌入目录,减少下游 Job 的操作 + # 1. 确保目标目录存在 mkdir -p internal/server/app/dist + # 2. 拷贝构建好的静态资源 cp -r web/dist/* internal/server/app/dist/ + # 3. 【关键步骤】删除 node_modules,避免它们被上传 + rm -rf web/node_modules + # 4. (可选) 如果你不需要 web 源码,也可以删掉源码目录只留 dist + # rm -rf web/src - name: Upload Integrated Workspace uses: actions/upload-artifact@v3 with: name: full-workspace + # 依然上传根目录,但此时 node_modules 已经没了 path: . retention-days: 1 - + build-binaries: needs: prepare-all runs-on: golang-latest From 08aa20445d64536c051297aa309b1c5bc4ad5b60 Mon Sep 17 00:00:00 2001 From: flik Date: Sat, 27 Dec 2025 00:50:07 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/build?= =?UTF-8?q?.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yaml | 121 +++++++++++++++++++++++------------- 1 file changed, 77 insertions(+), 44 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index d4e917d..5cec56c 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -9,71 +9,103 @@ on: - '.gitea/workflows/**' jobs: - prepare-all: - runs-on: node-latest + build-frontend: + runs-on: node-latest # 使用 Node.js 专用镜像 steps: - name: Checkout code - uses: actions/checkout@v3 - + uses: actions/checkout@v4 + - name: Build Frontend run: | cd web npm ci npm run build - - - name: Move Frontend to Go Folder - run: | - # 1. 确保目标目录存在 - mkdir -p internal/server/app/dist - # 2. 拷贝构建好的静态资源 - cp -r web/dist/* internal/server/app/dist/ - # 3. 【关键步骤】删除 node_modules,避免它们被上传 - rm -rf web/node_modules - # 4. (可选) 如果你不需要 web 源码,也可以删掉源码目录只留 dist - # rm -rf web/src - - - name: Upload Integrated Workspace + + - name: Upload Frontend Artifact uses: actions/upload-artifact@v3 with: - name: full-workspace - # 依然上传根目录,但此时 node_modules 已经没了 - path: . + name: frontend-dist + path: web/dist retention-days: 1 - + build-binaries: - needs: prepare-all - runs-on: golang-latest + needs: build-frontend + runs-on: golang-latest # 使用 Golang 专用镜像 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: windows, goarch: amd64, target: server, upx: true } - - { goos: windows, goarch: amd64, target: client, upx: true } - # (根据需要缩减或保留 matrix) + - 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 steps: - - name: Install Node.js + - name: Install Node.js for Actions 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: Download Workspace + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download Frontend Artifact uses: actions/download-artifact@v3 with: - name: full-workspace - path: . - + name: frontend-dist + path: internal/server/app/dist + - name: Build Binary env: GOOS: ${{ matrix.goos }} @@ -84,16 +116,17 @@ 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 Binary + + - name: Upload Individual Binary uses: actions/upload-artifact@v3 with: name: ${{ env.BINARY_NAME }} From 8a630aedec08e9e37eccde45cf31e3224d1adda7 Mon Sep 17 00:00:00 2001 From: flik Date: Sat, 27 Dec 2025 12:30:15 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/build?= =?UTF-8?q?.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yaml | 125 ++++++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 40 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 5cec56c..5461020 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -1,4 +1,5 @@ name: Build Multi-Platform Binaries + on: push: paths: @@ -9,125 +10,169 @@ on: - '.gitea/workflows/**' jobs: + # ======================= + # Frontend Build + # ======================= build-frontend: - runs-on: node-latest # 使用 Node.js 专用镜像 + runs-on: node-latest steps: - name: Checkout code uses: actions/checkout@v4 - + - name: Build Frontend run: | cd web npm ci npm run build - + - name: Upload Frontend Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: frontend-dist path: web/dist retention-days: 1 + # ======================= + # Backend Build Matrix + # ======================= build-binaries: needs: build-frontend - runs-on: golang-latest # 使用 Golang 专用镜像 + runs-on: golang-latest + strategy: + fail-fast: false matrix: include: + # ---------- Linux amd64 ---------- - goos: linux goarch: amd64 target: server upx: true + - goos: linux goarch: amd64 target: client upx: true + + # ---------- Linux arm64 ---------- - goos: linux goarch: arm64 target: server upx: true + - goos: linux goarch: arm64 target: client upx: true + + # ---------- Linux ARMv7 / ARMv8l ---------- + - goos: linux + goarch: arm + goarm: 7 + target: server + upx: false + + - goos: linux + goarch: arm + goarm: 7 + target: client + upx: false + + # ---------- (Optional) ARMv6 ---------- + - goos: linux + goarch: arm + goarm: 6 + target: client + upx: false + + # ---------- macOS ---------- - 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 + + # ---------- Windows ---------- - 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 + steps: - - name: Install Node.js for Actions - 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 - + + # ---------- Download frontend ---------- - name: Download Frontend Artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: frontend-dist path: internal/server/app/dist - + + # ---------- Build ---------- - name: Build Binary env: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} + GOARM: ${{ matrix.goarm }} CGO_ENABLED: 0 run: | + set -e + OUTPUT_NAME="${{ matrix.target }}-${{ matrix.goos }}-${{ matrix.goarch }}" + + if [ "${{ matrix.goarch }}" = "arm" ]; then + OUTPUT_NAME="${OUTPUT_NAME}v${{ matrix.goarm }}" + fi + 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 - + + echo "Building $OUTPUT_NAME" + + go build \ + -trimpath \ + -ldflags="-s -w" \ + -o "$OUTPUT_NAME" \ + ./cmd/${{ matrix.target }} + + echo "BINARY_NAME=$OUTPUT_NAME" >> $GITHUB_ENV + + # ---------- UPX (safe only) ---------- - name: Install and Run UPX - if: matrix.upx == true + if: matrix.upx == true && matrix.goarch != 'arm' run: | - apk add --no-cache upx || apt-get update && apt-get install -y upx-ucl + if command -v apk >/dev/null; then + apk add --no-cache upx + else + apt-get update && apt-get install -y upx-ucl + fi + upx -9 "${{ env.BINARY_NAME }}" || true - - - name: Upload Individual Binary - uses: actions/upload-artifact@v3 + + # ---------- Upload ---------- + - name: Upload Binary + uses: actions/upload-artifact@v4 with: name: ${{ env.BINARY_NAME }} - path: ${{ env.BINARY_NAME }} \ No newline at end of file + path: ${{ env.BINARY_NAME }} From c6d2a1f5c84299cad9177894b227f5ed16947cd7 Mon Sep 17 00:00:00 2001 From: flik Date: Sat, 27 Dec 2025 12:36:46 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/build?= =?UTF-8?q?.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 5461020..771e269 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -26,7 +26,7 @@ jobs: npm run build - name: Upload Frontend Artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v3 with: name: frontend-dist path: web/dist From 0ee14d3f79a64d60f5eeb743f1e448fa1c39fffe Mon Sep 17 00:00:00 2001 From: flik Date: Sat, 27 Dec 2025 16:31:10 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/build?= =?UTF-8?q?.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build.yaml | 173 ++++++++++++------------------------ 1 file changed, 55 insertions(+), 118 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 771e269..48f9d8b 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -1,5 +1,4 @@ name: Build Multi-Platform Binaries - on: push: paths: @@ -10,21 +9,19 @@ on: - '.gitea/workflows/**' jobs: - # ======================= - # Frontend Build - # ======================= + # --- 任务 1: 构建前端 --- build-frontend: runs-on: node-latest steps: - name: Checkout code uses: actions/checkout@v4 - + - name: Build Frontend run: | cd web npm ci npm run build - + - name: Upload Frontend Artifact uses: actions/upload-artifact@v3 with: @@ -32,103 +29,53 @@ jobs: path: web/dist retention-days: 1 - # ======================= - # Backend Build Matrix - # ======================= + # --- 任务 2: 构建多平台二进制文件 --- build-binaries: needs: build-frontend runs-on: golang-latest - strategy: - fail-fast: false + fail-fast: false # 即使某个平台失败,也继续构建其他平台 matrix: include: - # ---------- Linux amd64 ---------- - - goos: linux - goarch: amd64 - target: server - upx: true - - - goos: linux - goarch: amd64 - target: client - upx: true - - # ---------- Linux arm64 ---------- - - goos: linux - goarch: arm64 - target: server - upx: true - - - goos: linux - goarch: arm64 - target: client - upx: true - - # ---------- Linux ARMv7 / ARMv8l ---------- - - goos: linux - goarch: arm - goarm: 7 - target: server - upx: false - - - goos: linux - goarch: arm - goarm: 7 - target: client - upx: false - - # ---------- (Optional) ARMv6 ---------- - - goos: linux - goarch: arm - goarm: 6 - target: client - upx: false - - # ---------- macOS ---------- - - goos: darwin - goarch: amd64 - target: server - upx: false - - - goos: darwin - goarch: arm64 - target: server - upx: false - - # ---------- Windows ---------- - - 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 + # Linux 平台 + - { goos: linux, goarch: amd64, target: server, upx: true } + - { goos: linux, goarch: amd64, target: client, upx: true } + - { goos: linux, goarch: arm64, target: server, upx: true } # ARMv8 64-bit + - { goos: linux, goarch: arm64, target: client, upx: true } + # 针对 ARMv8 (v8l) 32位模式,使用 GOARM=7 确保最大兼容性 + - { goos: linux, goarch: arm, goarm: 7, target: server, upx: true } + - { goos: linux, goarch: arm, goarm: 7, target: client, upx: true } + + # Windows 平台 + - { goos: windows, goarch: amd64, target: server, upx: true } + - { goos: windows, goarch: amd64, target: client, upx: true } + - { goos: windows, goarch: arm64, target: server, upx: false } + + # Darwin (macOS) 平台 + - { goos: darwin, goarch: amd64, target: server, upx: false } + - { goos: darwin, goarch: arm64, target: server, upx: false } steps: + # 关键步骤:在 checkout 之前安装 Node.js,否则 checkout@v4 会报错 + - name: Install Node.js & UPX + run: | + if command -v apk > /dev/null; then + apk add --no-cache nodejs upx + elif command -v apt-get > /dev/null; then + apt-get update && apt-get install -y nodejs upx-ucl + else + echo "Unsupported package manager" && exit 1 + fi + - name: Checkout code uses: actions/checkout@v4 - # ---------- Download frontend ---------- - name: Download Frontend Artifact - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v3 with: name: frontend-dist path: internal/server/app/dist - # ---------- Build ---------- - name: Build Binary env: GOOS: ${{ matrix.goos }} @@ -136,43 +83,33 @@ jobs: GOARM: ${{ matrix.goarm }} CGO_ENABLED: 0 run: | - set -e - - OUTPUT_NAME="${{ matrix.target }}-${{ matrix.goos }}-${{ matrix.goarch }}" - + # 处理文件名后缀 + ARM_VAL="" if [ "${{ matrix.goarch }}" = "arm" ]; then - OUTPUT_NAME="${OUTPUT_NAME}v${{ matrix.goarm }}" + ARM_VAL="v${{ matrix.goarm }}" fi - + + EXT="" if [ "${{ matrix.goos }}" = "windows" ]; then - OUTPUT_NAME="${OUTPUT_NAME}.exe" + EXT=".exe" fi + + FILENAME="${{ matrix.target }}-${{ matrix.goos }}-${{ matrix.goarch }}${ARM_VAL}${EXT}" + + # 执行编译 + go build -ldflags="-s -w" -o "${FILENAME}" ./cmd/${{ matrix.target }} + + # 记录文件名供后续步骤使用 + echo "CURRENT_FILENAME=${FILENAME}" >> $GITHUB_ENV - echo "Building $OUTPUT_NAME" - - go build \ - -trimpath \ - -ldflags="-s -w" \ - -o "$OUTPUT_NAME" \ - ./cmd/${{ matrix.target }} - - echo "BINARY_NAME=$OUTPUT_NAME" >> $GITHUB_ENV - - # ---------- UPX (safe only) ---------- - - name: Install and Run UPX - if: matrix.upx == true && matrix.goarch != 'arm' + - name: Run UPX Compression + if: matrix.upx == true run: | - if command -v apk >/dev/null; then - apk add --no-cache upx - else - apt-get update && apt-get install -y upx-ucl - fi + # 尝试压缩,即使失败也不中断工作流(某些架构不支持 UPX) + upx -9 "${{ env.CURRENT_FILENAME }}" || echo "UPX skipped for this platform" - upx -9 "${{ env.BINARY_NAME }}" || true - - # ---------- Upload ---------- - name: Upload Binary - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v3 with: - name: ${{ env.BINARY_NAME }} - path: ${{ env.BINARY_NAME }} + name: ${{ env.CURRENT_FILENAME }} + path: ${{ env.CURRENT_FILENAME }} \ No newline at end of file