# NAC集成测试CI/CD配置 # 用于自动化测试流程 name: NAC Integration Tests on: push: branches: [ main, develop ] pull_request: branches: [ main ] schedule: # 每天凌晨2点运行 - cron: '0 2 * * *' env: RUST_VERSION: 1.75.0 CARGO_TERM_COLOR: always jobs: # 单元测试 unit-tests: name: 单元测试 runs-on: ubuntu-latest steps: - name: 检出代码 uses: actions/checkout@v3 - name: 安装Rust uses: actions-rs/toolchain@v1 with: toolchain: ${{ env.RUST_VERSION }} override: true components: rustfmt, clippy - name: 缓存依赖 uses: actions/cache@v3 with: path: | ~/.cargo/registry ~/.cargo/git target key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: 运行单元测试 run: cargo test --lib --verbose - name: 生成测试报告 if: always() run: | cargo test --lib --no-fail-fast -- --format json > test-results.json || true - name: 上传测试报告 if: always() uses: actions/upload-artifact@v3 with: name: unit-test-results path: test-results.json # 集成测试 integration-tests: name: 集成测试 runs-on: ubuntu-latest needs: unit-tests steps: - name: 检出代码 uses: actions/checkout@v3 - name: 安装Rust uses: actions-rs/toolchain@v1 with: toolchain: ${{ env.RUST_VERSION }} override: true - name: 缓存依赖 uses: actions/cache@v3 with: path: | ~/.cargo/registry ~/.cargo/git target key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: 运行集成测试 run: cargo test --test '*' --verbose -- --test-threads=1 - name: 生成测试报告 if: always() run: | cargo test --test '*' --no-fail-fast -- --format json > integration-results.json || true - name: 上传测试报告 if: always() uses: actions/upload-artifact@v3 with: name: integration-test-results path: integration-results.json # 性能测试 performance-tests: name: 性能测试 runs-on: ubuntu-latest needs: integration-tests steps: - name: 检出代码 uses: actions/checkout@v3 - name: 安装Rust uses: actions-rs/toolchain@v1 with: toolchain: ${{ env.RUST_VERSION }} override: true - name: 缓存依赖 uses: actions/cache@v3 with: path: | ~/.cargo/registry ~/.cargo/git target key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: 运行性能测试 run: cargo test --test 'performance/*' --release --verbose - name: 运行基准测试 run: cargo bench --verbose - name: 上传性能报告 if: always() uses: actions/upload-artifact@v3 with: name: performance-results path: target/criterion # 代码质量检查 code-quality: name: 代码质量检查 runs-on: ubuntu-latest steps: - name: 检出代码 uses: actions/checkout@v3 - name: 安装Rust uses: actions-rs/toolchain@v1 with: toolchain: ${{ env.RUST_VERSION }} override: true components: rustfmt, clippy - name: 代码格式检查 run: cargo fmt -- --check - name: Clippy检查 run: cargo clippy -- -D warnings # 测试覆盖率 coverage: name: 测试覆盖率 runs-on: ubuntu-latest steps: - name: 检出代码 uses: actions/checkout@v3 - name: 安装Rust uses: actions-rs/toolchain@v1 with: toolchain: ${{ env.RUST_VERSION }} override: true - name: 安装tarpaulin run: cargo install cargo-tarpaulin - name: 生成覆盖率报告 run: cargo tarpaulin --out Xml --output-dir ./coverage - name: 上传覆盖率报告 uses: codecov/codecov-action@v3 with: files: ./coverage/cobertura.xml fail_ci_if_error: false # 通知 notify: name: 测试结果通知 runs-on: ubuntu-latest needs: [unit-tests, integration-tests, performance-tests, code-quality, coverage] if: always() steps: - name: 发送通知 run: | echo "测试完成,结果:" echo "单元测试: ${{ needs.unit-tests.result }}" echo "集成测试: ${{ needs.integration-tests.result }}" echo "性能测试: ${{ needs.performance-tests.result }}" echo "代码质量: ${{ needs.code-quality.result }}" echo "测试覆盖率: ${{ needs.coverage.result }}"