Easy CI/CD Understanding.

You maybe wondering what CI/CD is and wanted a working short example. I’ve given you a very simple example below that you can play with. I hope it helps.

Hereโ€™s a clean, simple of CI/CD hands-on example you can run easily.

โœ… Prerequisites

  1. You have a git hub account
  2. Know some (very little) Python coding for this tutorial
  3. You understand basic git terminologies and git commands like git init, git add, git commit , git push etc.
  4. No worries if you don’t know #3, check out these two short videos :
  5. https://www.youtube.com/watch?v=USjZcfj8yxE
  6. https://www.youtube.com/watch?v=y-an0v208A0&t=68s
  7. Once you have git client installed and git account ready continue reading.

โœ… What is CI/CD?

CI/CD = Continuous Integration + Continuous Delivery (or Deployment).

It is a devops pipeline that automates:

  1. Building code
  2. Testing code
  3. Deploying it safely and quickly

๐Ÿ”น Continuous Integration (CI)

Developers merge code into the main branch frequently.
Every commit triggers:

  • Build
  • Automated tests
  • Static security testing (SAST)
  • Linting or code checks

Goal: Detect bugs early, prevent โ€œintegration hell.โ€


๐Ÿ”น Continuous Delivery (CD)

After CI passes, the system:

  • Packages the app
  • Prepares releases
  • Requires a human approval to deploy

Goal: Always be ready to deploy safely.


๐Ÿ”น Continuous Deployment (CD)

Fully automated deployment to production.

Goal: Every good commit automatically ships.


Simple CI/CD Example for You

Letโ€™s build a tiny pipeline using GitHub Actions.

๐Ÿ“Œ Step 1 โ€” Create a simple Python app

Create a file:

app.py

def add(a, b):
    return a + b

print(add(2, 3))

๐Ÿ“Œ Step 2 โ€” Add a unit test

Create:

test_app.py

from app import add

def test_add():
    assert add(2, 3) == 5

๐Ÿ“Œ Step 3 โ€” Create a CI workflow

You need to do this in your local machine. Lets say your code is in a folder called cicd_tutorial. The .github folder will be in it.

In your local GitHub repo, create:

cicd_tutorial/.github/workflows/ci.yml

Remember to go back to cicd_tutorial do the following:
1. git add .
2. git commit -m “your message”
3. git push


This will trigger the git Actions on your git account

name: Simple CI

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build-test:
    runs-on: ubuntu-latest

    steps:
      - name: Check out code
        uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'

      - name: Install dependencies
        run: pip install pytest

      - name: Run tests
        run: pytest -q

  deploy:
    needs: build-test
    runs-on: ubuntu-latest

    steps:
      - name: Deploy to server
        run: echo "Pretend deploying to production..."

What happens now? (CI in action)

You can look in Github Actions in your Git account, since this is just a tutorial. It mimics a build and deploy steps, please review ci.yml.

Whenever you:

  • Push code
  • Open a pull request

GitHub will automatically:

  1. Pull code
  2. Install Python
  3. Install pytest
  4. Run your test
  5. Show a green โœ” or red โŒ

Small CD Example

NOTE *** Add this after your CI job:
Its added for you CI job above, in Step 3. It is only here as reference.

deploy:
  needs: build-test
  runs-on: ubuntu-latest

  steps:
    - name: Deploy to server
      run: echo "Pretend deploying to production..."

This will only run if tests pass.


Visual Summary

Commit โ†’ CI (build + test + security checks)
        โ†’ CD (optional deploy to production)

What you’ll see in your github/Actions

Scroll to Top