Skip to content

Commit 8390ada

Browse files
authored
Update unit-tests.yml
1 parent bf6c29d commit 8390ada

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

.github/workflows/unit-tests.yml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
name: Unit tests
1+
name: Unit tests for Django
22

33
on:
44
push:
55
branches:
66
- main
7+
paths-ignore:
8+
- '**.md'
79
pull_request:
810
branches:
911
- main
12+
paths-ignore:
13+
- '**.md'
1014

1115
permissions:
12-
contents: read
13-
checks: write
16+
contents: read # Только чтение содержимого репозитория
17+
checks: write # Необходимо для отправки результатов тестов в GitHub Checks
1418

1519
jobs:
1620
test:
@@ -29,9 +33,39 @@ jobs:
2933
run: |
3034
python -m pip install --upgrade pip
3135
if [ -f "requirements.txt" ]; then
36+
echo "Installing dependencies from requirements.txt..."
3237
pip install -r requirements.txt || { echo "Dependency installation failed!"; exit 1; }
3338
else
3439
echo "requirements.txt not found! Skipping dependency installation."
40+
exit 1
41+
fi
42+
43+
- name: Validate installed packages
44+
run: |
45+
echo "Validating installed packages..."
46+
pip list
47+
if ! pip show django; then
48+
echo "Django is not installed!"
49+
exit 1
50+
fi
51+
52+
- name: Check Django version
53+
run: |
54+
echo "Checking Django version..."
55+
INSTALLED_VERSION=$(pip show django | grep Version | cut -d ' ' -f 2)
56+
REQUIRED_VERSION="4.2.19" # Требуемая версия Django
57+
if [ "$INSTALLED_VERSION" != "$REQUIRED_VERSION" ]; then
58+
echo "Incorrect Django version installed: $INSTALLED_VERSION. Required: $REQUIRED_VERSION"
59+
exit 1
60+
fi
61+
62+
- name: Run database migrations (if needed)
63+
run: |
64+
if command -v python manage.py &>/dev/null; then
65+
echo "Running database migrations..."
66+
python manage.py migrate --noinput
67+
else
68+
echo "manage.py not found. Skipping migrations."
3569
fi
3670
3771
- name: Run unit tests
@@ -43,10 +77,10 @@ jobs:
4377
if: steps.run-tests.outcome == 'failure'
4478
run: |
4579
echo "Tests failed! Review the logs for details."
46-
exit 1
80+
exit 1 # Завершить пайплайн с ошибкой, если тесты не прошли
4781
4882
- name: Upload test results
49-
if: always()
83+
if: always() # Выполнить этот шаг всегда, независимо от успеха предыдущих шагов
5084
uses: actions/upload-artifact@v4
5185
with:
5286
name: test-results

0 commit comments

Comments
 (0)