[T.10] 团队项目:CI/CD实践
选项及理由
单元测试与lint检查、编译检查
每个 PR/push 自动触发测试,开发者无需手动跑 go test ./...,在合入前就能发现编译错误或测试失败;触发lint进行规范检查;触发build进行编译检查
配置文件脚本
CI/CD平台:Github Action
name: CI
on:
push:
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
name: Go Lint
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.64
args: --timeout=5m
test:
name: Go Test
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Verify module files
run: go mod verify
- name: Run tests
run: go test ./...
build-dev:
name: Build Dev
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Build (standard compilation)
# Exclude cmd/paradiced-server (Nakama plugin, no main() function)
run: go build $(go list ./... | grep -v '/cmd/paradiced-server')
build-cli:
name: Build CLI
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Build pdcli
run: go build -o ./build/pdcli ./cmd/pdcli
分支策略与触发逻辑
当推送或PR到main分支时触发CI流程
CI/CD运行结果


浙公网安备 33010602011771号