From 190bf833b4dd38f5c192a73828f2bd87ea78dbd3 Mon Sep 17 00:00:00 2001 From: Iuri de Silvio Date: Wed, 7 Feb 2024 18:48:19 -0300 Subject: [PATCH] Run example without S3 when there is no secrets on CI (#52) --- .github/workflows/example-test.yml | 41 ++++++++++++++---------------- example/example/settings.py | 8 +----- example/pytest.ini | 3 +++ example/requirements.txt | 5 +++- 4 files changed, 27 insertions(+), 30 deletions(-) create mode 100644 example/pytest.ini diff --git a/.github/workflows/example-test.yml b/.github/workflows/example-test.yml index 15fd567..36642e9 100644 --- a/.github/workflows/example-test.yml +++ b/.github/workflows/example-test.yml @@ -6,6 +6,13 @@ name: Example test on: push: branches: [ "main" ] + pull_request: + branches: [ "main" ] + +defaults: + run: + shell: bash + working-directory: ./example jobs: build: @@ -14,18 +21,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.10", "3.11"] - - services: - postgres: - image: postgres - env: - POSTGRES_PASSWORD: postgres - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 @@ -37,16 +33,17 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - python -m pip install -r example/requirements.txt - python -m pip install . - - name: Migrate database + python -m pip install -r requirements.txt + python -m pip install .. + - name: Django migrate run: | - cd example - ./manage.py migrateci -v3 --parallel $(nproc) - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_S3_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }} + ./manage.py migrateci -v3 --parallel 2 + - name: Django migrate again to reuse cache + run: | + ./manage.py migrateci -v3 --parallel 2 - name: Test with Django run: | - cd example - ./manage.py test --keepdb + ./manage.py test -v3 --keepdb + - name: Test with pytest-django + run: | + pytest -vvv --migrateci --reuse-db -n 2 diff --git a/example/example/settings.py b/example/example/settings.py index 0788a5d..a239b91 100644 --- a/example/example/settings.py +++ b/example/example/settings.py @@ -1,3 +1,4 @@ +import os from pathlib import Path # Build paths inside the project like this: BASE_DIR / "subdir". @@ -25,10 +26,3 @@ }, } } - -# AWS credentials (AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY) are defined -# in .github/workflows/example-test.yml as environment variables. -AWS_STORAGE_BUCKET_NAME = "example-migrateci-cache" -AWS_S3_REGION_NAME = "us-east-2" - -MIGRATECI_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" diff --git a/example/pytest.ini b/example/pytest.ini new file mode 100644 index 0000000..d2696bb --- /dev/null +++ b/example/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +DJANGO_SETTINGS_MODULE=example.settings +python_files = tests.py diff --git a/example/requirements.txt b/example/requirements.txt index 84fcd1b..6f67ddf 100644 --- a/example/requirements.txt +++ b/example/requirements.txt @@ -1,2 +1,5 @@ django -django-storages[boto3] +django-storages +pytest +pytest-django<4.7 +pytest-xdist