From e5cbb8b4be04797deedc775a5143b5035e7dd3b7 Mon Sep 17 00:00:00 2001 From: Skyiesac Date: Mon, 19 Jan 2026 12:45:29 -0500 Subject: [PATCH] Fixed #36639 -- Added CI step to run makemigrations --check against test models. --- .github/workflows/check-migrations.yml | 68 ++++++++++++++++++++++++++ scripts/check_migrations.py | 31 ++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 .github/workflows/check-migrations.yml create mode 100644 scripts/check_migrations.py diff --git a/.github/workflows/check-migrations.yml b/.github/workflows/check-migrations.yml new file mode 100644 index 0000000000..8b29b2bb34 --- /dev/null +++ b/.github/workflows/check-migrations.yml @@ -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 diff --git a/scripts/check_migrations.py b/scripts/check_migrations.py new file mode 100644 index 0000000000..70d187e144 --- /dev/null +++ b/scripts/check_migrations.py @@ -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()