diff --git a/.github/workflows/django-ci.yml b/.github/workflows/django-ci.yml new file mode 100644 index 0000000..8f9a6ed --- /dev/null +++ b/.github/workflows/django-ci.yml @@ -0,0 +1,57 @@ +name: Django CI + +on: + push: + branches: [main, phase-1-ci-validation] + pull_request: + branches: [main] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: django-ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + name: Tests and Django checks + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: pip + cache-dependency-path: requirements.txt + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install -r requirements.txt + + - name: Run Django tests + env: + DJANGO_DEBUG: "False" + DJANGO_SECRET_KEY: ci-only-not-a-production-secret + DJANGO_ALLOWED_HOSTS: localhost,127.0.0.1,testserver + run: python manage.py test + + - name: Run Django system check + env: + DJANGO_DEBUG: "False" + DJANGO_SECRET_KEY: ci-only-not-a-production-secret + DJANGO_ALLOWED_HOSTS: localhost,127.0.0.1,testserver + run: python manage.py check + + - name: Check for missing migrations + env: + DJANGO_DEBUG: "False" + DJANGO_SECRET_KEY: ci-only-not-a-production-secret + DJANGO_ALLOWED_HOSTS: localhost,127.0.0.1,testserver + run: python manage.py makemigrations --check --dry-run diff --git a/README.md b/README.md index 8f98557..fcb1670 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ Open http://127.0.0.1:8000/ and create an account. ## Tests and checks +GitHub Actions runs the test suite, Django system check, and migration consistency check on pull requests to `main` and pushes to `main`. See `.github/workflows/django-ci.yml`. + Run the project's Django tests: ```bash diff --git a/notes/tests.py b/notes/tests.py index 63d6cf9..b17a456 100644 --- a/notes/tests.py +++ b/notes/tests.py @@ -3,7 +3,7 @@ from django.contrib.auth import get_user_model from django.core.management import call_command -from django.test import TestCase +from django.test import TestCase, override_settings from django.urls import reverse from django.utils import timezone @@ -279,6 +279,7 @@ def test_parse_tags(self): self.assertEqual(parse_tags(" Work , #ideas,WORK,, "), ["work", "ideas"]) self.assertEqual(parse_tags(""), []) + @override_settings(DEBUG=False) def test_error_pages_render(self): self.assertEqual(self.client.get("/definitely-missing/").status_code, 404) self.assertContains(self.client.get("/definitely-missing/"), "Note not found", status_code=404) diff --git a/templates/error.html b/templates/error.html new file mode 100644 index 0000000..c511f1f --- /dev/null +++ b/templates/error.html @@ -0,0 +1,29 @@ + + + + + + + + {% block title %}Something went wrong – Ember{% endblock %} + + + +
+
{% block code %}ERROR{% endblock %}
+

{% block heading %}Something went wrong{% endblock %}

+

{% block text %}The page could not be loaded. Please try again.{% endblock %}

+ Back to Ember +
+ +