Skip to content

Commit 35b4b45

Browse files
ci: Implement comprehensive CI/CD pipeline
This commit introduces a robust CI/CD pipeline using GitHub Actions, consolidating linting and testing into a single workflow. It also adds configuration for code coverage reporting. Key changes: - **New `ci.yml` Workflow:** A new `ci.yml` workflow replaces the old `linting.yml`. This new workflow includes jobs for: - **Linting:** Running `ruff` to check code style and formatting. - **Testing:** Building Docker containers, running the test suite with `coverage`, and uploading the results to Codecov. - **Coverage Configuration:** A `.coveragerc` file has been added to configure the source files for coverage analysis and to exclude irrelevant files like tests and migrations. - **README Update:** The `README.md` has been updated to include a Codecov badge and reflect the new `CI/CD` workflow name. - **Test Refinement:** Removed redundant assertions from `TestUserPromoFeed` that checked for the absence of `promo_common` and `promo_unique` fields, as this is handled by the serializer.
1 parent 7653bde commit 35b4b45

File tree

5 files changed

+89
-35
lines changed

5 files changed

+89
-35
lines changed

.github/workflows/ci.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
workflow_dispatch:
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ["3.13"]
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v3
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Install dependencies
26+
run: pip install ruff
27+
28+
- name: Run Ruff Linter
29+
uses: astral-sh/[email protected]
30+
with:
31+
github-token: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Run Ruff Formatter Check
34+
run: ruff format --check
35+
36+
test:
37+
runs-on: ubuntu-latest
38+
needs: lint
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v3
42+
43+
- name: Create .env file for Docker
44+
run: |
45+
echo "DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0" >> .env
46+
echo "DJANGO_SECRET_KEY=${{ secrets.DJANGO_SECRET_KEY }}" >> .env
47+
48+
echo "POSTGRES_DATABASE=${{ secrets.POSTGRES_DATABASE }}" >> .env
49+
echo "POSTGRES_USERNAME=${{ secrets.POSTGRES_USERNAME }}" >> .env
50+
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> .env
51+
52+
echo "ANTIFRAUD_INTERNAL_PORT=8081" >> .env
53+
echo "ANTIFRAUD_EXTERNAL_PORT=8081" >> .env
54+
echo "ANTIFRAUD_CACHE_MS=1000" >> .env
55+
56+
57+
- name: Build and run Docker containers
58+
run: docker-compose up -d --build
59+
60+
- name: Wait for services to be healthy
61+
run: |
62+
echo "Waiting for PostgreSQL..."
63+
sleep 20
64+
65+
- name: Run tests and generate coverage report 🛡️
66+
run: >
67+
docker-compose exec -T web sh -c
68+
"coverage run manage.py test && coverage xml"
69+
70+
- name: Upload coverage to Codecov 🚀
71+
uses: codecov/codecov-action@v5
72+
with:
73+
token: ${{ secrets.CODECOV_TOKEN }}
74+
fail_ci_if_error: true

.github/workflows/linting.yml

Lines changed: 0 additions & 28 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Promo Code API
22

3-
[![Linting](https://github.com/RandomProgramm3r/Promo-Code-API/actions/workflows/linting.yml/badge.svg)](https://github.com/RandomProgramm3r/Promo-Code-API/actions)
3+
[![CI/CD](https://github.com/RandomProgramm3r/Promo-Code-API/actions/workflows/linting.yml/badge.svg)](https://github.com/RandomProgramm3r/Promo-Code-API/actions)
44
[![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)
5+
[![codecov](https://codecov.io/gh/YourUsername/YourRepo/graph/badge.svg?token=YOUR_TOKEN)](https://codecov.io/gh/YourUsername/YourRepo)
56

67
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.
78

promo_code/.coveragerc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[run]
2+
source = business, promo_code, user, core
3+
omit =
4+
settings.py
5+
*/tests/*
6+
*/migrations/*
7+
*/__init__.py
8+
manage.py
9+
*/apps.py
10+
*/urls.py
11+
*/wsgi.py
12+
*/asgi.py

promo_code/user/tests/user/operations/test_feed.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,6 @@ def test_user3_lu_40_get_all_promos_pagination_offset10_limit2(self):
442442
response.status_code,
443443
rest_framework.status.HTTP_200_OK,
444444
)
445-
for item in response.data:
446-
self.assertNotIn('promo_common', item)
447-
self.assertNotIn('promo_unique', item)
448445
self.assertEqual(response['X-Total-Count'], '6')
449446
self.assertEqual(response.data, [])
450447

@@ -619,9 +616,7 @@ def test_user3_lu_40_get_promos_by_non_existent_category(self):
619616
response.status_code,
620617
rest_framework.status.HTTP_200_OK,
621618
)
622-
for item in response.data:
623-
self.assertNotIn('promo_common', item)
624-
self.assertNotIn('promo_unique', item)
619+
625620
self.assertEqual(response['X-Total-Count'], '0')
626621
self.assertEqual(response.data, [])
627622

0 commit comments

Comments
 (0)