111
This commit is contained in:
@@ -9,21 +9,29 @@ on:
|
|||||||
- '.gitea/workflows/**'
|
- '.gitea/workflows/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# --- 任务 1: 构建前端 ---
|
|
||||||
build-frontend:
|
build-frontend:
|
||||||
runs-on: node
|
runs-on: node
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# 缓存 node_modules
|
# 使用本地目录缓存(而非 actions/cache)
|
||||||
- name: Cache Node modules
|
- name: Cache Node modules
|
||||||
uses: actions/cache@v3
|
run: |
|
||||||
with:
|
CACHE_DIR="/data/cache/node-modules"
|
||||||
path: web/node_modules
|
CACHE_KEY="node-modules-${{ hashFiles('web/package-lock.json') }}"
|
||||||
key: node-modules-${{ hashFiles('web/package-lock.json') }}
|
|
||||||
restore-keys: |
|
mkdir -p "$CACHE_DIR"
|
||||||
node-modules-
|
|
||||||
|
# 如果缓存存在且匹配,恢复缓存
|
||||||
|
if [ -d "$CACHE_DIR/$CACHE_KEY" ]; then
|
||||||
|
echo "Cache hit: $CACHE_KEY"
|
||||||
|
cp -r "$CACHE_DIR/$CACHE_KEY" web/node_modules
|
||||||
|
else
|
||||||
|
echo "Cache miss: $CACHE_KEY"
|
||||||
|
# 清理旧缓存
|
||||||
|
rm -rf "$CACHE_DIR"/*
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Build Frontend
|
- name: Build Frontend
|
||||||
run: |
|
run: |
|
||||||
@@ -31,6 +39,20 @@ jobs:
|
|||||||
npm ci --prefer-offline --no-audit
|
npm ci --prefer-offline --no-audit
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
|
# 保存缓存到本地目录
|
||||||
|
- name: Save Node modules cache
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
CACHE_DIR="/data/cache/node-modules"
|
||||||
|
CACHE_KEY="node-modules-${{ hashFiles('web/package-lock.json') }}"
|
||||||
|
|
||||||
|
if [ -d "web/node_modules" ]; then
|
||||||
|
mkdir -p "$CACHE_DIR"
|
||||||
|
rm -rf "$CACHE_DIR/$CACHE_KEY"
|
||||||
|
cp -r web/node_modules "$CACHE_DIR/$CACHE_KEY"
|
||||||
|
echo "Cache saved: $CACHE_KEY"
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Upload Frontend Artifact
|
- name: Upload Frontend Artifact
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
@@ -38,7 +60,6 @@ jobs:
|
|||||||
path: web/dist
|
path: web/dist
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
# --- 任务 2: 构建多平台二进制文件 ---
|
|
||||||
build-binaries:
|
build-binaries:
|
||||||
needs: build-frontend
|
needs: build-frontend
|
||||||
runs-on: golang
|
runs-on: golang
|
||||||
@@ -46,25 +67,9 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
# Linux 平台
|
# ... 你的 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: 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:
|
steps:
|
||||||
# 在 checkout 前安装依赖
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: |
|
run: |
|
||||||
if command -v apk > /dev/null; then
|
if command -v apk > /dev/null; then
|
||||||
@@ -78,18 +83,25 @@ jobs:
|
|||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# 缓存 Go 模块
|
# 使用本地目录缓存 Go 模块
|
||||||
- name: Cache Go modules
|
- name: Cache Go modules
|
||||||
uses: actions/cache@v3
|
run: |
|
||||||
with:
|
CACHE_DIR="/data/cache/go-modules"
|
||||||
path: |
|
CACHE_KEY="go-${{ runner.os }}-${{ hashFiles('go.sum') }}"
|
||||||
~/.cache/go-build
|
|
||||||
~/go/pkg/mod
|
mkdir -p "$CACHE_DIR"
|
||||||
key: go-${{ runner.os }}-${{ hashFiles('go.sum') }}
|
|
||||||
restore-keys: |
|
if [ -d "$CACHE_DIR/$CACHE_KEY" ]; then
|
||||||
go-${{ runner.os }}-
|
echo "Cache hit: $CACHE_KEY"
|
||||||
|
mkdir -p ~/go/pkg/mod
|
||||||
|
mkdir -p ~/.cache/go-build
|
||||||
|
[ -d "$CACHE_DIR/$CACHE_KEY/mod" ] && cp -r "$CACHE_DIR/$CACHE_KEY/mod"/* ~/go/pkg/mod/ 2>/dev/null || true
|
||||||
|
[ -d "$CACHE_DIR/$CACHE_KEY/build" ] && cp -r "$CACHE_DIR/$CACHE_KEY/build"/* ~/.cache/go-build/ 2>/dev/null || true
|
||||||
|
else
|
||||||
|
echo "Cache miss: $CACHE_KEY"
|
||||||
|
rm -rf "$CACHE_DIR"/*
|
||||||
|
fi
|
||||||
|
|
||||||
# 下载依赖(只在缓存未命中时执行)
|
|
||||||
- name: Download Go dependencies
|
- name: Download Go dependencies
|
||||||
run: go mod download
|
run: go mod download
|
||||||
|
|
||||||
@@ -106,7 +118,6 @@ jobs:
|
|||||||
GOARM: ${{ matrix.goarm }}
|
GOARM: ${{ matrix.goarm }}
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
run: |
|
run: |
|
||||||
# 处理文件名
|
|
||||||
ARM_VAL=""
|
ARM_VAL=""
|
||||||
[ "${{ matrix.goarch }}" = "arm" ] && ARM_VAL="v${{ matrix.goarm }}"
|
[ "${{ matrix.goarch }}" = "arm" ] && ARM_VAL="v${{ matrix.goarm }}"
|
||||||
|
|
||||||
@@ -115,11 +126,24 @@ jobs:
|
|||||||
|
|
||||||
FILENAME="gotunnel-${{ matrix.target }}-${{ matrix.goos }}-${{ matrix.goarch }}${ARM_VAL}${EXT}"
|
FILENAME="gotunnel-${{ matrix.target }}-${{ matrix.goos }}-${{ matrix.goarch }}${ARM_VAL}${EXT}"
|
||||||
|
|
||||||
# 编译(使用 -trimpath 减小体积,利用缓存)
|
|
||||||
go build -trimpath -ldflags="-s -w" -o "${FILENAME}" ./cmd/${{ matrix.target }}
|
go build -trimpath -ldflags="-s -w" -o "${FILENAME}" ./cmd/${{ matrix.target }}
|
||||||
|
|
||||||
echo "CURRENT_FILENAME=${FILENAME}" >> $GITHUB_ENV
|
echo "CURRENT_FILENAME=${FILENAME}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
# 保存 Go 模块缓存
|
||||||
|
- name: Save Go modules cache
|
||||||
|
if: always()
|
||||||
|
run: |
|
||||||
|
CACHE_DIR="/data/cache/go-modules"
|
||||||
|
CACHE_KEY="go-${{ runner.os }}-${{ hashFiles('go.sum') }}"
|
||||||
|
|
||||||
|
mkdir -p "$CACHE_DIR/$CACHE_KEY"
|
||||||
|
|
||||||
|
[ -d ~/go/pkg/mod ] && cp -r ~/go/pkg/mod "$CACHE_DIR/$CACHE_KEY/" 2>/dev/null || true
|
||||||
|
[ -d ~/.cache/go-build ] && cp -r ~/.cache/go-build "$CACHE_DIR/$CACHE_KEY/" 2>/dev/null || true
|
||||||
|
|
||||||
|
echo "Cache saved: $CACHE_KEY"
|
||||||
|
|
||||||
- name: Run UPX Compression
|
- name: Run UPX Compression
|
||||||
if: matrix.upx == true
|
if: matrix.upx == true
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
Reference in New Issue
Block a user