# 模型构建CI/CD流程 name: Model Build on: push: branches: [ main, develop ] paths: - 'models/**' pull_request: branches: [ main, develop ] paths: - 'models/**' jobs: build: runs-on: ubuntu-latest strategy: matrix: model: [nlp_bert, vision_resnet, recommender_v2] steps: - name: Checkout code uses: actions/checkout@v3 - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.9' - name: Cache pip dependencies uses: actions/cache@v3 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('models/${{ matrix.model }}/requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - name: Install dependencies run: | cd models/${{ matrix.model }} pip install -r requirements.txt - name: Lint code run: | cd models/${{ matrix.model }} pip install flake8 black isort flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics black --check . isort --check-only . - name: Run tests run: | cd models/${{ matrix.model }} python -m pytest tests/ -v --cov=. --cov-report=xml - name: Upload coverage reports uses: codecov/codecov-action@v3 with: file: models/${{ matrix.model }}/coverage.xml flags: ${{ matrix.model }} - name: Build Docker image run: | cd models/${{ matrix.model }} docker build -t dualflow-${{ matrix.model }}:${{ github.sha }} . - name: Test Docker image run: | cd models/${{ matrix.model }} docker run --rm dualflow-${{ matrix.model }}:${{ github.sha }} python -c "import torch; print('Docker image works!')" - name: Upload model artifacts uses: actions/upload-artifact@v3 with: name: ${{ matrix.model }}-artifacts path: models/${{ matrix.model }}/outputs/ if-no-files-found: warn