Skip to content

Commit 47766f7

Browse files
authored
Merge pull request #1 from junior92jr/test-ci
Add GitHub Actions workflow for Django tests with PostgreSQL
2 parents 47ec842 + 0650b0f commit 47766f7

File tree

12 files changed

+145
-29
lines changed

12 files changed

+145
-29
lines changed

.devcontainer/docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
- ..:/workspace:cached
1010
working_dir: /workspace/src
1111
env_file:
12-
- ../.env
12+
- ../.env_files/.env
1313

1414
command: sleep infinity
1515
depends_on:
@@ -22,7 +22,7 @@ services:
2222
- ..:/workspace:cached
2323
working_dir: /workspace/src
2424
env_file:
25-
- ../.env
25+
- ../.env_files/.env
2626

2727
command: celery -A backend worker --loglevel=info
2828
depends_on:
@@ -37,7 +37,7 @@ services:
3737
- ..:/workspace:cached
3838
working_dir: /workspace/src
3939
env_file:
40-
- ../.env
40+
- ../.env_files/.env
4141
command: celery -A backend beat --loglevel=info --scheduler django_celery_beat.schedulers:DatabaseScheduler
4242
depends_on:
4343
- redis
@@ -57,7 +57,7 @@ services:
5757
ports:
5858
- "5432:5432"
5959
env_file:
60-
- ../.env
60+
- ../.env_files/.env
6161

6262
volumes:
6363
postgres-data:

.env_files/.env.ci

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Database
2+
DATABASE_URI=postgresql://postgres:postgres@localhost:5432/web_test
3+
DATABASE_URI_TEST=postgresql://postgres:postgres@localhost:5432/web_test
4+
5+
# Django
6+
SECRET_KEY=ci-secret-key
7+
DEBUG=False
8+
ALLOWED_HOSTS=localhost,127.0.0.1
9+
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
10+
11+
# Celery / Redis
12+
CELERY_BROKER_URL=redis://localhost:6379/0
13+
CELERY_RESULT_BACKEND=redis://localhost:6379/1
14+
15+
# Postgres
16+
POSTGRES_USER=postgres
17+
POSTGRES_PASSWORD=postgres
18+
POSTGRES_DB=postgres
File renamed without changes.

.github/workflows/django-ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Django CI (Postgres)
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
services:
13+
postgres:
14+
image: postgres:15
15+
env:
16+
POSTGRES_USER: postgres
17+
POSTGRES_PASSWORD: postgres
18+
POSTGRES_DB: web_test
19+
ports: ["5432:5432"]
20+
options: >-
21+
--health-cmd="pg_isready -U postgres"
22+
--health-interval=10s
23+
--health-timeout=5s
24+
--health-retries=5
25+
redis:
26+
image: redis:7
27+
ports: ["6379:6379"]
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
- name: Set up Python
33+
uses: actions/setup-python@v5
34+
with:
35+
python-version: "3.11"
36+
37+
- name: Install dependencies
38+
run: pip install -r requirements.txt
39+
40+
- name: Run migrations
41+
working-directory: src
42+
run: |
43+
set -o allexport
44+
source ../.env_files/.env.ci
45+
python manage.py migrate
46+
set +o allexport
47+
48+
- name: Run tests
49+
working-directory: src
50+
run: |
51+
set -o allexport
52+
source ../.env_files/.env.ci
53+
pytest
54+
set +o allexport

