From 5d8a103d72dfec39a973fa1645ea6198f923c03a Mon Sep 17 00:00:00 2001 From: Restioson Date: Tue, 5 Nov 2024 12:02:20 +0200 Subject: [PATCH 1/7] chore(makefile): allow running specific module tests This is done by a variable that can be passed on the command line, e.g. `make test module=general.tests.test_document_admin` --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9e73fd8..6af098a 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ create-schema: @docker compose run --rm web python manage.py graph_models -a -o schema/schema.png test: - @docker compose run --rm web python manage.py test + @docker compose run --rm web python manage.py test $(module) ruff-check: @docker compose run --rm web ruff check . From 566a1164a3976511d2cd706e4343d16322d9d5e4 Mon Sep 17 00:00:00 2001 From: Restioson Date: Tue, 5 Nov 2024 12:04:02 +0200 Subject: [PATCH 2/7] docs(dev): add notes to developers Describe some common commands and patterns to ease development of LwimiLinks --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 8c3971a..959006d 100644 --- a/README.md +++ b/README.md @@ -97,3 +97,17 @@ Docker Volumes for production: .env file * EMAIL_BACKEND_CONSOLE=False + +## Notes to Developers + +- When setting up the app (from scratch or from a wipe), the following commands should be run: + - (Optional) `make build` + - `make up` - wait for the database to start, then hit Control-C + - `make migrate` + - `make up` - runs the app +- To wipe the database, use `make down` +- The Django admin interface is at `/admin/` + - An admin user can be created through `make create-super-user` +- To run a single module of tests, you can pass the Makefile `module` variable on the command line. For instance, to run + only tests defined in [`test_document_admin.py`](./app/general/tests/test_document_admin.py), run + `make test module=general.tests.test_document_admin` \ No newline at end of file From 56032ea0afe7d260e92d07835b5ba03566a7ebba Mon Sep 17 00:00:00 2001 From: Restioson Date: Tue, 5 Nov 2024 12:46:19 +0200 Subject: [PATCH 3/7] chore(makefile): designate all targets as phony This prevents them from breaking if we ever accidentally create files with their names in the root directory of the project (and is also just good practice). See https://www.gnu.org/software/make/manual/html_node/Special-Targets.html for more --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 6af098a..a1531ac 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,8 @@ +.PHONY: list up upd build stop down restart make-migrations migrate collectstatic shell logs create-super-user \ + docker-stop-all create-schema test ruff-check ruff-fix ruff-format load-fixtures pre-commit-install \ + dev-import-documents dev-quick-install lighthouse dev_update_vector_search docker-shell check make-messages \ + compile-messages + list: @echo "Available commands:" @echo "up - Start the project" From 1d3bb85d1ac09f9d190d65ed624801dbc0d328a4 Mon Sep 17 00:00:00 2001 From: Restioson Date: Tue, 5 Nov 2024 12:46:55 +0200 Subject: [PATCH 4/7] chore(makefile): add fmt & lint aliases for ruff-format These are very commonly used command verbs, so they are nice to as shortcuts, especially for people getting used to the project --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a1531ac..b4aa8e6 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: list up upd build stop down restart make-migrations migrate collectstatic shell logs create-super-user \ docker-stop-all create-schema test ruff-check ruff-fix ruff-format load-fixtures pre-commit-install \ dev-import-documents dev-quick-install lighthouse dev_update_vector_search docker-shell check make-messages \ - compile-messages + compile-messages fmt lint list: @echo "Available commands:" @@ -80,9 +80,13 @@ test: ruff-check: @docker compose run --rm web ruff check . +lint: ruff-check + ruff-format: @docker compose run --rm web ruff format . +fmt: ruff-format + ruff-fix: @docker compose run --rm web ruff check --fix . From 288d416f7d9d3485befb9c6eb6b6c24bbd7cc335 Mon Sep 17 00:00:00 2001 From: Restioson Date: Tue, 5 Nov 2024 12:50:18 +0200 Subject: [PATCH 5/7] chore(lint): fix import order (lint error) --- app/general/tests/test_frontend.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/general/tests/test_frontend.py b/app/general/tests/test_frontend.py index e7df8d0..97779cd 100644 --- a/app/general/tests/test_frontend.py +++ b/app/general/tests/test_frontend.py @@ -1,10 +1,9 @@ from django.contrib.staticfiles.testing import StaticLiveServerTestCase from selenium.common import TimeoutException -from selenium.webdriver.chrome.webdriver import WebDriver, Options +from selenium.webdriver.chrome.webdriver import Options, WebDriver from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait - # Wait timeout in seconds WAIT_TIMEOUT = 5 From c18592bb56782ee9c50a54c9abe8fe219fe07a28 Mon Sep 17 00:00:00 2001 From: Restioson Date: Tue, 5 Nov 2024 12:53:49 +0200 Subject: [PATCH 6/7] fix(ci): run linter in CI We were not actually running the linter in CI (despite the name of the job saying so) --- .github/workflows/testing.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 79106b6..c9a9070 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -34,7 +34,8 @@ jobs: - name: Run linting tools run: | cd app/ - ruff format . + ruff format --diff . + ruff check --diff . - name: Create logging folder run: | sudo mkdir -p /logging From e07ccb8a702a2043d0108ad95956f54ff1565500 Mon Sep 17 00:00:00 2001 From: Restioson Date: Tue, 5 Nov 2024 13:21:51 +0200 Subject: [PATCH 7/7] fix(ci): set persist-credentials to false This was a linting failure from [zizmor](https://blog.yossarian.net/2024/10/27/Now-you-can-have-beautiful-clean-workflows). See https://github.com/actions/checkout/issues/485 for more info on why this is a potential security issue. --- .github/workflows/develop.yml | 2 ++ .github/workflows/production.yml | 2 ++ .github/workflows/testing.yml | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 62347b9..2c297fc 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -13,6 +13,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + persist-credentials: false - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to SADiLaR Container Registry diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index c8383e1..59c5d72 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -12,6 +12,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + persist-credentials: false - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to SADiLaR Container Registry diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index c9a9070..9590f0b 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -23,6 +23,8 @@ jobs: options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - uses: actions/checkout@v4 + with: + persist-credentials: false - uses: actions/setup-python@v5 with: python-version: 3.12 @@ -80,6 +82,8 @@ jobs: options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - uses: actions/checkout@v4 + with: + persist-credentials: false - uses: actions/setup-python@v5 with: python-version: 3.12 @@ -126,6 +130,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 + persist-credentials: false - name: Get all commits on current main run: git fetch origin main - name: Log all commits we will analyse