Add required model and config files for deployment; update .gitignore… #22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| schedule: | |
| # Run daily at 2 AM UTC for automated data collection | |
| - cron: '0 2 * * *' | |
| jobs: | |
| # Linting and Code Quality | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install flake8 black isort mypy | |
| - name: Lint with flake8 | |
| run: | | |
| # Stop build if there are Python syntax errors or undefined names | |
| flake8 backend/ ml_models/ --count --select=E9,F63,F7,F82 --show-source --statistics | |
| # Exit-zero treats all errors as warnings | |
| flake8 backend/ ml_models/ --count --exit-zero --max-complexity=15 --max-line-length=120 --statistics | |
| - name: Check code formatting with black | |
| run: | | |
| black --check backend/ ml_models/ | |
| - name: Check import sorting with isort | |
| run: | | |
| isort --check-only backend/ ml_models/ | |
| # Unit Tests | |
| test: | |
| runs-on: ubuntu-latest | |
| needs: lint | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pytest pytest-cov pytest-asyncio | |
| - name: Create .env file | |
| run: | | |
| echo "MONGODB_URI=${{ secrets.MONGODB_URI }}" >> .env | |
| echo "MONGODB_DATABASE=pearl_aqi_test_db" >> .env | |
| echo "OPENWEATHER_API_KEY=${{ secrets.OPENWEATHER_API_KEY }}" >> .env | |
| echo "WAQI_API_KEY=${{ secrets.WAQI_API_KEY }}" >> .env | |
| - name: Run tests | |
| run: | | |
| pytest tests/ --cov=backend --cov=ml_models --cov-report=xml --cov-report=html | |
| - name: Upload coverage reports | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./coverage.xml | |
| flags: unittests | |
| name: codecov-umbrella | |
| # API Integration Tests | |
| integration: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| services: | |
| mongodb: | |
| image: mongo:7.0 | |
| ports: | |
| - 27017:27017 | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install httpx pytest-asyncio | |
| - name: Create .env file | |
| run: | | |
| echo "MONGODB_URI=mongodb://localhost:27017/" >> .env | |
| echo "MONGODB_DATABASE=pearl_aqi_test_db" >> .env | |
| - name: Run FastAPI server | |
| run: | | |
| cd backend | |
| python main.py & | |
| sleep 10 | |
| - name: Test API endpoints | |
| run: | | |
| curl http://localhost:8000/health | |
| curl http://localhost:8000/api/v1/locations | |
| # Model Training and Validation | |
| model-validation: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Create .env file | |
| run: | | |
| echo "MONGODB_URI=${{ secrets.MONGODB_URI }}" >> .env | |
| echo "MONGODB_DATABASE=${{ secrets.MONGODB_DATABASE }}" >> .env | |
| - name: Validate model files | |
| run: | | |
| python -c " | |
| import os | |
| if os.path.exists('models/xgboost_model.json') and os.path.exists('models/model_metrics.json'): | |
| print('✅ Model files found') | |
| else: | |
| print('⚠️ Model files missing - skipping validation (expected in CI environment without DVC)') | |
| " | |
| - name: Test model inference | |
| run: | | |
| python tests/test_models.py | |
| # Automated Data Collection (scheduled job) | |
| data-collection: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'schedule' | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Create .env file | |
| run: | | |
| echo "MONGODB_URI=${{ secrets.MONGODB_URI }}" >> .env | |
| echo "MONGODB_DATABASE=${{ secrets.MONGODB_DATABASE }}" >> .env | |
| echo "OPENWEATHER_API_KEY=${{ secrets.OPENWEATHER_API_KEY }}" >> .env | |
| echo "WAQI_API_KEY=${{ secrets.WAQI_API_KEY }}" >> .env | |
| - name: Fetch air quality data | |
| run: | | |
| python scripts/automated_data_fetch.py | |
| - name: Generate predictions | |
| run: | | |
| python prediction_pipeline.py | |
| # Docker Build and Push (Disabled) | |
| # docker: | |
| # runs-on: ubuntu-latest | |
| # needs: [test, integration] | |
| # if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| # steps: | |
| # - uses: actions/checkout@v3 | |
| # - name: Set up Docker Buildx | |
| # uses: docker/setup-buildx-action@v2 | |
| # - name: Login to Docker Hub | |
| # uses: docker/login-action@v2 | |
| # with: | |
| # username: ${{ secrets.DOCKER_USERNAME }} | |
| # password: ${{ secrets.DOCKER_PASSWORD }} | |
| # - name: Build and push backend | |
| # uses: docker/build-push-action@v4 | |
| # with: | |
| # context: . | |
| # file: ./Dockerfile.backend | |
| # push: true | |
| # tags: ${{ secrets.DOCKER_USERNAME }}/pearl-aqi-backend:latest | |
| # - name: Build and push frontend | |
| # uses: docker/build-push-action@v4 | |
| # with: | |
| # context: . | |
| # file: ./Dockerfile.frontend | |
| # push: true | |
| # tags: ${{ secrets.DOCKER_USERNAME }}/pearl-aqi-frontend:latest | |
| # Deployment (optional - configure for your platform) | |
| # deploy: | |
| # runs-on: ubuntu-latest | |
| # needs: docker | |
| # if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| # steps: | |
| # - name: Deploy to production | |
| # run: | | |
| # echo "🚀 Deployment step - configure for your platform (AWS, Azure, GCP, etc.)" | |
| # # Add your deployment commands here |