Skip to content

Commit 1f9b087

Browse files
committed
Fix CI pipeline: add pytest-asyncio and fix deploy path variable
1 parent a191cd5 commit 1f9b087

File tree

7 files changed

+743
-156
lines changed

7 files changed

+743
-156
lines changed

.github/workflows/ci-cd.yml

Lines changed: 149 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: Django + Supabase CI/CD Pipeline
22

33
on:
44
push:
5-
branches: [ main, develop ]
5+
branches: [main, develop]
66
paths-ignore:
7-
- '**.md'
8-
- '_docs/**'
7+
- "**.md"
8+
- "_docs/**"
99
pull_request:
10-
branches: [ main, develop ]
10+
branches: [main, develop]
1111
paths-ignore:
12-
- '**.md'
13-
- '_docs/**'
12+
- "**.md"
13+
- "_docs/**"
1414
workflow_dispatch:
1515

1616
permissions:
@@ -23,44 +23,44 @@ jobs:
2323
runs-on: ubuntu-latest
2424
continue-on-error: true
2525
steps:
26-
- uses: actions/checkout@v3
27-
28-
- name: Set up Python
29-
uses: actions/setup-python@v4
30-
with:
31-
python-version: '3.11'
32-
cache: 'pip'
33-
34-
- name: Install dependencies
35-
run: |
36-
python -m pip install --upgrade pip
37-
pip install -r requirements.txt
38-
pip install black flake8 isort mypy
39-
40-
- name: Run linting
41-
run: |
42-
mkdir -p linting_reports
43-
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
44-
# In pull requests, auto-format the code
45-
black backend/
46-
isort --profile black backend/
47-
# Check if any files were changed
48-
if [[ -n "$(git status --porcelain)" ]]; then
49-
git config --local user.email "github-actions[bot]@users.noreply.github.com"
50-
git config --local user.name "github-actions[bot]"
51-
git add .
52-
git commit -m "Apply automatic formatting"
53-
git push
26+
- uses: actions/checkout@v3
27+
28+
- name: Set up Python
29+
uses: actions/setup-python@v4
30+
with:
31+
python-version: "3.11"
32+
cache: "pip"
33+
34+
- name: Install dependencies
35+
run: |
36+
python -m pip install --upgrade pip
37+
pip install -r requirements.txt
38+
pip install black flake8 isort mypy
39+
40+
- name: Run linting
41+
run: |
42+
mkdir -p linting_reports
43+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
44+
# In pull requests, auto-format the code
45+
black backend/
46+
isort --profile black backend/
47+
# Check if any files were changed
48+
if [[ -n "$(git status --porcelain)" ]]; then
49+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
50+
git config --local user.name "github-actions[bot]"
51+
git add .
52+
git commit -m "Apply automatic formatting"
53+
git push
54+
fi
55+
else
56+
# In other events, just check formatting but save output as JSON
57+
black --check --json backend/ > linting_reports/black_report.json || true
58+
isort --check-only --profile black backend/ || true
5459
fi
55-
else
56-
# In other events, just check formatting but save output as JSON
57-
black --check --json backend/ > linting_reports/black_report.json || true
58-
isort --check-only --profile black backend/ || true
59-
fi
60-
# Always run type checking and linting with JSON output where possible
61-
flake8 --format=json backend/ --config=backend/.flake8 > linting_reports/flake8_report.json || true
62-
mypy backend/ --ignore-missing-imports || true
63-
60+
# Always run type checking and linting with JSON output where possible
61+
flake8 --format=json backend/ --config=backend/.flake8 > linting_reports/flake8_report.json || true
62+
mypy backend/ --ignore-missing-imports || true
63+
6464
test:
6565
name: Run Tests
6666
runs-on: ubuntu-latest
@@ -88,116 +88,117 @@ jobs:
8888
--health-interval 10s
8989
--health-timeout 5s
9090
--health-retries 5
91-
91+
9292
steps:
93-
- uses: actions/checkout@v3
94-
95-
- name: Set up Python
96-
uses: actions/setup-python@v4
97-
with:
98-
python-version: '3.11'
99-
cache: 'pip'
100-
101-
- name: Install dependencies
102-
run: |
103-
python -m pip install --upgrade pip
104-
pip install -r requirements.txt
105-
pip install pytest pytest-django pytest-cov factory-boy
106-
107-
- name: Setup Supabase Local Environment
108-
uses: supabase/setup-cli@v1
109-
with:
110-
version: latest
111-
112-
- name: Start Supabase Local Development
113-
run: |
114-
supabase start
115-
env:
116-
SUPABASE_AUTH_EXTERNAL_GITHUB_CLIENT_ID: fake
117-
SUPABASE_AUTH_EXTERNAL_GITHUB_SECRET: fake
118-
119-
- name: Run tests
120-
env:
121-
DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY || 'test_secret_key' }}
122-
DJANGO_DEBUG: "${{ secrets.DJANGO_DEBUG || 'True' }}"
123-
DB_ENGINE: ${{ secrets.DB_ENGINE || 'django.db.backends.postgresql' }}
124-
DB_NAME: ${{ secrets.DB_NAME || 'test_db' }}
125-
DB_USER: ${{ secrets.DB_USER || 'postgres' }}
126-
DB_PASSWORD: ${{ secrets.DB_PASSWORD || 'postgres' }}
127-
DB_HOST: ${{ secrets.DB_HOST || 'localhost' }}
128-
DB_PORT: ${{ secrets.DB_PORT || '5432' }}
129-
SUPABASE_URL: ${{ secrets.SUPABASE_URL || 'http://localhost:54321' }}
130-
SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' }}
131-
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU' }}
132-
SUPABASE_JWT_SECRET: ${{ secrets.SUPABASE_JWT_SECRET || 'your-super-secret-jwt-token-with-at-least-32-characters-long' }}
133-
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD || 'redis_default_password_for_ci' }}
134-
REDIS_DB: ${{ secrets.REDIS_DB || '0' }}
135-
REDIS_PORT: ${{ secrets.REDIS_PORT || '6379' }}
136-
REDIS_URL: "redis://:${{ secrets.REDIS_PASSWORD || 'redis_default_password_for_ci' }}@localhost:${{ secrets.REDIS_PORT || '6379' }}/${{ secrets.REDIS_DB || '0' }}"
137-
run: |
138-
cd backend
139-
pytest --cov=. --cov-report=xml
140-
141-
- name: Upload coverage to Codecov
142-
uses: codecov/codecov-action@v3
143-
with:
144-
file: ./backend/coverage.xml
145-
fail_ci_if_error: false
93+
- uses: actions/checkout@v3
94+
95+
- name: Set up Python
96+
uses: actions/setup-python@v4
97+
with:
98+
python-version: "3.11"
99+
cache: "pip"
100+
101+
- name: Install dependencies
102+
run: |
103+
python -m pip install --upgrade pip
104+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
105+
# Install additional testing dependencies
106+
pip install pytest pytest-django pytest-cov pytest-asyncio
107+
108+
- name: Setup Supabase Local Environment
109+
uses: supabase/setup-cli@v1
110+
with:
111+
version: latest
112+
113+
- name: Start Supabase Local Development
114+
run: |
115+
supabase start
116+
env:
117+
SUPABASE_AUTH_EXTERNAL_GITHUB_CLIENT_ID: fake
118+
SUPABASE_AUTH_EXTERNAL_GITHUB_SECRET: fake
119+
120+
- name: Run tests
121+
env:
122+
DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY || 'test_secret_key' }}
123+
DJANGO_DEBUG: "${{ secrets.DJANGO_DEBUG || 'True' }}"
124+
DB_ENGINE: ${{ secrets.DB_ENGINE || 'django.db.backends.postgresql' }}
125+
DB_NAME: ${{ secrets.DB_NAME || 'test_db' }}
126+
DB_USER: ${{ secrets.DB_USER || 'postgres' }}
127+
DB_PASSWORD: ${{ secrets.DB_PASSWORD || 'postgres' }}
128+
DB_HOST: ${{ secrets.DB_HOST || 'localhost' }}
129+
DB_PORT: ${{ secrets.DB_PORT || '5432' }}
130+
SUPABASE_URL: ${{ secrets.SUPABASE_URL || 'http://localhost:54321' }}
131+
SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' }}
132+
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY || 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU' }}
133+
SUPABASE_JWT_SECRET: ${{ secrets.SUPABASE_JWT_SECRET || 'your-super-secret-jwt-token-with-at-least-32-characters-long' }}
134+
REDIS_PASSWORD: ${{ secrets.REDIS_PASSWORD || 'redis_default_password_for_ci' }}
135+
REDIS_DB: ${{ secrets.REDIS_DB || '0' }}
136+
REDIS_PORT: ${{ secrets.REDIS_PORT || '6379' }}
137+
REDIS_URL: "redis://:${{ secrets.REDIS_PASSWORD || 'redis_default_password_for_ci' }}@localhost:${{ secrets.REDIS_PORT || '6379' }}/${{ secrets.REDIS_DB || '0' }}"
138+
run: |
139+
cd backend
140+
pytest --cov=. --cov-report=xml
141+
142+
- name: Upload coverage to Codecov
143+
uses: codecov/codecov-action@v3
144+
with:
145+
file: ./backend/coverage.xml
146+
fail_ci_if_error: false
146147

147148
build:
148149
name: Build Docker Image
149150
needs: test
150151
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
151152
runs-on: ubuntu-latest
152-
153+
153154
steps:
154-
- uses: actions/checkout@v3
155-
156-
- name: Set up Docker Buildx
157-
uses: docker/setup-buildx-action@v2
158-
159-
- name: Cache Docker layers
160-
uses: actions/cache@v3
161-
with:
162-
path: /tmp/.buildx-cache
163-
key: ${{ runner.os }}-buildx-${{ github.sha }}
164-
restore-keys: |
165-
${{ runner.os }}-buildx-
166-
167-
- name: Login to GitHub Container Registry
168-
uses: docker/login-action@v2
169-
with:
170-
registry: ghcr.io
171-
username: ${{ github.repository_owner }}
172-
password: ${{ secrets.GITHUB_TOKEN }}
173-
174-
- name: Set environment based on branch
175-
id: set-env
176-
run: |
177-
if [[ ${{ github.ref }} == 'refs/heads/main' ]]; then
178-
echo "env=production" >> $GITHUB_OUTPUT
179-
echo "cache_tag=prod" >> $GITHUB_OUTPUT
180-
else
181-
echo "env=staging" >> $GITHUB_OUTPUT
182-
echo "cache_tag=staging" >> $GITHUB_OUTPUT
183-
fi
184-
185-
- name: Build and push Docker image
186-
uses: docker/build-push-action@v4
187-
with:
188-
context: .
189-
file: ./docker/Dockerfile
190-
push: true
191-
tags: |
192-
ghcr.io/${{ github.repository }}:${{ steps.set-env.outputs.env }}
193-
ghcr.io/${{ github.repository }}:${{ github.sha }}
194-
cache-from: type=local,src=/tmp/.buildx-cache
195-
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
196-
build-args: |
197-
ENVIRONMENT=${{ steps.set-env.outputs.env }}
198-
199-
# Temporary fix for caching issue
200-
- name: Move cache
201-
run: |
202-
rm -rf /tmp/.buildx-cache
203-
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
155+
- uses: actions/checkout@v3
156+
157+
- name: Set up Docker Buildx
158+
uses: docker/setup-buildx-action@v2
159+
160+
- name: Cache Docker layers
161+
uses: actions/cache@v3
162+
with:
163+
path: /tmp/.buildx-cache
164+
key: ${{ runner.os }}-buildx-${{ github.sha }}
165+
restore-keys: |
166+
${{ runner.os }}-buildx-
167+
168+
- name: Login to GitHub Container Registry
169+
uses: docker/login-action@v2
170+
with:
171+
registry: ghcr.io
172+
username: ${{ github.repository_owner }}
173+
password: ${{ secrets.GITHUB_TOKEN }}
174+
175+
- name: Set environment based on branch
176+
id: set-env
177+
run: |
178+
if [[ ${{ github.ref }} == 'refs/heads/main' ]]; then
179+
echo "env=production" >> $GITHUB_OUTPUT
180+
echo "cache_tag=prod" >> $GITHUB_OUTPUT
181+
else
182+
echo "env=staging" >> $GITHUB_OUTPUT
183+
echo "cache_tag=staging" >> $GITHUB_OUTPUT
184+
fi
185+
186+
- name: Build and push Docker image
187+
uses: docker/build-push-action@v4
188+
with:
189+
context: .
190+
file: ./docker/Dockerfile
191+
push: true
192+
tags: |
193+
ghcr.io/${{ github.repository }}:${{ steps.set-env.outputs.env }}
194+
ghcr.io/${{ github.repository }}:${{ github.sha }}
195+
cache-from: type=local,src=/tmp/.buildx-cache
196+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
197+
build-args: |
198+
ENVIRONMENT=${{ steps.set-env.outputs.env }}
199+
200+
# Temporary fix for caching issue
201+
- name: Move cache
202+
run: |
203+
rm -rf /tmp/.buildx-cache
204+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

.github/workflows/deploy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ jobs:
182182
username: ${{ secrets.DEPLOY_USER }}
183183
key: ${{ secrets.DEPLOY_SSH_KEY }}
184184
script: |
185-
cd ${{ secrets.DEPLOY_PATH }}
185+
cd ${DEPLOY_PATH:-/var/www/django-supabase}
186186
mkdir -p backups
187187
docker-compose exec -T postgres pg_dump -U postgres -d postgres > backups/backup-$(date +%Y%m%d%H%M%S).sql
188188
@@ -193,7 +193,7 @@ jobs:
193193
username: ${{ secrets.DEPLOY_USER }}
194194
key: ${{ secrets.DEPLOY_SSH_KEY }}
195195
script: |
196-
cd ${{ secrets.DEPLOY_PATH }}
196+
cd ${DEPLOY_PATH:-/var/www/django-supabase}
197197
docker pull ghcr.io/${{ steps.repo-vars.outputs.repo_owner }}/${{ steps.repo-vars.outputs.repo_name }}:${{ steps.set-env.outputs.env }}
198198
docker-compose -f docker-compose.${{ steps.set-env.outputs.env }}.yml up -d
199199
docker image prune -f
@@ -205,7 +205,7 @@ jobs:
205205
username: ${{ secrets.DEPLOY_USER }}
206206
key: ${{ secrets.DEPLOY_SSH_KEY }}
207207
script: |
208-
cd ${{ secrets.DEPLOY_PATH }}
208+
cd ${DEPLOY_PATH:-/var/www/django-supabase}
209209
# Run migrations
210210
docker-compose -f docker-compose.${{ steps.set-env.outputs.env }}.yml exec -T backend python manage.py migrate
211211

.github/workflows/security-scan.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
with:
6767
name: bandit-results
6868
path: reports/bandit-results.json
69-
69+
7070
- name: Upload Bandit HTML Results
7171
uses: actions/upload-artifact@v4
7272
with:
@@ -92,7 +92,7 @@ jobs:
9292
else
9393
echo "✅ No high severity issues found in application code." >> $GITHUB_STEP_SUMMARY
9494
fi
95-
95+
9696
echo "" >> $GITHUB_STEP_SUMMARY
9797
echo "### Safety Dependency Analysis" >> $GITHUB_STEP_SUMMARY
9898
echo "[Download Safety Results](../artifacts/safety-results)" >> $GITHUB_STEP_SUMMARY
@@ -107,7 +107,7 @@ jobs:
107107
else
108108
echo "⚠️ Safety report file not found." >> $GITHUB_STEP_SUMMARY
109109
fi
110-
110+
111111
echo "" >> $GITHUB_STEP_SUMMARY
112112
echo "**Note:** The Safety scan requires an API key to be set as a repository secret named 'SAFETY_API_KEY'." >> $GITHUB_STEP_SUMMARY
113113
echo "Get your API key from https://docs.safetycli.com/api-key" >> $GITHUB_STEP_SUMMARY
@@ -142,14 +142,14 @@ jobs:
142142
with:
143143
name: dependency-check-report
144144
path: reports/dependency-check-report.html
145-
145+
146146
- name: Check for Critical Vulnerabilities
147147
run: |
148148
if grep -q "CVSS Score: [8-9]\|CVSS Score: 10" reports/dependency-check-report.html; then
149149
echo "::warning::Critical vulnerabilities found in dependencies!"
150150
echo "Critical vulnerabilities with CVSS score >= 8.0 found in dependencies!" >> $GITHUB_STEP_SUMMARY
151151
fi
152-
152+
153153
# Add to summary
154154
echo "" >> $GITHUB_STEP_SUMMARY
155155
echo "### OWASP Dependency Check Results" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)