This repository is a simple example project to demonstrate a CI/CD pipeline using Python, GitHub Actions, and various development tools. The project starts with a "Hello World" script and includes tooling for code coverage, automated testing, linting, and more.
python-ci-cd-hello-world/
├── .github/
│ └── workflows/
│ └── python-ci.yml
├── .devcontainer/
│ └── devcontainer.json
├── src/
│ └── main.py
├── tests/
│ └── test_main.py
├── .coveragerc
├── .flake8
├── pyproject.toml
├── requirements.txt
├── README.md
└── setup.cfg
graph LR
A[Commit is Pushed] -->|Triggers| B[GitHub Actions Workflow]
B --> C[Job: Build]
C --> D[Checkout Code]
D --> E[Set Up Python]
E --> F[Install Dependencies]
F --> G[Lint Code with Flake8]
G --> H[Format Code with Black]
H --> I[Run Tests]
I --> J[Upload Coverage to Codecov]
J --> K[Workflow Completes]
- Python 3.x
- Git
-
Clone the repository:
git clone https://github.com/chrismarksus/python-ci-cd-hello-world.git cd python-ci-cd-hello-world
-
Set up a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Run the "Hello World" script:
python src/main.py
-
Run the tests:
coverage run -m unittest discover
-
Generate a coverage report:
coverage report
-
Lint the code:
flake8 src tests
-
Format the code:
black src tests
This project uses GitHub Actions to automate testing and code quality checks. The configuration is located in .github/workflows/python-ci.yml
. The pipeline includes:
- Checking out the code
- Setting up Python
- Installing dependencies
- Running linting with Flake8
- Checking code formatting with Black
- Running tests and generating a coverage report
- Uploading coverage results to Codecov
This project includes a configuration for GitHub Codespaces, located in .devcontainer/devcontainer.json
, to set up a consistent development environment using VS Code.
We welcome contributions to this project! Follow the steps below to get started:
- Navigate to the repository on GitHub.
- Click the "Fork" button in the top-right corner to create your own copy of the repository.
Clone your forked repository to your local machine:
git clone https://github.com/your-username/python-ci-cd-hello-world.git
cd python-ci-cd-hello-world
Create a new branch for your feature or bug fix:
git checkout -b feature/your-feature-name
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
Make your changes to the codebase. Ensure your code follows the project's coding standards and passes all tests.
-
Lint your code:
flake8 src tests
-
Format your code:
black src tests
-
Run tests:
coverage run -m unittest discover coverage report
Commit your changes with a meaningful commit message:
git add .
git commit -m "Description of your changes"
Push your changes to your forked repository:
git push origin feature/your-feature-name
- Navigate to the original repository on GitHub.
- Click the "New Pull Request" button.
- Select your fork and branch as the source, and the original repository and branch as the destination.
- Fill in the necessary details and create the pull request.
- Ensure your code passes all CI checks.
- Update documentation and add tests as needed.
- Be responsive to feedback on your pull request.
Thank you for contributing!