1- name : CI/CD Pipeline
2-
3- on :
4- push :
5- branches : [ main, develop ]
6- pull_request :
7- branches : [ main ]
8-
9- env :
10- PYTHON_VERSION : ' 3.11'
11- NODE_VERSION : ' 18'
12-
13- jobs :
14- test-backend :
15- name : Test Backend
16- runs-on : ubuntu-latest
17-
18- services :
19- postgres :
20- image : postgres:15
21- env :
22- POSTGRES_PASSWORD : postgres
23- POSTGRES_USER : postgres
24- POSTGRES_DB : test_db
25- options : >-
26- --health-cmd pg_isready
27- --health-interval 10s
28- --health-timeout 5s
29- --health-retries 5
30- ports :
31- - 5432:5432
32-
33- steps :
34- - name : Checkout code
35- uses : actions/checkout@v4
36-
37- - name : Set up Python
38- uses : actions/setup-python@v4
39- with :
40- python-version : ${{ env.PYTHON_VERSION }}
41-
42- - name : Install UV (fast Python package installer)
43- run : |
44- curl -LsSf https://astral.sh/uv/install.sh | sh
45- echo "$HOME/.cargo/bin" >> $GITHUB_PATH
46-
47- - name : Install dependencies
48- working-directory : ./backend
49- run : |
50- uv venv
51- source .venv/bin/activate
52- uv pip install -r requirements.txt
53- uv pip install pytest pytest-asyncio httpx
54-
55- - name : Run backend tests
56- working-directory : ./backend
57- env :
58- DATABASE_URL : postgresql://postgres:postgres@localhost:5432/test_db
59- DB_NAME : test_db
60- DB_HOST : localhost
61- DB_USER : postgres
62- DB_PASS : postgres
63- DB_PORT : 5432
64- run : |
65- source .venv/bin/activate
66- pytest tests/ -v --tb=short
67-
68- - name : Run API integration tests
69- working-directory : ./backend
70- env :
71- DATABASE_URL : postgresql://postgres:postgres@localhost:5432/test_db
72- DB_NAME : test_db
73- DB_HOST : localhost
74- DB_USER : postgres
75- DB_PASS : postgres
76- DB_PORT : 5432
77- run : |
78- source .venv/bin/activate
79- # Start the server in background
80- uvicorn main:app --host 0.0.0.0 --port 8000 &
81- sleep 10
82- # Run curl tests
83- python test_curl_examples.py
84-
85- test-frontend :
86- name : Test Frontend
87- runs-on : ubuntu-latest
88-
89- steps :
90- - name : Checkout code
91- uses : actions/checkout@v4
92-
93- - name : Set up Node.js
94- uses : actions/setup-node@v4
95- with :
96- node-version : ${{ env.NODE_VERSION }}
97- cache : ' npm'
98- cache-dependency-path : frontend/package-lock.json
99-
100- - name : Install frontend dependencies
101- working-directory : ./frontend
102- run : npm ci
103-
104- - name : Run frontend linter
105- working-directory : ./frontend
106- run : npm run lint
107-
108- - name : Build frontend
109- working-directory : ./frontend
110- run : npm run build
111-
112- - name : Run frontend tests (if any)
113- working-directory : ./frontend
114- run : |
115- if [ -f "package.json" ] && grep -q '"test"' package.json; then
116- npm test
117- else
118- echo "No frontend tests found, skipping..."
119- fi
120-
121- security-scan :
122- name : Security Scan
123- runs-on : ubuntu-latest
124- needs : [test-backend, test-frontend]
125-
126- steps :
127- - name : Checkout code
128- uses : actions/checkout@v4
129-
130- - name : Run Trivy vulnerability scanner
131- uses : aquasecurity/trivy-action@master
132- with :
133- scan-type : ' fs'
134- scan-ref : ' .'
135- format : ' sarif'
136- output : ' trivy-results.sarif'
137-
138- - name : Upload Trivy scan results to GitHub Security tab
139- uses : github/codeql-action/upload-sarif@v2
140- if : always()
141- with :
142- sarif_file : ' trivy-results.sarif'
143-
144- code-quality :
145- name : Code Quality
146- runs-on : ubuntu-latest
147-
148- steps :
149- - name : Checkout code
150- uses : actions/checkout@v4
151-
152- - name : Set up Python
153- uses : actions/setup-python@v4
154- with :
155- python-version : ${{ env.PYTHON_VERSION }}
156-
157- - name : Install Python quality tools
158- run : |
159- pip install black flake8 mypy bandit safety
160-
161- - name : Run Black (code formatter check)
162- working-directory : ./backend
163- run : black --check --diff .
164-
165- - name : Run Flake8 (linting)
166- working-directory : ./backend
167- run : flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
168-
169- - name : Run MyPy (type checking)
170- working-directory : ./backend
171- run : mypy . --ignore-missing-imports
172-
173- - name : Run Bandit (security linting)
174- working-directory : ./backend
175- run : bandit -r . -x tests/
176-
177- - name : Run Safety (dependency security check)
178- working-directory : ./backend
179- run : safety check -r requirements.txt
180-
181- build-and-push :
182- name : Build and Push Docker Images
183- runs-on : ubuntu-latest
184- needs : [test-backend, test-frontend, security-scan, code-quality]
185- if : github.ref == 'refs/heads/main'
186-
187- steps :
188- - name : Checkout code
189- uses : actions/checkout@v4
190-
191- - name : Set up Docker Buildx
192- uses : docker/setup-buildx-action@v3
193-
194- - name : Login to Docker Hub
195- uses : docker/login-action@v3
196- with :
197- username : ${{ secrets.DOCKER_USERNAME }}
198- password : ${{ secrets.DOCKER_PASSWORD }}
199-
200- - name : Build and push backend image
201- uses : docker/build-push-action@v5
202- with :
203- context : ./backend
204- push : true
205- tags : |
206- ${{ secrets.DOCKER_USERNAME }}/crud-api-backend:latest
207- ${{ secrets.DOCKER_USERNAME }}/crud-api-backend:${{ github.sha }}
208- cache-from : type=gha
209- cache-to : type=gha,mode=max
210-
211- - name : Build and push frontend image
212- uses : docker/build-push-action@v5
213- with :
214- context : ./frontend
215- push : true
216- tags : |
217- ${{ secrets.DOCKER_USERNAME }}/crud-api-frontend:latest
218- ${{ secrets.DOCKER_USERNAME }}/crud-api-frontend:${{ github.sha }}
219- cache-from : type=gha
220- cache-to : type=gha,mode=max
221-
222- generate-docs :
223- name : Generate and Deploy Documentation
224- runs-on : ubuntu-latest
225- needs : [test-backend]
226- if : github.ref == 'refs/heads/main'
227-
228- steps :
229- - name : Checkout code
230- uses : actions/checkout@v4
231-
232- - name : Set up Python
233- uses : actions/setup-python@v4
234- with :
235- python-version : ${{ env.PYTHON_VERSION }}
236-
237- - name : Install dependencies
238- working-directory : ./backend
239- run : |
240- pip install -r requirements.txt
241-
242- - name : Generate OpenAPI schema
243- working-directory : ./backend
244- run : |
245- python export_openapi.py
246- python generate_curl_snippets.py
247-
248- - name : Upload OpenAPI artifacts
249- uses : actions/upload-artifact@v3
250- with :
251- name : openapi-docs
252- path : |
253- backend/openapi_schema.json
254- backend/curl_examples.md
255- backend/curl_examples.json
256-
257- - name : Deploy to GitHub Pages (if enabled)
258- if : github.ref == 'refs/heads/main'
259- uses : peaceiris/actions-gh-pages@v3
260- with :
261- github_token : ${{ secrets.GITHUB_TOKEN }}
262- publish_dir : ./backend
263- destination_dir : api-docs
264- keep_files : true
265- publish_branch : gh-pages
1+ name : Install Keploy CLI
2+ run :
3+ curl --silent -L https://keploy.io/ent/install.sh | bash
4+
5+ name : Run Keploy Test Suite
6+ run :
7+ export KEPLOY_API_KEY=${{ secrets.KEPLOY_API_KEY }}
8+ keploy test-suite --app=4fda4fac-c01f-4e94-a26d-22f71997d39c --base-path https://crud-api-server-python.onrender.com/ --cloud
0 commit comments