Skip to content

Commit cef25bb

Browse files
authored
Update ci.yml
1 parent 022fc3f commit cef25bb

1 file changed

Lines changed: 32 additions & 38 deletions

File tree

.github/workflows/ci.yml

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI Pipeline
1+
name: CI Pipeline (Docker Compose)
22

33
on:
44
push:
@@ -7,55 +7,49 @@ on:
77
branches: [ main, develop ]
88

99
jobs:
10-
build-and-test:
11-
name: 🧪 Build, Lint & Test
10+
test:
11+
name: 🐳 Build & Test (Docker Compose)
1212
runs-on: ubuntu-latest
1313

14-
services:
15-
postgres:
16-
image: postgres:15
17-
env:
18-
POSTGRES_USER: ${{ secrets.POSTGRES_USER || 'user' }}
19-
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD || 'password' }}
20-
POSTGRES_DB: ${{ secrets.POSTGRES_DB || 'api_workout_db' }}
21-
ports:
22-
- 5432:5432
23-
options: >-
24-
--health-cmd="pg_isready -U ${{ secrets.POSTGRES_USER || 'user' }}"
25-
--health-interval=10s
26-
--health-timeout=5s
27-
--health-retries=5
28-
29-
env:
30-
# Variáveis usadas nos testes e na aplicação
31-
DATABASE_URL: postgresql+psycopg2://${{ secrets.POSTGRES_USER || 'user' }}:${{ secrets.POSTGRES_PASSWORD || 'password' }}@localhost:5432/${{ secrets.POSTGRES_DB || 'api_workout_db' }}
32-
PYTHONPATH: ./app
33-
ENVIRONMENT: test
34-
3514
steps:
3615
- name: 📥 Checkout do repositório
3716
uses: actions/checkout@v4
3817

39-
- name: 🐍 Configurar Python 3.11
40-
uses: actions/setup-python@v5
18+
- name: 🛠️ Configurar Docker Buildx
19+
uses: docker/setup-buildx-action@v3
20+
21+
- name: 🐳 Cache de camadas do Docker
22+
uses: actions/cache@v4
4123
with:
42-
python-version: '3.11'
24+
path: /tmp/.buildx-cache
25+
key: ${{ runner.os }}-buildx-${{ github.sha }}
26+
restore-keys: |
27+
${{ runner.os }}-buildx-
28+
29+
- name: 🐳 Subir containers (em background)
30+
run: |
31+
docker compose -f docker-compose.yml up -d --build
32+
33+
- name: ⏳ Aguardar Postgres ficar pronto
34+
run: |
35+
echo "Aguardando Postgres inicializar..."
36+
until docker compose exec -T db pg_isready -U ${POSTGRES_USER:-user}; do
37+
sleep 2
38+
done
4339
44-
- name: 📦 Instalar dependências
40+
- name: 🗃️ Rodar migrações Alembic
4541
run: |
46-
python -m pip install --upgrade pip
47-
pip install -r requirements.txt
42+
docker compose exec -T app alembic upgrade head
4843
49-
- name: 🧹 Rodar Linter (flake8)
44+
- name: 🧹 Lint (black + flake8)
5045
run: |
51-
pip install flake8
52-
flake8 app tests
46+
docker compose exec -T app bash -c "black --check . && flake8 app tests"
5347
54-
- name: 🧪 Rodar Testes com Pytest
48+
- name: 🧪 Rodar Testes
5549
run: |
56-
pip install pytest pytest-asyncio
57-
pytest -v --maxfail=1 --disable-warnings
50+
docker compose exec -T app pytest -v --maxfail=1 --disable-warnings
5851
59-
- name: 🗃️ Verificar Migrations Alembic
52+
- name: 🧼 Derrubar containers
53+
if: always()
6054
run: |
61-
alembic upgrade head
55+
docker compose down -v

0 commit comments

Comments
 (0)