Skip to content

Commit 9a46702

Browse files
authored
Update unit-tests.yml
1 parent 99f612d commit 9a46702

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

.github/workflows/unit-tests.yml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,29 @@ jobs:
1616
test:
1717
runs-on: ubuntu-latest
1818

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+
1934
steps:
2035
- name: Checkout code
2136
uses: actions/checkout@v3
2237

2338
- name: Set up Python
2439
uses: actions/setup-python@v4
2540
with:
26-
python-version: '3.9'
41+
python-version: '3.10' # Используем Python 3.10, так как он совместим с Django 4.2.4
2742

2843
- name: Install dependencies
2944
run: |
@@ -36,16 +51,14 @@ jobs:
3651
exit 1
3752
fi
3853
39-
- name: Validate Django version
54+
- name: Configure Django settings for testing
4055
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) # Импортируем переменные окружения
4760
48-
- name: Run database migrations (if needed)
61+
- name: Run database migrations
4962
run: |
5063
if command -v python manage.py &>/dev/null; then
5164
echo "Running database migrations..."
@@ -54,6 +67,15 @@ jobs:
5467
echo "manage.py not found. Skipping migrations."
5568
fi
5669
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+
5779
- name: Run unit tests
5880
run: |
5981
pytest --junitxml=test-results.xml || {

0 commit comments

Comments
 (0)