[T.10] 团队项目:CI/CD实践

类目详情内容
所属课程 2026年春季软件工程
作业要求 [T.10] 团队项目:CI/CD实践
课程目标 团队合作经过两轮迭代完成软件开发实践
作业价值 熟悉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运行结果

image

posted @ 2026-04-28 14:26  BitAction  阅读(9)  评论(0)    收藏  举报