sdforge 0.5.0-rc.2

Multi-protocol SDK framework with unified macro configuration
name: CI

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main, develop]

permissions:
  contents: read

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

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  fmt:
    name: Format
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@1.97.1
        with:
          components: rustfmt
      - name: Check formatting
        run: cargo fmt --all -- --check

  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@1.97.1
        with:
          components: clippy
      - uses: Swatinem/rust-cache@v2
      - name: Install protoc
        run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
      - name: Run clippy
        run: cargo clippy --all-targets --all-features --workspace -- -D warnings

  check:
    name: Check
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@1.97.1
      - uses: Swatinem/rust-cache@v2
      - name: Install protoc
        run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
      - name: Check all features
        run: cargo check --all-features --workspace

  build:
    name: Build (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@1.97.1
      - uses: Swatinem/rust-cache@v2
      - name: Install protoc (Linux)
        if: runner.os == 'Linux'
        run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
      - name: Install protoc (macOS)
        if: runner.os == 'macOS'
        run: brew install protobuf
      - name: Install protoc (Windows)
        if: runner.os == 'Windows'
        run: choco install protoc -y
      - name: Build
        run: cargo build --all-features --workspace

  test-features:
    name: Test (${{ matrix.features }})
    runs-on: ubuntu-latest
    timeout-minutes: 45
    strategy:
      fail-fast: false
      matrix:
        features:
          - "http"
          - "mcp"
          - "http,mcp"
          - "http,security"
          - "http,cache"
          - "http,websocket"
          - "http,grpc"
          - "http,streaming"
          - "full"
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@1.97.1
      - uses: Swatinem/rust-cache@v2
      - name: Install protoc
        run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
      - name: Run tests with features ${{ matrix.features }}
        run: cargo test --features "${{ matrix.features }}" --workspace

  doc:
    name: Documentation
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@1.97.1
      - uses: Swatinem/rust-cache@v2
      - name: Install protoc
        run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
      - name: Build documentation
        run: cargo doc --no-deps --all-features --workspace
        env:
          RUSTDOCFLAGS: -D warnings

  security:
    name: Security
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@1.97.1
      - uses: Swatinem/rust-cache@v2
      - name: Install tools
        uses: taiki-e/install-action@v2
        with:
          tool: cargo-audit,cargo-deny
      - name: cargo deny
        run: cargo deny check
      - name: cargo audit
        run: cargo audit

  coverage:
    name: Coverage
    runs-on: ubuntu-latest
    timeout-minutes: 90
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@1.97.1
        with:
          components: llvm-tools-preview
      - uses: Swatinem/rust-cache@v2
      - name: Install cargo-llvm-cov
        uses: taiki-e/install-action@v2
        with:
          tool: cargo-llvm-cov
      - name: Install protoc
        run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
      - name: Generate coverage (gate ≥80% lines)
        # `--features full --lib` 避免 macros crate 的 trybuild 集成测试超时;
        # 排除集与既有口径对齐(protobuf 生成码、examples、macros、benches)
        run: |
          cargo llvm-cov \
            --features full \
            --lib \
            --lcov \
            --output-path lcov.info \
            --fail-under-lines 80 \
            --ignore-filename-regex "(examples/|temp/|macros/|src/grpc/pb/|src/benches/)"
      - name: Upload coverage
        if: always()
        uses: codecov/codecov-action@v7
        with:
          files: lcov.info
          fail_ci_if_error: false