CI/CD: Automated Testing and Deployment
CI/CD stands for Continuous Integration / Continuous Deployment. It's the automation that runs every time you push code.
Why You Need It
Without CI/CD:
You: "I fixed the bug!"
Teammate: "Great, did you run the tests?"
You: "Uh... let me check."
Teammate: "Did you lint?"
You: "I think so."
Teammate: "Did you deploy?"
You: "I'll do that now... wait, I'm getting an error."
With CI/CD:
You: *pushes code*
GitHub: runs tests → runs lint → deploys automatically
You: "The bot handled everything."
The Pipeline
You push code ──▶ GitHub ──▶ CI (tests + lint) ──▶ Deploy (Hugging Face)
│
├── pass → deploy
└── fail → email alert
Files in This Project
.github/workflows/ci.yml — Runs on every push
name: CI
on: [push, pull_request]
jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- run: pip install ruff pytest
- run: ruff check backend/
- run: pytest backend/tests/ -v
What it does:
1. Checks out your code on a fresh Ubuntu machine
2. Installs Python + dependencies
3. Runs ruff check (linting)
4. Runs pytest -v (tests)
.github/workflows/deploy.yml — Runs on merge to main
Same as CI, but if lint + tests pass, it also pushes your backend code to Hugging Face Spaces.
How to Set It Up
Step 1: Push to GitHub
git remote add origin https://github.com/YOUR_USERNAME/aiproject.git
git push -u origin main
GitHub will automatically detect the .github/workflows/ folder and run the CI pipeline.
Step 2: Add Secrets (for Deploy)
- Go to your GitHub repo → Settings → Secrets and variables → Actions
- Add these repository secrets:
| Secret | Value |
|---|---|
HF_TOKEN |
A Hugging Face write token (Settings → Access Tokens → New token → write) |
HF_USERNAME |
Your Hugging Face username |
Step 3: See It in Action
Every push now shows up in the Actions tab of your GitHub repo:
✓ CI: lint + test passed
✓ Deploy: pushed to Hugging Face Spaces
The Pre-Deploy Checklist
Before deploying, the CI pipeline checks:
| Check | What it catches |
|---|---|
ruff check |
Syntax errors, unused imports, naming issues |
pytest |
Broken endpoints, wrong return types, edge cases |
Both must pass before the deploy step runs. If either fails, you get an email notification and the deploy is skipped.
Try It
Push a change and watch the Actions tab:
# Make a change
echo "# testing" >> backend/app/__init__.py
# Commit and push
git add .
git commit -m "Test CI pipeline"
git push
# Watch: https://github.com/YOUR_USERNAME/aiproject/actions
You should see the CI workflow run and either pass or fail.