From 80590b3fdb2b95dbe794c743cdcf0b8252d2ae66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=F0=9F=A6=8A=20=28TheFoxKD=29?= Date: Sat, 23 Nov 2024 22:31:17 +0300 Subject: [PATCH] Add CI/CD configuration --- .github/CODEOWNERS | 8 ++++ .github/dependabot.yml | 24 ++++++++++++ .github/workflows/ci.yml | 84 ++++++++++++++++++++++++++++++++++++++++ .gitignore | 22 ++++++----- README.md | 59 +++++++++++++++++++++++++++- 5 files changed, 187 insertions(+), 10 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..b6f14ac --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,8 @@ +# Default owners for everything in the repo +* @TheFoxKD + +# Specific owners for critical parts +/src/ @TheFoxKD +/tests/ @TheFoxKD +*.toml @TheFoxKD +*.yml @TheFoxKD diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..eafb9a6 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,24 @@ +version: 2 +updates: + # Update GitHub actions in workflows + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + groups: + github-actions: + patterns: + - "*" + + # Enable version updates for Python/Pip + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "weekly" + groups: + python-packages: + patterns: + - "*" + ignore: + - dependency-name: "*" + update-types: ["version-update:semver-major"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b9001ca --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,84 @@ +name: CI + +on: + pull_request: + branches: [ "main", "master" ] + push: + branches: [ "main", "master" ] + +concurrency: + group: ${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + linter: + runs-on: ubuntu-latest + steps: + - name: Checkout Code Repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: "pip" + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run pre-commit + uses: pre-commit/action@v3.0.1 + + pytest: + runs-on: ubuntu-latest + needs: linter + steps: + - name: Checkout Code Repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: "pip" + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run Tests + run: | + pytest --cov=./src --cov-report=xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.xml + flags: unittests + name: codecov-umbrella + fail_ci_if_error: true + + type-check: + runs-on: ubuntu-latest + needs: linter + steps: + - name: Checkout Code Repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: "pip" + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run MyPy + run: mypy src diff --git a/.gitignore b/.gitignore index a7b9ed8..84c057d 100644 --- a/.gitignore +++ b/.gitignore @@ -20,22 +20,26 @@ wheels/ .installed.cfg *.egg -# Virtual Environment +# Testing +.tox/ +.coverage +.coverage.* +.cache +coverage.xml +*.cover +*.py,cover +.pytest_cache/ +.mypy_cache/ .venv/ -env/ -ENV/ # IDE .idea/ .vscode/ *.swp *.swo +*~ # Project specific -data/*.json -!data/.gitkeep - -# OS -.DS_Store -Thumbs.db +/data/*.json +!/data/.gitkeep /uv.lock diff --git a/README.md b/README.md index cbb9197..a8085b0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # Book Manager System +[![CI](https://github.com/TheFoxKD/book-manager-sys/actions/workflows/ci.yml/badge.svg)](https://github.com/TheFoxKD/book-manager-sys/actions/workflows/ci.yml) +[![codecov](https://codecov.io/gh/TheFoxKD/book-manager-sys/branch/main/graph/badge.svg)](https://codecov.io/gh/TheFoxKD/book-manager-sys) +[![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/release/python-3120/) +[![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff) + A lightweight command-line library management system with JSON storage and intuitive CLI interface. ## Features @@ -9,12 +14,15 @@ A lightweight command-line library management system with JSON storage and intui - Track book availability status - Persistent JSON storage - Error handling and input validation +- 100% type-annotated code +- High test coverage ## Installation ```bash git clone https://github.com/TheFoxKD/book-manager-sys.git cd book-manager-sys +pip install -r requirements.txt ``` ## Usage @@ -23,9 +31,54 @@ cd book-manager-sys python src/main.py ``` +## Development + +### Testing and Quality Assurance + +The project uses several tools to ensure code quality: + +- **pytest**: For unit testing +- **mypy**: For static type checking +- **ruff**: For linting and code formatting +- **pre-commit**: For automated code quality checks + +### Continuous Integration + +The project uses GitHub Actions for CI/CD with the following checks: + +- Code linting and formatting +- Type checking +- Unit tests with coverage reporting +- Dependency updates via Dependabot + +### Pre-commit Hooks + +Before committing, ensure pre-commit hooks are installed: + +```bash +pip install pre-commit +pre-commit install +``` + +### Running Tests Locally + +```bash +# Run tests +pytest + +# Run tests with coverage +pytest --cov=./src --cov-report=term-missing + +# Run type checking +mypy src tests + +# Run linting +ruff check . +``` + ## Requirements -- Python 3.8+ +- Python 3.12+ - No external dependencies required ## Project Structure @@ -33,3 +86,7 @@ python src/main.py - `src/` - Main source code - `data/` - JSON storage - `tests/` - Unit tests + +## License + +MIT