.github/workflows/lint.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Lint & Format
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Set up Python
15+
uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.11"
18+
- name: Install dependencies
19+
run: pip install -r requirements.txt
20+
- name: Run Black
21+
run: black --check .
22+
- name: Run isort
23+
run: isort --check-only .
24+
- name: Run flake8
25+
run: flake8 .

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"python.testing.pytestEnabled": true,
2323
"editor.formatOnSave": true,
2424
"editor.codeActionsOnSave": {
25-
"source.organizeImports": "always"
25+
"source.organizeImports": "always",
26+
"source.fixAll": "always"
2627
},
2728
"editor.rulers": [
2829
88

docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
volumes:
88
- ./:/workspace:cached
99
env_file:
10-
- .env
10+
- .env_files/.env
1111
command: ["/bin/sh", "/workspace/scripts/django/start.sh"]
1212
ports:
1313
- "8000:8000"
@@ -25,7 +25,7 @@ services:
2525
volumes:
2626
- ./:/workspace:cached
2727
env_file:
28-
- .env
28+
- .env_files/.env
2929
command: ["/bin/sh", "/workspace/scripts/celery/worker.sh"]
3030
depends_on:
3131
db:
@@ -43,7 +43,7 @@ services:
4343
- ./:/workspace:cached
4444
working_dir: /workspace/src
4545
env_file:
46-
- .env
46+
- .env_files/.env
4747
command: ["/bin/sh", "/workspace/scripts/celery/beat.sh"]
4848
depends_on:
4949
db:
@@ -74,7 +74,7 @@ services:
7474
ports:
7575
- "5432:5432"
7676
env_file:
77-
- .env
77+
- .env_files/.env
7878
networks:
7979
- backend
8080
healthcheck:

setup.cfg

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
[black]
2-
line-length = 88 # Set line length to 88
2+
line-length = 88
33

4-
[pylint]
5-
disable = C0114 # Disable missing module docstring warning
4+
[isort]
5+
profile = black
6+
multi_line_output = 3
7+
include_trailing_comma = true
8+
force_grid_wrap = 0
9+
use_parentheses = true
10+
ensure_newline_before_comments = true
11+
line_length = 88
12+
remove_redundant_aliases = true
613

714
[flake8]
8-
max-line-length = 88 # Set line length to 88
9-
extend-ignore = E203, W503 # Ignore specific warnings
15+
max-line-length = 88
16+
extend-ignore = E203, W503
17+
exclude = .git,__pycache__,migrations,venv
18+
per-file-ignores =
19+
src/backend/settings_test.py: F405
1020

11-
[isort]
12-
multi_line_output = 3 # Vertical hanging indent for imports
13-
include_trailing_comma = true # Add trailing comma
14-
force_grid_wrap = 0 # Disable wrapping
15-
use_parentheses = true # Use parentheses for wrapping
16-
ensure_newline_before_comments = true # Newline before comments in imports
17-
line_length = 88 # Set line length to 88
18-
remove_redundant_aliases = true # Remove redundant aliases
21+
[pylint]
22+
disable = C0114
23+
24+
[mypy]
25+
plugins = mypy_django_plugin.main
26+
ignore_missing_imports = True
27+
28+
[mypy-tests.*]
29+
ignore_errors = True
30+
31+
[mypy.plugins.django-stubs]
32+
django_settings_module = "backend.settings"
33+
strict_settings = True

src/backend/settings.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"django.middleware.security.SecurityMiddleware",
4545
"django.contrib.sessions.middleware.SessionMiddleware",
4646
"django.middleware.common.CommonMiddleware",
47-
"corsheaders.middleware.CorsMiddleware", # CORS middleware should be high in the order
47+
"corsheaders.middleware.CorsMiddleware",
4848
"django.middleware.csrf.CsrfViewMiddleware",
4949
"django.contrib.auth.middleware.AuthenticationMiddleware",
5050
"django.contrib.messages.middleware.MessageMiddleware",
@@ -80,11 +80,13 @@
8080
# Password validation
8181
AUTH_PASSWORD_VALIDATORS = [
8282
{
83-
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
83+
"NAME": (
84+
"django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
85+
)
8486
},
85-
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
86-
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
87-
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
87+
{"NAME": ("django.contrib.auth.password_validation.MinimumLengthValidator")},
88+
{"NAME": ("django.contrib.auth.password_validation.CommonPasswordValidator")},
89+
{"NAME": ("django.contrib.auth.password_validation.NumericPasswordValidator")},
8890
]
8991

9092
# Internationalization settings

src/backend/settings_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from backend.settings import * # noqa: F401,F403
1+
from backend.settings import * # noqa: F401,F403,F405
22

33
DATABASES = {"default": env.db("DATABASE_URI")}

0 commit comments

Comments
 (0)