Days 58–59: CI/CD — Automating Your Way to Production
Life has been lifing and we need to do a couple of two-a-days to get caught up.
Hello Builders,
We’re back! Life can throw a few surprises, but the Zero to Builder train keeps rolling. Today, we’re entering a new territory that’s as close to "real-world dev" as it gets: CI/CD (Continuous Integration and Continuous Deployment).
If you’ve ever worked on a team, you know the pain of code that works on your machine but breaks somewhere else. CI/CD fixes that. It’s how professionals keep projects running smoothly—and we’re going to do it the AI-assisted way.
🔍 What’s CI/CD?
Continuous Integration (CI): Every time you push code, you want to make sure it doesn’t break anything. CI automatically runs your tests to give you a quick thumbs-up (or not).
Continuous Deployment (CD): Once the code passes all checks, CD can automatically ship it to your live environment—no manual clicks required.
🛠️ What Tools Are We Using?
pytest
: A popular Python tool that makes it easy to write and run tests.unittest
: Python’s built-in testing framework. A bit more verbose, but great for learning structure.GitHub Actions: A way to automate things like testing and deployment every time you push to GitHub.
🧪 Step 1: Write and Run a Simple Test
Let’s get our hands dirty with pytest
.
pip install pytest
Create a file named test_math.py
:
def add(a, b):
return a + b
def test_add():
assert add(2, 3) == 5
Now test it locally:
pytest
You should see something like 1 passed
— sweet.
🤖 Step 2: Add GitHub Actions for CI
Create a file in your repo at .github/workflows/ci.yml
:
name: Run Pytest
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
pip install pytest
- name: Run tests
run: |
pytest
Push this to GitHub. Go to the Actions tab—you’ll see your test running automatically!
🚀 Step 3: Deploy It!
Let’s automate your deployment too. If you’re using GitHub Pages for a front end, try this:
name: Deploy to GitHub Pages
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Deploy to Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./
Commit and push, and GitHub handles the rest.
✅ Vibe Code Prompt
"Write a GitHub Actions workflow that runs
pytest
on every push and deploys the app to GitHub Pages if the tests pass."
Try this in Cursor and co-build your CI/CD pipeline!
This is a big step. From here on out, your projects won’t just work, they’ll be production-ready.
Let’s keep pushing forward—two-a-days until we’re caught up.
Stay building,
Keith