From 971b58ccb097f9cfd5d5eb3c4bae5c59149c8f44 Mon Sep 17 00:00:00 2001 From: Mikhail Epifanov Date: Mon, 29 Jan 2024 09:48:19 +0100 Subject: [PATCH 1/5] add caching and test export --- .github/workflows/ci.yml | 83 ++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d699a5641..cb72bc0c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,31 +10,80 @@ jobs: max-parallel: 4 matrix: python-version: ['3.10'] + node-version: ['18'] steps: - uses: actions/checkout@v3 - - name: Set up Python 3.10 + - uses: awalsh128/cache-apt-pkgs-action@v1.3.1 + with: + packages: libsasl2-dev python3-dev libldap2-dev libssl-dev + version: 1.0 + + # Setup python & dependencies + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: - python-version: '3.10' - # Build Vue frontend - - uses: actions/setup-node@v3 - with: - node-version: '18' - - name: Install Vue dependencies - working-directory: ./vue - run: yarn install - - name: Build Vue dependencies - working-directory: ./vue - run: yarn build - - name: Install Django dependencies + python-version: ${{ matrix.python-version }} + cache: 'pip' + + - name: Install Python Dependencies run: | - sudo apt-get -y update - sudo apt-get install -y libsasl2-dev python3-dev libldap2-dev libssl-dev python -m pip install --upgrade pip pip install -r requirements.txt + + - name: Cache StaticFiles + uses: actions/cache@v3 + id: django_cache + with: + path: | + ./cookbook/static + ./vue/webpack-stats.json + ./staticfiles + key: | + ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.node-version }}-collectstatic-${{ hashFiles('**/*.css', '**/*.js', 'vue/src/*') }} + + # Build Vue frontend & Dependencies + - name: Set up Node ${{ matrix.node-version }} + if: steps.django_cache.outputs.cache-hit != 'true' + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'yarn' + cache-dependency-path: ./vue/yarn.lock + + - name: Install Vue dependencies + if: steps.django_cache.outputs.cache-hit != 'true' + working-directory: ./vue + run: yarn install + + - name: Build Vue dependencies + if: steps.django_cache.outputs.cache-hit != 'true' + working-directory: ./vue + run: yarn build + + - name: Compile Django StatisFiles + if: steps.django_cache.outputs.cache-hit != 'true' + run: | python3 manage.py collectstatic --noinput python3 manage.py collectstatic_js_reverse + + - uses: actions/cache/save@v3 + if: steps.django_cache.outputs.cache-hit != 'true' + with: + path: | + ./cookbook/static + ./vue/webpack-stats.json + ./staticfiles + key: | + ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.node-version }}-collectstatic-${{ hashFiles('**/*.css', '**/*.js', 'vue/src/*') }} + - name: Django Testing project - run: | - pytest + run: pytest --junitxml=junit/test-results-${{ matrix.python-version }}.xml + + - name: Publish Test Results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + comment_mode: off + files: | + junit/test-results-${{ matrix.python-version }}.xml From ce0ee8caaa34575127b2e4fa728f2c3514af954e Mon Sep 17 00:00:00 2001 From: software2000 Date: Sun, 4 Feb 2024 22:32:03 +0100 Subject: [PATCH 2/5] update postgres in documentation to version 16 --- docs/install/docker/ipv6_plain/docker-compose.yml | 2 +- docs/install/docker/nginx-proxy/docker-compose.yml | 2 +- docs/install/docker/plain/docker-compose.yml | 2 +- docs/install/docker/traefik-nginx/docker-compose.yml | 2 +- docs/install/swag.md | 2 +- docs/install/truenas_portainer.md | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/install/docker/ipv6_plain/docker-compose.yml b/docs/install/docker/ipv6_plain/docker-compose.yml index 312b14000..e989fc09c 100644 --- a/docs/install/docker/ipv6_plain/docker-compose.yml +++ b/docs/install/docker/ipv6_plain/docker-compose.yml @@ -2,7 +2,7 @@ version: "2.4" services: db_recipes: restart: always - image: postgres:15-alpine + image: postgres:16-alpine volumes: - ${POSTGRES_DATA_DIR:-./postgresql}:/var/lib/postgresql/data env_file: diff --git a/docs/install/docker/nginx-proxy/docker-compose.yml b/docs/install/docker/nginx-proxy/docker-compose.yml index 7040c566b..2e408646d 100644 --- a/docs/install/docker/nginx-proxy/docker-compose.yml +++ b/docs/install/docker/nginx-proxy/docker-compose.yml @@ -2,7 +2,7 @@ version: "3" services: db_recipes: restart: always - image: postgres:15-alpine + image: postgres:16-alpine volumes: - ./postgresql:/var/lib/postgresql/data env_file: diff --git a/docs/install/docker/plain/docker-compose.yml b/docs/install/docker/plain/docker-compose.yml index 203217e40..089e72c56 100644 --- a/docs/install/docker/plain/docker-compose.yml +++ b/docs/install/docker/plain/docker-compose.yml @@ -2,7 +2,7 @@ version: "3" services: db_recipes: restart: always - image: postgres:15-alpine + image: postgres:16-alpine volumes: - ./postgresql:/var/lib/postgresql/data env_file: diff --git a/docs/install/docker/traefik-nginx/docker-compose.yml b/docs/install/docker/traefik-nginx/docker-compose.yml index 9947c3a80..afe2fbfb7 100644 --- a/docs/install/docker/traefik-nginx/docker-compose.yml +++ b/docs/install/docker/traefik-nginx/docker-compose.yml @@ -2,7 +2,7 @@ version: "3" services: db_recipes: restart: always - image: postgres:15-alpine + image: postgres:16-alpine volumes: - ./postgresql:/var/lib/postgresql/data env_file: diff --git a/docs/install/swag.md b/docs/install/swag.md index 3f1eda6a1..15b2b9b65 100644 --- a/docs/install/swag.md +++ b/docs/install/swag.md @@ -69,7 +69,7 @@ services: db_recipes: restart: always container_name: db_recipes - image: postgres:15-alpine + image: postgres:16-alpine volumes: - ./recipes/db:/var/lib/postgresql/data env_file: diff --git a/docs/install/truenas_portainer.md b/docs/install/truenas_portainer.md index 7be57bf2a..436fc5952 100644 --- a/docs/install/truenas_portainer.md +++ b/docs/install/truenas_portainer.md @@ -81,7 +81,7 @@ version: "3" services: db_recipes: restart: always - image: postgres:15-alpine + image: postgres:16-alpine volumes: - ./postgresql:/var/lib/postgresql/data env_file: From 7e39e6fea5bdfd0f6511cab02672a742783bcc73 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Mon, 5 Feb 2024 13:52:52 +0100 Subject: [PATCH 3/5] fixed meal type constraint --- cookbook/admin.py | 4 ++-- cookbook/serializer.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cookbook/admin.py b/cookbook/admin.py index 823246283..fc148afe5 100644 --- a/cookbook/admin.py +++ b/cookbook/admin.py @@ -315,8 +315,8 @@ admin.site.register(MealPlan, MealPlanAdmin) class MealTypeAdmin(admin.ModelAdmin): - list_display = ('name', 'created_by', 'order') - search_fields = ('name', 'created_by__username') + list_display = ('name', 'space', 'created_by', 'order') + search_fields = ('name', 'space', 'created_by__username') admin.site.register(MealType, MealTypeAdmin) diff --git a/cookbook/serializer.py b/cookbook/serializer.py index 09e571032..df8aff885 100644 --- a/cookbook/serializer.py +++ b/cookbook/serializer.py @@ -348,7 +348,7 @@ class MealTypeSerializer(SpacedModelSerializer, WritableNestedModelSerializer): validated_data['name'] = validated_data['name'].strip() space = validated_data.pop('space', self.context['request'].space) validated_data['created_by'] = self.context['request'].user - obj, created = MealType.objects.get_or_create(name__iexact=validated_data['name'], space=space, defaults=validated_data) + obj, created = MealType.objects.get_or_create(name__iexact=validated_data['name'], space=space, created_by=self.context['request'].user, defaults=validated_data) return obj class Meta: From febf3a3d86edbe99541a379b8ad8a35404964292 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Mon, 5 Feb 2024 14:05:11 +0100 Subject: [PATCH 4/5] removed flawed duplicate detection --- ...tytype_options_remove_keyword_icon_and_more.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/cookbook/migrations/0200_alter_propertytype_options_remove_keyword_icon_and_more.py b/cookbook/migrations/0200_alter_propertytype_options_remove_keyword_icon_and_more.py index a57ad9773..f67a41884 100644 --- a/cookbook/migrations/0200_alter_propertytype_options_remove_keyword_icon_and_more.py +++ b/cookbook/migrations/0200_alter_propertytype_options_remove_keyword_icon_and_more.py @@ -13,24 +13,9 @@ def migrate_icons(apps, schema_editor): PropertyType = apps.get_model('cookbook', 'PropertyType') RecipeBook = apps.get_model('cookbook', 'RecipeBook') - duplicate_meal_types = MealType.objects.values('name').annotate(name_count=Count('name')).exclude(name_count=1).all() - if len(duplicate_meal_types) > 0: - raise RuntimeError(f'Duplicate MealTypes found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}') MealType.objects.update(name=Concat(F('icon'), Value(' '), F('name'))) - - duplicate_meal_types = Keyword.objects.values('name').annotate(name_count=Count('name')).exclude(name_count=1).all() - if len(duplicate_meal_types) > 0: - raise RuntimeError(f'Duplicate Keyword found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}') Keyword.objects.update(name=Concat(F('icon'), Value(' '), F('name'))) - - duplicate_meal_types = PropertyType.objects.values('name').annotate(name_count=Count('name')).exclude(name_count=1).all() - if len(duplicate_meal_types) > 0: - raise RuntimeError(f'Duplicate PropertyType found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}') PropertyType.objects.update(name=Concat(F('icon'), Value(' '), F('name'))) - - duplicate_meal_types = RecipeBook.objects.values('name').annotate(name_count=Count('name')).exclude(name_count=1).all() - if len(duplicate_meal_types) > 0: - raise RuntimeError(f'Duplicate RecipeBook found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}') RecipeBook.objects.update(name=Concat(F('icon'), Value(' '), F('name'))) From 36c0fbffbeebb940c8bcabcb1bf7f663e07e57bb Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Mon, 5 Feb 2024 14:52:40 +0100 Subject: [PATCH 5/5] fixed duplicate detection in migration 0200 --- .../management/commands/seed_basic_data.py | 25 +++++++++++++++++++ ...pe_options_remove_keyword_icon_and_more.py | 17 ++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 cookbook/management/commands/seed_basic_data.py diff --git a/cookbook/management/commands/seed_basic_data.py b/cookbook/management/commands/seed_basic_data.py new file mode 100644 index 000000000..25e5ef98f --- /dev/null +++ b/cookbook/management/commands/seed_basic_data.py @@ -0,0 +1,25 @@ +from django.conf import settings +from django.contrib.auth.models import User +from django.contrib.postgres.search import SearchVector +from django.core.management.base import BaseCommand +from django.utils import translation +from django.utils.translation import gettext_lazy as _ +from django_scopes import scopes_disabled + +from cookbook.managers import DICTIONARY +from cookbook.models import Recipe, Step, Space + + +class Command(BaseCommand): + help = 'Seeds some basic data (space, account, food)' + + def handle(self, *args, **options): + with scopes_disabled(): + user = User.objects.get_or_create(username='test')[0] + user.set_password('test') + user.save() + + space = Space.objects.get_or_create( + name='Test Space', + created_by=user + )[0] diff --git a/cookbook/migrations/0200_alter_propertytype_options_remove_keyword_icon_and_more.py b/cookbook/migrations/0200_alter_propertytype_options_remove_keyword_icon_and_more.py index f67a41884..03f7aa6d6 100644 --- a/cookbook/migrations/0200_alter_propertytype_options_remove_keyword_icon_and_more.py +++ b/cookbook/migrations/0200_alter_propertytype_options_remove_keyword_icon_and_more.py @@ -13,9 +13,24 @@ def migrate_icons(apps, schema_editor): PropertyType = apps.get_model('cookbook', 'PropertyType') RecipeBook = apps.get_model('cookbook', 'RecipeBook') + duplicate_meal_types = MealType.objects.values('space_id', 'name').annotate(name_count=Count('name')).exclude(name_count=1).all() + if len(duplicate_meal_types) > 0: + raise RuntimeError(f'Duplicate MealTypes found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}') MealType.objects.update(name=Concat(F('icon'), Value(' '), F('name'))) + + duplicate_meal_types = Keyword.objects.values('space_id', 'name').annotate(name_count=Count('name')).exclude(name_count=1).all() + if len(duplicate_meal_types) > 0: + raise RuntimeError(f'Duplicate Keyword found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}') Keyword.objects.update(name=Concat(F('icon'), Value(' '), F('name'))) + + duplicate_meal_types = PropertyType.objects.values('space_id', 'name').annotate(name_count=Count('name')).exclude(name_count=1).all() + if len(duplicate_meal_types) > 0: + raise RuntimeError(f'Duplicate PropertyType found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}') PropertyType.objects.update(name=Concat(F('icon'), Value(' '), F('name'))) + + duplicate_meal_types = RecipeBook.objects.values('space_id', 'name').annotate(name_count=Count('name')).exclude(name_count=1).all() + if len(duplicate_meal_types) > 0: + raise RuntimeError(f'Duplicate RecipeBook found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}') RecipeBook.objects.update(name=Concat(F('icon'), Value(' '), F('name'))) @@ -25,7 +40,7 @@ class Migration(migrations.Migration): ] operations = [ - migrations.RunPython( migrate_icons), + migrations.RunPython(migrate_icons), migrations.AlterModelOptions( name='propertytype', options={'ordering': ('order',)},