diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e2d67a5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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/ruff-action@v3.2.2 + 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 diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml deleted file mode 100644 index 6ade1f9..0000000 --- a/.github/workflows/linting.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Linting -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: Run Ruff via Action - uses: astral-sh/ruff-action@v3.2.2 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - - run: ruff format --check diff --git a/README.md b/README.md index efa130b..5824957 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/promo_code/.coveragerc b/promo_code/.coveragerc new file mode 100644 index 0000000..b306ead --- /dev/null +++ b/promo_code/.coveragerc @@ -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 diff --git a/promo_code/user/tests/user/operations/test_feed.py b/promo_code/user/tests/user/operations/test_feed.py index 898704a..fe9df74 100644 --- a/promo_code/user/tests/user/operations/test_feed.py +++ b/promo_code/user/tests/user/operations/test_feed.py @@ -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, []) @@ -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, []) diff --git a/requirements/prod.txt b/requirements/prod.txt index 18ecb42..4c0cc1c 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -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