|
| 1 | +name: CI Pipeline |
| 2 | + |
| 3 | +# This workflow runs on every push to main branch and on pull requests |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: [ main ] |
| 7 | + pull_request: |
| 8 | + branches: [ main ] |
| 9 | + |
| 10 | +jobs: |
| 11 | + # Job 1: Lint and Test |
| 12 | + # This job validates code quality and runs tests |
| 13 | + lint-and-test: |
| 14 | + name: Lint and Test |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + # Checkout the code from the repository |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + # Set up Python environment |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: '3.10' |
| 27 | + |
| 28 | + # Cache pip dependencies for faster builds |
| 29 | + - name: Cache pip packages |
| 30 | + uses: actions/cache@v4 |
| 31 | + with: |
| 32 | + path: ~/.cache/pip |
| 33 | + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} |
| 34 | + restore-keys: | |
| 35 | + ${{ runner.os }}-pip- |
| 36 | + |
| 37 | + # Install dependencies |
| 38 | + - name: Install dependencies |
| 39 | + run: | |
| 40 | + python -m pip install --upgrade pip |
| 41 | + pip install -r requirements.txt |
| 42 | + |
| 43 | + # Run code linting with flake8 |
| 44 | + # This checks for code style and potential errors |
| 45 | + - name: Run linting (flake8) |
| 46 | + run: | |
| 47 | + flake8 src/ tests/ --count --select=E9,F63,F7,F82 --show-source --statistics |
| 48 | + flake8 src/ tests/ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 49 | + |
| 50 | + # Run tests with pytest |
| 51 | + # This validates that all functionality works correctly |
| 52 | + - name: Run tests |
| 53 | + run: | |
| 54 | + pytest tests/ -v --cov=src --cov-report=term-missing |
| 55 | + |
| 56 | + # Optional: Run type checking with mypy |
| 57 | + # Uncomment if you want strict type checking |
| 58 | + # - name: Run type checking (mypy) |
| 59 | + # run: | |
| 60 | + # mypy src/ --ignore-missing-imports |
| 61 | + |
| 62 | + # Job 2: Training |
| 63 | + # This job trains the model to ensure training pipeline works |
| 64 | + train-model: |
| 65 | + name: Train Model |
| 66 | + runs-on: ubuntu-latest |
| 67 | + |
| 68 | + steps: |
| 69 | + # Checkout the code |
| 70 | + - name: Checkout code |
| 71 | + uses: actions/checkout@v4 |
| 72 | + |
| 73 | + # Set up Python environment |
| 74 | + - name: Set up Python |
| 75 | + uses: actions/setup-python@v5 |
| 76 | + with: |
| 77 | + python-version: '3.10' |
| 78 | + |
| 79 | + # Cache pip dependencies |
| 80 | + - name: Cache pip packages |
| 81 | + uses: actions/cache@v4 |
| 82 | + with: |
| 83 | + path: ~/.cache/pip |
| 84 | + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} |
| 85 | + restore-keys: | |
| 86 | + ${{ runner.os }}-pip- |
| 87 | + |
| 88 | + # Install dependencies |
| 89 | + - name: Install dependencies |
| 90 | + run: | |
| 91 | + python -m pip install --upgrade pip |
| 92 | + pip install -r requirements.txt |
| 93 | + |
| 94 | + # Run training script |
| 95 | + # This ensures the training pipeline works and produces model artifacts |
| 96 | + - name: Train model |
| 97 | + run: | |
| 98 | + python src/training/train.py |
| 99 | + |
| 100 | + # Upload model artifacts |
| 101 | + # This saves the trained model files so they can be downloaded later |
| 102 | + # Artifacts are stored for 90 days by default |
| 103 | + - name: Upload model artifacts |
| 104 | + uses: actions/upload-artifact@v4 |
| 105 | + with: |
| 106 | + name: trained-model |
| 107 | + path: | |
| 108 | + models/*.pkl |
| 109 | + retention-days: 7 |
| 110 | + if-no-files-found: warn |
| 111 | + |
0 commit comments