Skip to content

Commit b03cb3c

Browse files
Merge pull request #66 from RandomProgramm3r/develop
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. - Add Codecov badge URL in README - **`requirements/prod.txt`:** Added `coverage` to the list of production requirements. - **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.
2 parents fe82d03 + d073592 commit b03cb3c

File tree

6 files changed

+91
-35
lines changed

6 files changed

+91
-35
lines changed

.github/workflows/ci.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
cat <<'EOF' >> .env
46+
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
47+
DJANGO_SECRET_KEY=${{ secrets.DJANGO_SECRET_KEY }}
48+
POSTGRES_DATABASE=${{ secrets.POSTGRES_DB }}
49+
POSTGRES_USERNAME=${{ secrets.POSTGRES_USER }}
50+
POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}
51+
POSTGRES_HOST=db
52+
ANTIFRAUD_INTERNAL_PORT=9090
53+
ANTIFRAUD_EXTERNAL_PORT=9090
54+
ANTIFRAUD_CACHE_MS=5000
55+
ANTIFRAUD_ADDRESS=http://antifraud:9090
56+
EOF
57+
58+
- name: Build and run Docker containers
59+
run: docker compose up -d --build
60+
61+
- name: Wait for services to be healthy
62+
run: |
63+
echo "Waiting for PostgreSQL..."
64+
sleep 20
65+
66+
- name: Run tests and generate coverage report 🛡️
67+
run: >
68+
docker compose exec -T web sh -c
69+
"cd promo_code && coverage run manage.py test && coverage xml"
70+
71+
- name: Upload coverage to Codecov 🚀
72+
uses: codecov/codecov-action@v5
73+
with:
74+
token: ${{ secrets.CODECOV_TOKEN }}
75+
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/github/RandomProgramm3r/Promo-Code-API/graph/badge.svg?token=VNBK0FAU3Z)](https://codecov.io/github/RandomProgramm3r/Promo-Code-API)
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

requirements/prod.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ pycountry==24.6.1
99
python-dotenv==1.0.1
1010
requests==2.32.4
1111
parameterized==0.9.0
12+
coverage==7.9.2

0 commit comments

Comments
 (0)