Skip to content

Commit 0742753

Browse files
committed
Add test and github action
1 parent 8cca3ef commit 0742753

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

.github/workflows/tests.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
postgres:
15+
image: postgres:14
16+
env:
17+
POSTGRES_USER: postgres
18+
POSTGRES_PASSWORD: postgres
19+
POSTGRES_DB: fastapi_db
20+
ports:
21+
- 5432:5432
22+
options: >-
23+
--health-cmd pg_isready
24+
--health-interval 10s
25+
--health-timeout 5s
26+
--health-retries 5
27+
28+
env:
29+
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/fastapi_db
30+
PROJECT_NAME: "FastAPI with PostgreSQL"
31+
API_VERSION: "v1"
32+
PYTHONPATH: .
33+
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
38+
- name: Set up Python
39+
uses: actions/setup-python@v5
40+
with:
41+
python-version: "3.11"
42+
43+
- name: Install dependencies
44+
run: |
45+
python -m pip install --upgrade pip
46+
pip install -r requirements.txt
47+
48+
- name: Wait for PostgreSQL to be ready
49+
run: |
50+
for i in {1..10}; do
51+
pg_isready -h localhost -p 5432 && break
52+
sleep 2
53+
done
54+
55+
- name: Run tests
56+
run: pytest

0 commit comments

Comments
 (0)