ci.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. name: CI
  2. on:
  3. push:
  4. branches: [main]
  5. pull_request:
  6. branches: [main]
  7. jobs:
  8. # ──────────────────────────────────────────────
  9. # Secret leak scan — first line of defense
  10. # 在跑任何其他东西之前先扫秘钥,省 CI 分钟
  11. # ──────────────────────────────────────────────
  12. secret-scan:
  13. runs-on: ubuntu-latest
  14. steps:
  15. - uses: actions/checkout@v4
  16. with:
  17. fetch-depth: 0 # gitleaks 需要完整历史
  18. - name: Run gitleaks
  19. uses: gitleaks/gitleaks-action@v2
  20. env:
  21. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  22. # GITLEAKS_LICENSE only needed for org-level; OSS repo runs free
  23. GITLEAKS_CONFIG: .github/gitleaks.toml
  24. # ──────────────────────────────────────────────
  25. # Python tests on 3.10/3.11/3.12
  26. # ──────────────────────────────────────────────
  27. test:
  28. runs-on: ubuntu-latest
  29. needs: secret-scan
  30. strategy:
  31. fail-fast: false
  32. matrix:
  33. python-version: ["3.10", "3.11", "3.12"]
  34. steps:
  35. - uses: actions/checkout@v4
  36. - name: Set up Python
  37. uses: actions/setup-python@v5
  38. with:
  39. python-version: ${{ matrix.python-version }}
  40. cache: pip
  41. - name: Install lambdagent (src-layout) + agentpaas[dev]
  42. run: |
  43. pip install -e lambdagent/
  44. # [dev] pulls in httpx — required by fastapi.testclient.TestClient
  45. # used by tests/test_api_endpoints.py (audit critical #6 coverage).
  46. pip install -e "agentpaas/[dev]"
  47. pip install pytest pytest-asyncio
  48. # AUDIT_2026-06-11 ⑨: collected 数下限 — 防止依赖缺失/收集错误让
  49. # 测试"静默蒸发"还绿灯(本地曾因缺 pytest-asyncio 8 个鉴权测试没在跑)。
  50. # 新增测试只会让数字涨,阈值取当前数的约 95% 留余量。
  51. - name: Run platform tests (tests/)
  52. run: |
  53. N=$(python -m pytest tests/ --collect-only -q 2>/dev/null | grep -Eo '[0-9]+ tests? collected' | grep -Eo '^[0-9]+' || echo 0)
  54. echo "tests/ collected: $N"
  55. test "$N" -ge 240 || { echo "::error::tests/ collected only $N (< 240) — did tests silently vanish?"; exit 1; }
  56. python -m pytest tests/ -v --tb=short
  57. - name: Run lambdagent core tests (lambdagent/tests/)
  58. run: |
  59. N=$(python -m pytest lambdagent/tests/ --collect-only -q 2>/dev/null | grep -Eo '[0-9]+ tests? collected' | grep -Eo '^[0-9]+' || echo 0)
  60. echo "lambdagent/tests/ collected: $N"
  61. test "$N" -ge 540 || { echo "::error::lambdagent/tests/ collected only $N (< 540) — did tests silently vanish?"; exit 1; }
  62. python -m pytest lambdagent/tests/ --tb=short
  63. - name: Lint module loads
  64. run: python -c "from lambdagent.fromconfig import lint_config; print('Lint module OK')"
  65. # ──────────────────────────────────────────────
  66. # Package import smoke test
  67. # ──────────────────────────────────────────────
  68. imports:
  69. runs-on: ubuntu-latest
  70. needs: secret-scan
  71. steps:
  72. - uses: actions/checkout@v4
  73. - uses: actions/setup-python@v5
  74. with:
  75. python-version: "3.12"
  76. cache: pip
  77. - name: Install both packages
  78. run: |
  79. pip install -e lambdagent/
  80. pip install -e agentpaas/ # agentpaas needs fastapi/uvicorn/pydantic
  81. - name: Verify package surface
  82. run: |
  83. python -c "import lambdagent; print(f'lambdagent OK: {len(lambdagent.__all__)} exports')"
  84. python -c "from agentpaas.api.app import app; print(f'AgentPaaS OK: {len([r for r in app.routes if hasattr(r, \"methods\")])} routes')"
  85. # ──────────────────────────────────────────────
  86. # Web UI build (catch broken frontend before merge)
  87. # ──────────────────────────────────────────────
  88. webui:
  89. runs-on: ubuntu-latest
  90. needs: secret-scan
  91. defaults:
  92. run:
  93. working-directory: webui
  94. steps:
  95. - uses: actions/checkout@v4
  96. - uses: actions/setup-node@v4
  97. with:
  98. node-version: "20"
  99. cache: npm
  100. cache-dependency-path: webui/package-lock.json
  101. - run: npm ci
  102. - run: npm run build