Some checks failed
Build Multi-Platform Binaries / build-binaries (amd64, darwin, client, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / prepare-all (push) Has been cancelled
94 lines
3.0 KiB
YAML
94 lines
3.0 KiB
YAML
name: Build Multi-Platform Binaries
|
|
on:
|
|
push:
|
|
paths:
|
|
- '**.go'
|
|
- 'go.mod'
|
|
- 'go.sum'
|
|
- 'web/**'
|
|
- '.gitea/workflows/**'
|
|
|
|
jobs:
|
|
prepare-all:
|
|
runs-on: node-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3 # 保持 v3 兼容性
|
|
|
|
- name: Build Frontend
|
|
run: |
|
|
cd web
|
|
npm ci
|
|
npm run build
|
|
|
|
- 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: full-workspace
|
|
path: .
|
|
retention-days: 1
|
|
|
|
build-binaries:
|
|
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: windows, goarch: amd64, target: server, upx: true }
|
|
- { goos: windows, goarch: amd64, target: client, upx: true }
|
|
# (根据需要缩减或保留 matrix)
|
|
steps:
|
|
- name: Install Node.js
|
|
run: |
|
|
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
|
|
fi
|
|
|
|
- name: Set Node IPv4 Priority
|
|
run: echo "NODE_OPTIONS=--dns-result-order=ipv4first" >> $GITHUB_ENV
|
|
|
|
- name: Download Workspace
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: full-workspace
|
|
path: .
|
|
|
|
- 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 Binary
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: ${{ env.BINARY_NAME }}
|
|
path: ${{ env.BINARY_NAME }} |