Skip to content

ci: Implement comprehensive CI/CD pipeline #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: CI/CD

on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.13"]
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: pip install ruff

- name: Run Ruff Linter
uses: astral-sh/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Run Ruff Formatter Check
run: ruff format --check

test:
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Create .env file for Docker
run: |
cat <<'EOF' >> .env
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
DJANGO_SECRET_KEY=${{ secrets.DJANGO_SECRET_KEY }}
POSTGRES_DATABASE=${{ secrets.POSTGRES_DB }}
POSTGRES_USERNAME=${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_HOST=db
ANTIFRAUD_INTERNAL_PORT=9090
ANTIFRAUD_EXTERNAL_PORT=9090
ANTIFRAUD_CACHE_MS=5000
ANTIFRAUD_ADDRESS=http://antifraud:9090
EOF

- name: Build and run Docker containers
run: docker compose up -d --build

- name: Wait for services to be healthy
run: |
echo "Waiting for PostgreSQL..."
sleep 20

- name: Run tests and generate coverage report 🛡️
run: >
docker compose exec -T web sh -c
"cd promo_code && coverage run manage.py test && coverage xml"

- name: Upload coverage to Codecov 🚀
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
28 changes: 0 additions & 28 deletions .github/workflows/linting.yml

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Promo Code API

[![Linting](https://github.com/RandomProgramm3r/Promo-Code-API/actions/workflows/linting.yml/badge.svg)](https://github.com/RandomProgramm3r/Promo-Code-API/actions)
[![CI/CD](https://github.com/RandomProgramm3r/Promo-Code-API/actions/workflows/linting.yml/badge.svg)](https://github.com/RandomProgramm3r/Promo-Code-API/actions)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![codecov](https://codecov.io/github/RandomProgramm3r/Promo-Code-API/graph/badge.svg?token=VNBK0FAU3Z)](https://codecov.io/github/RandomProgramm3r/Promo-Code-API)

The application provides an HTTP API for companies and end-users, is integrated with an external anti-fraud service, and uses PostgreSQL and Redis for data storage and caching.

Expand Down
12 changes: 12 additions & 0 deletions promo_code/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[run]
source = business, promo_code, user, core
omit =
settings.py
*/tests/*
*/migrations/*
*/__init__.py
manage.py
*/apps.py
*/urls.py
*/wsgi.py
*/asgi.py
7 changes: 1 addition & 6 deletions promo_code/user/tests/user/operations/test_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,6 @@ def test_user3_lu_40_get_all_promos_pagination_offset10_limit2(self):
response.status_code,
rest_framework.status.HTTP_200_OK,
)
for item in response.data:
self.assertNotIn('promo_common', item)
self.assertNotIn('promo_unique', item)
self.assertEqual(response['X-Total-Count'], '6')
self.assertEqual(response.data, [])

Expand Down Expand Up @@ -619,9 +616,7 @@ def test_user3_lu_40_get_promos_by_non_existent_category(self):
response.status_code,
rest_framework.status.HTTP_200_OK,
)
for item in response.data:
self.assertNotIn('promo_common', item)
self.assertNotIn('promo_unique', item)

self.assertEqual(response['X-Total-Count'], '0')
self.assertEqual(response.data, [])

Expand Down
1 change: 1 addition & 0 deletions requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ pycountry==24.6.1
python-dotenv==1.0.1
requests==2.32.4
parameterized==0.9.0
coverage==7.9.2