Skip to content

Commit

Permalink
Django Migration Linter Integration (#43)
Browse files Browse the repository at this point in the history
* Added django-migration-linter to project dependencies and updated Makefile

* Poetry.lock fixes

* Excluded apps added for linter

* CI pipeline added

* Recent changes

* CI file updated for the lint migration job.

* Updated per review suggestions

* Pipeline test

* Custom django lint migrations script added for cleaner output

* Poetry lock file updated

* Lock file updated

* Fix lint-py errors

* Update README.md

* Fixed linting issues

* Lock file updated

* Outer scope variable redefining lint issue fixed

* Removing lintmigration step

* Django migration linter moved out of the dev dependency

* README updated and make file commands added for lintmigrations and lintmigrations custom output

* Migration linter step added back in

* Retry to execute make command for migration linter

* Retry

* Exit codes added to pass or fail the custom migration script run

* Changes from reviews

* Code formatted

* django migration linter removed from the dev dependencies

* Added django-migration-linter to dev.py

* Migration linter being added only in dev

* Lint errors fixed

* CI updated

* CI lint migration test

* env changed

* Test command removed

* CI changes reverted and MIGRATION_LINTER_OPTIONS moved to dev.py

* Update ci.yml

* Rename script

* Change lint-migrations command, delete script, fix documents error

* Document migration fixes and readme update

* Move CODEOWNER file location (#53)

* UAT fixes (#56)

* Fix cookiebanner settings link URL variable name (CMS-265)
* Make the contact details name + email unique (CMS-225)
  * Add test for the unique constraint
  * Update contact details listings to include email/phone
* Bump deps. Mainly Django 5.1.4
# Conflicts:
#	poetry.lock

* Documents migrations re-add

* Add noop for reverse migrations (create homepage/release calendar index)

* ci updated to run the migration linter as part of the test python job

* Fix documents

* Migrations files ignored

* Update poetry.lock

* Delete .docker/bashrc.sh

* Add .docker/bashrc.sh

* File permision change

---------

Co-authored-by: nehakerung <[email protected]>
Co-authored-by: Neha <[email protected]>
Co-authored-by: Mebin Abraham <[email protected]>
Co-authored-by: Dan Braghiș <[email protected]>
Co-authored-by: Dan Braghiș <[email protected]>
  • Loading branch information
6 people authored Jan 14, 2025
1 parent 69d21e3 commit 0ecb45c
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 150 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ jobs:
with:
name: html-report
path: htmlcov
- name: Lint Migrations
run: DJANGO_SETTINGS_MODULE=cms.settings.dev make lint-migrations

docker:
runs-on: ubuntu-latest
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ format-frontend: ## Format front-end files (CSS, JS, YAML, MD)
npm run format

.PHONY: lint
lint: lint-py lint-html lint-frontend ## Run all linters (python, html, front-end)
lint: lint-py lint-html lint-frontend lint-migrations ## Run all linters (python, html, front-end, migrations)

.PHONY: lint-py
lint-py: ## Run all Python linters (ruff/pylint/mypy).
Expand All @@ -50,6 +50,10 @@ lint-html: ## Run HTML Linters
lint-frontend: ## Run front-end linters
npm run lint

.PHONY: lint-migrations
lint-migrations: ## Run django-migration-linter
poetry run python manage.py lintmigrations --quiet ignore ok

.PHONY: test
test: ## Run the tests and check coverage.
poetry run coverage erase
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,18 @@ To lint the Python code, run:
make lint
```

#### Django Migration Linter

[Django Migration Linter](https://github.com/3YOURMIND/django-migration-linter) for linting migrations files in the project.

To lint the django migration files:

```bash
make lint-migrations
```

#### Format

To auto-format the Python code, and correct fixable linting issues, run:

```bash
Expand Down
2 changes: 1 addition & 1 deletion cms/home/migrations/0002_create_homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ class Migration(migrations.Migration):

dependencies = [("home", "0001_initial")]

operations = [migrations.RunPython(create_homepage)]
operations = [migrations.RunPython(create_homepage, migrations.RunPython.noop)]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def create_index_page(apps, schema_editor):
# Get models
ContentType = apps.get_model("contenttypes.ContentType")
IndexPage = apps.get_model("release_calendar", "ReleaseCalendarIndex")
ReleaseCalendarIndex = apps.get_model("release_calendar", "ReleaseCalendarIndex")
Page = apps.get_model("wagtailcore.Page")
Locale = apps.get_model("wagtailcore.Locale")

Expand All @@ -18,7 +18,7 @@ def create_index_page(apps, schema_editor):
now = timezone.now()

# Create a new page
IndexPage.objects.create(
ReleaseCalendarIndex.objects.create(
title="Release calendar",
draft_title="Release calendar",
live=True,
Expand All @@ -43,5 +43,5 @@ class Migration(migrations.Migration):
]

operations = [
migrations.RunPython(create_index_page),
migrations.RunPython(create_index_page, migrations.RunPython.noop),
]
22 changes: 21 additions & 1 deletion cms/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Enable Wagtail's style guide in Wagtail's settings menu.
# http://docs.wagtail.io/en/stable/contributing/styleguide.html
INSTALLED_APPS += ["wagtail.contrib.styleguide"] # noqa: F405

INSTALLED_APPS += ["django_migration_linter"]

# Disable forcing HTTPS locally since development server supports HTTP only.
SECURE_SSL_REDIRECT = False
Expand Down Expand Up @@ -57,3 +57,23 @@
except ImportError:
pass
# pylint: enable=unused-wildcard-import,useless-suppression

MIGRATION_LINTER_OPTIONS = {
"exclude_apps": [
"taggit",
"wagtailcore",
"wagtailembeds",
"wagtailimages",
"wagtailadmin",
"wagtailsearch",
"wagtaildocs",
"wagtailredirects",
"wagtailusers",
],
"ignore_name": [
"0002_alter_customdocument_file_size",
"0004_contactdetails_core_contactdetails_name_unique",
"0003_delete_tracking",
"0002_customimage_description",
],
}
Loading

0 comments on commit 0ecb45c

Please sign in to comment.