Files
GoTunnel/.gitea/workflows/build.yaml
Flik d09104f89b
Some checks failed
Build Multi-Platform Binaries / build-frontend (push) Successful in 38s
Build Multi-Platform Binaries / build-binaries (push) Failing after 37s
111
2026-01-09 22:15:47 +08:00

157 lines
4.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Build Multi-Platform Binaries
on:
push:
paths:
- '**.go'
- 'go.mod'
- 'go.sum'
- 'web/**'
- '.gitea/workflows/**'
jobs:
build-frontend:
runs-on: node
steps:
- name: Checkout code
uses: actions/checkout@v4
# 使用本地目录缓存(而非 actions/cache
- name: Cache Node modules
run: |
CACHE_DIR="/data/cache/node-modules"
CACHE_KEY="node-modules-${{ hashFiles('web/package-lock.json') }}"
mkdir -p "$CACHE_DIR"
# 如果缓存存在且匹配,恢复缓存
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
run: |
cd web
npm ci --prefer-offline --no-audit
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
uses: actions/upload-artifact@v3
with:
name: frontend-dist
path: web/dist
retention-days: 1
build-binaries:
needs: build-frontend
runs-on: golang
strategy:
fail-fast: false
matrix:
include:
# ... 你的 matrix 配置保持不变 ...
steps:
- name: Install Dependencies
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
# 使用本地目录缓存 Go 模块
- name: Cache Go modules
run: |
CACHE_DIR="/data/cache/go-modules"
CACHE_KEY="go-${{ runner.os }}-${{ hashFiles('go.sum') }}"
mkdir -p "$CACHE_DIR"
if [ -d "$CACHE_DIR/$CACHE_KEY" ]; then
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
run: go mod download
- 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 }}
GOARM: ${{ matrix.goarm }}
CGO_ENABLED: 0
run: |
ARM_VAL=""
[ "${{ matrix.goarch }}" = "arm" ] && ARM_VAL="v${{ matrix.goarm }}"
EXT=""
[ "${{ matrix.goos }}" = "windows" ] && EXT=".exe"
FILENAME="gotunnel-${{ matrix.target }}-${{ matrix.goos }}-${{ matrix.goarch }}${ARM_VAL}${EXT}"
go build -trimpath -ldflags="-s -w" -o "${FILENAME}" ./cmd/${{ matrix.target }}
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
if: matrix.upx == true
run: |
upx --best --lzma "${{ env.CURRENT_FILENAME }}" || echo "UPX skipped for this platform"
- name: Upload Binary
uses: actions/upload-artifact@v3
with:
name: ${{ env.CURRENT_FILENAME }}
path: ${{ env.CURRENT_FILENAME }}
retention-days: 7