Skip to content

GuitaristForEver/simple-calculator-demo

Repository files navigation

Calculator Robot

Simple Calculator App

Tests codecov CodeQL

A learning repository for modern CI/CD practices

πŸ“š Start Learning | πŸ“Š Live Demo | πŸ“– Documentation


Executive Summary

This is a learning repository that walks you through a clean, real-world CI/CD flow using a tiny Python calculator.

Simple Version (ELI5): Think of it like a school project with a smart checklist:

  1. Developer Flow: You make changes on your computer and run the calculator/tests.
  2. Pre-commit Hooks: A friendly gatekeeper checks your work before it gets saved.
  3. PR Review + CI Workflows: A robot team re-checks everything in GitHub before merge.
  4. Internal CI Tweaks: Extra speed + reporting tricks make the robot team fast and helpful.

Technical Version (for developers):

Stage What Happens Tools Used
Developer flow Local dev + tests before push Python + pytest
Pre-commit hooks Security + linting + formatting pre-commit + Ruff + Gitleaks
PR review & CI workflows Parallel/sequential jobs, coverage & security gates GitHub Actions + Codecov + CodeQL + Bandit
Internal CI tweaks Caching + report history + artifacts Actions cache + Allure + GitHub Pages

Live Demo: Test Reports on GitHub Pages


Table of Contents


What is This?

An instructional repository that teaches professional CI/CD through hands-on practice with a simple Python calculator.

You'll Learn

βœ… Python project structure and testing βœ… Pre-commit hooks for code quality βœ… GitHub Actions CI/CD pipelines βœ… Enterprise features (Allure, caching, quality gates)

Perfect for: Students, bootcamp grads, developers learning DevOps.


The 4-Stage Learning Path

This repository teaches CI/CD in 4 progressive stages:

1. Developer Flow
   β†’ Write code locally, run tests

2. Pre-commit Hooks
   β†’ Automatic quality checks before commits

3. CI/CD Workflows
   β†’ Automated testing in the cloud

4. Advanced Features
   β†’ Enterprise reporting, caching, quality gates

Total learning time: ~70 minutes


πŸ“š Start Learning

Follow the step-by-step guides in order:

Stage 1: Developer Flow (25 min)

# Guide Time
1 Getting Started 5 min
2 Understanding the Code 10 min
3 Running Tests 10 min

Stage 2: Pre-commit Hooks (10 min)

# Guide Time
4 Pre-commit Hooks 10 min

Stage 3: CI/CD Workflows (15 min)

# Guide Time
5 CI/CD Basics 15 min

Stage 4: Advanced Features (20 min)

# Guide Time
6 Advanced Features 20 min

πŸ‘‰ Begin with Guide 1: Getting Started


Quick Start

For those who want to jump right in:

Install & Run

Option A: Using pip (traditional)

# Install dependencies
pip install -r requirements.txt

# Run calculator
python -m src.calculator

# Run tests
pytest

Option B: Using uv (modern & fast) ⚑

# Install dependencies (creates venv automatically)
uv sync --dev

# Run calculator
uv run python -m src.calculator

# Run tests
uv run pytest

Pre-commit Hooks

Option A: Using pip

pip install pre-commit
pre-commit install

Option B: Using uv

uv sync --dev  # Includes pre-commit
pre-commit install

Allure Reports

pytest --alluredir=allure-results
allure serve allure-results

CI/CD Learning Insights

This is a learning repository! Here are key insights about CI/CD concepts demonstrated in this project.

Pipeline Architecture

This project demonstrates a sophisticated 8-job pipeline with parallel and sequential stages:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              STAGE 1: PARALLEL                       β”‚
β”‚       (all three jobs start simultaneously)          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚                β”‚                β”‚
     β–Ό                β–Ό                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ πŸ” Lint β”‚    β”‚πŸ”’Securityβ”‚    β”‚πŸ§ͺ Unit Testsβ”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
     β”‚              β”‚                 β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              STAGE 2: DOCKER                         β”‚
