@@ -16,14 +16,29 @@ jobs:
16
16
test :
17
17
runs-on : ubuntu-latest
18
18
19
+ services :
20
+ postgres : # Настройка PostgreSQL для тестов
21
+ image : postgres:14
22
+ env :
23
+ POSTGRES_USER : postgres
24
+ POSTGRES_PASSWORD : postgres
25
+ POSTGRES_DB : testdb
26
+ ports :
27
+ - 5432:5432
28
+ options : >-
29
+ --health-cmd pg_isready
30
+ --health-interval 10s
31
+ --health-timeout 5s
32
+ --health-retries 5
33
+
19
34
steps :
20
35
- name : Checkout code
21
36
uses : actions/checkout@v3
22
37
23
38
- name : Set up Python
24
39
uses : actions/setup-python@v4
25
40
with :
26
- python-version : ' 3.9 '
41
+ python-version : ' 3.10 ' # Используем Python 3.10, так как он совместим с Django 4.2.4
27
42
28
43
- name : Install dependencies
29
44
run : |
@@ -36,16 +51,14 @@ jobs:
36
51
exit 1
37
52
fi
38
53
39
- - name : Validate Django version
54
+ - name : Configure Django settings for testing
40
55
run : |
41
- INSTALLED_VERSION=$(pip show django | grep Version | cut -d ' ' -f 2)
42
- REQUIRED_VERSION="4.2.19" # Существующая стабильная версия Django
43
- if [ "$INSTALLED_VERSION" != "$REQUIRED_VERSION" ]; then
44
- echo "Incorrect Django version installed: $INSTALLED_VERSION. Required: $REQUIRED_VERSION"
45
- exit 1
46
- fi
56
+ echo "Configuring Django settings for testing..."
57
+ cp .env.example .env # Создаем файл окружения (если используется django-environ)
58
+ sed -i 's/DATABASE_URL=.*$/DATABASE_URL=postgres:\/\/postgres:postgres@localhost:5432\/testdb/' .env
59
+ export $(grep -v '^#' .env | xargs) # Импортируем переменные окружения
47
60
48
- - name : Run database migrations (if needed)
61
+ - name : Run database migrations
49
62
run : |
50
63
if command -v python manage.py &>/dev/null; then
51
64
echo "Running database migrations..."
54
67
echo "manage.py not found. Skipping migrations."
55
68
fi
56
69
70
+ - name : Collect static files (if needed)
71
+ run : |
72
+ if command -v python manage.py &>/dev/null; then
73
+ echo "Collecting static files..."
74
+ python manage.py collectstatic --noinput
75
+ else
76
+ echo "manage.py not found. Skipping static collection."
77
+ fi
78
+
57
79
- name : Run unit tests
58
80
run : |
59
81
pytest --junitxml=test-results.xml || {
0 commit comments