Skip to content

Commit ac2545e

Browse files
committed
add: CI with GitHub Actions and pytest
1 parent 3840e3a commit ac2545e

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

.github/workflows/ci.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Django CI with Docker
2+
3+
on:
4+
push:
5+
branches: [ "main", "master" ]
6+
pull_request:
7+
branches: [ "main", "master" ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
postgres:
15+
image: postgres:15
16+
env:
17+
POSTGRES_DB: test_db
18+
POSTGRES_USER: test_user
19+
POSTGRES_PASSWORD: test_pass
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+
DEBUG: 1
30+
SECRET_KEY: test-secret
31+
POSTGRES_DB: test_db
32+
POSTGRES_USER: test_user
33+
POSTGRES_PASSWORD: test_pass
34+
POSTGRES_HOST: localhost
35+
POSTGRES_PORT: 5432
36+
ALLOWED_HOSTS: localhost,127.0.0.1
37+
38+
steps:
39+
- name: ⬇️ Checkout código
40+
uses: actions/checkout@v4
41+
42+
- name: 🐍 Set up Python
43+
uses: actions/setup-python@v5
44+
with:
45+
python-version: 3.11
46+
47+
- name: 📦 Instalar dependencias
48+
run: |
49+
python -m pip install --upgrade pip
50+
pip install -r requirements.txt
51+
52+
- name: 🐘 Esperar PostgreSQL
53+
run: |
54+
until pg_isready -h localhost -p 5432; do
55+
echo "Esperando postgres..."
56+
sleep 2
57+
done
58+
59+
- name: 🧩 Migraciones
60+
run: |
61+
python manage.py migrate
62+
63+
- name: 🧪 Ejecutar tests
64+
run: |
65+
pytest

myproject/settings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@
7171
DATABASES = {
7272
'default': {
7373
'ENGINE': 'django.db.backends.postgresql',
74-
'NAME': os.environ.get("DB_NAME"),
75-
'USER': os.environ.get("DB_USER"),
76-
'PASSWORD': os.environ.get("DB_PASSWORD"),
77-
'HOST': os.environ.get("DB_HOST"),
78-
'PORT': os.environ.get("DB_PORT"),
74+
'NAME': os.getenv('POSTGRES_DB', 'postgres'),
75+
'USER': os.getenv('POSTGRES_USER', 'postgres'),
76+
'PASSWORD': os.getenv('POSTGRES_PASSWORD', 'postgres'),
77+
'HOST': os.getenv('POSTGRES_HOST', 'db'),
78+
'PORT': os.getenv('POSTGRES_PORT', '5432'),
7979
}
8080
}
8181

0 commit comments

Comments
 (0)