273 lines
7.6 KiB
YAML
273 lines
7.6 KiB
YAML
name: CI Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, develop ]
|
|
pull_request:
|
|
branches: [ main, develop ]
|
|
|
|
jobs:
|
|
test:
|
|
name: 测试和基准测试
|
|
runs-on: ubuntu-latest
|
|
|
|
strategy:
|
|
matrix:
|
|
go-version: [1.24.x, 1.25.x]
|
|
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 设置 Go 环境
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: ${{ matrix.go-version }}
|
|
|
|
- name: 验证 Go 模块
|
|
run: |
|
|
go mod tidy
|
|
git diff --exit-code go.mod go.sum
|
|
|
|
- name: 下载依赖
|
|
run: go mod download
|
|
|
|
- name: 代码格式检查
|
|
run: |
|
|
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
|
|
echo "以下文件需要格式化:"
|
|
gofmt -s -l .
|
|
exit 1
|
|
fi
|
|
|
|
- name: 静态代码检查
|
|
run: |
|
|
go vet ./...
|
|
|
|
- name: 运行单元测试
|
|
run: |
|
|
go test -v -race -coverprofile=coverage.out ./...
|
|
|
|
- name: 生成测试覆盖率报告
|
|
run: |
|
|
go tool cover -html=coverage.out -o coverage.html
|
|
go tool cover -func=coverage.out
|
|
|
|
- name: 运行基准测试
|
|
run: |
|
|
echo "=== 基础性能基准测试 ==="
|
|
go test -bench=BenchmarkPipelineDB -benchmem -benchtime=1s -run=^$ ./...
|
|
|
|
echo "=== 并发性能基准测试 ==="
|
|
go test -bench=BenchmarkConcurrent -benchmem -benchtime=500ms -run=^$ ./...
|
|
|
|
echo "=== 存储引擎基准测试 ==="
|
|
go test -bench=BenchmarkStorage -benchmem -benchtime=500ms -run=^$ ./...
|
|
|
|
echo "=== 缓存系统基准测试 ==="
|
|
go test -bench=BenchmarkCache -benchmem -benchtime=500ms -run=^$ ./...
|
|
|
|
echo "=== Handler 基准测试 ==="
|
|
go test -bench=BenchmarkHandler -benchmem -benchtime=500ms -run=^$ ./...
|
|
|
|
- name: 运行示例程序
|
|
run: |
|
|
echo "=== 测试基础使用示例 ==="
|
|
cd examples/basic-usage && timeout 10s go run main.go || true
|
|
|
|
echo "=== 测试组管理示例 ==="
|
|
cd ../group-management && timeout 10s go run main.go || true
|
|
|
|
echo "=== 测试外部处理器示例 ==="
|
|
cd ../external-handler && timeout 10s go run main.go || true
|
|
|
|
- name: 上传测试覆盖率
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: coverage-report-go${{ matrix.go-version }}
|
|
path: |
|
|
coverage.out
|
|
coverage.html
|
|
|
|
- name: 检查测试覆盖率
|
|
run: |
|
|
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
|
|
echo "测试覆盖率: ${COVERAGE}%"
|
|
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
|
|
echo "⚠️ 测试覆盖率低于 80%"
|
|
exit 1
|
|
fi
|
|
echo "✅ 测试覆盖率达标"
|
|
|
|
build:
|
|
name: 构建验证
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
|
|
strategy:
|
|
matrix:
|
|
goos: [linux, darwin, windows]
|
|
goarch: [amd64, arm64]
|
|
exclude:
|
|
- goos: windows
|
|
goarch: arm64
|
|
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 设置 Go 环境
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: 1.24.x
|
|
|
|
- name: 构建二进制文件
|
|
env:
|
|
GOOS: ${{ matrix.goos }}
|
|
GOARCH: ${{ matrix.goarch }}
|
|
run: |
|
|
echo "构建 ${{ matrix.goos }}/${{ matrix.goarch }}"
|
|
go build -v -ldflags="-s -w" ./...
|
|
|
|
- name: 构建示例程序
|
|
env:
|
|
GOOS: ${{ matrix.goos }}
|
|
GOARCH: ${{ matrix.goarch }}
|
|
run: |
|
|
cd examples/basic-usage && go build -v -ldflags="-s -w" .
|
|
cd ../group-management && go build -v -ldflags="-s -w" .
|
|
cd ../external-handler && go build -v -ldflags="-s -w" .
|
|
cd ../data-analytics && go build -v -ldflags="-s -w" .
|
|
cd ../concurrent-processing && go build -v -ldflags="-s -w" .
|
|
cd ../high-concurrency && go build -v -ldflags="-s -w" .
|
|
|
|
performance:
|
|
name: 性能回归测试
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
if: github.event_name == 'pull_request'
|
|
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 设置 Go 环境
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: 1.24.x
|
|
|
|
- name: 运行性能基准测试
|
|
run: |
|
|
echo "=== 性能基准测试 - 当前分支 ==="
|
|
go test -bench=. -benchmem -count=3 -benchtime=2s -run=^$ ./... > current_bench.txt
|
|
|
|
- name: 检出主分支
|
|
run: |
|
|
git fetch origin main
|
|
git checkout origin/main
|
|
|
|
- name: 运行性能基准测试 - 主分支
|
|
run: |
|
|
echo "=== 性能基准测试 - 主分支 ==="
|
|
go test -bench=. -benchmem -count=3 -benchtime=2s -run=^$ ./... > main_bench.txt || true
|
|
|
|
- name: 性能对比分析
|
|
run: |
|
|
echo "=== 性能对比报告 ==="
|
|
echo "当前分支性能:"
|
|
cat current_bench.txt | grep "Benchmark" | head -10
|
|
echo ""
|
|
echo "主分支性能:"
|
|
cat main_bench.txt | grep "Benchmark" | head -10 || echo "主分支基准测试数据不可用"
|
|
|
|
- name: 上传性能报告
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: performance-report
|
|
path: |
|
|
current_bench.txt
|
|
main_bench.txt
|
|
|
|
security:
|
|
name: 安全扫描
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 设置 Go 环境
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: 1.24.x
|
|
|
|
- name: 安装 gosec
|
|
run: go install github.com/securego/gosec/v2/cmd/gosec@latest
|
|
|
|
- name: 运行安全扫描
|
|
run: |
|
|
gosec -fmt json -out gosec-report.json ./...
|
|
gosec ./...
|
|
|
|
- name: 上传安全报告
|
|
uses: actions/upload-artifact@v3
|
|
if: always()
|
|
with:
|
|
name: security-report
|
|
path: gosec-report.json
|
|
|
|
quality:
|
|
name: 代码质量检查
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: 检出代码
|
|
uses: actions/checkout@v4
|
|
|
|
- name: 设置 Go 环境
|
|
uses: actions/setup-go@v4
|
|
with:
|
|
go-version: 1.24.x
|
|
|
|
- name: 安装代码质量工具
|
|
run: |
|
|
go install honnef.co/go/tools/cmd/staticcheck@latest
|
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
|
|
|
- name: 运行 staticcheck
|
|
run: staticcheck ./...
|
|
|
|
- name: 运行 golangci-lint
|
|
run: golangci-lint run ./...
|
|
|
|
- name: 检查循环复杂度
|
|
run: |
|
|
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
|
|
gocyclo -over 15 .
|
|
|
|
- name: 检查代码重复
|
|
run: |
|
|
go install github.com/mibk/dupl@latest
|
|
dupl -threshold 100 .
|
|
|
|
notification:
|
|
name: 通知
|
|
runs-on: ubuntu-latest
|
|
needs: [test, build, security, quality]
|
|
if: always()
|
|
|
|
steps:
|
|
- name: 构建状态通知
|
|
run: |
|
|
if [[ "${{ needs.test.result }}" == "success" && "${{ needs.build.result }}" == "success" && "${{ needs.security.result }}" == "success" && "${{ needs.quality.result }}" == "success" ]]; then
|
|
echo "✅ 所有检查通过!"
|
|
echo "STATUS=success" >> $GITHUB_ENV
|
|
else
|
|
echo "❌ 部分检查失败"
|
|
echo "测试结果: ${{ needs.test.result }}"
|
|
echo "构建结果: ${{ needs.build.result }}"
|
|
echo "安全扫描: ${{ needs.security.result }}"
|
|
echo "质量检查: ${{ needs.quality.result }}"
|
|
echo "STATUS=failure" >> $GITHUB_ENV
|
|
fi
|