β”‚  (only runs if Dockerfile/src/requirements changed)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
                    β–Ό
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β”‚πŸ”Ž Check Changesβ”‚
           β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β”‚πŸ³ Docker Buildβ”‚
           β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β”‚πŸ’¨ Smoke Test  β”‚
           β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              STAGE 3: REPORT & DEPLOY                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚πŸ“Š Report β”‚
            β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚πŸš€ Deploy β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β˜… Insight: Quality + Security Gate ─────────────────────────

Tool Focus Why It Matters
Codecov Code quality "Are you testing enough?" - tracks coverage trends
CodeQL Security "Is your code safe?" - finds vulnerabilities automatically

Together they form a quality + security gate that catches both coverage regressions and vulnerabilities before merge.


β˜… Insight: Why Exclude CLI Code from Coverage ────────────

# These lines are excluded from coverage (standard practice):
if __name__ == "__main__":
    main()

Why?

  • Interactive CLI code (input(), print()) is meant for human interaction, not unit tests
  • Testing these requires mocking stdin/stdout - low value, high complexity
  • The core logic (Calculator class) is what matters - and that's at 100%
  • This is standard practice in Python projects (Django, Flask, etc.)

β˜… Insight: GitHub Copilot Code Review ─────────────────────

Custom instructions in .github/copilot-instructions.md tell Copilot what's important for YOUR project:

  • Without context: Copilot reviews can be noisy with false positives
  • With instructions: Focused reviews on what actually matters
  • Think of it as: Giving a human reviewer onboarding docs

β˜… Insight: How GitHub Actions Parallelism Works ───────────

Concept How It Works
Parallel jobs Jobs without needs: start immediately together
Sequential jobs Jobs with needs: [job1, job2] wait for ALL listed jobs
Runners Each parallel job gets its own fresh VM
Total time max(parallel jobs) + sequential jobs

Example from this repo:

# These run in PARALLEL (no needs:)
lint:
  runs-on: ubuntu-latest

security:
  runs-on: ubuntu-latest

# This waits for BOTH to complete
test:
  needs: [lint, security]  # Won't start until both finish

β˜… Insight: Caching Strategy (3x Speedup) ──────────────────

Cache What It Stores Invalidates When
pip cache Downloaded Python packages requirements.txt changes
pytest cache Test collection data Test files change

Result: First run ~45s, subsequent runs ~15s (3x faster!)

Project Structure

simple-calculator/
β”œβ”€β”€ guides/              # πŸ“– Step-by-step learning (START HERE!)
β”œβ”€β”€ src/                 # 🧠 Calculator code
β”œβ”€β”€ tests/               # βœ… Test code
β”œβ”€β”€ docs/                # πŸ“š Deep-dive documentation
β”‚   └── assets/          # 🎨 Images
β”œβ”€β”€ .github/workflows/   # πŸ€– CI/CD automation
└── prompts/             # 🧩 Copy-paste CI/CD prompts

See docs/reference/STRUCTURE.md for details.


Documentation

For Learners

For Deep Dives

For Your Projects

  • 🧩 Prompts - Copy-paste CI/CD setup for your repos

More Ways to Interact with This Repo Knowledge

  • πŸ€– Copilot Spaces - Interactive AI-powered exploration of this repository (requires Copilot licensing)
  • πŸ’¬ GitMCP Chat - Chat with this repository using GitMCP

Awesome GitHub Tools

Enhance your GitHub workflow with these helpful tools:

  • πŸ“± GitHub Mobile App - Official GitHub app for iOS and Android. Manage repositories, review code, and respond to issues on the go.

  • 🎨 GitHub Material Design Chrome Extension - Apply Material Design styling to GitHub's interface for a modern, polished look.

  • ⚑ Refined GitHub - Browser extension that simplifies the GitHub interface and adds 200+ useful features including linkified references, reaction avatars, merge conflict fixers, and more. Available for Chrome and Firefox.

  • πŸ€– GitHub MCP - Model Context Protocol server for GitHub integration, enabling AI assistants to interact with GitHub repositories, issues, and pull requests through the MCP framework.


Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run pytest and pre-commit run --all-files
  5. Submit a pull request

CI will automatically test your changes.


License

This project is for educational purposes.


Ready to Learn?

πŸ‘‰ Start with Guide 1: Getting Started

Learn professional CI/CD practices through hands-on experience!

About

Simple Python calculator demonstrating basic CI/CD with GitHub Actions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors