Skip to content

Commit

Permalink
Run example without S3 when there is no secrets on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
iurisilvio committed Feb 7, 2024
1 parent bc19219 commit a09b2dc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
35 changes: 19 additions & 16 deletions .github/workflows/example-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ name: Example test
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

defaults:
run:
shell: bash
working-directory: ./example

jobs:
build:
Expand All @@ -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
Expand All @@ -37,16 +33,23 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r example/requirements.txt
python -m pip install .
python -m pip install -r requirements.txt
python -m pip install ..
- name: Migrate database
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 }}
- name: Migrate database again to reuse cache
run: |
./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 }}
- name: Test with Django
run: |
cd example
./manage.py test --keepdb
- name: Test with pytest-django
run: |
pytest --migrateci --reuse-db -n $(nproc)
5 changes: 4 additions & 1 deletion example/example/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / "subdir".
Expand Down Expand Up @@ -31,4 +32,6 @@
AWS_STORAGE_BUCKET_NAME = "example-migrateci-cache"
AWS_S3_REGION_NAME = "us-east-2"

MIGRATECI_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
# Use S3 only if github action provided secrets for that.
if os.getenv("AWS_ACCESS_KEY_ID"):
MIGRATECI_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
4 changes: 4 additions & 0 deletions example/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
django
django-storages[boto3]
pytest
pytest-cov
pytest-django
pytest-xdist

0 comments on commit a09b2dc

Please sign in to comment.