Fixed #36639 -- Added CI step to run makemigrations --check against test models.

This commit is contained in:
Skyiesac
2026-01-19 12:45:29 -05:00
committed by Jacob Walls
parent 748c2ba837
commit e5cbb8b4be
2 changed files with 99 additions and 0 deletions

68
.github/workflows/check-migrations.yml vendored Normal file
View File

@@ -0,0 +1,68 @@
name: Check migrations
on:
pull_request:
paths:
- 'tests/**/models.py'
- 'tests/**/migrations/**'
- 'tests/**/*migrations/**/*.py'
- 'scripts/check_migrations.py'
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
check-migrations:
name: Check test migrations
runs-on: ubuntu-latest
timeout-minutes: 60
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_DB: django
POSTGRES_USER: user
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.14'
cache: 'pip'
cache-dependency-path: 'tests/requirements/py3.txt'
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
python -m pip install -e . psycopg[binary]
- name: Create PostgreSQL settings file
run: mv ./.github/workflows/data/test_postgres.py.tpl ./tests/test_postgres.py
- name: Check for missing migrations
env:
DJANGO_SETTINGS_MODULE: test_postgres
PYTHONPATH: ${{ github.workspace }}/tests:${{ github.workspace }}
run: |
python scripts/check_migrations.py

View File

@@ -0,0 +1,31 @@
import sys
from pathlib import Path
def main():
repo_root = Path(__file__).resolve().parent.parent
sys.path[:0] = [str(repo_root / "tests"), str(repo_root)]
from runtests import ALWAYS_INSTALLED_APPS, get_apps_to_install, get_test_modules
import django
from django.apps import apps
from django.core.management import call_command
django.setup()
test_modules = list(get_test_modules(gis_enabled=False))
installed_apps = list(ALWAYS_INSTALLED_APPS)
for app in get_apps_to_install(test_modules):
# Check against the list to prevent duplicate errors.
if app not in installed_apps:
installed_apps.append(app)
apps.set_installed_apps(installed_apps)
# Note: We don't use check=True here because --check calls sys.exit(1)
# instead of raising CommandError when migrations are missing.
call_command("makemigrations", "--check", verbosity=3)
if __name__ == "__main__":
main()