name: 持续集成

on:
  pull_request:
    branches:
      - internal
      - main
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build-and-test:
    name: 构建/Vet/测试
    runs-on: ubuntu-latest
    timeout-minutes: 20

    steps:
      - name: 检出代码
        uses: actions/checkout@v6

      - name: 配置 Go 环境
        uses: actions/setup-go@v6
        with:
          go-version-file: go.mod
          cache: true

      - name: 下载依赖模块
        run: go mod download

      - name: 构建
        run: go build ./...

      - name: 运行 go vet
        run: go vet ./...

      - name: 运行测试
        run: go test -race -count=1 ./...

  lint:
    name: golangci-lint
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
      - name: 检出代码
        uses: actions/checkout@v6
        with:
          # Fetch base ref so golangci-lint can diff against it for only-new-issues.
          fetch-depth: 0

      - name: 配置 Go 环境
        uses: actions/setup-go@v6
        with:
          go-version-file: go.mod
          cache: true

      - name: golangci-lint
        uses: golangci/golangci-lint-action@v9
        with:
          version: latest
          args: --timeout=5m
          # Legacy codebase has ~47 pre-existing lint issues (errcheck / unused
          # carried over from upstream perfect-panel/server). Only flag NEW
          # issues introduced by this PR so CI stays useful without forcing a
          # mass cleanup. Backlog cleanup tracked separately.
          only-new-issues: true
