model_build.yml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # 模型构建CI/CD流程
  2. name: Model Build
  3. on:
  4. push:
  5. branches: [ main, develop ]
  6. paths:
  7. - 'models/**'
  8. pull_request:
  9. branches: [ main, develop ]
  10. paths:
  11. - 'models/**'
  12. jobs:
  13. build:
  14. runs-on: ubuntu-latest
  15. strategy:
  16. matrix:
  17. model: [nlp_bert, vision_resnet, recommender_v2]
  18. steps:
  19. - name: Checkout code
  20. uses: actions/checkout@v3
  21. - name: Set up Python
  22. uses: actions/setup-python@v4
  23. with:
  24. python-version: '3.9'
  25. - name: Cache pip dependencies
  26. uses: actions/cache@v3
  27. with:
  28. path: ~/.cache/pip
  29. key: ${{ runner.os }}-pip-${{ hashFiles('models/${{ matrix.model }}/requirements.txt') }}
  30. restore-keys: |
  31. ${{ runner.os }}-pip-
  32. - name: Install dependencies
  33. run: |
  34. cd models/${{ matrix.model }}
  35. pip install -r requirements.txt
  36. - name: Lint code
  37. run: |
  38. cd models/${{ matrix.model }}
  39. pip install flake8 black isort
  40. flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
  41. black --check .
  42. isort --check-only .
  43. - name: Run tests
  44. run: |
  45. cd models/${{ matrix.model }}
  46. python -m pytest tests/ -v --cov=. --cov-report=xml
  47. - name: Upload coverage reports
  48. uses: codecov/codecov-action@v3
  49. with:
  50. file: models/${{ matrix.model }}/coverage.xml
  51. flags: ${{ matrix.model }}
  52. - name: Build Docker image
  53. run: |
  54. cd models/${{ matrix.model }}
  55. docker build -t dualflow-${{ matrix.model }}:${{ github.sha }} .
  56. - name: Test Docker image
  57. run: |
  58. cd models/${{ matrix.model }}
  59. docker run --rm dualflow-${{ matrix.model }}:${{ github.sha }} python -c "import torch; print('Docker image works!')"
  60. - name: Upload model artifacts
  61. uses: actions/upload-artifact@v3
  62. with:
  63. name: ${{ matrix.model }}-artifacts
  64. path: models/${{ matrix.model }}/outputs/
  65. if-no-files-found: warn