@@ -2,15 +2,15 @@ name: Django + Supabase CI/CD Pipeline
22
33on :
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
1616permissions :
@@ -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
0 commit comments