Spaces:
Sleeping
Sleeping
| name: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Cache dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pytest pytest-cov | |
| - name: Run tests | |
| run: | | |
| pytest tests/ -v --cov=src --cov-report=term-missing | |
| - name: Lint code | |
| run: | | |
| pip install flake8 | |
| flake8 src/ --max-line-length=100 --ignore=E501,W503 | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Build Docker image | |
| run: | | |
| docker build -t fastapi-copilot:latest . | |
| - name: Test Docker image | |
| run: | | |
| docker run -d --name test-container -p 7860:7860 \ | |
| -e HF_TOKEN=${{ secrets.HF_TOKEN }} \ | |
| fastapi-copilot:latest | |
| sleep 10 | |
| curl -f http://localhost:7860/health || exit 1 | |
| docker stop test-container | |