Skip to content

Commit 0dca15b

Browse files
committed
Commit 4: Basic GitHub Actions Pipeline
- Add CI workflow (.github/workflows/ci.yml) - Lint and Test job: code quality checks and test execution - Training job: validates training pipeline works - Runs on push to main and pull requests - Uploads model artifacts for 7 days - Update documentation (docs/mlops-stages.md) - Document Stage 2: Automated CI Pipeline as implemented - Add workflow details and benefits
1 parent bd996bb commit 0dca15b

2 files changed

Lines changed: 136 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+

docs/mlops-stages.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,32 @@ docker run --rm -v $(pwd):/app mlops:latest python src/training/train.py
3030

3131
## Stage 2: Automated CI Pipeline
3232

33-
**Status**: To be implemented
33+
**Status**: ✅ Implemented
3434

35-
The CI pipeline will:
36-
- Run tests on code changes
37-
- Execute training jobs
38-
- Validate model performance
39-
- Store artifacts
35+
The CI pipeline automates quality checks and training on every code change:
36+
37+
**GitHub Actions Workflow** (`.github/workflows/ci.yml`):
38+
- **Lint and Test Job**:
39+
- Runs on every push and pull request
40+
- Code linting with flake8 (style and error checking)
41+
- Runs all tests with pytest
42+
- Code coverage reporting
43+
- **Training Job**:
44+
- Trains the model to ensure pipeline works
45+
- Validates training script executes successfully
46+
- Uploads model artifacts for download
47+
48+
**Benefits:**
49+
- Automatic validation on every code change
50+
- Catches errors before they reach production
51+
- Ensures training pipeline remains functional
52+
- Model artifacts stored for 7 days
53+
54+
**Usage:**
55+
- Automatically runs on push to `main` branch
56+
- Automatically runs on pull requests
57+
- View results in GitHub Actions tab
58+
- Download artifacts from workflow runs
4059

4160
## Stage 3: Artifact Handling
4261

0 commit comments

Comments
 (0)