更新 .gitea/workflows/build.yaml
All checks were successful
Build Multi-Platform Binaries / build-frontend (push) Successful in 29s
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Successful in 49s
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Successful in 38s
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Successful in 59s
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Successful in 35s
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Successful in 57s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Successful in 38s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Successful in 1m4s
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Successful in 51s
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Successful in 36s
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Successful in 58s
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Successful in 51s

This commit is contained in:
2025-12-27 16:31:10 +08:00
parent c6d2a1f5c8
commit 0ee14d3f79

View File

@@ -1,5 +1,4 @@
name: Build Multi-Platform Binaries name: Build Multi-Platform Binaries
on: on:
push: push:
paths: paths:
@@ -10,9 +9,7 @@ on:
- '.gitea/workflows/**' - '.gitea/workflows/**'
jobs: jobs:
# ======================= # --- 任务 1: 构建前端 ---
# Frontend Build
# =======================
build-frontend: build-frontend:
runs-on: node-latest runs-on: node-latest
steps: steps:
@@ -32,103 +29,53 @@ jobs:
path: web/dist path: web/dist
retention-days: 1 retention-days: 1
# ======================= # --- 任务 2: 构建多平台二进制文件 ---
# Backend Build Matrix
# =======================
build-binaries: build-binaries:
needs: build-frontend needs: build-frontend
runs-on: golang-latest runs-on: golang-latest
strategy: strategy:
fail-fast: false fail-fast: false # 即使某个平台失败,也继续构建其他平台
matrix: matrix:
include: include:
# ---------- Linux amd64 ---------- # Linux 平台
- goos: linux - { goos: linux, goarch: amd64, target: server, upx: true }
goarch: amd64 - { goos: linux, goarch: amd64, target: client, upx: true }
target: server - { goos: linux, goarch: arm64, target: server, upx: true } # ARMv8 64-bit
upx: true - { 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 }
- goos: linux # Windows 平台
goarch: amd64 - { goos: windows, goarch: amd64, target: server, upx: true }
target: client - { goos: windows, goarch: amd64, target: client, upx: true }
upx: true - { goos: windows, goarch: arm64, target: server, upx: false }
# ---------- Linux arm64 ---------- # Darwin (macOS) 平台
- goos: linux - { goos: darwin, goarch: amd64, target: server, upx: false }
goarch: arm64 - { goos: darwin, goarch: arm64, target: server, upx: false }
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
steps: 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 - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
# ---------- Download frontend ----------
- name: Download Frontend Artifact - name: Download Frontend Artifact
uses: actions/download-artifact@v4 uses: actions/download-artifact@v3
with: with:
name: frontend-dist name: frontend-dist
path: internal/server/app/dist path: internal/server/app/dist
# ---------- Build ----------
- name: Build Binary - name: Build Binary
env: env:
GOOS: ${{ matrix.goos }} GOOS: ${{ matrix.goos }}
@@ -136,43 +83,33 @@ jobs:
GOARM: ${{ matrix.goarm }} GOARM: ${{ matrix.goarm }}
CGO_ENABLED: 0 CGO_ENABLED: 0
run: | run: |
set -e # 处理文件名后缀
ARM_VAL=""
OUTPUT_NAME="${{ matrix.target }}-${{ matrix.goos }}-${{ matrix.goarch }}"
if [ "${{ matrix.goarch }}" = "arm" ]; then if [ "${{ matrix.goarch }}" = "arm" ]; then
OUTPUT_NAME="${OUTPUT_NAME}v${{ matrix.goarm }}" ARM_VAL="v${{ matrix.goarm }}"
fi fi
EXT=""
if [ "${{ matrix.goos }}" = "windows" ]; then if [ "${{ matrix.goos }}" = "windows" ]; then
OUTPUT_NAME="${OUTPUT_NAME}.exe" EXT=".exe"
fi fi
echo "Building $OUTPUT_NAME" FILENAME="${{ matrix.target }}-${{ matrix.goos }}-${{ matrix.goarch }}${ARM_VAL}${EXT}"
go build \ # 执行编译
-trimpath \ go build -ldflags="-s -w" -o "${FILENAME}" ./cmd/${{ matrix.target }}
-ldflags="-s -w" \
-o "$OUTPUT_NAME" \
./cmd/${{ matrix.target }}
echo "BINARY_NAME=$OUTPUT_NAME" >> $GITHUB_ENV # 记录文件名供后续步骤使用
echo "CURRENT_FILENAME=${FILENAME}" >> $GITHUB_ENV
# ---------- UPX (safe only) ---------- - name: Run UPX Compression
- name: Install and Run UPX if: matrix.upx == true
if: matrix.upx == true && matrix.goarch != 'arm'
run: | run: |
if command -v apk >/dev/null; then # 尝试压缩,即使失败也不中断工作流(某些架构不支持 UPX
apk add --no-cache upx upx -9 "${{ env.CURRENT_FILENAME }}" || echo "UPX skipped for this platform"
else
apt-get update && apt-get install -y upx-ucl
fi
upx -9 "${{ env.BINARY_NAME }}" || true
# ---------- Upload ----------
- name: Upload Binary - name: Upload Binary
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v3
with: with:
name: ${{ env.BINARY_NAME }} name: ${{ env.CURRENT_FILENAME }}
path: ${{ env.BINARY_NAME }} path: ${{ env.CURRENT_FILENAME }}