Skip to content

Commit f99c8bf

Browse files
committed
fix: 修复 CI 流水线后端 lint 和 Django check 失败问题
- Backend Lint: 改用 uvx ruff 避免安装全部重型依赖(torch 等) - Django Check: settings.py 读取 DB_ENGINE 环境变量,CI 使用 SQLite - Django Check: 补充所有缺失的环境变量(Redis/Celery/DB)
1 parent ab3d9d7 commit f99c8bf

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ jobs:
1818
- uses: astral-sh/setup-uv@v5
1919
with:
2020
python-version: "3.12"
21-
- name: Install dependencies
22-
run: uv sync --group dev
2321
- name: Run ruff
24-
run: uv run ruff check .
22+
run: uvx ruff check .
2523

2624
frontend-build:
2725
name: Frontend Build
@@ -53,12 +51,18 @@ jobs:
5351
with:
5452
python-version: "3.12"
5553
- name: Install dependencies
56-
run: uv sync
54+
run: uv sync --no-build-isolation
5755
- name: Django check
5856
run: uv run python manage.py check --deploy
5957
env:
6058
DJANGO_SETTINGS_MODULE: DjangoUserService.settings
6159
JWT_SECRET_KEY: ci-test-key
6260
DB_ENGINE: django.db.backends.sqlite3
63-
DB_NAME: db.sqlite3
64-
CELERY_TASK_ALWAYS_EAGER: "True"
61+
DB_NAME: ci_db.sqlite3
62+
DB_USER: ""
63+
DB_PASSWORD: ""
64+
DB_HOST: ""
65+
DB_PORT: ""
66+
REDIS_CACHE_URL: redis://localhost:6379/1
67+
CELERY_BROKER_URL: redis://localhost:6379/0
68+
CELERY_RESULT_BACKEND: redis://localhost:6379/0

DjangoUserService/DjangoUserService/settings.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,23 @@
100100

101101
DATABASES = {
102102
'default': {
103-
'ENGINE': 'django.db.backends.mysql',
103+
'ENGINE': os.getenv('DB_ENGINE', 'django.db.backends.mysql'),
104104
'NAME': os.getenv('DB_NAME'),
105105
'USER': os.getenv('DB_USER'),
106106
'PASSWORD': os.getenv('DB_PASSWORD'),
107107
'HOST': os.getenv('DB_HOST'),
108108
'PORT': os.getenv('DB_PORT'),
109-
'OPTIONS': {
110-
'charset': 'utf8mb4',
111-
'use_unicode': True,
112-
'init_command': 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci',
113-
},
114109
}
115110
}
116111

112+
# MySQL 特有配置(非 SQLite 时使用)
113+
if DATABASES['default']['ENGINE'] != 'django.db.backends.sqlite3':
114+
DATABASES['default']['OPTIONS'] = {
115+
'charset': 'utf8mb4',
116+
'use_unicode': True,
117+
'init_command': 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci',
118+
}
119+
117120
# Celery 配置
118121
CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL')
119122
CELERY_RESULT_BACKEND = os.getenv('CELERY_RESULT_BACKEND')

0 commit comments

Comments
 (0)