pr-check.yml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. name: PR Build Check
  2. # 在向 main 或 dev 分支提交 PR 时触发
  3. on:
  4. pull_request:
  5. branches:
  6. - main # 稳定版本分支
  7. - dev # 开发版本分支
  8. types: [opened, synchronize, reopened]
  9. env:
  10. REGISTRY: docker.io
  11. IMAGE_NAME: ding113/claude-code-hub
  12. jobs:
  13. # 代码质量检查任务
  14. code-quality:
  15. runs-on: ubuntu-latest
  16. name: Code Quality Check
  17. steps:
  18. - name: 📥 Checkout repository
  19. uses: actions/checkout@v5
  20. - name: 📦 Setup Bun
  21. uses: oven-sh/setup-bun@v2
  22. - name: 🟢 Setup Node.js
  23. uses: actions/setup-node@v4
  24. with:
  25. node-version: '20'
  26. - name: 📦 Install dependencies
  27. run: bun install
  28. - name: 🔍 Type check
  29. run: bun run typecheck
  30. - name: 🎨 Format check
  31. run: bun run format:check
  32. - name: 🛡️ Validate migrations
  33. run: bun run validate:migrations
  34. - name: Code quality checks passed
  35. run: |
  36. echo "All code quality checks passed!"
  37. echo "📝 Type checking: OK"
  38. echo "🎨 Code formatting: OK"
  39. echo "🛡️ Migration validation: OK"
  40. # PR 构建测试任务(不推送镜像)
  41. build-check:
  42. runs-on: ubuntu-latest
  43. name: Docker Build Test
  44. steps:
  45. - name: 📥 Checkout repository
  46. uses: actions/checkout@v5
  47. - name: 🔧 Set up Docker Buildx
  48. uses: docker/setup-buildx-action@v3
  49. - name: 📋 Extract metadata
  50. id: meta
  51. uses: docker/metadata-action@v5
  52. with:
  53. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  54. tags: |
  55. type=ref,event=pr
  56. type=sha,prefix=pr-
  57. - name: 🏗️ Build Docker image (Test Only - No Push)
  58. uses: docker/build-push-action@v6
  59. with:
  60. context: .
  61. file: ./deploy/Dockerfile
  62. platforms: linux/amd64 # PR检查使用单一架构提高速度
  63. push: false # 永远不推送,仅测试构建
  64. tags: ${{ steps.meta.outputs.tags }}
  65. labels: ${{ steps.meta.outputs.labels }}
  66. cache-from: type=gha
  67. cache-to: type=gha,mode=max
  68. - name: Build check passed
  69. run: |
  70. echo "Docker image build successful!"
  71. echo "📦 Image tags that would be used: ${{ steps.meta.outputs.tags }}"
  72. echo "🔍 All checks passed - PR is ready for review"
  73. # 如果构建失败,这个步骤会提供更详细的信息
  74. - name: ❌ Build failed diagnostics
  75. if: failure()
  76. run: |
  77. echo "❌ Build or test failed!"
  78. echo "Please check the logs above for details."
  79. docker images