From 84f13dd7920e71a29076ba03058ab4de7d9e3e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20I=C3=9Fbr=C3=BCcker?= Date: Sun, 21 May 2023 14:32:24 +0200 Subject: [PATCH] Reorganize scripts and E2E tests --- .dockerignore | 1 + .github/workflows/main.yaml | 2 +- .grenrc.js | 6 --- ...mark_form.py => e2e_test_bookmark_form.py} | 0 ...mark_list.py => e2e_test_bookmark_list.py} | 0 ...rtcuts.py => e2e_test_global_shortcuts.py} | 0 build-static.sh | 7 --- build-docker.sh => scripts/build-docker.sh | 0 coverage.sh => scripts/coverage.sh | 0 scripts/generate-changelog.py | 49 +++++++++++++++++++ scripts/run-docker.sh | 10 ++++ scripts/test-e2e.sh | 14 ++++++ scripts/test-postgres.sh | 29 +++++++++++ scripts/test-unit.sh | 1 + scripts/test.sh | 2 + 15 files changed, 107 insertions(+), 14 deletions(-) delete mode 100644 .grenrc.js rename bookmarks/e2e/{test_bookmark_form.py => e2e_test_bookmark_form.py} (100%) rename bookmarks/e2e/{test_bookmark_list.py => e2e_test_bookmark_list.py} (100%) rename bookmarks/e2e/{test_global_shortcuts.py => e2e_test_global_shortcuts.py} (100%) delete mode 100755 build-static.sh rename build-docker.sh => scripts/build-docker.sh (100%) rename coverage.sh => scripts/coverage.sh (100%) create mode 100755 scripts/generate-changelog.py create mode 100755 scripts/run-docker.sh create mode 100755 scripts/test-e2e.sh create mode 100755 scripts/test-postgres.sh create mode 100755 scripts/test-unit.sh create mode 100755 scripts/test.sh diff --git a/.dockerignore b/.dockerignore index a658cdf..123097d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,6 +6,7 @@ /tmp /docs /static +/scripts /build /out /.git diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index d80fc61..d7d48b9 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -44,4 +44,4 @@ jobs: python manage.py compilescss python manage.py collectstatic --ignore=*.scss - name: Run tests - run: python manage.py test bookmarks.e2e + run: python manage.py test bookmarks.e2e --pattern="e2e_test_*.py" diff --git a/.grenrc.js b/.grenrc.js deleted file mode 100644 index 12784d4..0000000 --- a/.grenrc.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - ignoreIssuesWith: [ - "wontfix", - "duplicate" - ] -} \ No newline at end of file diff --git a/bookmarks/e2e/test_bookmark_form.py b/bookmarks/e2e/e2e_test_bookmark_form.py similarity index 100% rename from bookmarks/e2e/test_bookmark_form.py rename to bookmarks/e2e/e2e_test_bookmark_form.py diff --git a/bookmarks/e2e/test_bookmark_list.py b/bookmarks/e2e/e2e_test_bookmark_list.py similarity index 100% rename from bookmarks/e2e/test_bookmark_list.py rename to bookmarks/e2e/e2e_test_bookmark_list.py diff --git a/bookmarks/e2e/test_global_shortcuts.py b/bookmarks/e2e/e2e_test_global_shortcuts.py similarity index 100% rename from bookmarks/e2e/test_global_shortcuts.py rename to bookmarks/e2e/e2e_test_global_shortcuts.py diff --git a/build-static.sh b/build-static.sh deleted file mode 100755 index a1f5570..0000000 --- a/build-static.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -rm -rf static -npm run build -python manage.py compilescss -python manage.py collectstatic --ignore=*.scss -python manage.py compilescss --delete-files diff --git a/build-docker.sh b/scripts/build-docker.sh similarity index 100% rename from build-docker.sh rename to scripts/build-docker.sh diff --git a/coverage.sh b/scripts/coverage.sh similarity index 100% rename from coverage.sh rename to scripts/coverage.sh diff --git a/scripts/generate-changelog.py b/scripts/generate-changelog.py new file mode 100755 index 0000000..3977f8f --- /dev/null +++ b/scripts/generate-changelog.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +import requests +from datetime import datetime + + +def load_releases_page(page): + url = f'https://api.github.com/repos/sissbruecker/linkding/releases?page={page}' + return requests.get(url).json() + + +def load_all_releases(): + load_next_page = True + page = 1 + releases = [] + + while load_next_page: + page_result = load_releases_page(page) + releases = releases + page_result + load_next_page = len(page_result) > 0 + page = page + 1 + + return releases + + +def render_release_section(release): + date = datetime.fromisoformat(release['published_at'].replace("Z", "+00:00")) + formatted_date = date.strftime('%d/%m/%Y') + section = f'## {release["name"]} ({formatted_date})\n\n' + body = release['body'] + # increase heading for body content + body = body.replace("## What's Changed", "### What's Changed") + body = body.replace("## New Contributors", "### New Contributors") + section += body.strip() + return section + + +def generate_change_log(): + releases = load_all_releases() + + change_log = '# Changelog\n\n' + sections = [render_release_section(release) for release in releases] + body = '\n\n---\n\n'.join(sections) + change_log = change_log + body + + with open("CHANGELOG.md", "w") as file: + file.write(change_log) + + +generate_change_log() diff --git a/scripts/run-docker.sh b/scripts/run-docker.sh new file mode 100755 index 0000000..936dc83 --- /dev/null +++ b/scripts/run-docker.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +docker build -t sissbruecker/linkding:local . + +docker rm -f linkding-local || true + +docker run --name linkding-local --rm -p 9090:9090 \ + -e LD_SUPERUSER_NAME=admin \ + -e LD_SUPERUSER_PASSWORD=admin \ + sissbruecker/linkding:local diff --git a/scripts/test-e2e.sh b/scripts/test-e2e.sh new file mode 100755 index 0000000..76f4385 --- /dev/null +++ b/scripts/test-e2e.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# Make sure Chromium is installed +playwright install chromium + +# Test server loads assets from static folder, so make sure files there are up-to-date +rm -rf static +npm run build +python manage.py compilescss +python manage.py collectstatic --ignore=*.scss +python manage.py compilescss --delete-files + +# Run E2E tests +python manage.py test bookmarks.e2e --pattern="e2e_test_*.py" diff --git a/scripts/test-postgres.sh b/scripts/test-postgres.sh new file mode 100755 index 0000000..660c43c --- /dev/null +++ b/scripts/test-postgres.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -euo pipefail + +# Remove previous container if exists +docker rm -f linkding-postgres-test || true + +# Run postgres container +docker run -d \ + -e POSTGRES_DB=linkding \ + -e POSTGRES_USER=linkding \ + -e POSTGRES_PASSWORD=linkding \ + -p 5432:5432 \ + --name linkding-postgres-test \ + postgres + +# Wait until postgres has started +echo >&2 "$(date +%Y%m%dt%H%M%S) Waiting for postgres container" +sleep 15 + +# Run tests using postgres +export LD_DB_ENGINE=postgres +export LD_DB_USER=linkding +export LD_DB_PASSWORD=linkding + +./scripts/test.sh + +# Remove postgres container +docker rm -f linkding-postgres-test || true diff --git a/scripts/test-unit.sh b/scripts/test-unit.sh new file mode 100755 index 0000000..3e085e8 --- /dev/null +++ b/scripts/test-unit.sh @@ -0,0 +1 @@ +python manage.py test bookmarks.tests diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..4750ce5 --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,2 @@ +./scripts/test-unit.sh +./scripts/test-e2e.sh